Fix narf/cycle-real-buffers + refactor

This commit is contained in:
Henrik Lissner 2015-10-03 19:39:58 -04:00
parent ccd99d50ab
commit f25950170d

View file

@ -47,18 +47,6 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
;; Buffer Life and Death ;;;;;;;;;;;;;;; ;; Buffer Life and Death ;;;;;;;;;;;;;;;
;;;###autoload
(defun narf:kill-real-buffer ()
"Kill buffer (but only bury scratch buffer), then switch to a real buffer."
(interactive)
(let ((bname (buffer-name)))
(cond ((string-match-p "^\\*scratch\\*" bname)
(erase-buffer))
((string-equal "*" (substring bname 0 1)))
(t (kill-this-buffer))))
(unless (narf/real-buffer-p (current-buffer))
(narf/previous-real-buffer)))
;;;###autoload ;;;###autoload
(defun narf/get-all-buffers () (defun narf/get-all-buffers ()
"Get all buffers across all workgroups. Depends on "Get all buffers across all workgroups. Depends on
@ -91,6 +79,17 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
(defun narf/get-real-buffers (&optional buffer-list) (defun narf/get-real-buffers (&optional buffer-list)
(-filter #'narf/real-buffer-p (or buffer-list (narf/get-buffers)))) (-filter #'narf/real-buffer-p (or buffer-list (narf/get-buffers))))
;;;###autoload
(defun narf:kill-real-buffer ()
"Kill buffer (but only bury scratch buffer), then switch to a real buffer."
(interactive)
(let ((bname (buffer-name)))
(cond ((string-match-p "^\\*scratch\\*" bname)
(erase-buffer))
(t (kill-this-buffer))))
(unless (narf/real-buffer-p (current-buffer))
(narf/previous-real-buffer)))
;;;###autoload ;;;###autoload
(defun narf:kill-unreal-buffers () (defun narf:kill-unreal-buffers ()
"Kill all buried, unreal buffers in current frame. See `narf-unreal-buffers'" "Kill all buried, unreal buffers in current frame. See `narf-unreal-buffers'"
@ -135,24 +134,29 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
(defun narf/cycle-real-buffers (&optional n scratch-default) (defun narf/cycle-real-buffers (&optional n scratch-default)
"Switch to the previous buffer and avoid special buffers. If there's nothing "Switch to the previous buffer and avoid special buffers. If there's nothing
left, create a scratch buffer." left, create a scratch buffer."
(let ((start-buffer (current-buffer)) (let* ((start-buffer (current-buffer))
(move-func (if (< n 0) 'switch-to-next-buffer 'switch-to-prev-buffer)) (move-func (if (< n 0) 'switch-to-next-buffer 'switch-to-prev-buffer))
(real-buffers (narf/get-real-buffers)) (real-buffers (narf/get-real-buffers))
(max 25) (realc (length real-buffers))
(i 0) (max 25)
(continue t)) (i 0)
(funcall move-func) (continue t))
(while (and continue (< i max)) (if (or (= realc 0)
(let ((current-buffer (current-buffer))) (and (= realc 1) (eq (car real-buffers) (current-buffer))))
(cond ((eq current-buffer start-buffer) (progn (switch-to-buffer "*scratch*")
(if scratch-default (message "Nowhere to go"))
(switch-to-buffer "*scratch*")) (funcall move-func)
(setq continue nil)) (while (and continue (< i max))
((not (memq current-buffer real-buffers)) (let ((current-buffer (current-buffer)))
(funcall move-func)) (cond ((eq current-buffer start-buffer)
(t (if scratch-default
(setq continue nil)))) (switch-to-buffer "*scratch*"))
(cl-incf i)))) (setq continue nil))
((not (memq current-buffer real-buffers))
(funcall move-func))
(t
(setq continue nil))))
(cl-incf i)))))
;;;###autoload ;;;###autoload
(defun narf/real-buffer-p (&optional buffer-or-name) (defun narf/real-buffer-p (&optional buffer-or-name)