emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] scratch/rfc-mode b885d6bd2b 50/52: Fix completing-read default


From: Stefan Monnier
Subject: [nongnu] scratch/rfc-mode b885d6bd2b 50/52: Fix completing-read default argument
Date: Wed, 12 Oct 2022 16:29:21 -0400 (EDT)

branch: scratch/rfc-mode
commit b885d6bd2b3be69a2413c4dc5cc34344d821cba2
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Nicolas Martyanoff <khaelin@gmail.com>

    Fix completing-read default argument
    
    * rfc-mode.el (rfc-mode-browse): Don't pass a numeric 'default'
    argument for completing-read to rfc-mode-browser-format-candidate,
    which expects a plist argument.  Instead, use the appropriate
    completion candidate as the default.  Also fix a thinko in the
    subsequent error message, and reuse rfc-mode-reload-index.
    
    Fixes #15.
---
 rfc-mode.el | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/rfc-mode.el b/rfc-mode.el
index a773b5e7b5..70c356b9a2 100644
--- a/rfc-mode.el
+++ b/rfc-mode.el
@@ -240,8 +240,7 @@ Offer the number at point as default."
   (interactive)
   (rfc-mode--fetch-document "-index" (rfc-mode-index-path))
   (unless rfc-mode-index-entries
-    (setq rfc-mode-index-entries
-          (rfc-mode-read-index-file (rfc-mode-index-path))))
+    (rfc-mode-reload-index))
   (pcase rfc-mode-browse-input-function
     ('read-number
      (display-buffer (rfc-mode--document-buffer
@@ -256,19 +255,22 @@ Offer the number at point as default."
        (user-error "Helm has to be installed explicitly")))
     ('completing-read
      (let* ((default (rfc-mode--integer-at-point))
-           (choice (completing-read
-                    "View RFC document: "
-                    (mapcar #'rfc-mode-browser-format-candidate
-                            rfc-mode-index-entries)
-                    nil nil nil nil
-                    (and default
-                         (rfc-mode-browser-format-candidate default))))
+            (cands (mapcar (lambda (entry)
+                             (let ((cand
+                                    (rfc-mode-browser-format-candidate entry)))
+                               (and (numberp default)
+                                    (= (plist-get entry :number) default)
+                                    (setq default (car cand)))
+                               cand))
+                           rfc-mode-index-entries))
+            (choice (completing-read "View RFC document: "
+                                     cands nil nil nil nil default))
            (number (or (and (string-match "\\`RFC\\([0-9]+\\)" choice)
                             (string-to-number (match-string 1 choice)))
                        (ignore-errors (string-to-number choice)))))
        (unless number
         (user-error
-         "%s doesn't match a complication candidate and is not a number"
+          "%s doesn't match a completion candidate and is not a number"
          choice))
        (display-buffer (rfc-mode--document-buffer number))))
     (_ (display-buffer (rfc-mode--document-buffer



reply via email to

[Prev in Thread] Current Thread [Next in Thread]