Add fancy-narrow; now :narrow toggles narrowing
This commit is contained in:
parent
bc33c1bce4
commit
d10d3948f9
4 changed files with 26 additions and 11 deletions
1
Cask
1
Cask
|
@ -44,6 +44,7 @@
|
||||||
(depends-on "avy")
|
(depends-on "avy")
|
||||||
(depends-on "emr")
|
(depends-on "emr")
|
||||||
(depends-on "expand-region")
|
(depends-on "expand-region")
|
||||||
|
(depends-on "fancy-narrow")
|
||||||
(depends-on "goto-last-change")
|
(depends-on "goto-last-change")
|
||||||
(depends-on "hl-todo" :git "https://github.com/tarsius/hl-todo")
|
(depends-on "hl-todo" :git "https://github.com/tarsius/hl-todo")
|
||||||
(depends-on "rainbow-delimiters")
|
(depends-on "rainbow-delimiters")
|
||||||
|
|
|
@ -125,6 +125,9 @@
|
||||||
(use-package expand-region
|
(use-package expand-region
|
||||||
:commands (er/expand-region er/contract-region er/mark-symbol er/mark-word))
|
:commands (er/expand-region er/contract-region er/mark-symbol er/mark-word))
|
||||||
|
|
||||||
|
(use-package fancy-narrow
|
||||||
|
:commands (fancy-narrow-to-region fancy-widen))
|
||||||
|
|
||||||
(use-package goto-last-change
|
(use-package goto-last-change
|
||||||
:commands goto-last-change)
|
:commands goto-last-change)
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,33 @@
|
||||||
;;; defuns-buffers.el
|
;;; defuns-buffers.el
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload (autoload 'narf:narrow "defuns-buffers" nil t)
|
||||||
(defun narf:narrow (start end)
|
(evil-define-operator narf:narrow (&optional beg end bang)
|
||||||
"Restrict editing in this buffer to the current region, indirectly.
|
"Restrict editing in this buffer to the current region, indirectly. With BANG,
|
||||||
|
clone the buffer and hard-narrow the selection. Otherwise use fancy-narrow. If
|
||||||
|
mark isn't active, then widen the buffer (if narrowed).
|
||||||
|
|
||||||
Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
|
Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
|
||||||
(interactive "r")
|
(interactive "<r><!>")
|
||||||
(deactivate-mark)
|
(if (region-active-p)
|
||||||
(let ((buf (clone-indirect-buffer nil nil)))
|
(if bang
|
||||||
(with-current-buffer buf
|
(progn
|
||||||
(narrow-to-region start end))
|
(deactivate-mark)
|
||||||
(switch-to-buffer buf)))
|
(let ((buf (clone-indirect-buffer nil nil)))
|
||||||
|
(with-current-buffer buf
|
||||||
|
(narrow-to-region start end))
|
||||||
|
(switch-to-buffer buf)))
|
||||||
|
(fancy-narrow-to-region beg end))
|
||||||
|
(narf:widen)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf:widen ()
|
(defun narf:widen ()
|
||||||
"Undo narrowing (see `narf:narrow')"
|
"Widen a buffer that has been narrowed with `narrow-to-region' or
|
||||||
|
`fancy-narrow-to-region'"
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (buffer-narrowed-p)
|
(when (buffer-narrowed-p)
|
||||||
(widen)))
|
(widen))
|
||||||
|
(when (and (featurep 'fancy-narrow) fancy-narrow--beginning fancy-narrow--end)
|
||||||
|
(fancy-widen)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/set-read-only-region (begin end)
|
(defun narf/set-read-only-region (begin end)
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
(exmap "ma[ke]" 'narf:build)
|
(exmap "ma[ke]" 'narf:build)
|
||||||
(exmap "mv" 'narf:file-move)
|
(exmap "mv" 'narf:file-move)
|
||||||
(exmap "na[rrow]" 'narf:narrow) ; Narrow buffer to selection
|
(exmap "na[rrow]" 'narf:narrow) ; Narrow buffer to selection
|
||||||
|
(exmap "wi[den]" 'narf:widen) ; Widen narrowed buffer
|
||||||
(exmap "proj[ect]" 'helm-projectile-switch-project)
|
(exmap "proj[ect]" 'helm-projectile-switch-project)
|
||||||
(exmap "rec[ent]" 'narf:helm-recentf)
|
(exmap "rec[ent]" 'narf:helm-recentf)
|
||||||
(exmap "re[gex]" 'narf:regex)
|
(exmap "re[gex]" 'narf:regex)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue