help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding last *Async Shell Command* buffer?


From: Jean Louis
Subject: Re: Finding last *Async Shell Command* buffer?
Date: Thu, 25 Mar 2021 22:31:04 +0300
User-agent: Mutt/2.0.6 (2021-03-06)

* Skip Montanaro <skip.montanaro@gmail.com> [2021-03-25 18:53]:
> > > The *Buffer List* should be sorted but if you want even
> > > faster, tell me what these buffers are called exactly...
> >
> > To find out the buffer by listing, I would need to enter each buffer
> > and review it if it is the right one.
> 
> You forgot to answer the last bit. How are these *Async Shell Command*
> buffers named? If there is just one, that is, by definition, the last
> one, I believe. If some counter is incremented each time one is
> created to avoid name collisions, choose the one with the largest
> number.

I have not inspected enough the function to understand how they are
created. But I know function `generate-new-buffer' and it seem like it
is created that way. It adds <NR> to the name of the buffer:

(generate-new-buffer "My new buffer") → My new buffer
(generate-new-buffer "My new buffer") → My new buffer<2>
(generate-new-buffer "My new buffer") → My new buffer<3>
(generate-new-buffer "My new buffer") → My new buffer<4>

Now if I delete buffer 2 by mistake or intentionally:

(kill-buffer "My new buffer<2>")

what happens in the next invokation is:

(generate-new-buffer "My new buffer") → My new buffer<2>

So that way among hundreds of buffer is difficult to find the buffer
that belongs to last invoked command.

> Can you give an example of how to create one or more of these
> buffers?

I invoke often commands by using M-S-& or in dired with & and it is
difficult to quickly find the output of last command. Sometimes is
output important.

> I'm not sure I've ever used an async shell before.

I am launching new programs and some Emacs commands also invoke async
shell. Sometimes I am using rsync as async-shell, so copy process goes
without blocking the interface.

Programmatically it should be easier to invoke it or I could even
change the function. But I was thinking there is maybe some way to
find the last async buffer.

>From description form M-&: `async-shell-command':

The output appears in the buffer whose name is stored in the
variable ‘shell-command-buffer-name-async’.  That buffer is in
shell mode.

Programmatically I could then make a function that changes the above
value by getting instead of the available number on the end, the date
or time part on the end, as that way it would be easy to parse list of
buffers created and find the last one. I I then replace M-& with that
new function that provides different buffer name by date/time, then it
is solved. That seem like direction forward.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]