Add fancy-narrow; now :narrow toggles narrowing

This commit is contained in:
Henrik Lissner 2015-09-28 14:41:37 -04:00
parent bc33c1bce4
commit d10d3948f9
4 changed files with 26 additions and 11 deletions

1
Cask
View file

@ -44,6 +44,7 @@
(depends-on "avy")
(depends-on "emr")
(depends-on "expand-region")
(depends-on "fancy-narrow")
(depends-on "goto-last-change")
(depends-on "hl-todo" :git "https://github.com/tarsius/hl-todo")
(depends-on "rainbow-delimiters")

View file

@ -125,6 +125,9 @@
(use-package expand-region
: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
:commands goto-last-change)

View file

@ -1,23 +1,33 @@
;;; defuns-buffers.el
;;;###autoload
(defun narf:narrow (start end)
"Restrict editing in this buffer to the current region, indirectly.
;;;###autoload (autoload 'narf:narrow "defuns-buffers" nil t)
(evil-define-operator narf:narrow (&optional beg end bang)
"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/"
(interactive "r")
(interactive "<r><!>")
(if (region-active-p)
(if bang
(progn
(deactivate-mark)
(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
(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)
(when (buffer-narrowed-p)
(widen)))
(widen))
(when (and (featurep 'fancy-narrow) fancy-narrow--beginning fancy-narrow--end)
(fancy-widen)))
;;;###autoload
(defun narf/set-read-only-region (begin end)

View file

@ -25,6 +25,7 @@
(exmap "ma[ke]" 'narf:build)
(exmap "mv" 'narf:file-move)
(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 "rec[ent]" 'narf:helm-recentf)
(exmap "re[gex]" 'narf:regex)