summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2023-02-26 10:27:18 +0000
committerJoão Távora <joaotavora@gmail.com>2023-02-26 10:29:14 +0000
commitb0e87e930e86d2e48659aed9cf85099c1fd2795c (patch)
tree8a2ae1092a9f440fce65f11f2036d17a21d3a629
parent5b174b96834af7153f2aec1ac10d91caa0d03e52 (diff)
downloademacs-b0e87e930e86d2e48659aed9cf85099c1fd2795c.tar.gz
Eglot: use faster strategy for moving to LSP positions (bug#61726)
Turns out we don't need encode-coding-region after all. * lisp/progmodes/eglot.el (eglot-move-to-lsp-abiding-column): Rewrite. Co-authored-by: Augusto Stoffel <arstoffel@gmail.com>
-rw-r--r--lisp/progmodes/eglot.el23
1 files changed, 10 insertions, 13 deletions
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 2b9d44f84e6..b52b4975a89 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -1491,19 +1491,16 @@ be set to `eglot-move-to-lsp-abiding-column' (the default), and
(line-end-position))))
(defun eglot-move-to-lsp-abiding-column (column)
- "Move to COLUMN abiding by the LSP spec."
- (save-restriction
- (cl-loop
- with lbp = (line-beginning-position)
- initially
- (narrow-to-region lbp (line-end-position))
- (move-to-column column)
- for diff = (- column
- (eglot-lsp-abiding-column lbp))
- until (zerop diff)
- do (condition-case eob-err
- (forward-char (/ (if (> diff 0) (1+ diff) (1- diff)) 2))
- (end-of-buffer (cl-return eob-err))))))
+ "Move to COLUMN as computed by LSP's UTF-16 criterion."
+ (let* ((bol (line-beginning-position))
+ (goal-char (+ bol column))
+ (eol (line-end-position)))
+ (goto-char bol)
+ (while (and (< (point) goal-char)
+ (< (point) eol))
+ (if (<= #x010000 (char-after) #x10ffff)
+ (setq goal-char (1- goal-char)))
+ (forward-char 1))))
(defun eglot--lsp-position-to-point (pos-plist &optional marker)
"Convert LSP position POS-PLIST to Emacs point.