help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Visiting buffers programmatically


From: Tim Johnson
Subject: Re: Visiting buffers programmatically
Date: Fri, 11 Jun 2021 09:27:42 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1



On 6/10/21 4:51 PM, Jean Louis wrote:
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))))))

Serendipity!It is more than I was looking for to roll my own,
but you have rolled some interesting code. I will give it a home.
Thank you Jean

--
Tim
tj49.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]