Subject: Re: bug#14015: Feature request: highlight partial matches in Info's index-search

From: Juri Linkov <[email-masked]>
Date: Fri, 22 Mar 2013 00:31:56 +0200

> When 'i foo RET' yields a partial match, e.g., finding "foobar" in the
> index, the stand-alone Info reader "highlights" the part that matched,
> like this:
>
>    Found FOObar in Some Node. (`,' tries to find next.)
>
> (The stand-alone reader is a text-mode program, so it changes the
> letter-case to emphasize the part that matched.)
>
> It would be nice if Emacs did something similar, although it is
> probably better to use colors if available.

info-look.el uses the following face to highlight found matches
in the Info reader:

  (defcustom info-lookup-highlight-face 'match
    "Face for highlighting looked up help items.
  Setting this variable to nil disables highlighting."
    :group 'info-lookup :type 'face)

Adding a similar face option to highlight the text matched by `Info-index'
will change the output of `Info-virtual-index' and `info-apropos'
to look exactly the same like as output of `occur' that is good
for consistency of the UI.  This is in addition to highlighting
the matches in the each area that you asked for:

=== modified file 'lisp/info.el'
--- lisp/info.el	2013-03-20 23:04:40 +0000
+++ lisp/info.el	2013-03-21 22:30:34 +0000
@@ -158,6 +158,13 @@ (defface info-header-node
   "Face for Info nodes in a node header."
   :group 'info)
 
+(defcustom Info-index-match-face 'match
+  "Face used by \\[Info-index] to show the text that matches.
+If the value is nil, don't highlight the matching portions specially."
+  :type 'face
+  :group 'info
+  :version "24.4")
+
 ;; This is a defcustom largely so that we can get the benefit
 ;; of custom-initialize-delay.  Perhaps it would work to make it a
 ;; defvar and explicitly give it a standard-value property, and
@@ -3295,12 +3302,14 @@ (defun Info-index (topic)
 	      (progn
 		(goto-char (point-min))
 		(while (re-search-forward pattern nil t)
-		  (push (list (match-string-no-properties 1)
-			      (match-string-no-properties 2)
-			      Info-current-node
-			      (string-to-number (concat "0"
-							(match-string 3))))
-			matches))
+		  (let ((entry (match-string-no-properties 1))
+			(nodename (match-string-no-properties 2))
+			(line (string-to-number (concat "0" (match-string 3)))))
+		    (when (and Info-index-match-face
+			       (string-match (regexp-quote topic) entry))
+		      (add-text-properties (match-beginning 0) (match-end 0)
+					   `(face ,Info-index-match-face) entry))
+		    (push (list entry nodename Info-current-node line) matches)))
 		(setq nodes (cdr nodes) node (car nodes)))
 	    (Info-goto-node node))
 	  (or matches
@@ -3559,12 +3568,15 @@ (defun Info-apropos-matches (string)
                         (progn
                           (goto-char (point-min))
                           (while (re-search-forward pattern nil t)
-			    (setq matches
-				  (cons (list manual
-					      (match-string-no-properties 1)
-					      (match-string-no-properties 2)
-					      (match-string-no-properties 3))
-					matches)))
+			    (let ((entry (match-string-no-properties 1))
+				  (nodename (match-string-no-properties 2))
+				  (line (match-string-no-properties 3)))
+			      (when (and Info-index-match-face
+					 (string-match (regexp-quote string) entry))
+				(add-text-properties (match-beginning 0) (match-end 0)
+						     `(face ,Info-index-match-face) entry))
+			      (setq matches (cons (list manual entry nodename line)
+						  matches))))
                           (setq nodes (cdr nodes) node (car nodes)))
                       (Info-goto-node node))))
 	    (error