Skip to content

Commit

Permalink
Change the default of eglot-move-to-column-function
Browse files Browse the repository at this point in the history
Previous default (move-to-column) works on visual columns, the LSP
specification and the new default (eglot-move-to-column) use "real"
columns.  Fixes #293 and #297.

* eglot.el (eglot-move-to-column): New function.
(eglot-move-to-column-function): Use it as default.

#293: joaotavora/eglot#293
#297: joaotavora/eglot#297
  • Loading branch information
nemethf authored and Felician Nemeth committed Sep 10, 2019
1 parent 074566a commit 4678385
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lisp/progmodes/eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ for all others.")
:character (progn (when pos (goto-char pos))
(funcall eglot-current-column-function)))))

(defvar eglot-move-to-column-function #'move-to-column
(defvar eglot-move-to-column-function #'eglot-move-to-column
"Function to move to a column reported by the LSP server.
According to the standard, LSP column/character offsets are based
Expand All @@ -999,7 +999,16 @@ where X is a multi-byte character, it actually means `b', not
For buffers managed by fully LSP-compliant servers, this should
be set to `eglot-move-to-lsp-abiding-column', and
`move-to-column' (the default) for all others.")
`eglot-move-to-column' (the default) for all others.")

(defun eglot-move-to-column (column)
"Move to COLUMN without closely following the LSP spec."
;; We cannot use `move-to-column' here, because it moves to *visual*
;; columns, which can be different from LSP columns in case of
;; `whitespace-mode', `prettify-symbols-mode', etc. (github#296,
;; github#297)
(goto-char (min (+ (line-beginning-position) column)
(line-end-position))))

(defun eglot-move-to-lsp-abiding-column (column)
"Move to COLUMN abiding by the LSP spec."
Expand Down

0 comments on commit 4678385

Please sign in to comment.