From d82e252617d25cecdce6ac0ce8f99d3dff92bdfe Mon Sep 17 00:00:00 2001 From: Magnar Sveen Date: Tue, 14 Aug 2012 06:41:18 +0200 Subject: [PATCH] Don't let fake cursors scroll the buffer --- multiple-cursors-core.el | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el index 9345e74..4d8d652 100644 --- a/multiple-cursors-core.el +++ b/multiple-cursors-core.el @@ -140,15 +140,16 @@ up the proper environment, and then removing the cursor. After executing the command, it sets up a new fake cursor with updated info." (mc/save-excursion - (mc/for-each-fake-cursor - (let ((id (overlay-get cursor 'mc-id)) - (annoying-arrows-mode nil) - (smooth-scroll-margin 0)) - (mc/add-fake-cursor-to-undo-list - (mc/pop-state-from-overlay cursor) - (ignore-errors - (mc/execute-command cmd) - (mc/create-fake-cursor-at-point id))))))) + (mc/save-window-scroll + (mc/for-each-fake-cursor + (save-excursion + (let ((id (overlay-get cursor 'mc-id)) + (annoying-arrows-mode nil)) + (mc/add-fake-cursor-to-undo-list + (mc/pop-state-from-overlay cursor) + (ignore-errors + (mc/execute-command cmd) + (mc/create-fake-cursor-at-point id))))))))) (defmacro mc/add-fake-cursor-to-undo-list (&rest forms) "Make sure point is in the right place when undoing" @@ -203,6 +204,18 @@ cursor with updated info." (save-excursion ,@forms) (mc/pop-state-from-overlay current-state))) +(defmacro mc/save-window-scroll (&rest forms) + "Saves and restores the window scroll position" + `(let ((p (set-marker (make-marker) (point))) + (start (set-marker (make-marker) (window-start))) + (hscroll (window-hscroll))) + ,@forms + (goto-char p) + (set-window-start nil start) + (set-window-hscroll nil hscroll) + (set-marker p nil) + (set-marker start nil))) + (defun mc/prompt-for-inclusion-in-whitelist (original-command) "Asks the user, then adds the command either to the once-list or the all-list." (let ((all-p (y-or-n-p (format "Do %S for all cursors?" original-command))))