diff options
author | Eli Zaretskii <eliz@gnu.org> | 2005-09-10 14:59:07 +0000 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2005-09-10 14:59:07 +0000 |
commit | 72f0712b757f881461b3e1129147854cbbc2e651 (patch) | |
tree | f5d0d27a3bdd3491bb232b06a006596a02029157 /lisp/woman.el | |
parent | 1486d036f4f92fd16238c04daa3662b0c4e8b36d (diff) | |
download | emacs-72f0712b757f881461b3e1129147854cbbc2e651.tar.gz |
(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.
Diffstat (limited to 'lisp/woman.el')
-rw-r--r-- | lisp/woman.el | 98 |
1 files changed, 46 insertions, 52 deletions
diff --git a/lisp/woman.el b/lisp/woman.el index e5753d746f7..9b7bce889b3 100644 --- a/lisp/woman.el +++ b/lisp/woman.el @@ -136,27 +136,23 @@ ;; man man_page_name -;; Using the `word at point' as a topic suggestion -;; =============================================== +;; Using the word at point as the default topic +;; ============================================ -;; By default, the `woman' command uses the word nearest to point in -;; the current buffer as a suggestion for the topic to look up. The -;; topic must be confirmed or edited in the minibuffer. This -;; suggestion can be turned off, or `woman' can use the suggested -;; topic without confirmation* if possible, by setting the user-option -;; `woman-topic-at-point' to nil or t respectively. (Its default -;; value is neither nil nor t, meaning ask for confirmation.) +;; The `woman' command uses the word nearest to point in the current +;; buffer as the default topic to look up if it matches the name of a +;; manual page installed on the system. The default topic can also be +;; used without confirmation by setting the user-option +;; `woman-use-topic-at-point' to t; thanks to Benjamin Riefenstahl for +;; suggesting this functionality. -;; [* Thanks to Benjamin Riefenstahl for suggesting this -;; functionality.] - -;; The variable `woman-topic-at-point' can be rebound locally, which -;; may be useful to provide special private key bindings, e.g. +;; The variable `woman-use-topic-at-point' can be rebound locally, +;; which may be useful to provide special private key bindings, e.g. ;; (global-set-key "\C-cw" ;; (lambda () ;; (interactive) -;; (let ((woman-topic-at-point t)) +;; (let ((woman-use-topic-at-point t)) ;; (woman))))) @@ -711,26 +707,21 @@ Default is \"CONTENTS\"." :type 'string :group 'woman-interface) -(defcustom woman-topic-at-point-default 'confirm - ;; `woman-topic-at-point' may be let-bound when woman is loaded, in - ;; which case its global value does not get defined. +(defcustom woman-use-topic-at-point-default nil + ;; `woman-use-topic-at-point' may be let-bound when woman is loaded, + ;; in which case its global value does not get defined. ;; `woman-file-name' sets it to this value if it is unbound. - "*Default value for `woman-topic-at-point'." + "*Default value for `woman-use-topic-at-point'." :type '(choice (const :tag "Yes" t) - (const :tag "No" nil) - (other :tag "Confirm" confirm)) + (const :tag "No" nil)) :group 'woman-interface) -(defcustom woman-topic-at-point woman-topic-at-point-default - "*Controls use by `woman' of `word at point' as a topic suggestion. -If non-nil then the `woman' command uses the word at point as an -initial topic suggestion when it reads a topic from the minibuffer; if -t then the `woman' command uses the word at point WITHOUT -INTERACTIVE CONFIRMATION if it exists as a topic. The default value -is `confirm', meaning suggest a topic and ask for confirmation." +(defcustom woman-use-topic-at-point woman-use-topic-at-point-default + "*Control use of the word at point as the default topic. +If non-nil the `woman' command uses the word at point automatically, +without interactive confirmation, if it exists as a topic." :type '(choice (const :tag "Yes" t) - (const :tag "No" nil) - (other :tag "Confirm" confirm)) + (const :tag "No" nil)) :group 'woman-interface) (defvar woman-file-regexp nil @@ -1198,10 +1189,11 @@ It is saved to the file named by the variable `woman-cache-filename'." (defun woman-file-name (topic &optional re-cache) "Get the name of the UN*X man-page file describing a chosen TOPIC. -When `woman' is called interactively, the word at point may be used as -the topic or initial topic suggestion, subject to the value of the -user option `woman-topic-at-point'. Return nil if no file can be found. -Optional argument RE-CACHE, if non-nil, forces the cache to be re-read." +When `woman' is called interactively, the word at point may be +automatically used as the topic, if the value of the user option +`woman-use-topic-at-point' is non-nil. Return nil if no file can +be found. Optional argument RE-CACHE, if non-nil, forces the +cache to be re-read." ;; Handle the caching of the directory and topic lists: (if (and (not re-cache) (or @@ -1222,25 +1214,27 @@ Optional argument RE-CACHE, if non-nil, forces the cache to be re-read." (let (files (default (current-word))) (or (stringp topic) - (and (eq t - (if (boundp 'woman-topic-at-point) - woman-topic-at-point - ;; Was let-bound when file loaded, so ... - (setq woman-topic-at-point woman-topic-at-point-default))) - (setq topic - (or (current-word t) "")) ; only within or adjacent to word - (assoc topic woman-topic-all-completions)) + (and (if (boundp 'woman-use-topic-at-point) + woman-use-topic-at-point + ;; Was let-bound when file loaded, so ... + (setq woman-use-topic-at-point woman-use-topic-at-point-default)) + (setq topic (or (current-word t) "")) ; only within or adjacent to word + (test-completion topic woman-topic-all-completions)) (setq topic - (completing-read - (if default - (format "Manual entry (default `%s'): " default) - "Manual entry: ") - woman-topic-all-completions nil 1 - nil - 'woman-topic-history - ;; Default topic. - (and woman-topic-at-point - default)))) + (let* ((word-at-point (current-word)) + (default + (when (and word-at-point + (test-completion + word-at-point woman-topic-all-completions)) + word-at-point))) + (completing-read + (if default + (format "Manual entry [default: %s]: " default) + "Manual entry: ") + woman-topic-all-completions nil 1 + nil + 'woman-topic-history + default)))) ;; Note that completing-read always returns a string. (if (= (length topic) 0) nil ; no topic, so no file! |