What the .emacs.d!?

Undo in region is one of those mind-blowing things about emacs. However, the region keeps jumping about when I use it. So I added this:


;; Keep region when undoing in region
(defadvice undo-tree-undo (around keep-region activate)
  (if (use-region-p)
      (let ((m (set-marker (make-marker) (mark)))
            (p (set-marker (make-marker) (point))))
        ad-do-it
        (goto-char p)
        (set-mark m)
        (set-marker p nil)
        (set-marker m nil))
    ad-do-it))

Now the region stays in place while I'm undoing.

Since I use undo-tree, that's what it advises, but I would guess it works the same for regular old undo too.

blog comments powered by Disqus