diff options
| author | Wolfgang Jenkner | 2013-01-10 10:01:35 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2013-01-10 10:01:35 -0500 |
| commit | 327a6ccaa01cdcd220e74df4f71acf0ad7e92f5f (patch) | |
| tree | ff27057bd411d31de8cc44960650ba210d7c1747 /lisp | |
| parent | ed9112575ebdf0fefec530d7b2687f83eea7bb8a (diff) | |
| download | emacs-327a6ccaa01cdcd220e74df4f71acf0ad7e92f5f.tar.gz emacs-327a6ccaa01cdcd220e74df4f71acf0ad7e92f5f.zip | |
* lisp/man.el: Handle different "man -k" behaviors. Use utf-8.
(Man-man-k-use-anchor): New var.
(Man-parse-man-k): New function.
(Man-completion-table): Use it.
(man): Flush the completion cache between uses.
* test/automated/man-tests.el: New file.
Fixes: debbugs:13160
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/man.el | 79 |
2 files changed, 74 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 507550dbec0..f26c009bf2b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2013-01-10 Wolfgang Jenkner <wjenkner@inode.at> | ||
| 2 | |||
| 3 | * man.el: Handle different "man -k" behaviors (bug#13160). Use utf-8. | ||
| 4 | (Man-man-k-use-anchor): New var. | ||
| 5 | (Man-parse-man-k): New function. | ||
| 6 | (Man-completion-table): Use it. | ||
| 7 | (man): Flush the completion cache between uses. | ||
| 8 | |||
| 1 | 2013-01-10 Michael Albinus <michael.albinus@gmx.de> | 9 | 2013-01-10 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 10 | ||
| 3 | * autorevert.el: Add file watch support. | 11 | * autorevert.el: Add file watch support. |
diff --git a/lisp/man.el b/lisp/man.el index b6a6c179374..93a67128de4 100644 --- a/lisp/man.el +++ b/lisp/man.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; man.el --- browse UNIX manual pages -*- coding: iso-8859-1 -*- | 1 | ;;; man.el --- browse UNIX manual pages -*- coding: utf-8 -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1993-1994, 1996-1997, 2001-2013 Free Software | 3 | ;; Copyright (C) 1993-1994, 1996-1997, 2001-2013 Free Software |
| 4 | ;; Foundation, Inc. | 4 | ;; Foundation, Inc. |
| @@ -276,7 +276,7 @@ Used in `bookmark-set' to get the default bookmark name." | |||
| 276 | :type 'hook | 276 | :type 'hook |
| 277 | :group 'man) | 277 | :group 'man) |
| 278 | 278 | ||
| 279 | (defvar Man-name-regexp "[-a-zA-Z0-9_+][-a-zA-Z0-9_.:+]*" | 279 | (defvar Man-name-regexp "[-a-zA-Z0-9_Â+][-a-zA-Z0-9_.:Â+]*" |
| 280 | "Regular expression describing the name of a manpage (without section).") | 280 | "Regular expression describing the name of a manpage (without section).") |
| 281 | 281 | ||
| 282 | (defvar Man-section-regexp "[0-9][a-zA-Z0-9+]*\\|[LNln]" | 282 | (defvar Man-section-regexp "[0-9][a-zA-Z0-9+]*\\|[LNln]" |
| @@ -780,6 +780,59 @@ POS defaults to `point'." | |||
| 780 | ;; but apparently that's not the case in all cases, so let's add a cache. | 780 | ;; but apparently that's not the case in all cases, so let's add a cache. |
| 781 | "Cache of completion table of the form (PREFIX . TABLE).") | 781 | "Cache of completion table of the form (PREFIX . TABLE).") |
| 782 | 782 | ||
| 783 | (defvar Man-man-k-use-anchor | ||
| 784 | ;; man-db or man-1.* | ||
| 785 | (memq system-type '(gnu gnu/linux gnu/kfreebsd)) | ||
| 786 | "If non-nil prepend ^ to the prefix passed to \"man -k\" for completion. | ||
| 787 | The value should be nil if \"man -k ^PREFIX\" may omit some man | ||
| 788 | pages whose names start with PREFIX. | ||
| 789 | |||
| 790 | Currently, the default value depends on `system-type' and is | ||
| 791 | non-nil where the standard man programs are known to behave | ||
| 792 | properly. Setting the value to nil always gives correct results | ||
| 793 | but computing the list of completions may take a bit longer.") | ||
| 794 | |||
| 795 | (defun Man-parse-man-k () | ||
| 796 | "Parse \"man -k\" output and return the list of page names. | ||
| 797 | |||
| 798 | The current buffer should contain the output of a command of the | ||
| 799 | form \"man -k keyword\", which is traditionally also available with | ||
| 800 | apropos(1). | ||
| 801 | |||
| 802 | While POSIX man(1p) is a bit vague about what to expect here, | ||
| 803 | this function tries to parse some commonly used formats, which | ||
| 804 | can be described in the following informal way, with square brackets | ||
| 805 | indicating optional parts and whitespace being interpreted | ||
| 806 | somewhat loosely. | ||
| 807 | |||
| 808 | foo[, bar [, ...]] [other stuff] (sec) - description | ||
| 809 | foo(sec)[, bar(sec) [, ...]] [other stuff] - description | ||
| 810 | |||
| 811 | For more details and some regression tests, please see | ||
| 812 | test/automated/man-tests.el in the emacs bzr repository." | ||
| 813 | (goto-char (point-min)) | ||
| 814 | ;; See man-tests for data about which systems use which format (hopefully we | ||
| 815 | ;; will be able to simplify the code if/when some of those formats aren't | ||
| 816 | ;; used any more). | ||
| 817 | (let (table) | ||
| 818 | (while (search-forward-regexp "^\\([^ \t,\n]+\\)\\(.*?\\)\ | ||
| 819 | \\(?:[ \t]\\(([^ \t,\n]+?)\\)\\)?\\(?:[ \t]+- ?\\(.*\\)\\)?$" nil t) | ||
| 820 | (let ((section (match-string 3)) | ||
| 821 | (description (match-string 4)) | ||
| 822 | (bound (match-end 2))) | ||
| 823 | (goto-char (match-end 1)) | ||
| 824 | (while | ||
| 825 | (progn | ||
| 826 | ;; The first regexp grouping may already match the section | ||
| 827 | ;; tacked on to the name, which is ok since for the formats we | ||
| 828 | ;; claim to support the third (non-shy) grouping does not | ||
| 829 | ;; match in this case, i.e., section is nil. | ||
| 830 | (push (propertize (concat (match-string 1) section) | ||
| 831 | 'help-echo description) | ||
| 832 | table) | ||
| 833 | (search-forward-regexp "\\=, *\\([^ \t,]+\\)" bound t))))) | ||
| 834 | (nreverse table))) | ||
| 835 | |||
| 783 | (defun Man-completion-table (string pred action) | 836 | (defun Man-completion-table (string pred action) |
| 784 | (cond | 837 | (cond |
| 785 | ;; This ends up returning t for pretty much any string, and hence leads to | 838 | ;; This ends up returning t for pretty much any string, and hence leads to |
| @@ -811,16 +864,15 @@ POS defaults to `point'." | |||
| 811 | ;; run differently in Man-getpage-in-background, an error | 864 | ;; run differently in Man-getpage-in-background, an error |
| 812 | ;; here may not necessarily mean that we'll also get an | 865 | ;; here may not necessarily mean that we'll also get an |
| 813 | ;; error later. | 866 | ;; error later. |
| 814 | (ignore-errors | 867 | (ignore-errors |
| 815 | (call-process manual-program nil '(t nil) nil | 868 | (call-process manual-program nil '(t nil) nil |
| 816 | "-k" (concat "^" prefix)))) | 869 | "-k" (concat (when (or Man-man-k-use-anchor |
| 817 | (goto-char (point-min)) | 870 | (string-equal prefix "")) |
| 818 | (while (re-search-forward "^\\([^ \t\n]+\\)\\(?: ?\\((.+?)\\)\\(?:[ \t]+- \\(.*\\)\\)?\\)?" nil t) | 871 | "^") |
| 819 | (push (propertize (concat (match-string 1) (match-string 2)) | 872 | prefix)))) |
| 820 | 'help-echo (match-string 3)) | 873 | (setq table (Man-parse-man-k))) |
| 821 | table))) | 874 | ;; Cache the table for later reuse. |
| 822 | ;; Cache the table for later reuse. | 875 | (setq Man-completion-cache (cons prefix table))) |
| 823 | (setq Man-completion-cache (cons prefix table))) | ||
| 824 | ;; The table may contain false positives since the match is made | 876 | ;; The table may contain false positives since the match is made |
| 825 | ;; by "man -k" not just on the manpage's name. | 877 | ;; by "man -k" not just on the manpage's name. |
| 826 | (if section | 878 | (if section |
| @@ -891,6 +943,7 @@ names or descriptions. The pattern argument is usually an | |||
| 891 | ;; ("man -k" is case-insensitive similarly, so the | 943 | ;; ("man -k" is case-insensitive similarly, so the |
| 892 | ;; table has everything available to complete) | 944 | ;; table has everything available to complete) |
| 893 | (completion-ignore-case t) | 945 | (completion-ignore-case t) |
| 946 | Man-completion-cache ;Don't cache across calls. | ||
| 894 | (input (completing-read | 947 | (input (completing-read |
| 895 | (format "Manual entry%s" | 948 | (format "Manual entry%s" |
| 896 | (if (string= default-entry "") | 949 | (if (string= default-entry "") |
| @@ -1395,7 +1448,7 @@ The following key bindings are currently in effect in the buffer: | |||
| 1395 | ;; Update len, in case a reference spans | 1448 | ;; Update len, in case a reference spans |
| 1396 | ;; more than two lines (paranoia). | 1449 | ;; more than two lines (paranoia). |
| 1397 | len (1- (length word)))) | 1450 | len (1- (length word)))) |
| 1398 | (if (memq (aref word len) '(?- ?)) | 1451 | (if (memq (aref word len) '(?- ?Â)) |
| 1399 | (setq hyphenated (substring word 0 len))) | 1452 | (setq hyphenated (substring word 0 len))) |
| 1400 | (and (string-match Man-reference-regexp word) | 1453 | (and (string-match Man-reference-regexp word) |
| 1401 | (not (member word Man--refpages)) | 1454 | (not (member word Man--refpages)) |