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:47:03 +0300 [thread overview]
Message-ID: <YMKyh74qU1eKhSsq@protected.localdomain> (raw)
In-Reply-To: <5fc2e0a6-470e-0ebc-fe81-9eea2dd7fa5f@akwebsoft.com>
* Tim Johnson <tim@akwebsoft.com> [2021-06-11 00:18]:
> GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo
> version 1.16.0)
> of 2021-06-04 ubuntu 20.04
>
> I would like to write three simple elisp routines that would each visit one
> of:
> *scratch*, *messages* and *shell*
>
> For *messages* I would only be reading or copying text.
> For *scratch* and *shell* I would be modifying those buffers.
>
> which elisp function is best for each of
> these buffers?
Here is function that will cycle over the list of buffer names:
(defvar rcd-switch-to-buffer-list '("*scratch*" "*shell*" "*Messages*"))
(defun rcd-switch-to-buffer ()
(interactive)
(if (member (current-buffer) (mapcar (lambda (buffer) (get-buffer buffer))
rcd-switch-to-buffer-list))
(when (buffer-live-p (next-circular-list-item
(mapcar (lambda (buffer) (get-buffer buffer))
rcd-switch-to-buffer-list)
(current-buffer)))
(switch-to-buffer
(next-circular-list-item
(mapcar (lambda (buffer) (get-buffer buffer))
rcd-switch-to-buffer-list)
(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 too:
(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))))))
Then M-x rcd-switch-to-buffer will cycle over the list of buffers.
--
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:47 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 [this message]
2021-06-11 0:51 ` Jean Louis
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=YMKyh74qU1eKhSsq@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).