1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-03 08:30:09 +00:00

Allow searching for regexps with a prefix

* doc/misc/info.texi (Search Index): Mention it.

* lisp/info.el (Info-find-node): Allow not signalling errors.
(Info-apropos-matches): Allow taking a regexp.
(info-apropos): Prefix now means looking for a regexp.
This commit is contained in:
Lars Ingebrigtsen 2022-04-21 17:05:23 +02:00
parent 11f66e16ac
commit f3a02858dc
3 changed files with 29 additions and 15 deletions

View File

@ -1083,7 +1083,9 @@ If you aren't sure which manual documents the topic you are looking
for, try the @kbd{M-x info-apropos} command in Emacs, or the @kbd{M-x
index-apropos} command in the stand-alone reader. It prompts for
a string and then looks up that string in all the indices of all the
Info documents installed on your system.
Info documents installed on your system. In Emacs, giving a prefix
argument to the command will try to search for a regular expression
instead of a string.
@node Go to node
@section @kbd{g} goes to a node by name

View File

@ -763,6 +763,9 @@ This fills the region to be no wider than a specified pixel width.
** Info
+++
*** 'M-x info-apropos' now takes a prefix argument to search for regexps.
---
*** New command 'Info-goto-node-web' and key binding 'G'.
This will take you to the gnu.org web server's version of the current

View File

@ -907,17 +907,20 @@ find a node."
filename)))
filename))))
(defun Info-find-node (filename nodename &optional no-going-back strict-case)
(defun Info-find-node (filename nodename &optional no-going-back strict-case
noerror)
"Go to an Info node specified as separate FILENAME and NODENAME.
NO-GOING-BACK is non-nil if recovering from an error in this function;
it says do not attempt further (recursive) error recovery.
This function first looks for a case-sensitive match for NODENAME;
if none is found it then tries a case-insensitive match (unless
STRICT-CASE is non-nil)."
STRICT-CASE is non-nil).
If NOERROR, inhibit error messages when we can't find the node."
(info-initialize)
(setq nodename (info--node-canonicalize-whitespace nodename))
(setq filename (Info-find-file filename))
(setq filename (Info-find-file filename noerror))
;; Go into Info buffer.
(or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
;; Record the node we are leaving, if we were in one.
@ -3613,13 +3616,16 @@ MATCHES is a list of index matches found by `Info-apropos-matches'.")
(format " (line %s)" (nth 3 entry))
"")))))))))
(defun Info-apropos-matches (string)
(defun Info-apropos-matches (string &optional regexp)
"Collect STRING matches from all known Info files on your system.
If REGEXP, use regexp matching instead of literal matching.
Return a list of matches where each element is in the format
\((FILENAME INDEXTEXT NODENAME LINENUMBER))."
(unless (string= string "")
(let ((pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
(regexp-quote string)))
(if regexp
string
(regexp-quote string))))
(ohist Info-history)
(ohist-list Info-history-list)
(current-node Info-current-node)
@ -3644,9 +3650,9 @@ Return a list of matches where each element is in the format
(dolist (manual (nreverse manuals))
(message "Searching %s" manual)
(condition-case err
(if (setq nodes (Info-index-nodes (Info-find-file manual)))
(if (setq nodes (Info-index-nodes (Info-find-file manual t)))
(save-excursion
(Info-find-node manual (car nodes))
(Info-find-node manual (car nodes) nil nil t)
(while
(progn
(goto-char (point-min))
@ -3673,19 +3679,22 @@ Return a list of matches where each element is in the format
(or (nreverse matches) t))))
;;;###autoload
(defun info-apropos (string)
"Grovel indices of all known Info files on your system for STRING.
Build a menu of the possible matches."
(interactive "sIndex apropos: ")
(defun info-apropos (string &optional regexp)
"Search indices of all known Info files on your system for STRING.
If REGEXP (interactively, the prefix), use a regexp match.
Display a menu of the possible matches."
(interactive "sIndex apropos: \nP")
(if (equal string "")
(Info-find-node Info-apropos-file "Top")
(let* ((nodes Info-apropos-nodes) nodename)
(let ((nodes Info-apropos-nodes)
nodename)
(while (and nodes (not (equal string (nth 1 (car nodes)))))
(setq nodes (cdr nodes)))
(if nodes
(Info-find-node Info-apropos-file (car (car nodes)))
(Info-find-node Info-apropos-file (car (car nodes)) nil nil t)
(setq nodename (format "Index for %s" string))
(push (list nodename string (Info-apropos-matches string))
(push (list nodename string (Info-apropos-matches string regexp))
Info-apropos-nodes)
(Info-find-node Info-apropos-file nodename)))))