Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cycle backwards #3

Open
mihaiolteanu opened this issue Jan 10, 2022 · 1 comment
Open

cycle backwards #3

mihaiolteanu opened this issue Jan 10, 2022 · 1 comment

Comments

@mihaiolteanu
Copy link

How would one cycle backwards using cbm?

That is, suppose I have three buffers, one, two, three.
The current selected buffer is one.
I call cbm-cycle and now the selected buffer is two.
If I want to select the buffer one again, I would have to call cbm-cycle two times, one to select buffer three and the second time to wrap-around to buffer one.
How would one implement a cbm-cycle-back function that would go from two to one in the previous scenario in a single step?

@letlambdafree
Copy link

letlambdafree commented Oct 5, 2022

You can use this function.

(defun cbm-cycle-reverse ()
    "Cycles reverse through buffers with same `major-mode'."
    (interactive)
    (unless (eq last-command #'cbm-cycle-reverse)
      (setq cbm-buffers nil))
    (unless cbm-buffers
      (cbm-make-buffer-list))
    (setq cbm-buffers (append (last cbm-buffers) (butlast cbm-buffers)))
    (let ((buffer (car cbm-buffers)))
      (when (bufferp buffer)
        (switch-to-buffer buffer))))

I tested this with 5 buffers, it worked.
(note: last and butlast are in ‘subr.el’.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants