diff options
| author | Stefan Monnier | 2024-11-17 16:52:33 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2024-11-17 16:52:33 -0500 |
| commit | 347750461e71eec4668fb265cd29cffce45783f2 (patch) | |
| tree | b51caf39771417415e9fb5652a462a0c21b6bd05 | |
| parent | b6181c9ec9f7dcbb1c5657537ccc52dc7a3bf6ac (diff) | |
| download | emacs-347750461e71eec4668fb265cd29cffce45783f2.tar.gz emacs-347750461e71eec4668fb265cd29cffce45783f2.zip | |
man.el: Guess flags for `man -k` to fix bug#73656
* lisp/man.el (Man-man-k-flags): New var.
(Man-completion-table): Use it.
| -rw-r--r-- | lisp/man.el | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/lisp/man.el b/lisp/man.el index 816c75d749c..d5ac8b93d99 100644 --- a/lisp/man.el +++ b/lisp/man.el | |||
| @@ -973,6 +973,27 @@ foo(sec)[, bar(sec) [, ...]] [other stuff] - description" | |||
| 973 | (search-forward-regexp "\\=, *\\([^ \t,]+\\)" bound t))))) | 973 | (search-forward-regexp "\\=, *\\([^ \t,]+\\)" bound t))))) |
| 974 | (nreverse table))) | 974 | (nreverse table))) |
| 975 | 975 | ||
| 976 | (defvar Man-man-k-flags | ||
| 977 | ;; It's not clear which man page will "always" be available, `man -k man' | ||
| 978 | ;; seems like the safest choice, but `man -k apropos' seems almost as safe | ||
| 979 | ;; and usually returns a much shorter output. | ||
| 980 | (with-temp-buffer | ||
| 981 | (with-demoted-errors "%S" (call-process "man" nil t nil "-k" "apropos")) | ||
| 982 | (let ((lines (count-lines (point-min) (point-max))) | ||
| 983 | (completions (Man-parse-man-k))) | ||
| 984 | (if (>= (length completions) lines) | ||
| 985 | '("-k") ;; "-k" seems to return sane results: look no further! | ||
| 986 | (erase-buffer) | ||
| 987 | ;; Try "-k -l" (bug#73656). | ||
| 988 | (with-demoted-errors "%S" (call-process "man" nil t nil | ||
| 989 | "-k" "-l" "apropos")) | ||
| 990 | (let ((lines (count-lines (point-min) (point-max))) | ||
| 991 | (completions (Man-parse-man-k))) | ||
| 992 | (if (and (> lines 0) (>= (length completions) lines)) | ||
| 993 | '("-k" "-l") ;; "-k -l" seems to return sane results. | ||
| 994 | '("-k")))))) | ||
| 995 | "List of arguments to pass to get the expected \"man -k\" output.") | ||
| 996 | |||
| 976 | (defun Man-completion-table (string pred action) | 997 | (defun Man-completion-table (string pred action) |
| 977 | (cond | 998 | (cond |
| 978 | ;; This ends up returning t for pretty much any string, and hence leads to | 999 | ;; This ends up returning t for pretty much any string, and hence leads to |
| @@ -1007,9 +1028,13 @@ foo(sec)[, bar(sec) [, ...]] [other stuff] - description" | |||
| 1007 | ;; error later. | 1028 | ;; error later. |
| 1008 | (when (eq 0 | 1029 | (when (eq 0 |
| 1009 | (ignore-errors | 1030 | (ignore-errors |
| 1010 | (process-file | 1031 | (apply |
| 1032 | #'process-file | ||
| 1011 | manual-program nil '(t nil) nil | 1033 | manual-program nil '(t nil) nil |
| 1012 | "-k" (concat (when (or Man-man-k-use-anchor | 1034 | ;; FIXME: When `process-file' runs on a remote hosts, |
| 1035 | ;; `Man-man-k-flags' may be wrong. | ||
| 1036 | `(,@Man-man-k-flags | ||
| 1037 | ,(concat (when (or Man-man-k-use-anchor | ||
| 1013 | (string-equal prefix "")) | 1038 | (string-equal prefix "")) |
| 1014 | "^") | 1039 | "^") |
| 1015 | (if (string-equal prefix "") | 1040 | (if (string-equal prefix "") |
| @@ -1021,7 +1046,7 @@ foo(sec)[, bar(sec) [, ...]] [other stuff] - description" | |||
| 1021 | ;; But we don't have that, and | 1046 | ;; But we don't have that, and |
| 1022 | ;; shell-quote-argument does | 1047 | ;; shell-quote-argument does |
| 1023 | ;; the job... | 1048 | ;; the job... |
| 1024 | (shell-quote-argument prefix)))))) | 1049 | (shell-quote-argument prefix))))))) |
| 1025 | (setq table (Man-parse-man-k))))) | 1050 | (setq table (Man-parse-man-k))))) |
| 1026 | ;; Cache the table for later reuse. | 1051 | ;; Cache the table for later reuse. |
| 1027 | (when table | 1052 | (when table |