Fix buffer defuns (fix cycle-real-buffers)
This commit is contained in:
parent
d4dc1eeeb3
commit
6e768382d0
1 changed files with 21 additions and 21 deletions
|
@ -38,12 +38,11 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf:kill-real-buffer ()
|
(defun narf:kill-real-buffer ()
|
||||||
"Kill buffer (but only bury scratch buffer), then switch to a living buffer."
|
"Kill buffer (but only bury scratch buffer), then switch to a real buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((bname (buffer-name)))
|
(let ((bname (buffer-name)))
|
||||||
(cond ((string-match-p "^\\*scratch\\*" bname)
|
(cond ((string-match-p "^\\*scratch\\*" bname)
|
||||||
(erase-buffer)
|
(erase-buffer))
|
||||||
(bury-buffer))
|
|
||||||
((string-equal "*" (substring bname 0 1)))
|
((string-equal "*" (substring bname 0 1)))
|
||||||
(t (kill-this-buffer))))
|
(t (kill-this-buffer))))
|
||||||
(unless (narf/real-buffer-p (current-buffer))
|
(unless (narf/real-buffer-p (current-buffer))
|
||||||
|
@ -78,13 +77,8 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
|
||||||
(or buffer-list (narf/get-buffers))))
|
(or buffer-list (narf/get-buffers))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/get-real-buffers(&optional buffer-list)
|
(defun narf/get-real-buffers (&optional buffer-list)
|
||||||
(-filter (lambda (buffer)
|
(-filter 'narf/real-buffer-p (or buffer-list (narf/get-buffers))))
|
||||||
(not (--any? (if (stringp it)
|
|
||||||
(string-match-p it (buffer-name buffer))
|
|
||||||
(eq (buffer-local-value 'major-mode buffer) it))
|
|
||||||
narf-unreal-buffers)))
|
|
||||||
(or buffer-list (narf/get-buffers))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf:kill-unreal-buffers ()
|
(defun narf:kill-unreal-buffers ()
|
||||||
|
@ -124,22 +118,28 @@ Inspired from http://demonastery.org/2013/04/emacs-evil-narrow-region/"
|
||||||
(if buffer-list buffer-list (narf/get-buffers))))
|
(if buffer-list buffer-list (narf/get-buffers))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun narf/cycle-real-buffers (&optional n)
|
(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)
|
||||||
|
(i 0)
|
||||||
|
(continue t))
|
||||||
(funcall move-func)
|
(funcall move-func)
|
||||||
(while (let ((current-buffer (current-buffer)))
|
(while (and continue (< i max))
|
||||||
(and (if (eq current-buffer start-buffer)
|
(let ((current-buffer (current-buffer)))
|
||||||
(ignore (switch-to-buffer "*scratch*"))
|
(cond ((eq current-buffer start-buffer)
|
||||||
t)
|
(if scratch-default
|
||||||
(not (= n 0))
|
(switch-to-buffer "*scratch*")
|
||||||
(not (eq current-buffer start-buffer))
|
(user-error "No other buffers"))
|
||||||
(not (memq current-buffer real-buffers))))
|
(setq continue nil))
|
||||||
(setq n (1- n))
|
((not (memq current-buffer real-buffers))
|
||||||
(funcall move-func))))
|
(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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue