From: Jean Louis <bugs@gnu.support>
To: Tim Johnson <tim@akwebsoft.com>
Cc: MLEmacs <Help-gnu-emacs@gnu.org>
Subject: Re: Visiting buffers programmatically
Date: Fri, 11 Jun 2021 03:51:29 +0300 [thread overview]
Message-ID: <YMKzkXcYkvB0Q1YS@protected.localdomain> (raw)
In-Reply-To: <5fc2e0a6-470e-0ebc-fe81-9eea2dd7fa5f@akwebsoft.com>
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/
next prev parent reply other threads:[~2021-06-11 0:51 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 [this message]
2021-06-11 17:27 ` Tim Johnson
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YMKzkXcYkvB0Q1YS@protected.localdomain \
--to=bugs@gnu.support \
--cc=Help-gnu-emacs@gnu.org \
--cc=tim@akwebsoft.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).