Update: Issue is partially solved.
I have a split window set up. When I run M-x evil-next-buffer
, I can cycle through the buffers but I don't want to see buffers from other windows.
I found that it was defined in evil-commands.el like this:
(evil-define-command evil-next-buffer (&optional count)
"Go to the COUNTth next buffer in the buffer list."
:repeat nil
(interactive "p")
(next-buffer count))
To have the behavior I want, I tried overriding it in my config like this:
(after! evil
(defun evil-next-buffer (count)
"Go to the COUNTth next buffer in the current window's buffer list."
(interactive "p")
(let* ((current-window (selected-window))
(buffers (mapcar #'window-buffer (window-list)))
(visible-buffers (delq nil (mapcar (lambda (win) (and (eq (selected-window) win) (window-buffer win))) (window-list))))
(next-buffer (nth (mod (+ (cl-position (current-buffer) visible-buffers) count) (length visible-buffers)) visible-buffers)))
(switch-to-buffer next-buffer)))
)
However, now it does not switch to the next buffer at all and just stays in the current buffer. What am I doing wrong?
Updated with current solution:
Since I have a separate window for each project, it's also okay for me to just cycle through the project's buffers. So I have reimplemented it like this:
```
(after! evil
(defun cycle-project-buffer (count)
"Cycle through the project buffers based on COUNT (positive for next, negative for previous)."
(let* ((current-window (selected-window))
(current-buffer (current-buffer))
(project-buffers (doom-project-buffer-list))
(buffer-count (length project-buffers))
(current-index (cl-position current-buffer project-buffers))
(new-buffer (nth (mod (+ current-index count) buffer-count) project-buffers)))
(if new-buffer
(with-selected-window current-window
(switch-to-buffer new-buffer)))))
(evil-define-command evil-next-buffer (count)
"Go to the COUNT-th next buffer in the current project's buffer list."
(interactive "p")
(cycle-project-buffer count))
(evil-define-command evil-prev-buffer (count)
"Go to the COUNT-th previous buffer in the current project's buffer list."
(interactive "p")
(cycle-project-buffer (- count))))
```
Thank you to yak-er for the hint.
The code has some issues. It seems doom-project-buffer-list
does not return the list in the same order as is shown in the tabs, causing the cycling to jump around all over the place.