doom-narrow-buffer renamed to doom/narrow-buffer and moved

This commit is contained in:
Henrik Lissner 2017-12-29 22:29:57 -05:00
parent 574a783f7f
commit 0c06514c6f
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 27 additions and 23 deletions

View file

@ -14,34 +14,17 @@
"The name of the buffer to fall back to if no other buffers exist (will create "The name of the buffer to fall back to if no other buffers exist (will create
it if it doesn't exist).") it if it doesn't exist).")
;;
;; Functions
;;
;;;###autoload ;;;###autoload
(defun doom-fallback-buffer () (defun doom-fallback-buffer ()
"Returns the fallback buffer, creating it if necessary. By default this is the "Returns the fallback buffer, creating it if necessary. By default this is the
scratch buffer." scratch buffer."
(get-buffer-create doom-fallback-buffer)) (get-buffer-create doom-fallback-buffer))
;;;###autoload
(defun doom-narrow-buffer (beg end &optional clone-p)
"Restrict editing in this buffer to the current region, indirectly. With CLONE-P,
clone the buffer and hard-narrow the selection. If mark isn't active, then widen
the buffer (if narrowed).
Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
(interactive "r")
(cond ((region-active-p)
(deactivate-mark)
(when clone-p
(let ((old-buf (current-buffer)))
(switch-to-buffer (clone-indirect-buffer nil nil))
(setq doom-buffer--narrowed-origin old-buf)))
(narrow-to-region beg end))
(doom-buffer--narrowed-origin
(kill-this-buffer)
(switch-to-buffer doom-buffer--narrowed-origin)
(setq doom-buffer--narrowed-origin nil))
(t
(widen))))
;; Buffer Life and Death ;;;;;;;;;;;;;;; ;; Buffer Life and Death ;;;;;;;;;;;;;;;
;;;###autoload ;;;###autoload

View file

@ -218,8 +218,29 @@ consistent throughout a selected region, depending on `indent-tab-mode'."
(tabify beg end) (tabify beg end)
(untabify beg end))) (untabify beg end)))
;;;###autoload
(defun doom/narrow-buffer (beg end &optional clone-p)
"Restrict editing in this buffer to the current region, indirectly. With CLONE-P,
clone the buffer and hard-narrow the selection. If mark isn't active, then widen
the buffer (if narrowed).
Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
(interactive "r")
(cond ((region-active-p)
(deactivate-mark)
(when clone-p
(let ((old-buf (current-buffer)))
(switch-to-buffer (clone-indirect-buffer nil nil))
(setq doom-buffer--narrowed-origin old-buf)))
(narrow-to-region beg end))
(doom-buffer--narrowed-origin
(kill-this-buffer)
(switch-to-buffer doom-buffer--narrowed-origin)
(setq doom-buffer--narrowed-origin nil))
(t
(widen))))
;;;###autoload ;;;###autoload
(defun doom|enable-delete-trailing-whitespace () (defun doom|enable-delete-trailing-whitespace ()
"Attaches `delete-trailing-whitespace' to a buffer-local `before-save-hook'." "Attaches `delete-trailing-whitespace' to a buffer-local `before-save-hook'."
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t)) (add-hook 'before-save-hook #'delete-trailing-whitespace nil t))