[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/eglot2emacs 6d815aaa98 057/120: Tweak on-type-formatting code
From: |
João Távora |
Subject: |
feature/eglot2emacs 6d815aaa98 057/120: Tweak on-type-formatting code |
Date: |
Thu, 20 Oct 2022 07:16:53 -0400 (EDT) |
branch: feature/eglot2emacs
commit 6d815aaa986f24d356aa08557095cbaab3414142
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Tweak on-type-formatting code
* eglot.el (eglot--post-self-insert-hook): Tweak.
(eglot-format): Tweak docstring.
GitHub-reference: per https://github.com/joaotavora/eglot/issues/899
---
lisp/progmodes/eglot.el | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 1cf0b7ae63..d71e5966a8 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -1974,18 +1974,16 @@ THINGS are either registrations or unregisterations
(sic)."
"If non-nil, value of the last inserted character in buffer.")
(defun eglot--post-self-insert-hook ()
- "Set `eglot--last-inserted-char', call on-type-formatting if necessary."
+ "Set `eglot--last-inserted-char', maybe call on-type-formatting."
(setq eglot--last-inserted-char last-input-event)
- (when (or (eq last-input-event
- (elt (eglot--server-capable
- :documentOnTypeFormattingProvider
- :firstTriggerCharacter)
- 0))
- (seq-find (lambda (elt) (eq last-input-event (elt elt 0)))
- (eglot--server-capable
- :documentOnTypeFormattingProvider
- :moreTriggerCharacter)))
- (eglot-format (point) nil (string last-input-event))))
+ (let ((ot-provider (eglot--server-capable
:documentOnTypeFormattingProvider)))
+ (when (and ot-provider
+ (or (eq last-input-event
+ (elt (plist-get ot-provider :firstTriggerCharacter) 0))
+ (cl-find last-input-event
+ (plist-get ot-provider :moreTriggerCharacter)
+ :key #'seq-first)))
+ (eglot-format (point) nil last-input-event))))
(defun eglot--pre-command-hook ()
"Reset `eglot--last-inserted-char'."
@@ -2373,9 +2371,8 @@ If either BEG or END is nil, format entire buffer.
Interactively, format active region, or entire buffer if region
is not active.
-If ON-TYPE-FORMAT is non-nil, request on-type-formatting from the
-server. The argument should be a one-character-long string that
-has just been inserted at BEG."
+If non-nil, ON-TYPE-FORMAT is a character just inserted at BEG
+for which LSP on-type-formatting should be requested."
(interactive (and (region-active-p) (list (region-beginning) (region-end))))
(pcase-let ((`(,method ,cap ,args)
(cond
@@ -2383,7 +2380,7 @@ has just been inserted at BEG."
`(:textDocument/onTypeFormatting
:documentOnTypeFormattingProvider
,`(:position ,(eglot--pos-to-lsp-position beg)
- :ch ,on-type-format)))
+ :ch ,(string on-type-format))))
((and beg end)
`(:textDocument/rangeFormatting
:documentRangeFormattingProvider
- branch feature/eglot2emacs created (now 0186faf2a1), João Távora, 2022/10/20
- feature/eglot2emacs bbdfbf0456 006/120: Add pyright language server support for python-mode, João Távora, 2022/10/20
- feature/eglot2emacs a35f6a7f9a 010/120: Support language server for html, css, json and docker, João Távora, 2022/10/20
- feature/eglot2emacs b527764963 023/120: Support racket-langserver, João Távora, 2022/10/20
- feature/eglot2emacs eacc40e3bf 015/120: ; update copyright years, João Távora, 2022/10/20
- feature/eglot2emacs 1616da4f26 030/120: * eglot.el (eglot-strict-mode): very minor docfix., João Távora, 2022/10/20
- feature/eglot2emacs 6a6f4c3d27 041/120: Don't use :exclusive no, João Távora, 2022/10/20
- feature/eglot2emacs 26bd153b90 028/120: Print server command to events buffer, João Távora, 2022/10/20
- feature/eglot2emacs abfb193201 032/120: Remove unnecessary compatibility code, João Távora, 2022/10/20
- feature/eglot2emacs 85ecf46a18 046/120: Have a couple of lsp faces inherit from basic "shadow", João Távora, 2022/10/20
- feature/eglot2emacs 6d815aaa98 057/120: Tweak on-type-formatting code,
João Távora <=
- feature/eglot2emacs b59fa2548e 083/120: Cosmetic decisions guaranteed to tick off someone somewhere (tm), João Távora, 2022/10/20
- feature/eglot2emacs 6717589c57 086/120: Be more conservative with the lsp identifier guess, João Távora, 2022/10/20
- feature/eglot2emacs 3967d22b9c 005/120: ; fix typos, João Távora, 2022/10/20
- feature/eglot2emacs 5c6eb3caa9 074/120: Don't ignore flymake-no-changes-timeout, João Távora, 2022/10/20
- feature/eglot2emacs 6ee995fe6b 094/120: Add marksman server for markdown, João Távora, 2022/10/20
- feature/eglot2emacs 0e8a8697ba 092/120: Merge commit '7738854e09' to fix fallout of force-push in gnu elpa, João Távora, 2022/10/20
- feature/eglot2emacs 51ae66b50c 099/120: Add eglot-show-configuration to debug workspace configurations, João Távora, 2022/10/20
- feature/eglot2emacs 14586fedcf 103/120: Don't exceed max-specdl-size in big go projects, João Távora, 2022/10/20
- feature/eglot2emacs a8b3b6a526 014/120: Add vim-language-server for vimrc-mode, João Távora, 2022/10/20
- feature/eglot2emacs b1c7aa1d17 003/120: Add yaml-language-server for yaml-mode, João Távora, 2022/10/20