GNU bug report logs -
#74561
[PATCH] Allow limiting the size of *Completions*
Previous Next
Reported by: Spencer Baugh <sbaugh <at> janestreet.com>
Date: Wed, 27 Nov 2024 20:26:02 UTC
Severity: wishlist
Tags: patch
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Fri, 21 Mar 2025 17:26:06 -0400
with message-id <jwva59e2i0i.fsf-monnier+emacs <at> gnu.org>
and subject line Re: bug#74561: [PATCH] Allow limiting the size of *Completions*
has caused the debbugs.gnu.org bug report #74561,
regarding [PATCH] Allow limiting the size of *Completions*
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
74561: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=74561
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
Tags: patch
From profiling, the main bottleneck in completion over large
completion sets is display-completion-list, when there are many
available candidates. For example, in my large monorepo, when
completing over the 589196 files or the 73897 branches, even with the
candidates narrowed down by typing some prefix to complete, TAB (when
it shows *Completions*) or ? is slow, mostly in
display-completion-list.
By adding completions-list-max with a very large default, performance
is greatly improved in these situations without impacting the normal
case of completion on reasonably sized sets.
Limiting the work done by display-completion-list is also important
for packages which auto-update *Completions* inside while-no-input:
since display-completion-list doesn't do anything which reads input,
while-no-input won't interrupt it. Such packages can instead just
bind completions-list-max to a smaller value.
* lisp/minibuffer.el (display-completion-list): Add FULL-COUNT
argument.
(completions-list-max): Add.
(minibuffer-completion-help): Truncate completions based on
completions-list-max.
In GNU Emacs 29.2.50 (build 9, x86_64-pc-linux-gnu, X toolkit, cairo
version 1.15.12, Xaw scroll bars) of 2024-11-20 built on
igm-qws-u22796a
Repository revision: 28dc0b6f9987e0def7dff4deaa23aa60f021d2a7
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Rocky Linux 8.10 (Green Obsidian)
Configured using:
'configure --with-x-toolkit=lucid --without-gpm --without-gconf
--without-selinux --without-imagemagick --with-modules --with-gif=no
--with-tree-sitter --with-native-compilation=aot
PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/'
[0001-Allow-limiting-the-size-of-Completions.patch (text/patch, attachment)]
[Message part 5 (message/rfc822, inline)]
[Message part 6 (text/plain, inline)]
>>> Any further thoughts about this patch?
>> LGTM,
> Could someone please install this change, then? (I can't do it myself)
Pushed with the additional patch below.
Stefan
[minibuffer.patch (text/x-diff, inline)]
commit b21636580bed822bd9fb8bb84014311fa9b4c071
Author: Spencer Baugh <sbaugh <at> catern.com>
Date: Fri Mar 21 17:24:50 2025 -0400
minibuffer.el: Fix warnings and coding style in last change
* lisp/minibuffer.el: Cut lines to fit into 80 columns.
(completion--insert-strings): Simplify `if` to `or`.
(completion--insert-horizontal, completion--insert-one-column):
Fix warning about used var starting with `_`. Avoid `apply-partially`.
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 47b152ed35d..8fba0b88b20 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2256,7 +2256,7 @@ completion--insert-strings
;; Windows can't show less than 3 lines anyway.
(max 1 (/ (length strings) 2))))
(colwidth (/ wwidth columns))
- (lines (if completions-max-height completions-max-height (frame-height))))
+ (lines (or completions-max-height (frame-height))))
(unless (or tab-stop-list (null completion-tab-width)
(zerop (mod colwidth completion-tab-width)))
;; Align to tab positions for the case
@@ -2264,15 +2264,17 @@ completion--insert-strings
(setq colwidth (- colwidth (mod colwidth completion-tab-width))))
(let ((completions-continuation
(catch 'completions-truncated
- (funcall (intern (format "completion--insert-%s" completions-format))
+ (funcall (intern (format "completion--insert-%s"
+ completions-format))
strings group-fun length wwidth colwidth columns lines)
nil)))
(when completions-continuation
;; If there's a bug which causes us to not insert the remaining
;; completions automatically, the user can at least press this button.
(setq-local completions--lazy-insert-button
- (insert-button "[Completions truncated, click here to insert the rest.]"
- 'action #'completion--lazy-insert-strings))
+ (insert-button
+ "[Completions truncated, click here to insert the rest.]"
+ 'action #'completion--lazy-insert-strings))
(button-put completions--lazy-insert-button
'completions-continuation completions-continuation))))))
@@ -2282,7 +2284,8 @@ completion--lazy-insert-strings
(let ((completion-lazy-hilit t)
(standard-output (current-buffer))
(inhibit-read-only t)
- (completions-continuation (button-get button 'completions-continuation)))
+ (completions-continuation
+ (button-get button 'completions-continuation)))
(save-excursion
(goto-char (button-start button))
(delete-region (point) (button-end button))
@@ -2291,7 +2294,7 @@ completion--lazy-insert-strings
(defun completion--insert-horizontal (strings group-fun
length wwidth
- colwidth _columns lines
+ colwidth columns lines
&optional last-title)
(let ((column 0)
(first t)
@@ -2306,26 +2309,28 @@ completion--insert-horizontal
(unless (equal title last-title)
(setq last-title title)
(when title
- (insert (if first "" "\n") (format completions-group-format title) "\n")
+ (insert (if first "" "\n")
+ (format completions-group-format title) "\n")
(setq column 0
first t)))))
(unless first
;; FIXME: `string-width' doesn't pay attention to
;; `display' properties.
- (if (< wwidth (+ column (max colwidth
- (if (consp str)
- (apply #'+ (mapcar #'string-width str))
- (string-width str)))))
+ (if (< wwidth (+ column
+ (max colwidth
+ (if (consp str)
+ (apply #'+ (mapcar #'string-width str))
+ (string-width str)))))
;; No space for `str' at point, move to next line.
(progn
(insert "\n")
(when (and lines (> (line-number-at-pos) lines))
(throw 'completions-truncated
- (apply-partially
- #'completion--insert-horizontal
- ;; Add str back, since we haven't inserted it yet.
- (cons str strings) group-fun length wwidth colwidth _columns nil
- last-title)))
+ (lambda ()
+ (completion--insert-horizontal
+ ;; Add str back, since we haven't inserted it yet.
+ (cons str strings) group-fun length wwidth colwidth
+ columns nil last-title))))
(setq column 0))
(insert " \t")
;; Leave the space unpropertized so that in the case we're
@@ -2397,8 +2402,8 @@ completion--insert-vertical
(insert "\n"))
(setq row (1+ row)))))))
-(defun completion--insert-one-column (strings group-fun _length _wwidth _colwidth _columns lines
- &optional last-title)
+(defun completion--insert-one-column ( strings group-fun length wwidth colwidth
+ columns lines &optional last-title)
(let ((last-string nil)
str)
(while strings
@@ -2415,10 +2420,10 @@ completion--insert-one-column
(insert "\n")
(when (and lines (> (line-number-at-pos) lines))
(throw 'completions-truncated
- (apply-partially
- #'completion--insert-one-column
- strings group-fun _length _wwidth _colwidth _columns nil
- last-title)))))
+ (lambda ()
+ (completion--insert-one-column
+ strings group-fun length wwidth colwidth columns nil
+ last-title))))))
(delete-char -1)))
(defun completion--insert (str group-fun)
This bug report was last modified 57 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.