]> code.delx.au - gnu-emacs/blobdiff - lisp/play/fortune.el
Merge changes from emacs-23 branch
[gnu-emacs] / lisp / play / fortune.el
index 0ae1a841f430fec57e7d8798d308f2cb42984b15..05775c8a85e5af2b72d430ce1c17e5a2b2b2c90b 100644 (file)
@@ -1,15 +1,16 @@
-;;; fortune.el --- Use fortune to create signatures
-;; Copyright (C) 1999, 2001 Free Software Foundation, Inc.
+;;; fortune.el --- use fortune to create signatures
+
+;; Copyright (C) 1999, 2001-2011  Free Software Foundation, Inc.
 
 ;; Author: Holger Schauer <Holger.Schauer@gmx.de>
 ;; Keywords: games utils mail
 
-;; This file is part of Emacs.
+;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,9 +18,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 ;; This utility allows you to automatically cut regions to a fortune
@@ -33,8 +32,8 @@
 
 ;;; Installation:
 
-;; Please check the customize settings - you will at least have to modify the
-;; values of `fortune-dir' and `fortune-file'.
+;; Please check the customize settings -- you will at least have to
+;; modify the values of `fortune-dir' and `fortune-file'.
 
 ;; I then use this in my .gnus:
 ;;(message "Making new signature: %s" (fortune-to-signature "~/fortunes/"))
@@ -44,9 +43,7 @@
 
 ;; If you like to get a new signature for every message, you can also hook
 ;; it into message-mode:
-;; (add-hook 'message-setup-hook
-;;           '(lambda ()
-;;              (fortune-to-signature)))
+;; (add-hook 'message-setup-hook 'fortune-to-signature)
 ;; This time no fortune-file is specified, so fortune-to-signature would use
 ;; the default-file as specified by fortune-file.
 
@@ -63,6 +60,7 @@
 ;;; Customizable Settings
 (defgroup fortune nil
   "Settings for fortune."
+  :link '(emacs-commentary-link "fortune.el")
   :version "21.1"
   :group 'games)
 (defgroup fortune-signature nil
   :group 'mail)
 
 (defcustom fortune-dir "~/docs/ascii/misc/fortunes/"
-  "*The directory to look in for local fortune cookies files."
+  "The directory to look in for local fortune cookies files."
+  :type 'directory
   :group 'fortune)
 (defcustom fortune-file
   (expand-file-name "usenet" fortune-dir)
-  "*The file in which local fortune cookies will be stored."
+  "The file in which local fortune cookies will be stored."
+  :type 'file
   :group 'fortune)
 (defcustom fortune-database-extension  ".dat"
   "The extension of the corresponding fortune database.
 Normally you won't have a reason to change it."
+  :type 'string
   :group 'fortune)
 (defcustom fortune-program "fortune"
   "Program to select a fortune cookie."
+  :type 'string
   :group 'fortune)
-(defcustom fortune-program-options ""
-  "Options to pass to the fortune program."
+(defcustom fortune-program-options ()
+  "List of options to pass to the fortune program."
+  :type '(choice (repeat (string :tag "Option"))
+                 (string :tag "Obsolete string of options"))
+  :version "23.1"
   :group 'fortune)
 (defcustom fortune-strfile "strfile"
   "Program to compute a new fortune database."
+  :type 'string
   :group 'fortune)
 (defcustom fortune-strfile-options ""
-  "Options to pass to the strfile program."
+  "Options to pass to the strfile program (a string)."
+  :type 'string
   :group 'fortune)
 (defcustom fortune-quiet-strfile-options "> /dev/null"
   "Text added to the command for running `strfile'.
 By default it discards the output produced by `strfile'.
 Set this to \"\" if you would like to see the output."
+  :type 'string
   :group 'fortune)
 
 (defcustom fortune-always-compile t
-  "*Non-nil means automatically compile fortune files.
+  "Non-nil means automatically compile fortune files.
 If nil, you must invoke `fortune-compile' manually to do that."
+  :type 'boolean
   :group 'fortune)
 (defcustom fortune-author-line-prefix "                  -- "
   "Prefix to put before the author name of a fortunate."
+  :type 'string
   :group 'fortune-signature)
 (defcustom fortune-fill-column fill-column
   "Fill column for fortune files."
+  :type 'integer
   :group 'fortune-signature)
 (defcustom fortune-from-mail "private e-mail"
   "String to use to characterize that the fortune comes from an e-mail.
@@ -115,10 +126,12 @@ No need to add an `in'."
   :type 'string
   :group 'fortune-signature)
 (defcustom fortune-sigstart ""
-  "*Some text to insert before the fortune cookie, in a mail signature."
+  "Some text to insert before the fortune cookie, in a mail signature."
+  :type 'string
   :group 'fortune-signature)
 (defcustom fortune-sigend ""
-  "*Some text to insert after the fortune cookie, in a mail signature."
+  "Some text to insert after the fortune cookie, in a mail signature."
+  :type 'string
   :group 'fortune-signature)
 
 
@@ -201,9 +214,9 @@ read the file name to use.  Otherwise use the value of `fortune-file'."
             (point-max) t))
       (if help-point
          (setq newsgroup (buffer-substring (match-beginning 1) help-point))
-       (setq newsgroup (if (or (eql major-mode 'gnus-article-mode)
-                               (eql major-mode 'vm-mode)
-                               (eql major-mode 'rmail-mode))
+       (setq newsgroup (if (or (eq major-mode 'gnus-article-mode)
+                               (eq major-mode 'vm-mode)
+                               (eq major-mode 'rmail-mode))
                            fortune-from-mail
                          "unknown"))))
 
@@ -240,8 +253,8 @@ the value of `fortune-file'.  This currently cannot handle directories."
                     (concat fortune-strfile fortune-strfile-options
                             " " fortune-file fortune-quiet-strfile-options))))))
        (t (error "Can't compile fortune file %s" fortune-file)))))
-  
-        
+
+
 ;;; **************
 ;;; Use fortune for signature
 ;;;###autoload
@@ -258,7 +271,7 @@ and choose the directory as the fortune-file."
         (fortune-ask-file)
        fortune-file)))
    (save-excursion
-    (fortune-in-buffer (interactive-p) file)
+    (fortune-in-buffer t file)
     (set-buffer fortune-buffer-name)
     (let* ((fortune (buffer-string))
           (signature (concat fortune-sigstart fortune fortune-sigend)))
@@ -271,48 +284,41 @@ and choose the directory as the fortune-file."
 ;;; Display fortune
 (defun fortune-in-buffer (interactive &optional file)
   "Put a fortune cookie in the *fortune* buffer.
-
-When INTERACTIVE is nil, don't display it.  Optional argument FILE,
-when supplied, specifies the file to choose the fortune from."
+INTERACTIVE is ignored.  Optional argument FILE, when supplied,
+specifies the file to choose the fortune from."
   (let ((fortune-buffer (or (get-buffer fortune-buffer-name)
                            (generate-new-buffer fortune-buffer-name)))
        (fort-file (expand-file-name
                    (substitute-in-file-name
                     (or file fortune-file)))))
-    (save-excursion
-      (set-buffer fortune-buffer)
-      (toggle-read-only 0)
-      (erase-buffer)
-
-      (if fortune-always-compile
-         (fortune-compile fort-file))
-
-      (call-process
-        fortune-program  ;; programm to call
-       nil fortune-buffer nil ;; INFILE BUFFER DISPLAYP
-       (concat fortune-program-options fort-file)))))
-
+    (with-current-buffer fortune-buffer
+      (let ((inhibit-read-only t))
+        (erase-buffer)
+        (if fortune-always-compile
+            (fortune-compile fort-file))
+        (apply 'call-process
+               fortune-program            ; program to call
+               nil fortune-buffer nil     ; INFILE BUFFER DISPLAY
+               (append (if (stringp fortune-program-options)
+                           (split-string fortune-program-options)
+                         fortune-program-options) (list fort-file)))))))
 
 ;;;###autoload
 (defun fortune (&optional file)
   "Display a fortune cookie.
-
 If called with a prefix asks for the FILE to choose the fortune from,
 otherwise uses the value of `fortune-file'.  If you want to have fortune
 choose from a set of files in a directory, call interactively with prefix
 and choose the directory as the fortune-file."
-  (interactive
-    (list
-     (if current-prefix-arg
-        (fortune-ask-file)
-       fortune-file)))
+  (interactive (list (if current-prefix-arg
+                         (fortune-ask-file)
+                       fortune-file)))
   (fortune-in-buffer t file)
   (switch-to-buffer (get-buffer fortune-buffer-name))
-  (toggle-read-only 1))
+  (setq buffer-read-only t))
 
 
 ;;; Provide ourselves.
 (provide 'fortune)
 
 ;;; fortune.el ends here
-