diff options
| author | João Távora | 2026-01-11 02:05:56 +0000 |
|---|---|---|
| committer | João Távora | 2026-01-11 03:42:01 +0000 |
| commit | 4e6a81da6ce9a4ec44642424533496db483c139a (patch) | |
| tree | 3c485b3e9212609327124f5ceec15398ef032455 | |
| parent | fde1a5ebeb5ff0f2a88d83f6c76984c8a4b19946 (diff) | |
| download | emacs-4e6a81da6ce9a4ec44642424533496db483c139a.tar.gz emacs-4e6a81da6ce9a4ec44642424533496db483c139a.zip | |
Eglot: add new command 'eglot-momentary-inlay-hints'
* doc/misc/eglot.texi (Eglot Commands)
(Customization Variables): Advertise eglot-momentary-inlay-hints.
* etc/EGLOT-NEWS: Advertise new command.
* lisp/progmodes/eglot.el (eglot--momentary-hints-data): New variable.
(eglot-momentary-inlay-hints): New command.
| -rw-r--r-- | doc/misc/eglot.texi | 17 | ||||
| -rw-r--r-- | etc/EGLOT-NEWS | 9 | ||||
| -rw-r--r-- | lisp/progmodes/eglot.el | 39 |
3 files changed, 65 insertions, 0 deletions
diff --git a/doc/misc/eglot.texi b/doc/misc/eglot.texi index 579c568f264..8483881c52a 100644 --- a/doc/misc/eglot.texi +++ b/doc/misc/eglot.texi | |||
| @@ -766,6 +766,22 @@ serve hints about positional parameter names in function calls and a | |||
| 766 | variable's automatically deduced type. Inlay hints help the user not | 766 | variable's automatically deduced type. Inlay hints help the user not |
| 767 | have to remember these things by heart. | 767 | have to remember these things by heart. |
| 768 | 768 | ||
| 769 | @cindex momentary inlay hints | ||
| 770 | @item eglot-momentary-inlay-hints | ||
| 771 | When bound to a single key in @code{eglot-mode-map} | ||
| 772 | (@pxref{Customization Variables}), this will arrange for inlay hints to | ||
| 773 | be displayed as long as the key is held down, and then hidden shortly | ||
| 774 | after it is released. The best way to set it up is something like this: | ||
| 775 | |||
| 776 | @lisp | ||
| 777 | (define-key eglot-mode-map [f7] 'eglot-momentary-inlay-hints) | ||
| 778 | @end lisp | ||
| 779 | |||
| 780 | @noindent | ||
| 781 | Note that Emacs doesn't support binding to \"key up\" events, so this | ||
| 782 | command offers an approximation by estimating your system keyboard delay | ||
| 783 | and repeat rate. | ||
| 784 | |||
| 769 | @cindex semantic tokens | 785 | @cindex semantic tokens |
| 770 | @item M-x eglot-semantic-tokens-mode | 786 | @item M-x eglot-semantic-tokens-mode |
| 771 | This command toggles LSP @dfn{semantic tokens} fontification on and off | 787 | This command toggles LSP @dfn{semantic tokens} fontification on and off |
| @@ -978,6 +994,7 @@ For example: | |||
| 978 | (define-key eglot-mode-map (kbd "C-c o") 'eglot-code-action-organize-imports) | 994 | (define-key eglot-mode-map (kbd "C-c o") 'eglot-code-action-organize-imports) |
| 979 | (define-key eglot-mode-map (kbd "C-c h") 'eldoc) | 995 | (define-key eglot-mode-map (kbd "C-c h") 'eldoc) |
| 980 | (define-key eglot-mode-map (kbd "<f6>") 'xref-find-definitions) | 996 | (define-key eglot-mode-map (kbd "<f6>") 'xref-find-definitions) |
| 997 | (define-key eglot-mode-map (kbd "<f7>") 'eglot-momentary-inlay-hints) | ||
| 981 | @end lisp | 998 | @end lisp |
| 982 | 999 | ||
| 983 | @cindex progress | 1000 | @cindex progress |
diff --git a/etc/EGLOT-NEWS b/etc/EGLOT-NEWS index 3fe87d77690..a6425ea4234 100644 --- a/etc/EGLOT-NEWS +++ b/etc/EGLOT-NEWS | |||
| @@ -49,6 +49,15 @@ requests diagnostics explicitly rather than relying on sporadic | |||
| 49 | server is known to support the "pull" variant exclusively, while the | 49 | server is known to support the "pull" variant exclusively, while the |
| 50 | 'ty' server is known to support it alongside "push". | 50 | 'ty' server is known to support it alongside "push". |
| 51 | 51 | ||
| 52 | ** New command 'eglot-momentary-inlay-hints' | ||
| 53 | |||
| 54 | When bound to a single key in 'eglot-mode-map' this will arrange for | ||
| 55 | inlay hints to be displayed as long as the key is held down, and then | ||
| 56 | hidden shortly after it is released. Emacs doesn't support binding to | ||
| 57 | \"key up\" events, but this function offers an approximation. It relies | ||
| 58 | on measuring your keyboard initial delay and repeat rate, and may not be | ||
| 59 | 100% accurate. | ||
| 60 | |||
| 52 | ** Support for watching files outside the project (bug#79809) | 61 | ** Support for watching files outside the project (bug#79809) |
| 53 | 62 | ||
| 54 | Eglot now supports and advertises the 'relativePatternSupport' | 63 | Eglot now supports and advertises the 'relativePatternSupport' |
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index f95451b35af..b22ed2b9c57 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el | |||
| @@ -4882,6 +4882,45 @@ If NOERROR, return predicate, else erroring function." | |||
| 4882 | (jit-lock-unregister #'eglot--update-hints) | 4882 | (jit-lock-unregister #'eglot--update-hints) |
| 4883 | (eglot--delete-overlays 'eglot--inlay-hint)))) | 4883 | (eglot--delete-overlays 'eglot--inlay-hint)))) |
| 4884 | 4884 | ||
| 4885 | (defvar eglot--momentary-hints-data (list nil nil nil 0 nil)) | ||
| 4886 | |||
| 4887 | (defun eglot-momentary-inlay-hints () | ||
| 4888 | "Display inlay hints while holding down a key. | ||
| 4889 | Emacs doesn't support binding to \"key up\" events, but this function | ||
| 4890 | offers an approximation. When bound to a key it will arrange for inlay | ||
| 4891 | hints to be displayed as long as the key is held down, and then hidden | ||
| 4892 | shortly after it is released. This relies on measuring your keyboard | ||
| 4893 | initial delay and repeat rate, and may not be 100% accurate." | ||
| 4894 | (interactive) | ||
| 4895 | (when eglot-inlay-hints-mode | ||
| 4896 | (eglot-inlay-hints-mode -1)) | ||
| 4897 | (cl-symbol-macrolet | ||
| 4898 | ((timer (nth 0 eglot--momentary-hints-data)) | ||
| 4899 | (initial-delay (nth 1 eglot--momentary-hints-data)) | ||
| 4900 | (repeat-delay (nth 2 eglot--momentary-hints-data)) | ||
| 4901 | (calls (nth 3 eglot--momentary-hints-data)) | ||
| 4902 | (last-call-time (nth 4 eglot--momentary-hints-data))) | ||
| 4903 | (cl-incf calls) | ||
| 4904 | (cl-flet ((runit (delay) | ||
| 4905 | (setf timer | ||
| 4906 | (run-at-time (+ 0.1 delay) | ||
| 4907 | nil (lambda () | ||
| 4908 | (dolist (o (overlays-in (point-min) (point-max))) | ||
| 4909 | (when (overlay-get o 'eglot--inlay-hint) | ||
| 4910 | (delete-overlay o))) | ||
| 4911 | (setf timer nil calls 0))) | ||
| 4912 | last-call-time (float-time)))) | ||
| 4913 | (cond ((timerp timer) | ||
| 4914 | (when (and (not initial-delay) (= calls 2)) | ||
| 4915 | (setf initial-delay (- (float-time) last-call-time))) | ||
| 4916 | (when (and (not repeat-delay) (= calls 3)) | ||
| 4917 | (setf repeat-delay (- (float-time) last-call-time))) | ||
| 4918 | (cancel-timer timer) | ||
| 4919 | (runit (or repeat-delay 0.5))) | ||
| 4920 | (t | ||
| 4921 | (eglot--update-hints-1 (window-start) (window-end)) | ||
| 4922 | (runit (or initial-delay 1.0))))))) | ||
| 4923 | |||
| 4885 | 4924 | ||
| 4886 | ;;; Semantic tokens | 4925 | ;;; Semantic tokens |
| 4887 | (defmacro eglot--semtok-define-things () | 4926 | (defmacro eglot--semtok-define-things () |