mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-25 10:47:00 +00:00
(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.
This commit is contained in:
parent
daecec4e85
commit
fb925bd896
46
lisp/man.el
46
lisp/man.el
@ -276,6 +276,12 @@ This regular expression should start with a `^' character.")
|
||||
|
||||
(defvar Man-reference-regexp
|
||||
(concat "\\(" Man-name-regexp "\\)(\\(" Man-section-regexp "\\))")
|
||||
"Regular expression describing a reference to another manpage.")
|
||||
|
||||
;; This includes the section as an optional part to catch hyphenated
|
||||
;; refernces to manpages.
|
||||
(defvar Man-hyphenated-reference-regexp
|
||||
(concat "\\(" Man-name-regexp "\\)\\((\\(" Man-section-regexp "\\))\\)?")
|
||||
"Regular expression describing a reference in the SEE ALSO section.")
|
||||
|
||||
(defvar Man-switches ""
|
||||
@ -887,16 +893,21 @@ The following key bindings are currently in effect in the buffer:
|
||||
(back-to-indentation)
|
||||
(while (and (not (eobp)) (/= (point) runningpoint))
|
||||
(setq runningpoint (point))
|
||||
(if (re-search-forward Man-reference-regexp end t)
|
||||
(if (re-search-forward Man-hyphenated-reference-regexp end t)
|
||||
(let* ((word (Man-match-substring 0))
|
||||
(len (1- (length word))))
|
||||
(if hyphenated
|
||||
(setq word (concat hyphenated word)
|
||||
hyphenated nil))
|
||||
hyphenated nil
|
||||
;; Update len, in case a reference spans
|
||||
;; more than two lines (paranoia).
|
||||
len (1- (length word))))
|
||||
(if (= (aref word len) ?-)
|
||||
(setq hyphenated (substring word 0 len))
|
||||
(setq hyphenated (substring word 0 len)))
|
||||
(if (string-match Man-reference-regexp word)
|
||||
(aput 'Man-refpages-alist word))))
|
||||
(skip-chars-forward " \t\n,")))))))
|
||||
(skip-chars-forward " \t\n,"))))))
|
||||
(setq Man-refpages-alist (nreverse Man-refpages-alist)))
|
||||
|
||||
(defun Man-build-page-list ()
|
||||
"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'."
|
||||
(error (concat "No " Man-see-also-regexp
|
||||
" section found in the current manpage"))))
|
||||
|
||||
(defun Man-possibly-hyphenated-word ()
|
||||
"Return a possibly hyphenated word at point.
|
||||
If the word starts at the first non-whitespace column, and the
|
||||
previous line ends with a hyphen, return the last word on the previous
|
||||
line instead. Thus, if a reference to \"tcgetpgrp(3V)\" is hyphenated
|
||||
as \"tcgetp-grp(3V)\", and point is at \"grp(3V)\", we return
|
||||
\"tcgetp-\" instead of \"grp\"."
|
||||
(save-excursion
|
||||
(skip-syntax-backward "w()")
|
||||
(skip-chars-forward " \t")
|
||||
(let ((beg (point))
|
||||
(word (current-word)))
|
||||
(when (eq beg (save-excursion
|
||||
(back-to-indentation)
|
||||
(point)))
|
||||
(end-of-line 0)
|
||||
(if (eq (char-before) ?-)
|
||||
(setq word (current-word))))
|
||||
word)))
|
||||
|
||||
(defun Man-follow-manual-reference (reference)
|
||||
"Get one of the manpages referred to in the \"SEE ALSO\" section.
|
||||
Specify which REFERENCE to use; default is based on word at point."
|
||||
@ -1060,15 +1091,12 @@ Specify which REFERENCE to use; default is based on word at point."
|
||||
(error "There are no references in the current man page")
|
||||
(list (let* ((default (or
|
||||
(car (all-completions
|
||||
(save-excursion
|
||||
(skip-syntax-backward "w()")
|
||||
(skip-chars-forward " \t")
|
||||
(let ((word (current-word)))
|
||||
(let ((word (Man-possibly-hyphenated-word)))
|
||||
;; strip a trailing '-':
|
||||
(if (string-match "-$" word)
|
||||
(substring word 0
|
||||
(match-beginning 0))
|
||||
word)))
|
||||
word))
|
||||
Man-refpages-alist))
|
||||
(aheadsym Man-refpages-alist)))
|
||||
chosen
|
||||
|
Loading…
Reference in New Issue
Block a user