From: Phil Sainty <psainty@orcon.net.nz>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 53935@debbugs.gnu.org
Subject: bug#53935: 27.2; [PATCH] ecomplete.el: Auto-select when there is only a single option
Date: Fri, 11 Feb 2022 23:24:15 +1300 [thread overview]
Message-ID: <009c72c3522443ee13e5a276fdb26d4f@webmail.orcon.net.nz> (raw)
In-Reply-To: <1800d942d3cdf963c15cd970ba64bd37@webmail.orcon.net.nz>
[-- Attachment #1: Type: text/plain, Size: 223 bytes --]
I realised this would be better with some minor refactoring of
the existing code, so I'm attaching a new version of that patch.
I've used "git diff --ignore-space-change" for clarity (hence the
indentation isn't correct).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ecomplete-auto-select2.patch --]
[-- Type: text/x-diff; name=ecomplete-auto-select2.patch, Size: 2466 bytes --]
diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el
index 260657e0f7..ad3cf199e7 100644
--- a/lisp/ecomplete.el
+++ b/lisp/ecomplete.el
@@ -149,10 +149,14 @@ ecomplete-get-matches
(defun ecomplete-display-matches (type word &optional choose)
"Display the top-rated elements TYPE that match WORD.
If CHOOSE, allow the user to choose interactively between the
-matches."
+matches.
+
+Auto-select when `ecomplete-message-display-abbrev-auto-select' is
+non-nil and there is only a single completion option available."
(let* ((matches (ecomplete-get-matches type word))
+ (match-list (and matches (split-string matches "\n")))
+ (max-lines (and matches (- (length match-list) 2)))
(line 0)
- (max-lines (when matches (- (length (split-string matches "\n")) 2)))
(message-log-max nil)
command highlight)
(if (not matches)
@@ -163,25 +167,30 @@ ecomplete-display-matches
(progn
(message "%s" matches)
nil)
- (setq highlight (ecomplete-highlight-match-line matches line))
+ (if (and ecomplete-message-display-abbrev-auto-select
+ (eql 0 max-lines))
+ ;; Auto-select when only one option is available.
+ (nth 0 match-list)
+ ;; Interactively choose from the filtered completions.
(let ((local-map (make-sparse-keymap))
(prev-func (lambda () (setq line (max (1- line) 0))))
(next-func (lambda () (setq line (min (1+ line) max-lines))))
selected)
(define-key local-map (kbd "RET")
- (lambda () (setq selected (nth line (split-string matches "\n")))))
+ (lambda () (setq selected (nth line match-list))))
(define-key local-map (kbd "M-n") next-func)
(define-key local-map (kbd "<down>") next-func)
(define-key local-map (kbd "M-p") prev-func)
(define-key local-map (kbd "<up>") prev-func)
(let ((overriding-local-map local-map))
+ (setq highlight (ecomplete-highlight-match-line matches line))
(while (and (null selected)
(setq command (read-key-sequence highlight))
(lookup-key local-map command))
(apply (key-binding command) nil)
(setq highlight (ecomplete-highlight-match-line matches line))))
(message (or selected "Abort"))
- selected)))))
+ selected))))))
(defun ecomplete-highlight-match-line (matches line)
(with-temp-buffer
next prev parent reply other threads:[~2022-02-11 10:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-11 2:47 bug#53935: 27.2; [PATCH] ecomplete.el: Auto-select when there is only a single option Phil Sainty
2022-02-11 6:30 ` Lars Ingebrigtsen
2022-02-11 8:28 ` Phil Sainty
2022-02-11 10:24 ` Phil Sainty [this message]
2022-09-08 12:53 ` Lars Ingebrigtsen
2022-02-12 6:49 ` Lars Ingebrigtsen
2022-02-12 10:27 ` Phil Sainty
2022-02-13 8:14 ` Lars Ingebrigtsen
2022-02-13 17:24 ` bug#53935: [External] : " Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=009c72c3522443ee13e5a276fdb26d4f@webmail.orcon.net.nz \
--to=psainty@orcon.net.nz \
--cc=53935@debbugs.gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.