From d1bc95b3a4ab4ddfcb8c97104e1a2dbb306ea515 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 16 Apr 2022 16:35:57 +0200 Subject: [PATCH] Improve completion in `C-h R' * lisp/info.el (info-display-manual): Use it (bug#54961). (info--filter-manual-names): Filter away duplicates and irrelevant files. --- lisp/info.el | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lisp/info.el b/lisp/info.el index db95574bf72..ac4169b5504 100644 --- a/lisp/info.el +++ b/lisp/info.el @@ -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))