From: Eshel Yaron <me@eshelyaron.com>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: How do I find out, in a Lisp program, what is the current buffer?
Date: Tue, 05 Dec 2023 16:03:18 +0100 [thread overview]
Message-ID: <m1h6kwk7yh.fsf@dazzs-mbp.home> (raw)
In-Reply-To: <ZW81RPhXsI2mq8F0@ACM> (Alan Mackenzie's message of "Tue, 5 Dec 2023 14:35:48 +0000")
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*>".
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. 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.
Good luck,
Eshel
next prev parent reply other threads:[~2023-12-05 15:03 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 [this message]
2023-12-05 15:20 ` Alan Mackenzie
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=m1h6kwk7yh.fsf@dazzs-mbp.home \
--to=me@eshelyaron.com \
--cc=acm@muc.de \
--cc=emacs-devel@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 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).