Smarter :narrow command

This commit is contained in:
Henrik Lissner 2016-10-04 22:53:49 +02:00
parent 09c805b84e
commit 615cffe42e

View file

@ -1,5 +1,7 @@
;;; defuns-buffers.el ;;; defuns-buffers.el
(defvar-local doom--narrowed-origin nil)
;;;###autoload (autoload 'doom:narrow "defuns-buffers" nil t) ;;;###autoload (autoload 'doom:narrow "defuns-buffers" nil t)
(evil-define-operator doom:narrow (&optional beg end bang) (evil-define-operator doom:narrow (&optional beg end bang)
"Restrict editing in this buffer to the current region, indirectly. With BANG, "Restrict editing in this buffer to the current region, indirectly. With BANG,
@ -11,11 +13,17 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
(if (region-active-p) (if (region-active-p)
(progn (progn
(deactivate-mark) (deactivate-mark)
(let ((buf (clone-indirect-buffer nil nil))) (when bang
(with-current-buffer buf (let ((old-buf (current-buffer)))
(narrow-to-region beg end)) (switch-to-buffer (clone-indirect-buffer nil nil))
(switch-to-buffer buf))) (setq doom--narrowed-origin old-buf)))
(widen))) (narrow-to-region beg end))
(if doom--narrowed-origin
(progn
(kill-this-buffer)
(switch-to-buffer doom--narrowed-origin)
(setq doom--narrowed-origin nil))
(widen))))
;;;###autoload ;;;###autoload
(defun doom/set-read-only-region (begin end) (defun doom/set-read-only-region (begin end)