From: Tim Johnson <tim@akwebsoft.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Visiting buffers programmatically
Date: Fri, 11 Jun 2021 09:27:42 -0800 [thread overview]
Message-ID: <00afe9a3-2f29-7a57-0358-2463dc028aca@akwebsoft.com> (raw)
In-Reply-To: <YMKzkXcYkvB0Q1YS@protected.localdomain>
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
prev parent reply other threads:[~2021-06-11 17:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-10 21:17 Visiting buffers programmatically Tim Johnson
2021-06-10 23:31 ` pillule
2021-06-11 0:12 ` Tim Johnson
2021-06-11 0:17 ` pillule
2021-06-11 0:32 ` Tim Johnson
2021-06-11 0:47 ` Jean Louis
2021-06-11 0:51 ` Jean Louis
2021-06-11 17:27 ` Tim Johnson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=00afe9a3-2f29-7a57-0358-2463dc028aca@akwebsoft.com \
--to=tim@akwebsoft.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.