From 4678385786ab8a1a939b2320c84c12d63cf012d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felici=C3=A1n=20N=C3=A9meth?= Date: Tue, 10 Sep 2019 15:31:16 +0200 Subject: [PATCH] Change the default of eglot-move-to-column-function 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: https://github.com/joaotavora/eglot/issues/293 #297: https://github.com/joaotavora/eglot/issues/297 --- lisp/progmodes/eglot.el | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 23d53edc2b..b87d5bb7c3 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -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 @@ -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."