emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot 8332cdf 52/54: Fix eglot-move-to-lsp-abiding-colu


From: João Távora
Subject: [elpa] externals/eglot 8332cdf 52/54: Fix eglot-move-to-lsp-abiding-column (#361)
Date: Thu, 16 Apr 2020 05:31:53 -0400 (EDT)

branch: externals/eglot
commit 8332cdffeab89f6ba3bf7bc5c744d8ced1f4fda2
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Fix eglot-move-to-lsp-abiding-column (#361)
    
    Ensure conformance with the this part of the specification: "if the
    character value is greater than the line length it defaults back to
    the line length."
    
    * eglot.el: (eglot-move-to-lsp-abiding-column): Don't move beyond
    line-end.
---
 eglot.el | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/eglot.el b/eglot.el
index 3149cd5..2a50611 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1050,15 +1050,20 @@ be set to `eglot-move-to-lsp-abiding-column', and
 
 (defun eglot-move-to-lsp-abiding-column (column)
   "Move to COLUMN abiding by the LSP spec."
-  (cl-loop
-   initially (move-to-column column)
-   with lbp = (line-beginning-position)
-   for diff = (- column
-                 (/ (- (length (encode-coding-region lbp (point) 'utf-16 t))
-                       2)
-                    2))
-   until (zerop diff)
-   do (forward-char (/ (if (> diff 0) (1+ diff) (1- diff)) 2))))
+  (save-restriction
+    (cl-loop
+     with lbp = (line-beginning-position)
+     initially
+     (narrow-to-region lbp (line-end-position))
+     (move-to-column column)
+     for diff = (- column
+                   (/ (- (length (encode-coding-region lbp (point) 'utf-16 t))
+                         2)
+                      2))
+     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))))))
 
 (defun eglot--lsp-position-to-point (pos-plist &optional marker)
   "Convert LSP position POS-PLIST to Emacs point.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]