branch: externals/polymode commit 3ac3e26a3214a950188fc2d50890612d398cc83a Author: Dan Kessler <kessl...@umich.edu> Commit: Vitalie Spinu <spinu...@gmail.com>
Avoid moving point during pm--lsp-text --- polymode-compat.el | 69 ++++++++++++++++++++++++++++-------------------------- polymode-core.el | 2 ++ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/polymode-compat.el b/polymode-compat.el index ba122d5a5f..a05773c1e2 100644 --- a/polymode-compat.el +++ b/polymode-compat.el @@ -251,39 +251,42 @@ are passed to ORIG-FUN." (list :text (pm--lsp-text))) (defun pm--lsp-text (&optional beg end) - (save-restriction - (widen) - (setq beg (or beg (point-min))) - (setq end (or end (point-max))) - (let ((cmode major-mode) - (end-eol (save-excursion (goto-char end) - (line-end-position))) - line-acc acc) - (pm-map-over-modes - (lambda (sbeg send) - (let ((beg1 (max sbeg beg)) - (end1 (min send end)) - (rem)) - (if (eq cmode major-mode) - (progn - (when (eq sbeg beg1) - ;; first line of mode; use line-acc - (setq acc (append line-acc acc)) - (setq line-acc nil)) - ;; if cur-mode follows after end on same line, accumulate the - ;; last line but not the actual text - (when (< beg1 end) - (push (buffer-substring-no-properties beg1 end1) acc))) - (goto-char beg1) - (if (<= end1 (line-end-position)) - (when (< beg1 end1) ; don't accumulate on last line - (push (make-string (- end1 beg1) ? ) line-acc)) - (while (< (line-end-position) end1) - (push "\n" acc) - (forward-line 1)) - (setq line-acc (list (make-string (- end1 (point)) ? ))))))) - beg end-eol) - (apply #'concat (reverse acc))))) + (prog1 + (save-excursion + (save-restriction + (widen) + (setq beg (or beg (point-min))) + (setq end (or end (point-max))) + (let ((cmode major-mode) + (end-eol (save-excursion (goto-char end) + (point-at-eol))) + line-acc acc) + (pm-map-over-modes + (lambda (sbeg send) + (let ((beg1 (max sbeg beg)) + (end1 (min send end)) + (rem)) + (if (eq cmode major-mode) + (progn + (when (eq sbeg beg1) + ;; first line of mode; use line-acc + (setq acc (append line-acc acc)) + (setq line-acc nil)) + ;; if cur-mode follows after end on same line, accumulate the + ;; last line but not the actual text + (when (< beg1 end) + (push (buffer-substring-no-properties beg1 end1) acc))) + (goto-char beg1) + (if (<= end1 (point-at-eol)) + (when (< beg1 end1) ; don't accumulate on last line + (push (make-string (- end1 beg1) ? ) line-acc)) + (while (< (point-at-eol) end1) + (push "\n" acc) + (forward-line 1)) + (setq line-acc (list (make-string (- end1 (point)) ? ))))))) + beg end-eol) + (apply #'concat (reverse acc))))) + (pm--synchronize-points))) ;; We cannot compute original change location when modifications are complex ;; (aka multiple changes are combined). In those cases we send an entire diff --git a/polymode-core.el b/polymode-core.el index a69729dd54..04935468d0 100644 --- a/polymode-core.el +++ b/polymode-core.el @@ -1473,6 +1473,8 @@ Placed with low priority in `before-change-functions' hook." "Polymode after-change fixes. Run `polymode-run-these-after-change-functions-in-other-buffers'. Placed with low priority in `after-change-functions' hook." + ;; ensure points are synchronized (after-change runs BEFORE post-command-hook) + (pm--synchronize-points) (pm--run-other-hooks pm-allow-after-change-hook polymode-run-these-after-change-functions-in-other-buffers 'after-change-functions