diff options
| author | Stefan Monnier | 2009-11-27 04:08:04 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2009-11-27 04:08:04 +0000 |
| commit | 10c877fedc42f0d9cefde95eb52e8d3df5265602 (patch) | |
| tree | 9637d014039c694c972342310c62ccd360b8fc66 | |
| parent | c074ba4a567963720aefde4d38c447660d09e330 (diff) | |
| download | emacs-10c877fedc42f0d9cefde95eb52e8d3df5265602.tar.gz emacs-10c877fedc42f0d9cefde95eb52e8d3df5265602.zip | |
(Man-completion-table): Trim a terminating "(".
Remove the space between name page a section.
Add the command's description on the `help-echo' property.
Remove `process-connection-type' binding since it's unused by call-process.
Provide completion for the "<section> <name>" format as well.
(Man-default-man-entry): Remove spurious var shadowing the argument.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/man.el | 74 |
2 files changed, 54 insertions, 29 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 18ced5b6512..9ad26342746 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2009-11-27 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * man.el (Man-completion-table): Trim a terminating "(". | ||
| 4 | Remove the space between name page a section. | ||
| 5 | Add the command's description on the `help-echo' property. | ||
| 6 | Remove `process-connection-type' binding since it's unused by call-process. | ||
| 7 | Provide completion for the "<section> <name>" format as well. | ||
| 8 | (Man-default-man-entry): Remove spurious var shadowing the argument. | ||
| 9 | |||
| 1 | 2009-11-26 Kevin Ryde <user42@zip.com.au> | 10 | 2009-11-26 Kevin Ryde <user42@zip.com.au> |
| 2 | 11 | ||
| 3 | * log-view.el: Add "Keywords: tools", since its other keywords | 12 | * log-view.el: Add "Keywords: tools", since its other keywords |
diff --git a/lisp/man.el b/lisp/man.el index 050ebed81a0..d40f21c0ca8 100644 --- a/lisp/man.el +++ b/lisp/man.el | |||
| @@ -84,11 +84,6 @@ | |||
| 84 | ;; only. Is it worth doing? | 84 | ;; only. Is it worth doing? |
| 85 | ;; - Allow a user option to mean that all the manpages should go in | 85 | ;; - Allow a user option to mean that all the manpages should go in |
| 86 | ;; the same buffer, where they can be browsed with M-n and M-p. | 86 | ;; the same buffer, where they can be browsed with M-n and M-p. |
| 87 | ;; - Allow completion on the manpage name when calling man. This | ||
| 88 | ;; requires a reliable list of places where manpages can be found. The | ||
| 89 | ;; drawback would be that if the list is not complete, the user might | ||
| 90 | ;; be led to believe that the manpages in the missing directories do | ||
| 91 | ;; not exist. | ||
| 92 | 87 | ||
| 93 | 88 | ||
| 94 | ;;; Code: | 89 | ;;; Code: |
| @@ -660,7 +655,7 @@ a new value." | |||
| 660 | (defun Man-default-man-entry (&optional pos) | 655 | (defun Man-default-man-entry (&optional pos) |
| 661 | "Guess default manual entry based on the text near position POS. | 656 | "Guess default manual entry based on the text near position POS. |
| 662 | POS defaults to `point'." | 657 | POS defaults to `point'." |
| 663 | (let (word start pos column distance) | 658 | (let (word start column distance) |
| 664 | (save-excursion | 659 | (save-excursion |
| 665 | (when pos (goto-char pos)) | 660 | (when pos (goto-char pos)) |
| 666 | (setq pos (point)) | 661 | (setq pos (point)) |
| @@ -756,33 +751,54 @@ POS defaults to `point'." | |||
| 756 | 751 | ||
| 757 | (defun Man-completion-table (string pred action) | 752 | (defun Man-completion-table (string pred action) |
| 758 | (cond | 753 | (cond |
| 759 | ((memq action '(t nil)) | 754 | ((eq action 'lambda) |
| 760 | (let ((table (cdr Man-completion-cache))) | 755 | (not (string-match "([^)]*\\'" string))) |
| 756 | (t | ||
| 757 | (let ((table (cdr Man-completion-cache)) | ||
| 758 | (section nil) | ||
| 759 | (prefix string)) | ||
| 760 | (when (string-match "\\`\\([[:digit:]].*?\\) " string) | ||
| 761 | (setq section (match-string 1 string)) | ||
| 762 | (setq prefix (substring string (match-end 0)))) | ||
| 761 | (unless (and Man-completion-cache | 763 | (unless (and Man-completion-cache |
| 762 | (string-prefix-p (car Man-completion-cache) string)) | 764 | (string-prefix-p (car Man-completion-cache) prefix)) |
| 763 | (with-temp-buffer | 765 | (with-temp-buffer |
| 764 | (setq default-directory "/") ;; in case inherited doesn't exist | 766 | (setq default-directory "/") ;; in case inherited doesn't |
| 765 | ;; Actually for my `man' the arg is a regexp. Don't know how | 767 | ;; exist Actually for my `man' the arg is a regexp. |
| 766 | ;; standard that is. Also, it's not clear what kind of | 768 | ;; POSIX says it must be ERE and GNU/Linux seems to agree, |
| 767 | ;; regexp are accepted: under GNU/Linux it seems it's ERE-style, | 769 | ;; whereas under MacOSX it seems to be BRE-style and doesn't |
| 768 | ;; whereas under MacOSX it seems to be BRE-style and | 770 | ;; accept backslashes at all. Let's not bother to |
| 769 | ;; doesn't accept backslashes at all. Let's not bother to | 771 | ;; quote anything. |
| 770 | ;; quote anything. | 772 | (let ((process-environment (copy-sequence process-environment))) |
| 771 | (let ((process-connection-type nil) ;; pipe | 773 | (setenv "COLUMNS" "999") ;; don't truncate long names |
| 772 | (process-environment (copy-sequence process-environment))) | 774 | (call-process manual-program nil '(t nil) nil |
| 773 | (setenv "COLUMNS" "999") ;; don't truncate long names | 775 | "-k" (concat "^" prefix))) |
| 774 | (call-process manual-program nil '(t nil) nil | 776 | (goto-char (point-min)) |
| 775 | "-k" (concat "^" string))) | 777 | (while (re-search-forward "^\\([^ \t\n]+\\)\\(?: ?\\((.+?)\\)\\(?:[ \t]+- \\(.*\\)\\)?\\)?" nil t) |
| 776 | (goto-char (point-min)) | 778 | (push (propertize (concat (match-string 1) (match-string 2)) |
| 777 | (while (re-search-forward "^[^ \t\n]+\\(?: (.+?)\\)?" nil t) | 779 | 'help-echo (match-string 3)) |
| 778 | (push (match-string 0) table))) | 780 | table))) |
| 779 | ;; Cache the table for later reuse. | 781 | ;; Cache the table for later reuse. |
| 780 | (setq Man-completion-cache (cons string table))) | 782 | (setq Man-completion-cache (cons prefix table))) |
| 781 | ;; The table may contain false positives since the match is made | 783 | ;; The table may contain false positives since the match is made |
| 782 | ;; by "man -k" not just on the manpage's name. | 784 | ;; by "man -k" not just on the manpage's name. |
| 783 | (complete-with-action action table string pred))) | 785 | (if section |
| 784 | ((eq action 'lambda) t) | 786 | (let ((re (concat "(" (regexp-quote section) ")\\'"))) |
| 785 | ((eq (car-safe action) 'boundaries) nil))) | 787 | (dolist (comp (prog1 table (setq table nil))) |
| 788 | (if (string-match re comp) | ||
| 789 | (push (substring comp 0 (match-beginning 0)) table))) | ||
| 790 | (completion-table-with-context (concat section " ") table | ||
| 791 | prefix pred action)) | ||
| 792 | (let ((res (complete-with-action action table string pred))) | ||
| 793 | ;; In case we're completing to a single name that exists in | ||
| 794 | ;; several sections, the longest prefix will look like "foo(". | ||
| 795 | (if (and (stringp res) | ||
| 796 | (string-match "([^(]*\\'" res) | ||
| 797 | ;; In case the paren was already in `prefix', don't | ||
| 798 | ;; remove it. | ||
| 799 | (> (match-beginning 0) (length prefix))) | ||
| 800 | (substring res 0 (match-beginning 0)) | ||
| 801 | res))))))) | ||
| 786 | 802 | ||
| 787 | ;;;###autoload | 803 | ;;;###autoload |
| 788 | (defun man (man-args) | 804 | (defun man (man-args) |