doom--cycle-real-buffers: if n=0, switch to fallback buffer

This commit is contained in:
Henrik Lissner 2018-01-03 13:44:14 -05:00
parent fa72e8d09b
commit 00cc57a2bd
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -126,29 +126,31 @@ If DERIVED-P, test with `derived-mode-p', otherwise use `eq'."
when (string-match-p pattern (buffer-name buf)) when (string-match-p pattern (buffer-name buf))
collect buf)) collect buf))
(defun doom--cycle-real-buffers (&optional n) (defun doom--cycle-real-buffers (n)
"Switch to the next buffer N times (previous, if N < 0), skipping over unreal "Switch to the next buffer N times (previous, if N < 0), skipping over unreal
buffers. If there's nothing left, switch to `doom-fallback-buffer'. See buffers. If there's nothing left, switch to `doom-fallback-buffer'. See
`doom-real-buffer-p' for what 'real' means." `doom-real-buffer-p' for what 'real' means."
(let ((buffers (delq (current-buffer) (doom-real-buffer-list)))) (if (null n)
(cond ((or (not buffers) (switch-to-buffer (doom-fallback-buffer) nil t)
(zerop (% n (1+ (length buffers))))) (let ((buffers (delq (current-buffer) (doom-real-buffer-list))))
(switch-to-buffer (doom-fallback-buffer) nil t)) (cond ((or (not buffers)
((= (length buffers) 1) (zerop (% n (1+ (length buffers)))))
(switch-to-buffer (car buffers) nil t)) (switch-to-buffer (doom-fallback-buffer) nil t))
(t ((= (length buffers) 1)
;; Why this instead of switching straight to the Nth buffer in (switch-to-buffer (car buffers) nil t))
;; BUFFERS? Because `switch-to-next-buffer' and (t
;; `switch-to-prev-buffer' properly update buffer list order. ;; Why this instead of switching straight to the Nth buffer in
(cl-loop with move-func = ;; BUFFERS? Because `switch-to-next-buffer' and
(if (> n 0) #'switch-to-next-buffer #'switch-to-prev-buffer) ;; `switch-to-prev-buffer' properly update buffer list order.
for i to 20 (cl-loop with move-func =
while (not (memq (current-buffer) buffers)) (if (> n 0) #'switch-to-next-buffer #'switch-to-prev-buffer)
do for i to 20
(dotimes (_i (abs n)) while (not (memq (current-buffer) buffers))
(funcall move-func))))) do
(force-mode-line-update) (dotimes (_i (abs n))
(current-buffer))) (funcall move-func)))))))
(force-mode-line-update)
(current-buffer))
;;;###autoload ;;;###autoload
(defun doom-set-buffer-real (buffer flag) (defun doom-set-buffer-real (buffer flag)