From: Lars Ingebrigtsen Date: Thu, 21 Apr 2022 15:05:23 +0000 (+0200) Subject: Allow searching for regexps with a prefix X-Git-Tag: emacs-29.0.90~1931^2~371 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f3a02858dccbac36bbf0fb19a29fab59013a56a0;p=emacs.git 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. --- diff --git a/doc/misc/info.texi b/doc/misc/info.texi index 6ebf60ce360..4db35ebf0fc 100644 --- a/doc/misc/info.texi +++ b/doc/misc/info.texi @@ -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 diff --git a/etc/NEWS b/etc/NEWS index 3442ebd81b3..36db29bbbeb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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 diff --git a/lisp/info.el b/lisp/info.el index 380a8e2780d..8ca6c549791 100644 --- a/lisp/info.el +++ b/lisp/info.el @@ -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)))))