core/autoload/buffers: rewrite switch-to-{next,prev} real buffer behavior
This commit is contained in:
parent
2cb115ebb7
commit
585a559422
1 changed files with 21 additions and 30 deletions
|
@ -94,36 +94,27 @@ match the regex PATTERN."
|
||||||
(or buffer-list (doom-buffer-list))))
|
(or buffer-list (doom-buffer-list))))
|
||||||
|
|
||||||
(defun doom--cycle-real-buffers (&optional n)
|
(defun doom--cycle-real-buffers (&optional n)
|
||||||
"Switch to the next buffer N times (previous, if N < 0), skipping over special
|
"Switch to the next buffer N times (previous, if N < 0), skipping over unreal
|
||||||
and unreal buffers. If there's nothing left, create a scratch buffer.
|
buffers. If there's nothing left, switch to `doom-fallback-buffer'. See
|
||||||
|
`doom-real-buffer-p' for what 'real' means."
|
||||||
See `doom-real-buffer-p' for what 'real' means."
|
(let ((buffers (delq (current-buffer) (doom-real-buffers-list)))
|
||||||
(let* ((start-buffer (current-buffer))
|
(project-dir (doom-project-root)))
|
||||||
(move-func (if (> n 0) 'switch-to-next-buffer 'switch-to-prev-buffer))
|
(cond ((or (not buffers)
|
||||||
(max 25)
|
(zerop (mod n (1+ (length buffers)))))
|
||||||
(i 0)
|
(set-window-buffer nil (doom-fallback-buffer)))
|
||||||
(project-dir (doom-project-root))
|
((= (length buffers) 1)
|
||||||
(buffers (doom-real-buffers-list))
|
(set-window-buffer nil (car buffers)))
|
||||||
destbuf)
|
(t
|
||||||
(setq destbuf
|
(let ((move-func (if (> n 0) 'switch-to-next-buffer 'switch-to-prev-buffer)))
|
||||||
(catch 'goto
|
;; Why this instead of switching straight to the Nth buffer in
|
||||||
(if (or (not buffers)
|
;; BUFFERS? Because `switch-to-next-buffer' and
|
||||||
(= (length buffers) 1))
|
;; `switch-to-prev-buffer' properly update buffer list order.
|
||||||
(throw 'goto t)
|
(while (not (memq (current-buffer) buffers))
|
||||||
(funcall move-func)
|
(dotimes (i (abs n))
|
||||||
(while (not (memq (current-buffer) buffers))
|
(funcall move-func))))))
|
||||||
(if (or (eq (current-buffer) start-buffer)
|
(when (eq (current-buffer) (doom-fallback-buffer))
|
||||||
(>= i max))
|
(cd project-dir))
|
||||||
(throw 'goto t)
|
(current-buffer)))
|
||||||
(funcall move-func))
|
|
||||||
(cl-incf i))
|
|
||||||
(current-buffer))))
|
|
||||||
(when (eq destbuf t)
|
|
||||||
(setq destbuf (doom-fallback-buffer)))
|
|
||||||
(prog1
|
|
||||||
(switch-to-buffer destbuf)
|
|
||||||
(when (eq destbuf (doom-fallback-buffer))
|
|
||||||
(cd project-dir)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-real-buffer-p (&optional buffer-or-name)
|
(defun doom-real-buffer-p (&optional buffer-or-name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue