* How to know the buffer I will return to from the minibuffer?
@ 2019-02-14 7:10 Marcin Borkowski
2019-02-14 8:39 ` tomas
2019-02-14 15:38 ` Drew Adams
0 siblings, 2 replies; 5+ messages in thread
From: Marcin Borkowski @ 2019-02-14 7:10 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Hi all,
I am writing an interactive command to be used while in the minibuffer.
I need to know the buffer I was in when I issued the command that put me
in the minibuffer (like M-: or M-!). I tried (other-buffer
(current-buffer)) and (last-buffer (current-buffer)), but to no avail.
Then I re-read the docs for `other-buffer' and used this: (other-buffer
(current-buffer) t), and it seemed to work. The question is, how
reliable it is. Am I doing this correctly?
TIA,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to know the buffer I will return to from the minibuffer?
2019-02-14 7:10 How to know the buffer I will return to from the minibuffer? Marcin Borkowski
@ 2019-02-14 8:39 ` tomas
2019-02-17 6:00 ` Marcin Borkowski
2019-02-14 15:38 ` Drew Adams
1 sibling, 1 reply; 5+ messages in thread
From: tomas @ 2019-02-14 8:39 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 967 bytes --]
On Thu, Feb 14, 2019 at 08:10:54AM +0100, Marcin Borkowski wrote:
> Hi all,
>
> I am writing an interactive command to be used while in the minibuffer.
> I need to know the buffer I was in when I issued the command that put me
> in the minibuffer (like M-: or M-!). I tried (other-buffer
> (current-buffer)) and (last-buffer (current-buffer)), but to no avail.
> Then I re-read the docs for `other-buffer' and used this: (other-buffer
> (current-buffer) t), and it seemed to work. The question is, how
> reliable it is. Am I doing this correctly?
There's also minibuffer-selected-window (Emacs 27.0.50 here):
minibuffer-selected-window is a built-in function in ‘C source code’.
(minibuffer-selected-window)
Return window selected just before minibuffer window was selected.
Return nil if the selected window is not a minibuffer window.
This function does not change global state, including the match data.
HTH
-- tomás
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to know the buffer I will return to from the minibuffer?
2019-02-14 8:39 ` tomas
@ 2019-02-17 6:00 ` Marcin Borkowski
0 siblings, 0 replies; 5+ messages in thread
From: Marcin Borkowski @ 2019-02-17 6:00 UTC (permalink / raw)
To: tomas; +Cc: help-gnu-emacs
On 2019-02-14, at 09:39, tomas@tuxteam.de wrote:
> On Thu, Feb 14, 2019 at 08:10:54AM +0100, Marcin Borkowski wrote:
>> Hi all,
>>
>> I am writing an interactive command to be used while in the minibuffer.
>> I need to know the buffer I was in when I issued the command that put me
>> in the minibuffer (like M-: or M-!). I tried (other-buffer
>> (current-buffer)) and (last-buffer (current-buffer)), but to no avail.
>> Then I re-read the docs for `other-buffer' and used this: (other-buffer
>> (current-buffer) t), and it seemed to work. The question is, how
>> reliable it is. Am I doing this correctly?
>
> There's also minibuffer-selected-window (Emacs 27.0.50 here):
>
> minibuffer-selected-window is a built-in function in ‘C source code’.
>
> (minibuffer-selected-window)
>
> Return window selected just before minibuffer window was selected.
> Return nil if the selected window is not a minibuffer window.
> This function does not change global state, including the match data.
>
> HTH
> -- tomás
Yes, that seems to help a lot - thanks!
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: How to know the buffer I will return to from the minibuffer?
2019-02-14 7:10 How to know the buffer I will return to from the minibuffer? Marcin Borkowski
2019-02-14 8:39 ` tomas
@ 2019-02-14 15:38 ` Drew Adams
2019-02-17 5:59 ` Marcin Borkowski
1 sibling, 1 reply; 5+ messages in thread
From: Drew Adams @ 2019-02-14 15:38 UTC (permalink / raw)
To: Marcin Borkowski, Help Gnu Emacs mailing list
> I am writing an interactive command to be used while in the minibuffer.
> I need to know the buffer I was in when I issued the command that put
> me in the minibuffer (like M-: or M-!). I tried (other-buffer
> (current-buffer)) and (last-buffer (current-buffer)), but to no avail.
> Then I re-read the docs for `other-buffer' and used this: (other-buffer
> (current-buffer) t), and it seemed to work. The question is, how
> reliable it is. Am I doing this correctly?
If you use Icicles then that buffer is the value of variable
`icicle-pre-minibuffer-buffer':
Buffer that was current before the minibuffer became active.
and its window is the last-used window showing it:
(icicle-mru-window-for-buffer
icicle-pre-minibuffer-buffer 'noMNI 0)
When minibuffer setup occurs, the variable is set using
function `icicle-last-non-minibuffer-buffer', which does this:
(let ((live-bufs (icicle-remove-if
(lambda (buf) (not (buffer-live-p buf)))
(buffer-list))))
(or (car bufs) (car live-bufs)))
If you don't use Icicles you can do the same kind of thing.
Use `minibuffer-setup-hook' to set a variable to the last
live non-minibuffer buffer.
This is `icicle-mru-window-for-buffer':
(defun icicle-mru-window-for-buffer (buffer &optional
minibuf all-frames)
"Return the most recently used window for BUFFER.
Optional args MINIBUF and ALL-FRAMES are as for
`get-buffer-window-list'."
(let* ((wins (get-buffer-window-list
buffer minibuf all-frames))
(mru-win (car wins))
(mru-time (window-use-time mru-win))
wtime)
(unless (listp mru-time)
(setq mru-time (seconds-to-time mru-time)))
(dolist (win (cdr wins))
(setq wtime (window-use-time win))
(unless (listp wtime)
(setq wtime (seconds-to-time wtime)))
(unless (time-less-p wtime mru-time)
(setq mru-time wtime
mru-win win)))
mru-win))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to know the buffer I will return to from the minibuffer?
2019-02-14 15:38 ` Drew Adams
@ 2019-02-17 5:59 ` Marcin Borkowski
0 siblings, 0 replies; 5+ messages in thread
From: Marcin Borkowski @ 2019-02-17 5:59 UTC (permalink / raw)
To: Drew Adams; +Cc: Help Gnu Emacs mailing list
On 2019-02-14, at 16:38, Drew Adams <drew.adams@oracle.com> wrote:
>> I am writing an interactive command to be used while in the minibuffer.
>> I need to know the buffer I was in when I issued the command that put
>> me in the minibuffer (like M-: or M-!). I tried (other-buffer
>> (current-buffer)) and (last-buffer (current-buffer)), but to no avail.
>> Then I re-read the docs for `other-buffer' and used this: (other-buffer
>> (current-buffer) t), and it seemed to work. The question is, how
>> reliable it is. Am I doing this correctly?
>
> If you use Icicles then that buffer is the value of variable
> `icicle-pre-minibuffer-buffer':
I don't, but thanks for pointing me to `minibuffer-setup-hook' - it is
interesting in itself.
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-02-17 6:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-14 7:10 How to know the buffer I will return to from the minibuffer? Marcin Borkowski
2019-02-14 8:39 ` tomas
2019-02-17 6:00 ` Marcin Borkowski
2019-02-14 15:38 ` Drew Adams
2019-02-17 5:59 ` Marcin Borkowski
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).