]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve completion in `C-h R'
authorLars Ingebrigtsen <larsi@gnus.org>
Sat, 16 Apr 2022 14:35:57 +0000 (16:35 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 16 Apr 2022 14:35:57 +0000 (16:35 +0200)
* lisp/info.el (info-display-manual): Use it (bug#54961).
(info--filter-manual-names): Filter away duplicates and irrelevant
files.

lisp/info.el

index db95574bf727339f94fa51c69673f4015135aa5e..ac4169b55040446bb89d71699db3ba4b6a7a49fd 100644 (file)
@@ -5440,7 +5440,8 @@ completion alternatives to currently visited manuals."
     (progn
       (info-initialize)
       (completing-read "Manual name: "
-                      (info--manual-names current-prefix-arg)
+                      (info--filter-manual-names
+                        (info--manual-names current-prefix-arg))
                       nil t))))
   (let ((blist (buffer-list))
        (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
@@ -5468,6 +5469,22 @@ completion alternatives to currently visited manuals."
       (info (Info-find-file manual)
            (generate-new-buffer-name "*info*")))))
 
+(defun info--filter-manual-names (names)
+  (cl-flet ((strip (name)
+              (replace-regexp-in-string "\\([-.]info\\)?\\(\\.gz\\)?\\'"
+                                        "" name)))
+    (seq-uniq (sort (seq-filter
+                     (lambda (name)
+                       (and (not (string-match-p "info-[0-9]" name))
+                            (not (member name '("./" "../" "ChangeLog"
+                                                "NEWS" "README")))))
+                     names)
+                    ;; We prefer the shorter names ("foo" over "foo.gz").
+                    (lambda (s1 s2)
+                      (< (length s1) (length s2))))
+              (lambda (s1 s2)
+                (equal (strip s1) (strip s2))))))
+
 (defun info--manual-names (visited-only)
   (let (names)
     (dolist (buffer (buffer-list))