Subject: bug#14915: [PATCH] Enhancement to fortune.el

From: Joshua Datko <[email-masked]>
Date: Fri, 19 Jul 2013 21:01:30 -0600

So, this is my first time submitting a patch.  I believe I followed the
CONTRIBUTE instructions and I built this to the latest source in bzr but
please let me know if I need to correct anything.

It's a small change, but I'm willing to sign a copyright assignment
(hopefully, it's not my last submission.)

-Josh

** Description

This is an enhancement to fortune.el to display fortunes in the
mini-buffer.  The original implementation generates fortunes and
displays them to the buffer *fortune* (this behavior did not change),
but it would change the focus to the *fortune* buffer as well.

Sometimes, I would just want to see my fortune but NOT switch over to
that buffer, hence this patch which adds an interactive function (and
small helper function) to display the fortune in the mini-buffer.

** Changelog

2013-07-20  Josh Datko  <[email-masked]>

	* fortune.el: Added fortune-message which displays fortunes to the
	minibuffer.

** Patch

=== modified file 'lisp/play/fortune.el'
*** lisp/play/fortune.el	2013-02-15 01:30:11 +0000
--- lisp/play/fortune.el	2013-07-20 02:25:53 +0000
*************** specifies the file to choose the fortune
*** 302,307 ****
--- 302,325 ----
                             (split-string fortune-program-options)
                           fortune-program-options) (list fort-file)))))))

+ (defun fortune-generate (&optional file)
+   "Generate a new fortune and return it as a string.
+ Without an optional FILE argument it will use the value of `fortune-file'."
+   (save-excursion
+     (progn (fortune-in-buffer t file)
+            (with-current-buffer fortune-buffer-name
+              (buffer-string)))))
+
+ ;;;###autoload
+ (defun fortune-message (&optional file)
+   "Display a fortune cookie to the mini-buffer.
+ If called with a prefix, it has the same behavior as `fortune'.
+ Optional FILE is a fortune file from which a cookie will be selected."
+   (interactive (list (if current-prefix-arg
+                          (fortune-ask-file)
+                        fortune-file)))
+   (message (fortune-generate file)))
+
  ;;;###autoload
  (defun fortune (&optional file)
    "Display a fortune cookie.