* lisp/minibuffer.el (define-completion-category): New function.
(completion-category-get): New function, implements completion
category property lookup with (multiple) inheritance.
(completion-metadata-get, completion--styles)
(completion--cycle-threshold): Use it.
(completion-category-defaults): Mention it in docstring.
Remove entry for 'project-buffer' category, and instead...
* lisp/progmodes/project.el: ...have 'project-buffer' inherit
from 'buffer'.
* test/lisp/minibuffer-tests.el
(completion-category-inheritance): New test.
* etc/NEWS: Announce support for category inheritance.
Revert "Avoid duplicating strings in pcm--merge-completions",
commit b511c38bba. It broke
existing behavior, now covered by tests adding in this commit.
* lisp/minibuffer.el (completion-pcm--merge-completions):
* test/lisp/minibuffer-tests.el (completion-pcm-test-anydelim):
(completion-pcm-bug4219):
Previously, one could select a completion via M-<up>/M-<down>,
but then RET would not actually select the chosen completion.
With the addition of completion-auto-deselect, this is not
actually necessary: we can reasonably assume that when a
completion is selected, the user wants to use that, since their
last action must have been to select it. So, just choose the
selected completion on RET. This lets us default
minibuffer-completion-auto-choose to nil.
For minibuffers with require-match completion, this can be done
by changing the existing command bound to RET. For minibuffers
with nil require-match completion, RET was previously bound to
exit-minibuffer, and changing exit-minibuffer to have this logic
is risky. We handle that case by adding a new
minibuffer-completion-exit which wraps exit-minibuffer and bind
RET to it.
* lisp/minibuffer.el (minibuffer-insert-completion-if-selected)
(minibuffer-completion-exit, completion--selected-candidate):
Add.
(minibuffer-complete-and-exit): Call
minibuffer-choose-completion. (bug#77253)
(minibuffer-local-completion-map): Bind RET to
minibuffer-completion-exit, overriding exit-minibuffer.
(completion-in-region-mode-map): Bind RET to
minibuffer-choose-completion when there's a selected candidate.
(minibuffer-completion-auto-choose): Default to nil.
(minibuffer-visible-completions--filter)
(minibuffer-visible-completions-map): Delete RET binding, no
longer necessary.
* lisp/simple.el (completion-setup-function): Update completion
help text to show more correct bindings.
* test/lisp/minibuffer-tests.el (completions-header-format-test)
(minibuffer-next-completion): Set
minibuffer-completion-auto-choose=t explicitly.
(with-minibuffer-setup, minibuffer-completion-RET-prefix)
(completion-in-region-next-completion): Add new tests.
* etc/NEWS: Announce.
* etc/NEWS: Mention the change.
* lisp/minibuffer.el (completion-category-defaults):
Add an entry for it.
* lisp/progmodes/project.el (project--buffers-completion-table):
Return category 'project-buffer'.
At various places, instead of just checking that there's any
window displaying a buffer named *Completions*, we should
additionally check that that *Completions* buffer is actually
for the current completion session.
minibuffer--completions-visible does that.
* lisp/comint.el (comint-complete-input-ring)
(comint-dynamic-list-completions): Call
minibuffer--completions-visible.
* lisp/minibuffer.el (minibuffer--completions-visible):
Add. (bug#77253)
(completion--do-completion, completions--post-command-update)
(completions--after-change, minibuffer-hide-completions)
(minibuffer-visible-completions)
(minibuffer-visible-completions--always-bind)
(minibuffer-visible-completions--filter)
(with-minibuffer-completions-window, minibuffer-complete-history)
(minibuffer-complete-defaults): Call
minibuffer--completions-visible.
* lisp/pcomplete.el (pcomplete-show-completions): Call
minibuffer--completions-visible.
* lisp/simple.el (switch-to-completions): Call
minibuffer--completions-visible.
* test/lisp/minibuffer-tests.el (completion-auto-help-test)
(completion-auto-select-test): Call
minibuffer--completions-visible.
Make completion-pcm--merge-completions operate only on the text
matched by the wildcards, instead of also the text in between
the wildcards. This improves performance and simplifies the
code by removing the need for the previous mutable variable
"fixed".
* lisp/minibuffer.el (completion-pcm--merge-completions):
Operate only on text matched by wildcards. (bug#79265)
Properly fix bug#38458, which is fundamentally an issue with
completion-ignore-case, by checking if the completions are
unique ignoring case. When the completions are unique, the
normal code to delete a wildcard naturally causes point to be
moved to the end of the minibuffer, which is the correct
behavior.
Now that the bug is fixed properly, remove a hack which
previously was used to "fix" it, which made point behave
inconsistently if it was in the middle of the minibuffer versus
at the end of the minibuffer.
* lisp/minibuffer.el (completion-pcm--merge-completions):
Respect completion-ignore-case when checking for completion
uniqueness. (bug#79265)
(completion-pcm--string->pattern)
(completion-pcm--optimize-pattern): Allow point at the end of
the pattern.
* test/lisp/minibuffer-tests.el (completion-table-test-quoting)
(completion-test--pcm-bug38458, completion-pcm-test-8): Update
tests for more correct behavior.
Add support for updating the *Completions* buffer as you type,
controlled by a new completion metadata symbol 'eager-update'
and a new defcustom 'completion-eager-update'.
You can configure a completion category to update *Completions*
as you type by setting 'completion-category-overrides'
appropriately; or set 'completion-eager-update' to t to always
update *Completions* as you type.
This is similar to the recently added 'completion-eager-display'.
* lisp/minibuffer.el (completion-eager-update): Add new
defcustom defaulting to 'auto. (Bug#77649)
(completion--eager-update-p, completions--background-update)
(completions--post-command-update): Add.
(completions--after-change): Call
'completions--post-command-update' via 'post-command-hook'.
(minibuffer-completion-help): Check 'completion-eager-update'
and install 'completions--after-change'.
(completion-help-at-point): Call 'completion--eager-update-p'
if ONLY-IF-EAGER is non-nil.
* etc/NEWS: Announce completion-eager-update. Reword the
announcement of 'completion-eager-display' for consistency.
509cbe1c35 "Improve env var handling in read-file-name"
caused 'try-completion' and 'all-completion' operations with
'completion--file-name-table' to no longer update the case of
text which was already present in the input string. That is,
completions would be returned ignoring case, but the completions
would have letter-casing which matched the input string rather
than matching the actual file names.
This was caused by unnecessarily replacing text in the returned
file name completions with text from the input string ORIG,
which in turn was caused by the desire to preserve text from
ORIG even after 'substitute-in-file-name' changed it. Fix this
by detecting when ORIG was not substantially changed by
'substitute-in-file-name'; in that case, the returned file name
completions also don't need substantial changes.
* lisp/minibuffer.el (completion--file-name-table): Use text
from the completions, not the input string. (Bug#78323)
* test/lisp/minibuffer-tests.el (completion-table-test-quoting):
Test with 'completion-ignore-case' as well.
Previously, we assumed (roughly) that substitute-in-file-name
always returns a suffix of the original string. But
substitute-in-file-name on "/ssh:user@host:/~/" returns
"/ssh:user@host:~/", preserving the TRAMP magic prefix. Weaken
the assertion in completion--sifn-boundaries to allow this; the
new assertion is more clear about the property we care about,
anyway.
* lisp/minibuffer.el (completion--sifn-boundaries): Weaken
assertion slightly.
* test/lisp/net/tramp-tests.el (tramp--test-emacs31-p)
(tramp--split-on-boundary)
(tramp-test51-file-name-completion-boundaries): Add.
Fix various bugs, including bug#77718, by rewriting the way file
name completion handles environment variable expansion. Instead
of using completion-table-with-quoting to manipulate the string
being completed on, simply make the completion table itself
understand substitute-in-file-name.
Tests are updated: partial-completion now preserves unexpanded
environment variables. However, partial-completion no longer
works across environment variables containing delimiters; that's
an acceptable sacrifice.
* lisp/minibuffer.el (completion--sifn-boundaries): Add.
(completion--file-name-table): Rewrite to use
substitute-in-file-name explicitly. (bug#77718)
* test/lisp/minibuffer-tests.el (completion-table-test-quoting):
Update.
An explicitly typed * has different semantics from automatically
inserted PCM wildcards, so it should be preserved on try-completion. We
already do this in some cases, but now we do it more.
This is especially significant for filename completion: removing an
explicit * can take us from
~/src/emacs/trunk/*/minibuf
to
~/src/emacs/trunk//minibuf
The explicit double slash is interpreted by the file name completion
table to mean "start completing from the root directory", so deleting
the * here substantially changes semantics.
* lisp/minibuffer.el (completion-pcm--merge-completions): Don't drop
important wildcards. (bug#74420)
* test/lisp/minibuffer-tests.el (completion-pcm-test-7): Add tests.
* lisp/minibuffer.el (completion--replace):
* lisp/emacs-lisp/cl-lib.el (cl--set-buffer-substring):
* lisp/subr.el (replace-string-in-region):
Use `replace-region-contents` instead of insert+delete.
* lisp/help-fns.el (help-fns--signature):
Use `replace-region-contents` instead of `cl--set-buffer-substring`.
* lisp/language/japan-util.el (japanese-replace-region):
Rewrite using `replace-region-contents` and mark obsolete.
(japanese-katakana-region, japanese-hankaku-region):
Use `replace-region-contents` instead.
* lisp/progmodes/flymake-proc.el (flymake-proc--replace-region):
Rewrite using `replace-region-contents` and mark obsolete.
(flymake-proc--check-patch-master-file-buffer):
Use `replace-region-contents` instead.
This fixes a regression introduced in b12a3a03ae, where
repeating a completion command (e.g. TAB in the minibuffer)
would no longer scroll through all available completions.
* lisp/minibuffer.el (completion--in-region-1): Call
'completion--lazy-insert-strings' before scrolling
the completions list.
* 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`.
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.
However, rendering all the completion candidates is unnecessary if
the *Completions* window is never scrolled to see those candiates. By
eagerly inserting only some candidates and lazily highlighting and
inserting the remaining candidates only when necessary, performance is
much improved.
* lisp/minibuffer.el (completion--insert-strings): Insert
completions lazily. (bug#74561)
(completions--lazy-insert-button): Add.
(completion--insert-horizontal, completion--insert-one-column):
Throw a continuation when enough lines of completions are
inserted.
(completion--insert-vertical): Add ignored lines argument.
(minibuffer-completion-help): Set completion-lazy-hilit.
(with-minibuffer-completions-window): Call
completion--lazy-insert-strings.
(with-minibuffer-completions-window):
* lisp/simple.el (completion-setup-function): Preserve
buffer-locals required for lazy completion insertion.
(switch-to-completions): Call completion--lazy-insert-strings.
* etc/NEWS: Announce.
* lisp/help-fns.el (help--recommend-setopt): New function to
automatically document the need to use `setopt` to set the values of
any defcustoms with a `:set` property.
(help-fns-describe-variable-functions): Add above new function to
hook.
* lisp/follow.el (follow-mode-prefix-key):
* lisp/minibuffer.el (minibuffer-regexp-prompts):
* lisp/register.el (register-use-preview):
* lisp/savehist.el (savehist-autosave-interval):
* lisp/saveplace.el (save-place-autosave-interval):
* lisp/tab-bar.el (tab-bar-define-keys):
* lisp/textmodes/text-mode.el (text-mode-ispell-word-completion):
Delete now redundant text from docstrings.
* lisp/minibuffer.el (completion-category-defaults): Move the
'calendar-month' default value to the metadata in calendar-read-date.
* lisp/calendar/calendar.el (calendar-read-date): Add
display-sort-function moved from completion-category-defaults.
completion-pcm--find-all-completions has two different phases:
First we turn the minibuffer text into a regex and matches
completion alternatives against it. If that finds no matches,
then we strip some text off the completions and minibuffer text
and call ourselves recursively to find completions, then filter
the results with the removed text (converted into a regex).
Because of this, completion-pcm-leading-wildcard had
inconsistent behavior: in the second phase, the filter created
from the removed text would have a leading wildcard. That
effectively adds wildcards in the middle of the minibuffer text
at the start of each "word". But the first phrase created a
regex which had no such wildcards. Thus, the two phases could
get substantially different results.
We fix this by changing completion-pcm-leading-wildcard to
consistently add a leading wildcard for each word. This was
always my intention.
* lisp/minibuffer.el (completion-pcm--string->pattern): Include
a wildcard after each delimter with
completion-pcm-leading-wildcard. (bug#74772)
* lisp/minibuffer.el (completion-pcm-leading-wildcard): Update
docs.
* doc/emacs/mini.texi (Completion Styles): Update docs.
The customization option can be set to t or nil, to respectively
always or never show the *Completions* buffer eagerly at the
beginning of a completion session. Furthermore the option can
be set to the value auto. In this case the *Completions* buffer
will only be shown if requested by the completion table.
Completion tables can use the `eager-display' completion
metadata to do so. (Bug#74616, Bug#74617)
* lisp/minibuffer.el (completion-eager-display): New
customization variable.
(completion-metadata): Update docstring, document the
new `eager-display' completion metadata.
(completion-extra-properties): Update docstring, document the
new `:eager-display' completion metadata.
(completion-category-overrides): Add `eager-display' to the
custom type specification.
(completing-read-default): Handle the `completion-eager-display'
customization variable and the `eager-display' completion
metadata.
(completion-table-with-metadata): New function to create
a completion table with metadata.
(minibuffer-complete-defaults, minibuffer-complete-history):
Use it.
* lisp/ffap.el (ffap-menu-ask): Add `ffap-menu' completion
category and `eager-display' completion metadata. Use
`completion-table-with-metadata'.
* lisp/imenu.el (imenu-eager-completion-buffer): Correct
docstring, which had been inverted.
(imenu--completion-buffer): Add `eager-display' completion
metadata. Use `completion-table-with-metadata'.
* lisp/tmm.el (tmm-prompt): Add `tmm' completion category and
`eager-display' completion metadata. Use
`completion-table-with-metadata'. Add keymap setup.
(tmm-add-prompt): Remove keymap setup.
(tmm-goto-completions): Call `tmm-add-prompt' to ensure that a
*Completions* buffer is shown.
(tmm--completion-table): Remove unused internal function.
* etc/NEWS: Announce the change.
Replace `completions--start-of-candidate-at' with the new
function `completion-list-candidate-at-point' which returns the
candidate string and the candidate bounds as a list in the
format (STR BEG END).
* lisp/simple.el (completions--start-of-candidate-at): Remove.
(completion-list-candidate-at-point): New function.
(choose-completion): Use it.
* lisp/minibuffer.el (minibuffer-completion-help): Use it.
When *Completions* is updated and point was on some completion
candidate, move point to the same candidate after the update.
Also, a selected completion in *Completions* is now always
highlighted, even if it was selected by the user or other code
moving point rather than by minibuffer-next-completion, because
cursor-face-highlight-nonselected-window is now set in
completion-setup-function.
Other completion UIs (e.g. ido, vertico, etc) effectively have
this behavior: whenever they update the list of completions,
they preserve whatever candidate is selected. This matters a
lot when completions are auto-updated, but is still useful
without auto-updating. Including this behavior is a step
towards supporting auto-updating in the default completion UI.
* lisp/minibuffer.el (minibuffer-completion-help): Preserve the
selected completion candidate across updates. (bug#74019)
(minibuffer-hide-completions): Move point to BOB.
(minibuffer-next-completion): Don't set
cursor-face-highlight-nonselected-window.
* lisp/simple.el (completions--start-of-candidate-at)
(choose-completion): Extract the current-completion-finding code
into a separate function.
(completion-setup-function): Set
cursor-face-highlight-nonselected-window.
* etc/NEWS: Announce new behavior.
In 03ac16ece4 I fixed a bug with the
PCM implementation of substring completion, relating to the handling
of PCM wildcards.
However, this fix was incomplete. This change completes the fix by
also including a fixed string if it appears before a 'prefix'
wildcard, even if 'try-completion' doesn't discover that fixed
string grows to a unique completion.
I discovered this bug while working on enhancements to PCM
completion related to 'completion-pcm-leading-wildcard'.
* lisp/minibuffer.el (completion-pcm--merge-completions): Include
fixed strings before 'prefix wildcard. (Bug#72819)
* test/lisp/minibuffer-tests.el (completion-substring-test-5): Add a
test for this behavior.
In 69ec333eab I allowed
completion-styles to contain a list of bindings. Now the
'defcustom' type also supports this.
Since the type is somewhat unusual (a value in the list can be
either a symbol or a list) I had to add a new widget to support
it.
* lisp/minibuffer.el (completion--styles-type): Update to allow
setting variable overrides.
(completion-styles, completion-category-overrides)
(completion-pcm-leading-wildcard): Update :version.
* lisp/wid-edit.el (widget-single-or-list-to-internal)
(single-or-list): Add.
The substring completion style completes "foo-bar" as "*foo-bar*". The
partial-completion completion style completes "foo-bar" as "foo*bar*".
Previously, it was not possible to get completion of "foo-bar" to act as
"*foo*bar*", e.g. combining the partial-completion and substring styles.
This would be especially useful for things like project-find-file.
Now it is possible by customizing the completion-pcm-leading-wildcard variable
to a non-nil value.
Furthermore, it's convenient to be able to run
regular (completion-pcm-leading-wildcard=t, non-substring)
partial-completion before running completion-pcm-leading-wildcard=nil
partial-completion, since the former provides more narrowly targeted
completions.
It's possible to do this by customizing completion-styles. Just add
'(partial-completion ((completion-pcm-leading-wildcard t))) and
'(partial-completion ((completion-pcm-leading-wildcard nil))) in that
order. Then the completion machinery will first run partial-completion
with completion-pcm-leading-wildcard=t, and if that returns no
completions, run partial-completion with
completion-pcm-leading-wildcard=nil.
* lisp/minibuffer.el (completion--nth-completion): Allow an element of
completion-styles to contain a list of bindings.
(completion-styles): Document that.
(completion-pcm-leading-wildcard): Add.
(completion-pcm--string->pattern): Check completion-pcm-leading-wildcard.
(bug#70217)