Refactor buffer library fns
This commit is contained in:
parent
b3c1351fa6
commit
036b7521dc
1 changed files with 23 additions and 27 deletions
|
@ -22,18 +22,18 @@ killed by `doom:kill-old-buffers', or after `doom-kill-buffer').")
|
||||||
checks before killing processes. If there are no buffers with matching
|
checks before killing processes. If there are no buffers with matching
|
||||||
major-modes, the process gets killed.")
|
major-modes, the process gets killed.")
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom-buffer:narrow "core/autoload/buffers" nil t)
|
;;;###autoload
|
||||||
(evil-define-operator doom-buffer:narrow (&optional beg end bang)
|
(defun doom-narrow-buffer (beg end &optional clone-p)
|
||||||
"Restrict editing in this buffer to the current region, indirectly. With BANG,
|
"Restrict editing in this buffer to the current region, indirectly. With BANG,
|
||||||
clone the buffer and hard-narrow the selection. If mark isn't active, then widen
|
clone the buffer and hard-narrow the selection. If mark isn't active, then widen
|
||||||
the buffer (if narrowed).
|
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")
|
||||||
(if (region-active-p)
|
(if (region-active-p)
|
||||||
(progn
|
(progn
|
||||||
(deactivate-mark)
|
(deactivate-mark)
|
||||||
(when bang
|
(when clone-p
|
||||||
(let ((old-buf (current-buffer)))
|
(let ((old-buf (current-buffer)))
|
||||||
(switch-to-buffer (clone-indirect-buffer nil nil))
|
(switch-to-buffer (clone-indirect-buffer nil nil))
|
||||||
(setq doom-buffer--narrowed-origin old-buf)))
|
(setq doom-buffer--narrowed-origin old-buf)))
|
||||||
|
@ -45,6 +45,12 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
|
||||||
(setq doom-buffer--narrowed-origin nil))
|
(setq doom-buffer--narrowed-origin nil))
|
||||||
(widen))))
|
(widen))))
|
||||||
|
|
||||||
|
;;;###autoload (autoload 'doom:buffer-narrow "core/autoload/buffers" nil t)
|
||||||
|
(after! evil
|
||||||
|
(evil-define-operator doom:buffer-narrow (&optional beg end bang)
|
||||||
|
(interactive "<r><!>")
|
||||||
|
(doom-narrow-buffer beg end bang)))
|
||||||
|
|
||||||
|
|
||||||
;; Buffer Life and Death ;;;;;;;;;;;;;;;
|
;; Buffer Life and Death ;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
@ -152,14 +158,6 @@ popup (or temporary) window and b) it isn't a special buffer (e.g. scratch or
|
||||||
(--any? (string-match-p it (buffer-name buffer))
|
(--any? (string-match-p it (buffer-name buffer))
|
||||||
(-filter 'stringp doom-buffers-unreal-alist)))))))
|
(-filter 'stringp doom-buffers-unreal-alist)))))))
|
||||||
|
|
||||||
(defun doom--kill-buffers (buffers &optional filter-func)
|
|
||||||
(let ((buffers (if filter-func (-filter filter-func buffers) buffers))
|
|
||||||
(affected 0))
|
|
||||||
(mapc (lambda (b) (when (kill-buffer b) (incf affected))) buffers)
|
|
||||||
(unless (doom-real-buffer-p)
|
|
||||||
(doom--cycle-real-buffers -1))
|
|
||||||
(message "Killed %s buffers" affected)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom/next-buffer ()
|
(defun doom/next-buffer ()
|
||||||
"Switch to the next real buffer, skipping special buffers. See
|
"Switch to the next real buffer, skipping special buffers. See
|
||||||
|
@ -196,8 +194,8 @@ See `doom-real-buffer-p' for what 'real' means."
|
||||||
(when only-buffer-window-p
|
(when only-buffer-window-p
|
||||||
(kill-buffer buffer)
|
(kill-buffer buffer)
|
||||||
(unless (doom-real-buffer-p)
|
(unless (doom-real-buffer-p)
|
||||||
(doom--cycle-real-buffers -1))))))
|
(doom--cycle-real-buffers -1))))
|
||||||
t)
|
(eq (current-buffer) buffer))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-kill-buffer-and-windows (buffer)
|
(defun doom-kill-buffer-and-windows (buffer)
|
||||||
|
@ -237,9 +235,7 @@ regex PATTERN. Returns the number of killed buffers."
|
||||||
(defun doom/kill-this-buffer ()
|
(defun doom/kill-this-buffer ()
|
||||||
"Uses `doom-kill-buffer' on the current buffer."
|
"Uses `doom-kill-buffer' on the current buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(doom-kill-buffer (current-buffer))
|
(when (and (doom-kill-buffer) (called-interactively-p 'interactive))
|
||||||
(when (and (called-interactively-p 'interactive)
|
|
||||||
(eq (current-buffer) doom-fallback-buffer))
|
|
||||||
(message "Nowhere left to go!")))
|
(message "Nowhere left to go!")))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue