* How do I find out, in a Lisp program, what is the current buffer? @ 2023-12-05 14:35 Alan Mackenzie 2023-12-05 15:03 ` Eshel Yaron 0 siblings, 1 reply; 3+ messages in thread From: Alan Mackenzie @ 2023-12-05 14:35 UTC (permalink / raw) To: emacs-devel Hello, Emacs. 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. 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? Thanks in advance! -- Alan Mackenzie (Nuremberg, Germany). ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How do I find out, in a Lisp program, what is the current buffer? 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 0 siblings, 1 reply; 3+ messages in thread From: Eshel Yaron @ 2023-12-05 15:03 UTC (permalink / raw) To: Alan Mackenzie; +Cc: emacs-devel 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How do I find out, in a Lisp program, what is the current buffer? 2023-12-05 15:03 ` Eshel Yaron @ 2023-12-05 15:20 ` Alan Mackenzie 0 siblings, 0 replies; 3+ messages in thread From: Alan Mackenzie @ 2023-12-05 15:20 UTC (permalink / raw) To: Eshel Yaron; +Cc: emacs-devel 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). ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-05 15:20 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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
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).