From: Alan Mackenzie <acm@muc.de>
To: Eshel Yaron <me@eshelyaron.com>
Cc: emacs-devel@gnu.org
Subject: Re: How do I find out, in a Lisp program, what is the current buffer?
Date: Tue, 5 Dec 2023 15:20:23 +0000 [thread overview]
Message-ID: <ZW8_t1y5Lcz3xkzF@ACM> (raw)
In-Reply-To: <m1h6kwk7yh.fsf@dazzs-mbp.home>
Hello, Eshel.
Thanks for such a rapid reply!
On Tue, Dec 05, 2023 at 16:03:18 +0100, Eshel Yaron wrote:
> Hi Alan,
> Alan Mackenzie <acm@muc.de> writes:
> > I want to find out what is the current buffer, and I mean the REAL
> > current buffer.
> > In particular, if that is the minibuffer, I want to be told it's the (or
> > a) minibuffer, not the buffer it was invoked from. The function
> > current-buffer won't do this.
> My two cents: AFAICT, `current-buffer` does do this, in some sense at
> least. To see that, type `M-x (current-buffer) C-x C-e`, here Emacs
> says "#<buffer *Minibuf-1*>".
Ah. Thanks for the clarification.
> Note that when you say `M-: (current-buffer) RET` the form is read in
> the minibuffer, but it's evaluated in the original buffer. That's why you
> get the original buffer as the return value.
> `M-: (current-buffer) C-x C-e` points at the minibuffer as expected OTOH.
> > I want to use this for writing the current buffer into the new position
> > info in the doc string (bug #67455). Evaluating a defun in the
> > minibuffer is different from evaluating one in *scratch*.
> > Is there some way I can get this information from Lisp, or do I have to
> > write a new C primitive?
> IIUC, you need the buffer from which the form was read, not the one in
> which it was evaluated.
Yes, indeed. Thanks! If I read a form from the minibuffer with M-:,
which then evaluates it, the current buffer for the evaluation is not
the minibuffer any more.
> Perhaps `read_internal_start` could store its `stream` argument in
> some variable so if you immediately evaluate a form with that variable
> it would tell you where it was read from. It's just a rough idea,
> though.
It might be a good one, though. I'll have a close look at lread.c, and
see whether or not I can slip that in.
> Good luck,
> Eshel
--
Alan Mackenzie (Nuremberg, Germany).
prev parent reply other threads:[~2023-12-05 15:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-05 14:35 How do I find out, in a Lisp program, what is the current buffer? Alan Mackenzie
2023-12-05 15:03 ` Eshel Yaron
2023-12-05 15:20 ` Alan Mackenzie [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
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=ZW8_t1y5Lcz3xkzF@ACM \
--to=acm@muc.de \
--cc=emacs-devel@gnu.org \
--cc=me@eshelyaron.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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).