diff options
| author | Stefan Monnier | 2009-11-24 20:00:41 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2009-11-24 20:00:41 +0000 |
| commit | bb301b9aff1ccb7a28e4f9bae3adef3f03d2b3e4 (patch) | |
| tree | fa1ef0424af9b7c300431641fe93433e4e552f24 /lisp/man.el | |
| parent | 35179414e41c6064b484854fbc01a9db6ce2a866 (diff) | |
| download | emacs-bb301b9aff1ccb7a28e4f9bae3adef3f03d2b3e4.tar.gz emacs-bb301b9aff1ccb7a28e4f9bae3adef3f03d2b3e4.zip | |
(Man-completion-table): New function.
(man): Use it.
Diffstat (limited to 'lisp/man.el')
| -rw-r--r-- | lisp/man.el | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lisp/man.el b/lisp/man.el index d305d54dd43..5923b3909ee 100644 --- a/lisp/man.el +++ b/lisp/man.el | |||
| @@ -749,6 +749,26 @@ POS defaults to `point'." | |||
| 749 | ;;;###autoload | 749 | ;;;###autoload |
| 750 | (defalias 'manual-entry 'man) | 750 | (defalias 'manual-entry 'man) |
| 751 | 751 | ||
| 752 | (defun Man-completion-table (string pred action) | ||
| 753 | (cond | ||
| 754 | ((memq action '(t nil)) | ||
| 755 | (let ((table '())) | ||
| 756 | (with-temp-buffer | ||
| 757 | ;; Actually for my `man' the arg is a regexp. Don't know how | ||
| 758 | ;; standard that is. Also, it's not clear what kind of | ||
| 759 | ;; regexp are accepted: under GNU/Linux it seems it's ERE-style, | ||
| 760 | ;; whereas under MacOSX it seems to be BRE-style and | ||
| 761 | ;; doesn't accept backslashes at all. Let's not bother to | ||
| 762 | ;; quote anything. | ||
| 763 | (call-process "man" nil '(t nil) nil "-k" (concat "^" string)) | ||
| 764 | (goto-char (point-min)) | ||
| 765 | (while (re-search-forward "^[^ \t\n]+" nil t) | ||
| 766 | (push (match-string 0) table))) | ||
| 767 | ;; The table may contain false positives since the match is made | ||
| 768 | ;; by "man -k" not just on the manpage's name. | ||
| 769 | (complete-with-action action table string pred))) | ||
| 770 | ((eq action 'lambda) t) | ||
| 771 | ((eq (car-safe action) 'boundaries) nil))) | ||
| 752 | 772 | ||
| 753 | ;;;###autoload | 773 | ;;;###autoload |
| 754 | (defun man (man-args) | 774 | (defun man (man-args) |
| @@ -765,12 +785,13 @@ all sections related to a subject, put something appropriate into the | |||
| 765 | `Man-switches' variable, which see." | 785 | `Man-switches' variable, which see." |
| 766 | (interactive | 786 | (interactive |
| 767 | (list (let* ((default-entry (Man-default-man-entry)) | 787 | (list (let* ((default-entry (Man-default-man-entry)) |
| 768 | (input (read-string | 788 | (input (completing-read |
| 769 | (format "Manual entry%s" | 789 | (format "Manual entry%s" |
| 770 | (if (string= default-entry "") | 790 | (if (string= default-entry "") |
| 771 | ": " | 791 | ": " |
| 772 | (format " (default %s): " default-entry))) | 792 | (format " (default %s): " default-entry))) |
| 773 | nil 'Man-topic-history default-entry))) | 793 | 'Man-completion-table |
| 794 | nil nil nil 'Man-topic-history default-entry))) | ||
| 774 | (if (string= input "") | 795 | (if (string= input "") |
| 775 | (error "No man args given") | 796 | (error "No man args given") |
| 776 | input)))) | 797 | input)))) |