[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
- [nongnu] scratch/rfc-mode 476bff817d 42/52: Don't turn the beginning of every page into a button, (continued)
- [nongnu] scratch/rfc-mode 476bff817d 42/52: Don't turn the beginning of every page into a button, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 6e41dcd82f 43/52: Autoload rfc-mode-browse, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode e21fb7e134 05/52: fix comment, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode c550aa0530 03/52: v1.0.0, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode ff7a36b810 44/52: Offer number at point as default in rfc-mode-read, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 3a7afa19e7 08/52: make some functions private, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode ea349f3441 41/52: Improve doc-strings, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 0f95e3f79b 21/52: fix mode detection regexp, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 8587416c21 40/52: Add prefix argument support to rfc-mode-read, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 3ef663203b 51/52: Consistently use spaces for indentation, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode b885d6bd2b 50/52: Fix completing-read default argument,
Stefan Monnier <=
- [nongnu] scratch/rfc-mode 21c966a02c 47/52: update changelog, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 697158dc0f 45/52: Extract rfc-mode--integer-at-point from rfc-mode-read, Stefan Monnier, 2022/10/12
- [nongnu] scratch/rfc-mode 5d0c8096b2 48/52: * rfc-mode.el: Explicitly load cl-lib dependency., Stefan Monnier, 2022/10/12