annotate lisp/play/fortune.el @ 28973:d87cf6d0bd48

*** empty log message ***
author Eli Zaretskii <eliz@gnu.org>
date Thu, 18 May 2000 14:46:49 +0000
parents f33ed9540026
children d0e5a99cbda1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25480
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; fortune.el --- Use fortune to create signatures
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1999 Free Software Foundation, Inc.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; Author: Holger Schauer <Holger.Schauer@gmx.de>
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Keywords: games utils mail
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; This file is part of Emacs.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; any later version.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;;; Commentary:
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; This utility allows you to automatically cut regions to a fortune
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; file. In case that the region stems from an article buffer (mail or
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; news), it will try to automatically determine the author of the
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; fortune. It will also allow you to compile your fortune-database
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; as well as providing a function to extract a fortune for use as your
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; signature.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; Of course, it can simply display a fortune, too.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; Use prefix arguments to specify different fortune databases.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; Installation:
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; Please check the customize settings - you will at least have to modify the
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; values of `fortune-dir' and `fortune-file'.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; I then use this in my .gnus:
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;(message "Making new signature: %s" (fortune-to-signature "~/fortunes/"))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; This automagically creates a new signature when starting up Gnus.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; Note that the call to fortune-to-signature specifies a directory in which
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; several fortune-files and their databases are stored.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; If you like to get a new signature for every message, you can also hook
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; it into message-mode:
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; (add-hook 'message-setup-hook
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; '(lambda ()
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; (fortune-to-signature)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; This time no fortune-file is specified, so fortune-to-signature would use
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; the default-file as specified by fortune-file.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; I have also this in my .gnus:
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;(add-hook 'gnus-article-mode-hook
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; '(lambda ()
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; (define-key gnus-article-mode-map "i" 'fortune-from-region)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; which allows marking a region and then pressing "i" so that the marked
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; region will be automatically added to my favourite fortune-file.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;; Code:
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;; **************
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; Customizable Settings
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (defgroup fortune nil
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 "Settings for fortune."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 :group 'games)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (defgroup fortune-signature nil
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 "Settings for use of fortune for signatures."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 :group 'fortune
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 :group 'mail)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (defcustom fortune-dir "~/docs/ascii/misc/fortunes/"
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 "*The directory to look in for local fortune cookies files."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 :group 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (defcustom fortune-file
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (expand-file-name "usenet" fortune-dir)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 "*The file in which local fortune cookies will be stored."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 :group 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (defcustom fortune-database-extension ".dat"
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 "The extension of the corresponding fortune database.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 Normally you won't have a reason to change it."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 :group 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (defcustom fortune-program "fortune"
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 "Program to select a fortune cookie."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 :group 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (defcustom fortune-program-options ""
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 "Options to pass to the fortune program."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 :group 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (defcustom fortune-strfile "strfile"
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 "Program to compute a new fortune database."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 :group 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (defcustom fortune-strfile-options ""
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 "Options to pass to the strfile program."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 :group 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (defcustom fortune-quiet-strfile-options "> /dev/null"
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 "Text added to the command for running `strfile'.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 By default it discards the output produced by `strfile'.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 Set this to \"\" if you would like to see the output."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 :group 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (defcustom fortune-always-compile t
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 "*Non-nil means automatically compile fortune files.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 If nil, you must invoke `fortune-compile' manually to do that."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 :group 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (defcustom fortune-author-line-prefix " -- "
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 "Prefix to put before the author name of a fortunate."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 :group 'fortune-signature)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defcustom fortune-fill-column fill-column
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 "Fill column for fortune files."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 :group 'fortune-signature)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defcustom fortune-from-mail "private e-mail"
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 "String to use to characterize that the fortune comes from an e-mail.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 No need to add an `in'."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 :type 'string
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 :group 'fortune-signature)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (defcustom fortune-sigstart ""
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 "*Some text to insert before the fortune cookie, in a mail signature."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 :group 'fortune-signature)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (defcustom fortune-sigend ""
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 "*Some text to insert after the fortune cookie, in a mail signature."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 :group 'fortune-signature)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ;; not customizable settings
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (defvar fortune-buffer-name "*fortune*")
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (defconst fortune-end-sep "\n%\n")
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;;; **************
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;;; Inserting a new fortune
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (defun fortune-append (string &optional interactive file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 "Appends STRING to the fortune FILE.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 If INTERACTIVE is non-nil, don't compile the fortune file afterwards."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (setq file (expand-file-name
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (substitute-in-file-name (or file fortune-file))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (if (file-directory-p file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (error "Cannot append fortune to directory %s." file))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (if interactive ; switch to file and return buffer
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (find-file-other-frame file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (find-file-noselect file))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (let ((fortune-buffer (get-file-buffer file)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (set-buffer fortune-buffer)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (goto-char (point-max))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (setq fill-column fortune-fill-column)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (setq auto-fill-inhibit-regexp "^%")
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (turn-on-auto-fill)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (insert string fortune-end-sep)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (unless interactive
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (save-buffer)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (if fortune-always-compile
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (fortune-compile file)))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (defun fortune-ask-file ()
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 "Asks the user for a file-name."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (expand-file-name
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (read-file-name
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 "Fortune file to use: "
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 fortune-dir nil nil "")))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;;; ###autoload
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (defun fortune-add-fortune (string file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 "Add STRING to a fortune file FILE.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 Interactively, if called with a prefix argument,
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 read the file name to use. Otherwise use the value of `fortune-file'."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (interactive
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (list (read-string "Fortune: ")
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (if current-prefix-arg (fortune-ask-file))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (fortune-append string t file))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;;; ###autoload
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (defun fortune-from-region (beg end file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 "Appends the current region to a local fortune-like data file.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 Interactively, if called with a prefix argument,
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 read the file name to use. Otherwise use the value of `fortune-file'."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (interactive
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (list (region-beginning) (region-end)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (if current-prefix-arg (fortune-ask-file))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (let ((string (buffer-substring beg end))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 author newsgroup help-point)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 ;; try to determine author ...
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (save-excursion
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (goto-char (point-min))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (setq help-point
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (search-forward-regexp
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "^From: \\(.*\\)$"
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (point-max) t))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (if help-point
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (setq author (buffer-substring (match-beginning 1) help-point))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (setq author "An unknown author")))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ;; ... and newsgroup
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (save-excursion
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (goto-char (point-min))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (setq help-point
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (search-forward-regexp
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 "^Newsgroups: \\(.*\\)$"
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (point-max) t))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (if help-point
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (setq newsgroup (buffer-substring (match-beginning 1) help-point))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (setq newsgroup (if (or (eql major-mode 'gnus-article-mode)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (eql major-mode 'vm-mode)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (eql major-mode 'rmail-mode))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 fortune-from-mail
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 "unknown"))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ;; append entry to end of fortune file, and display result
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (setq string (concat "\"" string "\""
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 "\n"
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 fortune-author-line-prefix
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 author " in " newsgroup))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (fortune-append string t file)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;;; **************
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;;; Compile new database with strfile
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ;;; ###autoload
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (defun fortune-compile (&optional file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 "Compile fortune file.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 If called with a prefix asks for the FILE to compile, otherwise uses
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 the value of `fortune-file'. This currently cannot handle directories."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (interactive
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (list
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (if current-prefix-arg
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (fortune-ask-file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 fortune-file)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (let* ((fortune-file (expand-file-name (substitute-in-file-name file)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (fortune-dat (expand-file-name
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (substitute-in-file-name
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (concat fortune-file fortune-database-extension)))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (cond ((file-exists-p fortune-file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (if (file-exists-p fortune-dat)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (cond ((file-newer-than-file-p fortune-file fortune-dat)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (message "Compiling new fortune database %s" fortune-dat)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (shell-command
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (concat fortune-strfile fortune-strfile-options
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 " " fortune-file fortune-quiet-strfile-options))))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (t (error "Can't compile fortune file %s" fortune-file)))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 ;;; **************
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 ;;; Use fortune for signature
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 ;;; ###autoload
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (defun fortune-to-signature (&optional file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 "Create signature from output of the fortune program.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 If called with a prefix asks for the FILE to choose the fortune from,
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 otherwise uses the value of `fortune-file'. If you want to have fortune
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 choose from a set of files in a directory, call interactively with prefix
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 and choose the directory as the fortune-file."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (interactive
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (list
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (if current-prefix-arg
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (fortune-ask-file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 fortune-file)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (save-excursion
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (fortune-in-buffer (interactive-p) file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (set-buffer fortune-buffer-name)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (let* ((fortune (buffer-string))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (signature (concat fortune-sigstart fortune fortune-sigend)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (setq mail-signature signature)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (if (boundp 'message-signature)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (setq message-signature signature)))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 ;;; **************
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 ;;; Display fortune
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (defun fortune-in-buffer (interactive &optional file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 "Put a fortune cookie in the *fortune* buffer.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 When INTERACTIVE is nil, don't display it. Optional argument FILE,
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 when supplied, specifies the file to choose the fortune from."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (let ((fortune-buffer (or (get-buffer fortune-buffer-name)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (generate-new-buffer fortune-buffer-name)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (fort-file (expand-file-name
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (substitute-in-file-name
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (or file fortune-file)))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (save-excursion
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (set-buffer fortune-buffer)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (toggle-read-only 0)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (erase-buffer)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (if fortune-always-compile
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (fortune-compile fort-file))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (call-process
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 fortune-program ;; programm to call
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 nil fortune-buffer nil ;; INFILE BUFFER DISPLAYP
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (concat fortune-program-options fort-file)))))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 ;;; ###autoload
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (defun fortune (&optional file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 "Display a fortune cookie.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 If called with a prefix asks for the FILE to choose the fortune from,
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 otherwise uses the value of `fortune-file'. If you want to have fortune
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 choose from a set of files in a directory, call interactively with prefix
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 and choose the directory as the fortune-file."
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (interactive
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (list
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (if current-prefix-arg
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (fortune-ask-file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 fortune-file)))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (fortune-in-buffer t file)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (switch-to-buffer (get-buffer fortune-buffer-name))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (toggle-read-only 1))
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;;; Provide ourselves.
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (provide 'fortune)
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 ;;; fortune.el ends here
f33ed9540026 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317