aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2001-03-06 13:42:06 +0000
committerEli Zaretskii2001-03-06 13:42:06 +0000
commitfb925bd896938768c4b9214687ba8fcdcedef812 (patch)
tree01ca2fc8decf85919d3d821625c6506e67059c1e
parentdaecec4e85e10d2ef83649712a0fa429286d836c (diff)
downloademacs-fb925bd896938768c4b9214687ba8fcdcedef812.tar.gz
emacs-fb925bd896938768c4b9214687ba8fcdcedef812.zip
(Man-hyphenated-reference-regexp): New variable.
(Man-build-references-alist): Use it to search for referenced manpages. If hyphenated is non-nil, record a concatenated word in Man-refpages-alist only if it matches Man-reference-regexp. Update word's length when it is concatenated. Reverse the list, to get the first manpage at the head. (Man-possibly-hyphenated-word): New function. (Man-follow-manual-reference): Use it instead of current-word to find a manpage at point, in a way that accounts for hyphenated references.
-rw-r--r--lisp/man.el62
1 files changed, 45 insertions, 17 deletions
diff --git a/lisp/man.el b/lisp/man.el
index 406085a094f..2454b48ded9 100644
--- a/lisp/man.el
+++ b/lisp/man.el
@@ -276,6 +276,12 @@ This regular expression should start with a `^' character.")
276 276
277(defvar Man-reference-regexp 277(defvar Man-reference-regexp
278 (concat "\\(" Man-name-regexp "\\)(\\(" Man-section-regexp "\\))") 278 (concat "\\(" Man-name-regexp "\\)(\\(" Man-section-regexp "\\))")
279 "Regular expression describing a reference to another manpage.")
280
281;; This includes the section as an optional part to catch hyphenated
282;; refernces to manpages.
283(defvar Man-hyphenated-reference-regexp
284 (concat "\\(" Man-name-regexp "\\)\\((\\(" Man-section-regexp "\\))\\)?")
279 "Regular expression describing a reference in the SEE ALSO section.") 285 "Regular expression describing a reference in the SEE ALSO section.")
280 286
281(defvar Man-switches "" 287(defvar Man-switches ""
@@ -887,16 +893,21 @@ The following key bindings are currently in effect in the buffer:
887 (back-to-indentation) 893 (back-to-indentation)
888 (while (and (not (eobp)) (/= (point) runningpoint)) 894 (while (and (not (eobp)) (/= (point) runningpoint))
889 (setq runningpoint (point)) 895 (setq runningpoint (point))
890 (if (re-search-forward Man-reference-regexp end t) 896 (if (re-search-forward Man-hyphenated-reference-regexp end t)
891 (let* ((word (Man-match-substring 0)) 897 (let* ((word (Man-match-substring 0))
892 (len (1- (length word)))) 898 (len (1- (length word))))
893 (if hyphenated 899 (if hyphenated
894 (setq word (concat hyphenated word) 900 (setq word (concat hyphenated word)
895 hyphenated nil)) 901 hyphenated nil
902 ;; Update len, in case a reference spans
903 ;; more than two lines (paranoia).
904 len (1- (length word))))
896 (if (= (aref word len) ?-) 905 (if (= (aref word len) ?-)
897 (setq hyphenated (substring word 0 len)) 906 (setq hyphenated (substring word 0 len)))
898 (aput 'Man-refpages-alist word)))) 907 (if (string-match Man-reference-regexp word)
899 (skip-chars-forward " \t\n,"))))))) 908 (aput 'Man-refpages-alist word))))
909 (skip-chars-forward " \t\n,"))))))
910 (setq Man-refpages-alist (nreverse Man-refpages-alist)))
900 911
901(defun Man-build-page-list () 912(defun Man-build-page-list ()
902 "Build the list of separate manpages in the buffer." 913 "Build the list of separate manpages in the buffer."
@@ -1052,6 +1063,26 @@ Actually the section moved to is described by `Man-see-also-regexp'."
1052 (error (concat "No " Man-see-also-regexp 1063 (error (concat "No " Man-see-also-regexp
1053 " section found in the current manpage")))) 1064 " section found in the current manpage"))))
1054 1065
1066(defun Man-possibly-hyphenated-word ()
1067 "Return a possibly hyphenated word at point.
1068If the word starts at the first non-whitespace column, and the
1069previous line ends with a hyphen, return the last word on the previous
1070line instead. Thus, if a reference to \"tcgetpgrp(3V)\" is hyphenated
1071as \"tcgetp-grp(3V)\", and point is at \"grp(3V)\", we return
1072\"tcgetp-\" instead of \"grp\"."
1073 (save-excursion
1074 (skip-syntax-backward "w()")
1075 (skip-chars-forward " \t")
1076 (let ((beg (point))
1077 (word (current-word)))
1078 (when (eq beg (save-excursion
1079 (back-to-indentation)
1080 (point)))
1081 (end-of-line 0)
1082 (if (eq (char-before) ?-)
1083 (setq word (current-word))))
1084 word)))
1085
1055(defun Man-follow-manual-reference (reference) 1086(defun Man-follow-manual-reference (reference)
1056 "Get one of the manpages referred to in the \"SEE ALSO\" section. 1087 "Get one of the manpages referred to in the \"SEE ALSO\" section.
1057Specify which REFERENCE to use; default is based on word at point." 1088Specify which REFERENCE to use; default is based on word at point."
@@ -1059,18 +1090,15 @@ Specify which REFERENCE to use; default is based on word at point."
1059 (if (not Man-refpages-alist) 1090 (if (not Man-refpages-alist)
1060 (error "There are no references in the current man page") 1091 (error "There are no references in the current man page")
1061 (list (let* ((default (or 1092 (list (let* ((default (or
1062 (car (all-completions 1093 (car (all-completions
1063 (save-excursion 1094 (let ((word (Man-possibly-hyphenated-word)))
1064 (skip-syntax-backward "w()") 1095 ;; strip a trailing '-':
1065 (skip-chars-forward " \t") 1096 (if (string-match "-$" word)
1066 (let ((word (current-word))) 1097 (substring word 0
1067 ;; strip a trailing '-': 1098 (match-beginning 0))
1068 (if (string-match "-$" word) 1099 word))
1069 (substring word 0 1100 Man-refpages-alist))
1070 (match-beginning 0)) 1101 (aheadsym Man-refpages-alist)))
1071 word)))
1072 Man-refpages-alist))
1073 (aheadsym Man-refpages-alist)))
1074 chosen 1102 chosen
1075 (prompt (concat "Refer to: (default " default ") "))) 1103 (prompt (concat "Refer to: (default " default ") ")))
1076 (setq chosen (completing-read prompt Man-refpages-alist nil t)) 1104 (setq chosen (completing-read prompt Man-refpages-alist nil t))