Mercurial > emacs
annotate lisp/play/fortune.el @ 109089:bd58a72bb9bb
Fix application of default-frame-alist (Bug#5378).
* lisp/frame.el (make-frame): Add default-frame-alist to the PARAMETERS
argument passed to frame-creation-function (Bug#5378).
* lisp/faces.el (x-handle-named-frame-geometry)
(x-handle-reverse-video, x-create-frame-with-faces)
(face-set-after-frame-default, tty-create-frame-with-faces): Don't
separately consult default-frame-alist. It is now passed as the
PARAMETER argument.
* src/frame.c (get_future_frame_param, Fmake_terminal_frame): Don't
check default-frame-alist.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Wed, 30 Jun 2010 20:14:17 -0400 |
parents | 1d1d5d9bd884 |
children | 516f3d80dac6 |
rev | line source |
---|---|
38425
c6e12c6b1498
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38397
diff
changeset
|
1 ;;; fortune.el --- use fortune to create signatures |
38524 | 2 |
98271
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
3 ;; Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
106815 | 4 ;; 2008, 2009, 2010 Free Software Foundation, Inc. |
25480 | 5 |
6 ;; Author: Holger Schauer <Holger.Schauer@gmx.de> | |
7 ;; Keywords: games utils mail | |
8 | |
38425
c6e12c6b1498
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38397
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
25480 | 10 |
94675
949bd6ad1ba4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
25480 | 12 ;; it under the terms of the GNU General Public License as published by |
94675
949bd6ad1ba4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
949bd6ad1ba4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
25480 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94675
949bd6ad1ba4
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
25480 | 23 |
24 ;;; Commentary: | |
25 ;; This utility allows you to automatically cut regions to a fortune | |
26 ;; file. In case that the region stems from an article buffer (mail or | |
27 ;; news), it will try to automatically determine the author of the | |
28 ;; fortune. It will also allow you to compile your fortune-database | |
29 ;; as well as providing a function to extract a fortune for use as your | |
30 ;; signature. | |
31 ;; Of course, it can simply display a fortune, too. | |
32 ;; Use prefix arguments to specify different fortune databases. | |
33 | |
34 ;;; Installation: | |
35 | |
38524 | 36 ;; Please check the customize settings -- you will at least have to |
37 ;; modify the values of `fortune-dir' and `fortune-file'. | |
25480 | 38 |
39 ;; I then use this in my .gnus: | |
40 ;;(message "Making new signature: %s" (fortune-to-signature "~/fortunes/")) | |
41 ;; This automagically creates a new signature when starting up Gnus. | |
42 ;; Note that the call to fortune-to-signature specifies a directory in which | |
43 ;; several fortune-files and their databases are stored. | |
44 | |
45 ;; If you like to get a new signature for every message, you can also hook | |
46 ;; it into message-mode: | |
38524 | 47 ;; (add-hook 'message-setup-hook 'fortune-to-signature) |
25480 | 48 ;; This time no fortune-file is specified, so fortune-to-signature would use |
49 ;; the default-file as specified by fortune-file. | |
50 | |
51 ;; I have also this in my .gnus: | |
52 ;;(add-hook 'gnus-article-mode-hook | |
53 ;; '(lambda () | |
54 ;; (define-key gnus-article-mode-map "i" 'fortune-from-region))) | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
55 ;; which allows marking a region and then pressing "i" so that the marked |
25480 | 56 ;; region will be automatically added to my favourite fortune-file. |
57 | |
58 ;;; Code: | |
59 | |
60 ;;; ************** | |
61 ;;; Customizable Settings | |
62 (defgroup fortune nil | |
63 "Settings for fortune." | |
38524 | 64 :link '(emacs-commentary-link "fortune.el") |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
65 :version "21.1" |
25480 | 66 :group 'games) |
67 (defgroup fortune-signature nil | |
68 "Settings for use of fortune for signatures." | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
69 :group 'fortune |
25480 | 70 :group 'mail) |
71 | |
72 (defcustom fortune-dir "~/docs/ascii/misc/fortunes/" | |
98271
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
73 "The directory to look in for local fortune cookies files." |
38524 | 74 :type 'directory |
75 :group 'fortune) | |
76 (defcustom fortune-file | |
77 (expand-file-name "usenet" fortune-dir) | |
98271
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
78 "The file in which local fortune cookies will be stored." |
38524 | 79 :type 'file |
80 :group 'fortune) | |
25480 | 81 (defcustom fortune-database-extension ".dat" |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
82 "The extension of the corresponding fortune database. |
25480 | 83 Normally you won't have a reason to change it." |
38524 | 84 :type 'string |
85 :group 'fortune) | |
25480 | 86 (defcustom fortune-program "fortune" |
87 "Program to select a fortune cookie." | |
38524 | 88 :type 'string |
89 :group 'fortune) | |
98269
c4f6098c0914
Justin Bogner <mail at justinbogner.com> (tiny change)
Glenn Morris <rgm@gnu.org>
parents:
94675
diff
changeset
|
90 (defcustom fortune-program-options () |
98271
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
91 "List of options to pass to the fortune program." |
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
92 :type '(choice (repeat (string :tag "Option")) |
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
93 (string :tag "Obsolete string of options")) |
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
94 :version "23.1" |
38524 | 95 :group 'fortune) |
25480 | 96 (defcustom fortune-strfile "strfile" |
97 "Program to compute a new fortune database." | |
38524 | 98 :type 'string |
99 :group 'fortune) | |
25480 | 100 (defcustom fortune-strfile-options "" |
38524 | 101 "Options to pass to the strfile program (a string)." |
102 :type 'string | |
103 :group 'fortune) | |
25480 | 104 (defcustom fortune-quiet-strfile-options "> /dev/null" |
105 "Text added to the command for running `strfile'. | |
106 By default it discards the output produced by `strfile'. | |
107 Set this to \"\" if you would like to see the output." | |
38524 | 108 :type 'string |
109 :group 'fortune) | |
25480 | 110 |
111 (defcustom fortune-always-compile t | |
98271
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
112 "Non-nil means automatically compile fortune files. |
25480 | 113 If nil, you must invoke `fortune-compile' manually to do that." |
38524 | 114 :type 'boolean |
115 :group 'fortune) | |
25480 | 116 (defcustom fortune-author-line-prefix " -- " |
117 "Prefix to put before the author name of a fortunate." | |
38524 | 118 :type 'string |
119 :group 'fortune-signature) | |
25480 | 120 (defcustom fortune-fill-column fill-column |
121 "Fill column for fortune files." | |
38524 | 122 :type 'integer |
123 :group 'fortune-signature) | |
25480 | 124 (defcustom fortune-from-mail "private e-mail" |
125 "String to use to characterize that the fortune comes from an e-mail. | |
126 No need to add an `in'." | |
127 :type 'string | |
128 :group 'fortune-signature) | |
129 (defcustom fortune-sigstart "" | |
98271
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
130 "Some text to insert before the fortune cookie, in a mail signature." |
38524 | 131 :type 'string |
132 :group 'fortune-signature) | |
25480 | 133 (defcustom fortune-sigend "" |
98271
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
134 "Some text to insert after the fortune cookie, in a mail signature." |
38524 | 135 :type 'string |
136 :group 'fortune-signature) | |
25480 | 137 |
138 | |
139 ;; not customizable settings | |
140 (defvar fortune-buffer-name "*fortune*") | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
141 (defconst fortune-end-sep "\n%\n") |
25480 | 142 |
143 | |
144 ;;; ************** | |
145 ;;; Inserting a new fortune | |
146 (defun fortune-append (string &optional interactive file) | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
147 "Appends STRING to the fortune FILE. |
25480 | 148 |
149 If INTERACTIVE is non-nil, don't compile the fortune file afterwards." | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
150 (setq file (expand-file-name |
25480 | 151 (substitute-in-file-name (or file fortune-file)))) |
152 (if (file-directory-p file) | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
153 (error "Cannot append fortune to directory %s" file)) |
25480 | 154 (if interactive ; switch to file and return buffer |
155 (find-file-other-frame file) | |
156 (find-file-noselect file)) | |
157 (let ((fortune-buffer (get-file-buffer file))) | |
158 | |
159 (set-buffer fortune-buffer) | |
160 (goto-char (point-max)) | |
161 (setq fill-column fortune-fill-column) | |
162 (setq auto-fill-inhibit-regexp "^%") | |
163 (turn-on-auto-fill) | |
164 (insert string fortune-end-sep) | |
165 (unless interactive | |
166 (save-buffer) | |
167 (if fortune-always-compile | |
168 (fortune-compile file))))) | |
169 | |
170 (defun fortune-ask-file () | |
171 "Asks the user for a file-name." | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
172 (expand-file-name |
25480 | 173 (read-file-name |
174 "Fortune file to use: " | |
175 fortune-dir nil nil ""))) | |
176 | |
37426 | 177 ;;;###autoload |
25480 | 178 (defun fortune-add-fortune (string file) |
179 "Add STRING to a fortune file FILE. | |
180 | |
181 Interactively, if called with a prefix argument, | |
182 read the file name to use. Otherwise use the value of `fortune-file'." | |
183 (interactive | |
184 (list (read-string "Fortune: ") | |
185 (if current-prefix-arg (fortune-ask-file)))) | |
186 (fortune-append string t file)) | |
187 | |
37426 | 188 ;;;###autoload |
25480 | 189 (defun fortune-from-region (beg end file) |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
190 "Append the current region to a local fortune-like data file. |
25480 | 191 |
192 Interactively, if called with a prefix argument, | |
193 read the file name to use. Otherwise use the value of `fortune-file'." | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
194 (interactive |
25480 | 195 (list (region-beginning) (region-end) |
196 (if current-prefix-arg (fortune-ask-file)))) | |
197 (let ((string (buffer-substring beg end)) | |
198 author newsgroup help-point) | |
199 ;; try to determine author ... | |
200 (save-excursion | |
201 (goto-char (point-min)) | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
202 (setq help-point |
25480 | 203 (search-forward-regexp |
204 "^From: \\(.*\\)$" | |
205 (point-max) t)) | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
206 (if help-point |
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
207 (setq author (buffer-substring (match-beginning 1) help-point)) |
25480 | 208 (setq author "An unknown author"))) |
209 ;; ... and newsgroup | |
210 (save-excursion | |
211 (goto-char (point-min)) | |
212 (setq help-point | |
213 (search-forward-regexp | |
214 "^Newsgroups: \\(.*\\)$" | |
215 (point-max) t)) | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
216 (if help-point |
25480 | 217 (setq newsgroup (buffer-substring (match-beginning 1) help-point)) |
37428
6586c75e5eda
(fortune-from-region): Use `eq' instead of `eql'.
Gerd Moellmann <gerd@gnu.org>
parents:
37426
diff
changeset
|
218 (setq newsgroup (if (or (eq major-mode 'gnus-article-mode) |
6586c75e5eda
(fortune-from-region): Use `eq' instead of `eql'.
Gerd Moellmann <gerd@gnu.org>
parents:
37426
diff
changeset
|
219 (eq major-mode 'vm-mode) |
6586c75e5eda
(fortune-from-region): Use `eq' instead of `eql'.
Gerd Moellmann <gerd@gnu.org>
parents:
37426
diff
changeset
|
220 (eq major-mode 'rmail-mode)) |
25480 | 221 fortune-from-mail |
222 "unknown")))) | |
223 | |
224 ;; append entry to end of fortune file, and display result | |
225 (setq string (concat "\"" string "\"" | |
226 "\n" | |
227 fortune-author-line-prefix | |
228 author " in " newsgroup)) | |
229 (fortune-append string t file))) | |
230 | |
231 | |
232 ;;; ************** | |
233 ;;; Compile new database with strfile | |
37426 | 234 ;;;###autoload |
25480 | 235 (defun fortune-compile (&optional file) |
236 "Compile fortune file. | |
237 | |
238 If called with a prefix asks for the FILE to compile, otherwise uses | |
239 the value of `fortune-file'. This currently cannot handle directories." | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
240 (interactive |
25480 | 241 (list |
242 (if current-prefix-arg | |
243 (fortune-ask-file) | |
244 fortune-file))) | |
245 (let* ((fortune-file (expand-file-name (substitute-in-file-name file))) | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
246 (fortune-dat (expand-file-name |
25480 | 247 (substitute-in-file-name |
248 (concat fortune-file fortune-database-extension))))) | |
249 (cond ((file-exists-p fortune-file) | |
250 (if (file-exists-p fortune-dat) | |
251 (cond ((file-newer-than-file-p fortune-file fortune-dat) | |
252 (message "Compiling new fortune database %s" fortune-dat) | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
253 (shell-command |
25480 | 254 (concat fortune-strfile fortune-strfile-options |
255 " " fortune-file fortune-quiet-strfile-options)))))) | |
256 (t (error "Can't compile fortune file %s" fortune-file))))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38524
diff
changeset
|
257 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38524
diff
changeset
|
258 |
25480 | 259 ;;; ************** |
260 ;;; Use fortune for signature | |
37426 | 261 ;;;###autoload |
25480 | 262 (defun fortune-to-signature (&optional file) |
263 "Create signature from output of the fortune program. | |
264 | |
265 If called with a prefix asks for the FILE to choose the fortune from, | |
266 otherwise uses the value of `fortune-file'. If you want to have fortune | |
267 choose from a set of files in a directory, call interactively with prefix | |
268 and choose the directory as the fortune-file." | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
269 (interactive |
25480 | 270 (list |
271 (if current-prefix-arg | |
272 (fortune-ask-file) | |
273 fortune-file))) | |
274 (save-excursion | |
57825
627816ec9a05
(fortune-to-signature): Don't use interactive-p.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
275 (fortune-in-buffer t file) |
25480 | 276 (set-buffer fortune-buffer-name) |
277 (let* ((fortune (buffer-string)) | |
278 (signature (concat fortune-sigstart fortune fortune-sigend))) | |
279 (setq mail-signature signature) | |
280 (if (boundp 'message-signature) | |
281 (setq message-signature signature))))) | |
282 | |
283 | |
284 ;;; ************** | |
285 ;;; Display fortune | |
286 (defun fortune-in-buffer (interactive &optional file) | |
287 "Put a fortune cookie in the *fortune* buffer. | |
288 | |
57825
627816ec9a05
(fortune-to-signature): Don't use interactive-p.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
289 INTERACTIVE is ignored. Optional argument FILE, |
25480 | 290 when supplied, specifies the file to choose the fortune from." |
291 (let ((fortune-buffer (or (get-buffer fortune-buffer-name) | |
292 (generate-new-buffer fortune-buffer-name))) | |
293 (fort-file (expand-file-name | |
294 (substitute-in-file-name | |
295 (or file fortune-file))))) | |
105829
328150f0cf76
* url-util.el (url-insert-entities-in-string):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
296 (with-current-buffer fortune-buffer |
25480 | 297 (toggle-read-only 0) |
298 (erase-buffer) | |
299 | |
300 (if fortune-always-compile | |
301 (fortune-compile fort-file)) | |
302 | |
98269
c4f6098c0914
Justin Bogner <mail at justinbogner.com> (tiny change)
Glenn Morris <rgm@gnu.org>
parents:
94675
diff
changeset
|
303 (apply 'call-process |
98271
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
304 fortune-program ; program to call |
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
305 nil fortune-buffer nil ; INFILE BUFFER DISPLAY |
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
306 (append (if (stringp fortune-program-options) |
7aacb688e121
Remove leading `*' from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents:
98269
diff
changeset
|
307 (split-string fortune-program-options) |
98292
1943be2bc7c2
(fortune-in-buffer): Fix a bug which forced
Tassilo Horn <tassilo@member.fsf.org>
parents:
98271
diff
changeset
|
308 fortune-program-options) (list fort-file)))))) |
25480 | 309 |
37426 | 310 ;;;###autoload |
25480 | 311 (defun fortune (&optional file) |
312 "Display a fortune cookie. | |
313 | |
314 If called with a prefix asks for the FILE to choose the fortune from, | |
315 otherwise uses the value of `fortune-file'. If you want to have fortune | |
316 choose from a set of files in a directory, call interactively with prefix | |
317 and choose the directory as the fortune-file." | |
30860
d0e5a99cbda1
(fortune) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
25480
diff
changeset
|
318 (interactive |
25480 | 319 (list |
320 (if current-prefix-arg | |
321 (fortune-ask-file) | |
322 fortune-file))) | |
323 (fortune-in-buffer t file) | |
324 (switch-to-buffer (get-buffer fortune-buffer-name)) | |
325 (toggle-read-only 1)) | |
326 | |
327 | |
328 ;;; Provide ourselves. | |
329 (provide 'fortune) | |
330 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79716
diff
changeset
|
331 ;; arch-tag: a1e4cb8a-3792-40e7-86a7-fc75ce094bcc |
25480 | 332 ;;; fortune.el ends here |