Mercurial > emacs
comparison lisp/woman.el @ 65428:25502a355957
(woman-topic-at-point-default): Renamed to woman-use-topic-at-point-default.
(woman-topic-at-point): Renamed to woman-use-topic-at-point.
(woman-file-name): Reflect renames above. Automatically use the
word at point as topic if woman-use-topic-at-point is non-nil.
Otherwise offer it as default but don't insert it in the
minibuffer. Also use `test-completion' instead of `assoc' as
suggested by Stefan Monnier.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 10 Sep 2005 14:57:32 +0000 |
parents | ff96330a04d3 |
children | 4d1085b02d64 10fe5fadaf89 |
comparison
equal
deleted
inserted
replaced
65427:153350fbd860 | 65428:25502a355957 |
---|---|
134 ;; Start menu) just execute | 134 ;; Start menu) just execute |
135 | 135 |
136 ;; man man_page_name | 136 ;; man man_page_name |
137 | 137 |
138 | 138 |
139 ;; Using the `word at point' as a topic suggestion | 139 ;; Using the word at point as the default topic |
140 ;; =============================================== | 140 ;; ============================================ |
141 | 141 |
142 ;; By default, the `woman' command uses the word nearest to point in | 142 ;; The `woman' command uses the word nearest to point in the current |
143 ;; the current buffer as a suggestion for the topic to look up. The | 143 ;; buffer as the default topic to look up if it matches the name of a |
144 ;; topic must be confirmed or edited in the minibuffer. This | 144 ;; manual page installed on the system. The default topic can also be |
145 ;; suggestion can be turned off, or `woman' can use the suggested | 145 ;; used without confirmation by setting the user-option |
146 ;; topic without confirmation* if possible, by setting the user-option | 146 ;; `woman-use-topic-at-point' to t; thanks to Benjamin Riefenstahl for |
147 ;; `woman-topic-at-point' to nil or t respectively. (Its default | 147 ;; suggesting this functionality. |
148 ;; value is neither nil nor t, meaning ask for confirmation.) | 148 |
149 | 149 ;; The variable `woman-use-topic-at-point' can be rebound locally, |
150 ;; [* Thanks to Benjamin Riefenstahl for suggesting this | 150 ;; which may be useful to provide special private key bindings, e.g. |
151 ;; functionality.] | |
152 | |
153 ;; The variable `woman-topic-at-point' can be rebound locally, which | |
154 ;; may be useful to provide special private key bindings, e.g. | |
155 | 151 |
156 ;; (global-set-key "\C-cw" | 152 ;; (global-set-key "\C-cw" |
157 ;; (lambda () | 153 ;; (lambda () |
158 ;; (interactive) | 154 ;; (interactive) |
159 ;; (let ((woman-topic-at-point t)) | 155 ;; (let ((woman-use-topic-at-point t)) |
160 ;; (woman))))) | 156 ;; (woman))))) |
161 | 157 |
162 | 158 |
163 ;; Customization, Hooks and Imenu | 159 ;; Customization, Hooks and Imenu |
164 ;; ============================== | 160 ;; ============================== |
709 "*The title to use if WoMan adds a Contents menu to the menubar. | 705 "*The title to use if WoMan adds a Contents menu to the menubar. |
710 Default is \"CONTENTS\"." | 706 Default is \"CONTENTS\"." |
711 :type 'string | 707 :type 'string |
712 :group 'woman-interface) | 708 :group 'woman-interface) |
713 | 709 |
714 (defcustom woman-topic-at-point-default 'confirm | 710 (defcustom woman-use-topic-at-point-default nil |
715 ;; `woman-topic-at-point' may be let-bound when woman is loaded, in | 711 ;; `woman-use-topic-at-point' may be let-bound when woman is loaded, |
716 ;; which case its global value does not get defined. | 712 ;; in which case its global value does not get defined. |
717 ;; `woman-file-name' sets it to this value if it is unbound. | 713 ;; `woman-file-name' sets it to this value if it is unbound. |
718 "*Default value for `woman-topic-at-point'." | 714 "*Default value for `woman-use-topic-at-point'." |
719 :type '(choice (const :tag "Yes" t) | 715 :type '(choice (const :tag "Yes" t) |
720 (const :tag "No" nil) | 716 (const :tag "No" nil)) |
721 (other :tag "Confirm" confirm)) | |
722 :group 'woman-interface) | 717 :group 'woman-interface) |
723 | 718 |
724 (defcustom woman-topic-at-point woman-topic-at-point-default | 719 (defcustom woman-use-topic-at-point woman-use-topic-at-point-default |
725 "*Controls use by `woman' of `word at point' as a topic suggestion. | 720 "*Control use of the word at point as the default topic. |
726 If non-nil then the `woman' command uses the word at point as an | 721 If non-nil the `woman' command uses the word at point automatically, |
727 initial topic suggestion when it reads a topic from the minibuffer; if | 722 without interactive confirmation, if it exists as a topic." |
728 t then the `woman' command uses the word at point WITHOUT | |
729 INTERACTIVE CONFIRMATION if it exists as a topic. The default value | |
730 is `confirm', meaning suggest a topic and ask for confirmation." | |
731 :type '(choice (const :tag "Yes" t) | 723 :type '(choice (const :tag "Yes" t) |
732 (const :tag "No" nil) | 724 (const :tag "No" nil)) |
733 (other :tag "Confirm" confirm)) | |
734 :group 'woman-interface) | 725 :group 'woman-interface) |
735 | 726 |
736 (defvar woman-file-regexp nil | 727 (defvar woman-file-regexp nil |
737 "Regexp used to select (possibly compressed) man source files, e.g. | 728 "Regexp used to select (possibly compressed) man source files, e.g. |
738 \"\\.\\([0-9lmnt]\\w*\\)\\(\\.\\(g?z\\|bz2\\)\\)?\\'\". | 729 \"\\.\\([0-9lmnt]\\w*\\)\\(\\.\\(g?z\\|bz2\\)\\)?\\'\". |
1196 (defvar woman-topic-history nil "Topic read history.") | 1187 (defvar woman-topic-history nil "Topic read history.") |
1197 (defvar woman-file-history nil "File-name read history.") | 1188 (defvar woman-file-history nil "File-name read history.") |
1198 | 1189 |
1199 (defun woman-file-name (topic &optional re-cache) | 1190 (defun woman-file-name (topic &optional re-cache) |
1200 "Get the name of the UN*X man-page file describing a chosen TOPIC. | 1191 "Get the name of the UN*X man-page file describing a chosen TOPIC. |
1201 When `woman' is called interactively, the word at point may be used as | 1192 When `woman' is called interactively, the word at point may be |
1202 the topic or initial topic suggestion, subject to the value of the | 1193 automatically used as the topic, if the value of the user option |
1203 user option `woman-topic-at-point'. Return nil if no file can be found. | 1194 `woman-use-topic-at-point' is non-nil. Return nil if no file can |
1204 Optional argument RE-CACHE, if non-nil, forces the cache to be re-read." | 1195 be found. Optional argument RE-CACHE, if non-nil, forces the |
1196 cache to be re-read." | |
1205 ;; Handle the caching of the directory and topic lists: | 1197 ;; Handle the caching of the directory and topic lists: |
1206 (if (and (not re-cache) | 1198 (if (and (not re-cache) |
1207 (or | 1199 (or |
1208 (and woman-expanded-directory-path woman-topic-all-completions) | 1200 (and woman-expanded-directory-path woman-topic-all-completions) |
1209 (woman-read-directory-cache))) | 1201 (woman-read-directory-cache))) |
1220 ;; does not seem to work properly by default, so I re-do the | 1212 ;; does not seem to work properly by default, so I re-do the |
1221 ;; completion if necessary. | 1213 ;; completion if necessary. |
1222 (let (files | 1214 (let (files |
1223 (default (current-word))) | 1215 (default (current-word))) |
1224 (or (stringp topic) | 1216 (or (stringp topic) |
1225 (and (eq t | 1217 (and (if (boundp 'woman-use-topic-at-point) |
1226 (if (boundp 'woman-topic-at-point) | 1218 woman-use-topic-at-point |
1227 woman-topic-at-point | 1219 ;; Was let-bound when file loaded, so ... |
1228 ;; Was let-bound when file loaded, so ... | 1220 (setq woman-use-topic-at-point woman-use-topic-at-point-default)) |
1229 (setq woman-topic-at-point woman-topic-at-point-default))) | 1221 (setq topic (or (current-word t) "")) ; only within or adjacent to word |
1230 (setq topic | 1222 (test-completion topic woman-topic-all-completions)) |
1231 (or (current-word t) "")) ; only within or adjacent to word | |
1232 (assoc topic woman-topic-all-completions)) | |
1233 (setq topic | 1223 (setq topic |
1234 (completing-read | 1224 (let* ((word-at-point (current-word)) |
1235 (if default | 1225 (default |
1236 (format "Manual entry (default `%s'): " default) | 1226 (when (and word-at-point |
1237 "Manual entry: ") | 1227 (test-completion |
1238 woman-topic-all-completions nil 1 | 1228 word-at-point woman-topic-all-completions)) |
1239 nil | 1229 word-at-point))) |
1240 'woman-topic-history | 1230 (completing-read |
1241 ;; Default topic. | 1231 (if default |
1242 (and woman-topic-at-point | 1232 (format "Manual entry [default: %s]: " default) |
1243 default)))) | 1233 "Manual entry: ") |
1234 woman-topic-all-completions nil 1 | |
1235 nil | |
1236 'woman-topic-history | |
1237 default)))) | |
1244 ;; Note that completing-read always returns a string. | 1238 ;; Note that completing-read always returns a string. |
1245 (if (= (length topic) 0) | 1239 (if (= (length topic) 0) |
1246 nil ; no topic, so no file! | 1240 nil ; no topic, so no file! |
1247 (cond | 1241 (cond |
1248 ((setq files (woman-file-name-all-completions topic))) | 1242 ((setq files (woman-file-name-all-completions topic))) |