[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: new-flex-completion-style
From: |
João Távora |
Subject: |
Re: new-flex-completion-style |
Date: |
Mon, 18 Feb 2019 20:46:19 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Stefan Monnier <address@hidden> writes:
> How 'bout we change the buffer name completion table so it specifies its
> own cycle-sort-function which uses buffer-list, then. It seems like it
> would be a clear win (the buffer-list order is a much better heuristic
> than the length).
Hi again,
Here are two patches: the first does exactly what you propose above, the
second goes a little bit further, but I still think it's the right
thing...
Lightly tested stuff...
João
>From f170e728c1c1ac426bb73c63cc54ba2ae30afd1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= <address@hidden>
Date: Mon, 18 Feb 2019 20:32:38 +0000
Subject: [PATCH 1/2] switch-to-buffer's completion table uses its own sorting
* src/minibuf.c (Finternal_complete_buffer): Add
Qcycle_sort_function to completion table's metadata.
(syms_of_minibuf): New symbol Qcycle_sort_function.
---
src/minibuf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/minibuf.c b/src/minibuf.c
index 321fda1ba8..b23e24c4bd 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -1801,7 +1801,9 @@ If FLAG is nil, invoke `try-completion'; if it is t,
invoke
else if (EQ (flag, Qlambda))
return Ftest_completion (string, Vbuffer_alist, predicate);
else if (EQ (flag, Qmetadata))
- return list2 (Qmetadata, Fcons (Qcategory, Qbuffer));
+ return list3 (Qmetadata,
+ Fcons (Qcategory, Qbuffer),
+ Fcons (Qcycle_sort_function, Qidentity));
else
return Qnil;
}
@@ -1922,6 +1924,8 @@ syms_of_minibuf (void)
DEFSYM (Qactivate_input_method, "activate-input-method");
DEFSYM (Qcase_fold_search, "case-fold-search");
DEFSYM (Qmetadata, "metadata");
+ DEFSYM (Qcycle_sort_function, "cycle-sort-function");
+
/* A frame parameter. */
DEFSYM (Qminibuffer_exit, "minibuffer-exit");
--
2.20.0
>From f8ce65482d86a136f1320dac89e71662256c2168 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= <address@hidden>
Date: Mon, 18 Feb 2019 20:41:09 +0000
Subject: [PATCH 2/2] cycle-sort-function prevails in
completion-all-sorted-completions
* lisp/minibuffer.el (completion-all-sorted-completions): Don't
re-sort if completion table has cycle-sort-function.
---
lisp/minibuffer.el | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 7413be42eb..cc87ffaced 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1246,20 +1246,23 @@ completion-all-sorted-completions
(setq all (delete-dups all))
(setq last (last all))
- (setq all (if sort-fun (funcall sort-fun all)
- ;; Prefer shorter completions, by default.
- (sort all (lambda (c1 c2) (< (length c1) (length c2))))))
- ;; Prefer recently used completions and put the default, if
- ;; it exists, on top.
- (when (minibufferp)
- (let ((hist (symbol-value minibuffer-history-variable)))
- (setq all (sort all
+ (cond
+ (sort-fun
+ (setq all (funcall sort-fun all)))
+ (t
+ ;; Prefer shorter completions, by default.
+ (setq all (sort all (lambda (c1 c2) (< (length c1) (length c2)))))
+ (when (minibufferp)
+ ;; Prefer recently used completions and put the default, if
+ ;; it exists, on top.
+ (let ((hist (symbol-value minibuffer-history-variable)))
+ (setq all
+ (sort all
(lambda (c1 c2)
(cond ((equal c1 minibuffer-default) t)
((equal c2 minibuffer-default) nil)
(t (> (length (member c1 hist))
- (length (member c2 hist))))))))))
+ (length (member c2 hist))))))))))))
;; Cache the result. This is not just for speed, but also so that
;; repeated calls to minibuffer-force-complete can cycle through
;; all possibilities.
--
2.20.0
- Re: new-flex-completion-style, (continued)
- Re: new-flex-completion-style, João Távora, 2019/02/14
- RE: new-flex-completion-style, Drew Adams, 2019/02/14
- Re: new-flex-completion-style, João Távora, 2019/02/14
- RE: new-flex-completion-style, Drew Adams, 2019/02/14
- Re: new-flex-completion-style, João Távora, 2019/02/14
- Re: new-flex-completion-style, Stefan Monnier, 2019/02/14
- RE: new-flex-completion-style, Drew Adams, 2019/02/14
- Re: new-flex-completion-style, Stefan Monnier, 2019/02/14
- Re: new-flex-completion-style, Dmitry Gutov, 2019/02/15
- RE: new-flex-completion-style, Drew Adams, 2019/02/15
- Re: new-flex-completion-style,
João Távora <=
- Re: new-flex-completion-style, Stefan Monnier, 2019/02/18
- Re: new-flex-completion-style, João Távora, 2019/02/19
- Re: new-flex-completion-style, Stefan Monnier, 2019/02/19
- Re: new-flex-completion-style, João Távora, 2019/02/19
- Re: new-flex-completion-style, Stefan Monnier, 2019/02/19
RE: new-flex-completion-style (was: [Emacs-diffs] scratch/ 2c75775 2/2: Score, sort and annotate flex-style completions according to match tightness), Drew Adams, 2019/02/11