[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Visiting buffers programmatically
From: |
Jean Louis |
Subject: |
Re: Visiting buffers programmatically |
Date: |
Fri, 11 Jun 2021 03:51:29 +0300 |
User-agent: |
Mutt/2.0.7+183 (3d24855) (2021-05-28) |
The previous one was repetitive, here is shorter version:
(defvar rcd-switch-to-buffer-list '("*scratch*" "*shell*" "*Messages*"))
(defun rcd-switch-to-buffer ()
(interactive)
(let ((buffers (mapcar (lambda (buffer) (get-buffer buffer))
rcd-switch-to-buffer-list)))
(if (member (current-buffer) buffers)
(when (buffer-live-p (next-circular-list-item buffers (current-buffer)))
(switch-to-buffer
(next-circular-list-item buffers (current-buffer))))
(when (buffer-live-p (get-buffer (nth 0 rcd-switch-to-buffer-list)))
(switch-to-buffer (nth 0 rcd-switch-to-buffer-list))))))
and you need this one:
(defun next-circular-list-item (list previous-item)
"Return the next element in the LIST by looking at PREVIOUS-ITEM.
All elements in the LIST have to be different.
If last element of LIST is equal to PREVIOUS-ITEM then first element is
returned."
(let ((last-element (car (last list))))
(cond ((eq last-element previous-item) (car list))
(t (nth 1 (member previous-item list))))))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/