Commit graph

28 commits

Author SHA1 Message Date
Eshel Yaron
f240f482e2
New user option 'completion-preview-idle-delay'
Support displaying the completion preview shortly after you
pause typing (on idle) rather than immediately.

* lisp/completion-preview.el (Commentary): Update.
(completion-preview--try-update):
(completion-preview--update-from-timer): New functions.
(completion-preview--timer): New buffer-local variable.
(completion-preview-idle-delay): New user option.
(completion-preview--show): Use it.
(completion-preview--post-command):
(completion-preview-mode): Disable idle timer if active.
2024-06-05 12:10:02 +02:00
Eshel Yaron
c11fe94006
Allow 'completion-preview-require-minimum-symbol-length' to be nil
With some completion backends, completion preview is useful not only
after a partial symbol, but also after punctuation and other non-symbol
characters.  For example, in C code it's helpful to display the
completion preview for struct members when point is after 'foo->'.
Provide an option to skip the check for minimum symbol length at point
in order to support this use case.

* lisp/completion-preview.el
(completion-preview-minimum-symbol-length): Mention possible nil
value in type and docstring.
(completion-preview-require-minimum-symbol-length): Skip check
if 'completion-preview-minimum-symbol-length' is nil.
2024-06-05 12:09:56 +02:00
Paul Eggert
3dcac22dd4 Spelling fixes 2024-06-04 22:16:28 -07:00
Eshel Yaron
6d856acf17
; Refine 'completion-preview-exact' face
* lisp/completion-preview.el (completion-preview-exact): Use
different underline color to further distinguish this face from
'completion-preview-common', and improve legibility with dark
background color.
2024-05-24 11:21:16 +02:00
Eshel Yaron
fda9ecc150
; Exclude a few more modes in 'global-completion-preview-mode'
* lisp/completion-preview.el (global-completion-preview-mode):
Exclude a few non-edit major modes whose definition sets
'major-mode' directly, rather than using 'define-derived-mode'.
2024-05-24 11:18:33 +02:00
Eshel Yaron
a45ae6bce9
; Exclude more modes in 'global-completion-preview-mode'
Avoid activating Completion Preview mode in a few more major
modes when 'global-completion-preview-mode' is enabled.

* lisp/completion-preview.el (global-completion-preview-mode):
By default, exclude a few more major modes for which Completion
Preview mode isn't suitable.
2024-04-25 14:49:39 +02:00
Eshel Yaron
2234fe929a
(completion-preview-prev-candidate): add numeric prefix argument
* lisp/completion-preview.el (completion-preview-prev-candidate):
Add numeric prefix argument N.
(completion-preview-next-candidate): Update documentation.
2024-04-23 14:35:45 +02:00
Eshel Yaron
6b26644300
; Fix Completion Preview mode mouse-click bindings
* lisp/completion-preview.el (completion-preview--ignore): New
internal command.
(completion-preview--internal-commands): Add it.
(completion-preview--mouse-map): Use it to fix bindings.
2024-04-23 14:35:38 +02:00
Eshel Yaron
00caec8058
New command 'completion-preview-complete'
This command completes the symbol at point up to the longest
common prefix of all completions candidates.  We also add an
indication of the longest common prefix in the completion
preview by highlighting that part of the preview with the
'completion-preview-exact' face.  To facilitate these features
we change the way we store the completion candidates while the
preview is visible, to explicitly keep the common prefix along
with a list of its suffixes.

* lisp/completion-preview.el (completion-preview--try-table):
Return longest common prefix and list of suffixes instead of
list of full candidates.  Add illustrative comment.
(completion-preview--capf-wrapper, completion-preview--update)
(completion-preview--show, completion-preview-insert)
(completion-preview-next-candidate): Adjust.
(completion-preview-common): New face.
(completion-preview-exact): Tweak to distinguish it from
'completion-preview-common'.
(completion-preview-complete): New command.
(completion-preview-active-mode-map): Bind it.
(completion-preview-mode): Mention it in docstring.
(completion-preview-commands): Add 'completion-preview-complete'.
(completion-preview--make-overlay): Simplify.
(completion-preview--internal-command-p): Remove.
(completion-preview-require-certain-commands): Update.
(completion-preview--inhibit-update): New inline function.
(completion-preview--inhibit-update-p): New local variable.
(completion-preview--post-command, completion-preview-hide):
Reset it to nil.

* test/lisp/completion-preview-tests.el
(completion-preview-tests--check-preview): Check the 'face'
property of both the first and last character.  Update callers.
(completion-preview-insert-calls-exit-function)
(completion-preview-complete): New tests.  (Bug#70381)
2024-04-20 14:32:00 +03:00
Eshel Yaron
4ff852a558
; Optimize 'completion-preview--try-table'
* lisp/completion-preview.el (completion-preview-completion-styles):
New variable.  Default to only include the 'basic' completion style.
(completion-preview--try-table): Let-bind 'completion-styles' when
calling 'completion-all-completions'.  With the default value of
'completion-preview-completion-styles', this yields a significant
performance improvement (up to 4 times faster compared to the
'substring' style when tested with 'elisp-completion-at-point').

Suggested by Ergus <spacibba@aol.com>
2024-04-12 10:20:25 +02:00
Eshel Yaron
3a91186ad3
; Remove obsolete 'mouse-wheel-up/down-event' bindings
Following commit e720ba6219 'mouse-wheel-up-event' and
'mouse-wheel-down-event' are translated to 'wheel-up/down'
events, so we only need to bind 'wheel-down/up' in
'completion-preview--mouse-map'.

* lisp/completion-preview.el: Don't require 'mwheel'.
(completion-preview--mouse-map): Remove bindings for
'mouse-wheel-up/down-event'.
2024-04-10 22:03:38 +02:00
Stefan Monnier
e720ba6219 (mouse-wheel-buttons): Map old-style wheel buttons to actual wheel events
Change the handling of the old X11 convention that uses mouse-4/5/6/7
events to represent wheel events: instead of asking downstream
packages to use the `mouse-wheel-*-event` variables to know which events
represent wheel events, use new var `mouse-wheel-buttons` to directly
convert those events into the standard `wheel-up/down/left/right` events
used everywhere else.

This will simplify the work of packages which can thus just bind their
commands to `wheel-up/down/left/right`.

* lisp/mouse.el (mouse-wheel-buttons): New custom variable.

* src/keyboard.c (make_lispy_event): Adjust for "wheel-clicks" on the tab-bar.
* src/xterm.c (x_construct_mouse_click): Add `xi2` argument and
obey `mouse-wheel-buttons` variable.
(handle_one_xevent): Adjust calls accordingly.
(syms_of_xterm): Define the `mouse-wheel-buttons` and the
`wheel-up/down/left/right`symbols.

* lisp/xt-mouse.el: Don't require `mwheel` any more.
(xterm-mouse--same-button-p): Delete function.
(xterm-mouse--read-event-sequence): Use `mouse-wheel-buttons`.

* lisp/mwheel.el (mouse-wheel-up-event, mouse-wheel-down-event)
(mouse-wheel-left-event, mouse-wheel-right-event): Make obsolete.
(mouse-wheel-obey-old-style-wheel-buttons): Delete variable.

* lisp/completion-preview.el (completion-preview--mouse-map):
* lisp/progmodes/flymake.el (flymake--mode-line-counter-map):
* lisp/edmacro.el (edmacro-fix-menu-commands): Silence warnings.
2024-04-09 10:26:07 -04:00
Eshel Yaron
5e5e74b17a
; Autoload 'global-completion-preview-mode'
* lisp/completion-preview.el (global-completion-preview-mode):
Add autoload cookie.
2024-04-03 08:35:18 +02:00
Eshel Yaron
de8cae30bc
Add global minor mode 'global-completion-preview-mode'
This is a global variant of 'completion-preview-mode'.

* lisp/completion-preview.el (global-completion-preview-mode): New
global minor mode.

* doc/emacs/programs.texi (Symbol Completion): Document it.

* etc/NEWS: Announce it.  (Bug#70010)
2024-03-31 09:32:50 +02:00
Eshel Yaron
e6882a5cc8
; Fix mid-symbol updating/cycling completion preview
This fixes an issue where 'completion-preview-next-candidate'
would fail to take into account the part of the symbol that
follows point (the suffix) when point is at the middle of a
symbol, as well as a similar issue in 'completion-preview--show'
that would manifest with slow 'completion-at-point-functions'.

* lisp/completion-preview.el (completion-preview-next-candidate)
(completion-preview--show): Ensure that the completion preview
remains at the end of a symbol, when updating it while point is
in the middle of that symbol.

* test/lisp/completion-preview-tests.el
(completion-preview-mid-symbol-cycle): New test.  (Bug#68875)
2024-02-21 17:47:12 +01:00
Stefan Monnier
1f3371b46e Take stock of the wheel-up/down confusion
While we're hopefully all aware of the usual confusion between
the scroll operation moving the document or moving the viewport, Emacs
has its very own instance of that confusion where the
`mouse-wheel-down-event` variable is the one that (used to) hold
the value `wheel-up` and vice versa.

Thanks for Po Lu's commit 957b4f826a which not only fixed my change
but brought that confusion to my attention.
This patch doesn't fix the problem, but tries to fix the other places
in the code where we did not take it into account.

* doc/lispref/commands.texi (Misc Events): Mention the
wheel-up/down confusion.

* lisp/progmodes/flymake.el (flymake--mode-line-counter-map):
* lisp/completion-preview.el (completion-preview--mouse-map):
Fix wheel-up/down confusion.

* lisp/mwheel.el (mouse-wheel-down-event, mouse-wheel-up-event):
Fix docstrings.
2024-01-24 12:57:33 -05:00
Stefan Monnier
18294854c7 mwheel.el: Remove mouse-wheel-*-alternate-event vars
Now that `wheel-DIR` events are hardcoded, we never need more than
one variable (which we actually never needed anyway, we could have
let `mouse-wheel-*-event` vars hold lists of events instead), so
remove the `mouse-wheel-*-alternate-event` vars by merging their
default value into that of the corresponding `mouse-wheel-*-event`.

* lisp/mwheel.el (mouse-wheel-down-event, mouse-wheel-up-event)
(mouse-wheel-left-event, mouse-wheel-right-event): Don't bother holding
`wheel-DIR` events since these are already handled anyway.
Hold the event that would have been held in
`mouse-wheel-DIR-alternate-event` instead.
(mouse-wheel-down-alternate-event, mouse-wheel-up-alternate-event)
(mouse-wheel-left-alternate-event, mouse-wheel-right-alternate-event):
Delete vars.
(mwheel--is-dir-p, mouse-wheel--setup-bindings):
* lisp/edmacro.el (edmacro-fix-menu-commands):
* lisp/completion-preview.el (completion-preview--mouse-map):
Don't use `mouse-wheel-up/down-alternate-event` any more.
* lisp/progmodes/flymake.el (flymake--mode-line-counter-map):
Do nothing, because it already ignored those vars.
2024-01-20 15:03:26 -05:00
Stefan Monnier
db8890b3c9 mwheel.el: Unconditionally use the wheel-up/down/... events
The `mouse-wheel-DIR-event` vars were introduced because under X11
we get different `mouse-N` events depending on the users' mouse and
those same events can be used for other things for other rodents, so we
can't unconditionally treat those events as mouse-wheel events.

But this does not apply to the `wheel-up/down/...` events.
So hard code them.

* lisp/mwheel.el (mwheel--is-dir-p): Always consider the `wheel-DIR` events.
(mouse-wheel--setup-bindings): Always bind the `wheel-DIR` events.

* lisp/completion-preview.el (completion-preview--mouse-map):
Unconditionally bind the `wheel-DIR` events.
* lisp/edmacro.el (edmacro-fix-menu-commands): Hard code the
`wheel-DIR` events as mouse events regardless of `mouse-wheel-*-event`s.
* lisp/progmodes/flymake.el (flymake--mode-line-counter-map):
Do nothing, because it's already been done in commit e5be6c7ae3.

* doc/lispref/commands.texi (Misc Events): Document the need to use
`wheel-up/down/left/right` unconditionally.
2024-01-20 15:03:26 -05:00
Stefan Monnier
82f71e106a * lisp/completion-preview.el: Fix use in non-GUI session
Fix loading in non-GUI sessions where `mwheel` is not preloaded.
Not requiring `mwheel` would be a lot more complex, since it would
require delaying the construction of `completion-preview--mouse-map`.

* lisp/completion-preview.el (<toplevel>): Require `mwheel`.
Remove correspondingly redundant `defvar`s.
(completion-preview--mouse-map): Use `key-description` rather than mimicking
it with `format`.
2024-01-20 15:03:26 -05:00
Eli Zaretskii
7592c3a6e0 ; Fix compilation errors in completion-preview.el
* lisp/completion-preview.el (mouse-wheel-up-event)
(mouse-wheel-up-alternate-event, mouse-wheel-down-event)
(mouse-wheel-down-alternate-event): Defvar, to avoid warnings and
errors in builds --without-x.  (Bug#68213)
2024-01-02 19:10:33 +02:00
Po Lu
070cb32463 ; Add 2024 to copyright years 2024-01-02 10:30:05 +08:00
Eshel Yaron
d30a648488 ; Hide completion preview when switching windows
* lisp/completion-preview.el
(completion-preview--window-selection-change): New function.
(completion-preview-active-mode): Add it to
'window-selection-change-functions'.  (Bug#67650)
2023-12-09 11:06:54 +02:00
Eshel Yaron
790a96ac99 Facilitate using Completion Preview with the mouse (bug#67479)
Allow users to accept the completion suggestion by clicking on it, and
to cycle between completion suggestions by scrolling (with a mouse
wheel or a trackpad) over the preview.

Also display a message by default when cycling to inform the user
about the index of the current suggestion out of the available total.

* lisp/completion-preview.el (completion-preview-highlight): New face.
(completion-preview-message-format): New user option.
(completion-preview--mouse-map): New keymap.
(completion-preview--try-table, completion-preview--show)
(completion-preview-next-candidate): Apply 'keymap' and 'mouse-face'
properties to completion preview string.
(completion-preview--internal-commands): Add 'mwheel-scroll'.  This
prevents incidental scrolls outside of the preview from dismissing the
preview when you actually want to cycle it.
(completion-preview--active-p): New function.  Use it as a
'completion-predicate' symbol property for commands that should only
be used when the preview is shown to otherwise exclude these commands
from M-x completion candidates.
2023-12-02 14:54:21 +02:00
Eshel Yaron
dd1c5cca70 ; Avoid 'completion-at-point' in 'completion-preview-insert'
Insert the completion suggestion directly in
'completion-preview-insert' instead of using 'completion-at-point' to
do that.  This fixes an issue where 'completion-preview-insert' would
not work correctly when the user uses 'add-hook' with a DEPTH argument
below a certain value to add functions to
'completion-at-point-functions', and obviates the need to manipulate
'completion-at-point-functions' when showing the preview all together.

* lisp/completion-preview.el (completion-preview--make-overlay)
(completion-preview-prev-candidate)
(completion-preview-next-candidate)
(completion-preview-mode): Improve docstring.
(completion-preview--exit-function)
(completion-preview--insert)
(completion-preview-insert-on-completion): Remove, no longer used.
(completion-preview--get): Turn into a 'defsubst'.
(completion-preview-active-mode)
(completion-preview--capf-wrapper): Simplify.
(completion-preview--try-table)
(completion-preview--update): Keep the completion "base" as a property
of the preview overlay, for use in completion exit functions.
(completion-preview-insert): Insert completion and call exit function
directly instead of manipulating 'completion-at-point' to do so.
(Bug#67275)
2023-11-25 12:09:48 +02:00
Eshel Yaron
3c3c46f429 ; Improve and add tests for Completion Preview mode
Fix handling of capfs that return a function or signal an error,
respect the ':exclusive' completion property, fix lingering "exact"
face after deletion that makes the matches non-exact, and add tests.

* lisp/completion-preview.el (completion-preview--make-overlay): Only
reuse the previous 'after-string' if it has the right face.
(completion-preview--try-table)
(completion-preview--capf-wrapper): New functions.
(completion-preview--update): Use them.
* test/lisp/completion-preview-tests.el: New file.  (Bug#67275)
2023-11-25 12:06:03 +02:00
Po Lu
dd0f009c51 ; Commit omitted change
* lisp/completion-preview.el (completion-preview-commands):
Substitute analyze-text-conversion for text-conversion, as this
list enumerates commands, not events.
2023-11-16 17:39:14 +08:00
Po Lu
d03677343e Pan during touch screen pinch gestures
* doc/lispref/commands.texi (Touchscreen Events): Document new
ratio-diff parameter to touchscreen-pinch events.

* lisp/completion-preview.el (completion-preview-commands):
Account text-conversion events preview commands as well.

* lisp/touch-screen.el (touch-screen-aux-tool): Introduce two
new elements.
(touch-screen-pinch): Scroll window in accord with event deltas.
(touch-screen-handle-aux-point-update): Supply the ratio
difference in generated events.
(touch-screen-handle-touch): Create a vector with those two new
elements.
2023-11-16 11:29:58 +08:00
Eshel Yaron
e82d807a28 Add Completion Preview mode
This adds a new minor mode, 'completion-preview-mode', that displays
in-buffer completion suggestions with an inline "preview" overlay.
(Bug#66948)

* lisp/completion-preview.el: New file.
* doc/emacs/programs.texi (Symbol Completion): Document it.
* etc/NEWS: Announce it.
2023-11-15 19:15:49 +02:00