all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Finding last *Async Shell Command* buffer?
@ 2021-03-25 14:33 Jean Louis
  2021-03-25 15:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-25 18:10 ` Filipp Gunbin
  0 siblings, 2 replies; 58+ messages in thread
From: Jean Louis @ 2021-03-25 14:33 UTC (permalink / raw)
  To: Help GNU Emacs

Is there way to find the last *Async Shell Command* buffer? 

Often I like running commands in background but there is hundreds of
buffers and it would be useful to have a command to quickly change to
the last one invoked.

Jean



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 14:33 Finding last *Async Shell Command* buffer? Jean Louis
@ 2021-03-25 15:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-25 15:08   ` Jean Louis
  2021-03-25 15:18   ` Jean Louis
  2021-03-25 18:10 ` Filipp Gunbin
  1 sibling, 2 replies; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-25 15:03 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> Is there way to find the last *Async Shell Command* buffer?
>
> Often I like running commands in background but there is
> hundreds of buffers and it would be useful to have a command
> to quickly change to the last one invoked.

The *Buffer List* should be sorted but if you want even
faster, tell me what these buffers are called exactly...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 15:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-25 15:08   ` Jean Louis
  2021-03-25 20:27     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-25 15:18   ` Jean Louis
  1 sibling, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-25 15:08 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-25 18:05]:
> Jean Louis wrote:
> 
> > Is there way to find the last *Async Shell Command* buffer?
> >
> > Often I like running commands in background but there is
> > hundreds of buffers and it would be useful to have a command
> > to quickly change to the last one invoked.
> 
> The *Buffer List* should be sorted but if you want even
> faster, tell me what these buffers are called exactly...

Well, they are called like below.

In this buffer, type RET to select the completion near point.

Possible completions are:
*Async Shell Command* 	*Async Shell Command*<100> 	*Async Shell Command*<101> 	*Async Shell Command*<102>
*Async Shell Command*<103> 	*Async Shell Command*<104> 	*Async Shell Command*<105> 	*Async Shell Command*<106>
*Async Shell Command*<107> 	*Async Shell Command*<108> 	*Async Shell Command*<109> 	*Async Shell Command*<10>
*Async Shell Command*<110> 	*Async Shell Command*<111> 	*Async Shell Command*<112> 	*Async Shell Command*<113>
...

but I think not the last number is really the last if any of those
buffers was killed previously.




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 15:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-25 15:08   ` Jean Louis
@ 2021-03-25 15:18   ` Jean Louis
  2021-03-25 15:54     ` Skip Montanaro
  1 sibling, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-25 15:18 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-25 18:05]:
> Jean Louis wrote:
> 
> > Is there way to find the last *Async Shell Command* buffer?
> >
> > Often I like running commands in background but there is
> > hundreds of buffers and it would be useful to have a command
> > to quickly change to the last one invoked.
> 
> 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.

I rather think of having last buffer somehow somewhere recorded that I
can just click on a key and get or browse those bufers by repeating
the key.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 15:18   ` Jean Louis
@ 2021-03-25 15:54     ` Skip Montanaro
  2021-03-25 19:31       ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Skip Montanaro @ 2021-03-25 15:54 UTC (permalink / raw)
  To: Help GNU Emacs

> > 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.

Can you give an example of how to create one or more of these buffers?
I'm not sure I've ever used an async shell before.

Skip Montanaro



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 14:33 Finding last *Async Shell Command* buffer? Jean Louis
  2021-03-25 15:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-25 18:10 ` Filipp Gunbin
  2021-03-25 19:40   ` Jean Louis
  2021-03-25 20:05   ` Jean Louis
  1 sibling, 2 replies; 58+ messages in thread
From: Filipp Gunbin @ 2021-03-25 18:10 UTC (permalink / raw)
  To: Jean Louis; +Cc: Help GNU Emacs

On 25/03/2021 17:33 +0300, Jean Louis wrote:

> Is there way to find the last *Async Shell Command* buffer?
>
> Often I like running commands in background but there is hundreds of
> buffers and it would be useful to have a command to quickly change to
> the last one invoked.
>
> Jean

isearch over minibuffer "future history" will give the same order as
*Buffer List* (latest first), so

C-x b C-s async (possibly followed by more C-s)

Filipp



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 15:54     ` Skip Montanaro
@ 2021-03-25 19:31       ` Jean Louis
  0 siblings, 0 replies; 58+ messages in thread
From: Jean Louis @ 2021-03-25 19:31 UTC (permalink / raw)
  To: Skip Montanaro; +Cc: Help GNU Emacs

* 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.






^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 18:10 ` Filipp Gunbin
@ 2021-03-25 19:40   ` Jean Louis
  2021-03-26 13:09     ` Filipp Gunbin
  2021-03-25 20:05   ` Jean Louis
  1 sibling, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-25 19:40 UTC (permalink / raw)
  To: Help GNU Emacs

* Filipp Gunbin <fgunbin@fastmail.fm> [2021-03-25 21:10]:
> On 25/03/2021 17:33 +0300, Jean Louis wrote:
> 
> > Is there way to find the last *Async Shell Command* buffer?
> >
> > Often I like running commands in background but there is hundreds of
> > buffers and it would be useful to have a command to quickly change to
> > the last one invoked.
> >
> > Jean
> 
> isearch over minibuffer "future history" will give the same order as
> *Buffer List* (latest first), so
> 
> C-x b C-s async (possibly followed by more C-s)

Yes, I could peek in the list. What I mean is to press a key and get
latest buffer, maybe there is some internal date/time when buffers
were created.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 18:10 ` Filipp Gunbin
  2021-03-25 19:40   ` Jean Louis
@ 2021-03-25 20:05   ` Jean Louis
  1 sibling, 0 replies; 58+ messages in thread
From: Jean Louis @ 2021-03-25 20:05 UTC (permalink / raw)
  To: Help GNU Emacs

(defun rcd-async-shell-command (command &rest args)
  "Remembers last async shell command on `C-c l'"
  (interactive)
  (let* ((shell-command-buffer-name-async (concat "RCD Async: " (format-time-string "%T")))
	 (last-buffer shell-command-buffer-name-async))
    (global-set-key (kbd "C-c l") `(lambda () 
				     (interactive)
				     (switch-to-buffer ,last-buffer)))
    (apply #'async-shell-command command args)))

(rcd-async-shell-command "gimp") → works, I can find last buffer with C-c l

(global-set-key (kbd "M-&") 'rcd-async-shell-command) → not working, as when I press M-& I get funcall-interactively: Wrong number of arguments: (lambda (command &rest args) "Remembers last async shell command on `C-c l'" (interactive) (let* ((shell-command-buffer-name-async (concat "RCD Async: " (format-time-string "%T"))) (last-buffer shell-command-buffer-name-async)) (global-set-key (kbd "C-c l") (list 'lambda nil '(interactive) (list 'switch-to-buffer last-buffer))) (apply #'async-shell-command command args))), 0

So I need sharp eye to tell me what I do wrong.




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 15:08   ` Jean Louis
@ 2021-03-25 20:27     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-25 20:36       ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-25 20:27 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>> The *Buffer List* should be sorted but if you want even
>> faster, tell me what these buffers are called exactly...
>
> Well, they are called like below.
>
> In this buffer, type RET to select the completion
> near point.
>
> Possible completions are: *Async Shell Command* *Async Shell
> Command*<100> *Async Shell Command*<101> *Async Shell
> Command*<102> *Async Shell Command*<103> *Async Shell
> Command*<104> *Async Shell Command*<105> *Async Shell
> Command*<106> *Async Shell Command*<107> *Async Shell
> Command*<108> *Async Shell Command*<109> *Async Shell
> Command*<10> *Async Shell Command*<110> *Async Shell
> Command*<111> *Async Shell Command*<112> *Async Shell
> Command*<113> ...
>
> but I think not the last number is really the last if any of
> those buffers was killed previously.

That doesn't matter, I have what you need:

;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;;   http://user.it.uu.se/~embe8573/emacs-init/switch-to-buffer-regexp.el
;;;   https://dataswamp.org/~incal/emacs-init/switch-to-buffer-regexp.el

(require 'cl-lib)

(defun buffer-names ()
  (mapcar #'buffer-name (buffer-list)) )

(defun switch-to-buffer-regexp (buf-re)
  (let*((ori-buf  (buffer-name (current-buffer)))
        (hits     (cl-remove-if-not
                   (lambda (b) (string-match buf-re b)) (buffer-names)) ))
    (when hits
      (let ((new-hits (cl-remove ori-buf hits)))
        (when new-hits
          (when (string-match buf-re ori-buf)
            (bury-buffer ori-buf) )
          (switch-to-buffer (car new-hits)) )))))

;; try it!
;; (require 'gnus)
;; (dotimes (i 4) (gnus-post-news 'post "")) ; create 4 posts

(global-set-key "\C-cu" (lambda () (interactive) (switch-to-buffer-regexp "\*unsent posting\*.*")))
;; hit again to iterate

(provide 'switch-to-buffer-regexp)

Then do:

(defun switch-to-async-buffer ()
  (interactive)
  (switch-to-buffer-regexp "\*Async Shell Command\*") )

Assign key - done

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 20:27     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-25 20:36       ` Jean Louis
  2021-03-25 20:50         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-25 20:36 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-25 23:29]:

> (defun switch-to-async-buffer ()
>   (interactive)
>   (switch-to-buffer-regexp "\*Async Shell Command\*") )

Thanks for attempt. It is switching somewhere, true, but not the last
one, seem random or catching first buffers among hundreds.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 20:36       ` Jean Louis
@ 2021-03-25 20:50         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-25 20:59           ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-25 20:50 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>> (defun switch-to-async-buffer ()
>>   (interactive)
>>   (switch-to-buffer-regexp "\*Async Shell Command\*") )
>
> Thanks for attempt. It is switching somewhere, true, but not
> the last one, seem random or catching first buffers
> among hundreds.

Nope. Same order that they appear in *Buffer List*.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 20:50         ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-25 20:59           ` Jean Louis
  2021-03-25 21:08             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-25 20:59 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-25 23:55]:
> Jean Louis wrote:
> 
> >> (defun switch-to-async-buffer ()
> >>   (interactive)
> >>   (switch-to-buffer-regexp "\*Async Shell Command\*") )
> >
> > Thanks for attempt. It is switching somewhere, true, but not
> > the last one, seem random or catching first buffers
> > among hundreds.
> 
> Nope. Same order that they appear in *Buffer List*.

But you did get idea that order of creation of buffers is not really
numbered? When buffer 1 is created, 2 and 3, and buffer 2 deleted,
next buffer created becomes 2, and not 4, if you have 200 such
buffers, maybe 15, 18, 19, 112, and 113 were killed, and now populated
with recent buffers, but there is no way of knowing which one is
recent one to quickly look into standard output of the async command.

The last one is what is useful, or browsing through last few.

I am almost there, I just don't know how to assign it to command that
it works.




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 20:59           ` Jean Louis
@ 2021-03-25 21:08             ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-25 21:12               ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-25 21:08 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>>> Thanks for attempt. It is switching somewhere, true, but
>>> not the last one, seem random or catching first buffers
>>> among hundreds.
>> 
>> Nope. Same order that they appear in *Buffer List*.
>
> But you did get idea that order of creation of buffers is
> not really numbered?

It doesn't matter in this case.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 21:08             ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-25 21:12               ` Jean Louis
  2021-03-26  5:52                 ` Robert Thorpe
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-25 21:12 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-26 00:09]:
> Jean Louis wrote:
> 
> >>> Thanks for attempt. It is switching somewhere, true, but
> >>> not the last one, seem random or catching first buffers
> >>> among hundreds.
> >> 
> >> Nope. Same order that they appear in *Buffer List*.
> >
> > But you did get idea that order of creation of buffers is
> > not really numbered?
> 
> It doesn't matter in this case.

No S in S hot S today, and now it does not matter...

Puzzle: 

1. S ends with a and spricht Hochdeutsch
2. S ends with h and bears no mask
3. S ends with a and is neighbor to one with no mask



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 21:12               ` Jean Louis
@ 2021-03-26  5:52                 ` Robert Thorpe
  2021-03-26  6:47                   ` Eli Zaretskii
  2021-03-26  7:01                   ` Jean Louis
  0 siblings, 2 replies; 58+ messages in thread
From: Robert Thorpe @ 2021-03-26  5:52 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs

Jean Louis <bugs@gnu.support> writes:

> * Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-26 00:09]:
>> Jean Louis wrote:
>> 
>> >>> Thanks for attempt. It is switching somewhere, true, but
>> >>> not the last one, seem random or catching first buffers
>> >>> among hundreds.
>> >> 
>> >> Nope. Same order that they appear in *Buffer List*.
>> >
>> > But you did get idea that order of creation of buffers is
>> > not really numbered?
>> 
>> It doesn't matter in this case.
>
> No S in S hot S today, and now it does not matter...
>
> Puzzle: 
>
> 1. S ends with a and spricht Hochdeutsch
> 2. S ends with h and bears no mask
> 3. S ends with a and is neighbor to one with no mask

For what it's worth Jean, I understand your problem with async buffers.
I've had the same problem.  I haven't found a solution to it.  If I find
one I'll tell you.

On the other hand, I don't understand your riddle.

BR,
Robert Thorpe




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  5:52                 ` Robert Thorpe
@ 2021-03-26  6:47                   ` Eli Zaretskii
  2021-03-26  7:04                     ` Jean Louis
  2021-03-26  7:17                     ` Jean Louis
  2021-03-26  7:01                   ` Jean Louis
  1 sibling, 2 replies; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26  6:47 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Robert Thorpe <rt@robertthorpeconsulting.com>
> Date: Fri, 26 Mar 2021 05:52:22 +0000
> Cc: help-gnu-emacs@gnu.org
> 
> For what it's worth Jean, I understand your problem with async buffers.
> I've had the same problem.  I haven't found a solution to it.  If I find
> one I'll tell you.

Did you try writing a simple function to put on
buffer-list-update-hook?  Then you can in that function define a
buffer-local variable whose value is a simple monotonically increasing
counter, or even the time when the buffer was created.  Then write a
command to sort buffers in the order determined by that variable.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  5:52                 ` Robert Thorpe
  2021-03-26  6:47                   ` Eli Zaretskii
@ 2021-03-26  7:01                   ` Jean Louis
  2021-03-26  7:09                     ` Eli Zaretskii
  1 sibling, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26  7:01 UTC (permalink / raw)
  To: Robert Thorpe; +Cc: help-gnu-emacs

* Robert Thorpe <rt@robertthorpeconsulting.com> [2021-03-26 08:53]:
> For what it's worth Jean, I understand your problem with async buffers.
> I've had the same problem.  I haven't found a solution to it.  If I find
> one I'll tell you.

Please look here:
https://lists.gnu.org/archive/html/help-gnu-emacs/2021-03/msg00250.html

As maybe you can help me figure out why I cannot invoke that function
from a key like M-& -- as when I solve that, I will easily be able to
switch to last buffer with a key.

Jean



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  6:47                   ` Eli Zaretskii
@ 2021-03-26  7:04                     ` Jean Louis
  2021-03-26  7:18                       ` Eli Zaretskii
  2021-03-26  7:28                       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26  7:17                     ` Jean Louis
  1 sibling, 2 replies; 58+ messages in thread
From: Jean Louis @ 2021-03-26  7:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2021-03-26 09:48]:
> > From: Robert Thorpe <rt@robertthorpeconsulting.com>
> > Date: Fri, 26 Mar 2021 05:52:22 +0000
> > Cc: help-gnu-emacs@gnu.org
> > 
> > For what it's worth Jean, I understand your problem with async buffers.
> > I've had the same problem.  I haven't found a solution to it.  If I find
> > one I'll tell you.
> 
> Did you try writing a simple function to put on
> buffer-list-update-hook?  Then you can in that function define a
> buffer-local variable whose value is a simple monotonically increasing
> counter, or even the time when the buffer was created.  Then write a
> command to sort buffers in the order determined by that variable.

OK, good insight into possibility.

Personally I have almost solved it, can you please look here:
https://lists.gnu.org/archive/html/help-gnu-emacs/2021-03/msg00250.html

This function is to replace the `async-shell-command' on a key M-&:

(defun rcd-async-shell-command (command &rest args)
  "Remembers last async shell command on `C-c l'"
  (interactive)
  (let* ((shell-command-buffer-name-async (concat "RCD Async: " 
(format-time-string "%T")))
         (last-buffer shell-command-buffer-name-async))
    (global-set-key (kbd "C-c l") `(lambda () 
                                     (interactive)
                                     (switch-to-buffer ,last-buffer)))
    (apply #'async-shell-command command args)))

(rcd-async-shell-command "gimp") → works, I can find last buffer with C-c l

(global-set-key (kbd "M-&") 'rcd-async-shell-command) → not working, as when I 
press M-& I get funcall-interactively: Wrong number of arguments: (lambda 
(command &rest args) "Remembers last async shell command on `C-c l'" 
(interactive) (let* ((shell-command-buffer-name-async (concat "RCD Async: " 
(format-time-string "%T"))) (last-buffer shell-command-buffer-name-async)) 
(global-set-key (kbd "C-c l") (list 'lambda nil '(interactive) (list 
'switch-to-buffer last-buffer))) (apply #'async-shell-command command
args))), 0

That would be simplest solution, but I cannot see to what "Wrong
number of arguments" relate exactly.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:01                   ` Jean Louis
@ 2021-03-26  7:09                     ` Eli Zaretskii
  2021-03-26  7:25                       ` [solved]: " Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26  7:09 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 26 Mar 2021 10:01:31 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
> 
> Please look here:
> https://lists.gnu.org/archive/html/help-gnu-emacs/2021-03/msg00250.html
> 
> As maybe you can help me figure out why I cannot invoke that function
> from a key like M-& -- as when I solve that, I will easily be able to
> switch to last buffer with a key.

Emacs told you what's wrong: "Wrong number of arguments".  What isn't
clear about that error message?



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  6:47                   ` Eli Zaretskii
  2021-03-26  7:04                     ` Jean Louis
@ 2021-03-26  7:17                     ` Jean Louis
  2021-03-26  7:47                       ` Eli Zaretskii
  1 sibling, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26  7:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2021-03-26 09:48]:
> > From: Robert Thorpe <rt@robertthorpeconsulting.com>
> > Date: Fri, 26 Mar 2021 05:52:22 +0000
> > Cc: help-gnu-emacs@gnu.org
> > 
> > For what it's worth Jean, I understand your problem with async buffers.
> > I've had the same problem.  I haven't found a solution to it.  If I find
> > one I'll tell you.
> 
> Did you try writing a simple function to put on
> buffer-list-update-hook?  Then you can in that function define a
> buffer-local variable whose value is a simple monotonically increasing
> counter, or even the time when the buffer was created.  Then write a
> command to sort buffers in the order determined by that variable.

I have tried using that function, but again, how do I get the last
buffer?

As when I put the function `rcd-last-async-buffer' into
`buffer-list-update-hook' with:

(add-hook 'buffer-list-update-hook 'rcd-last-async-buffer)

then from the function, when I invoke `M-& ls RET':

(defun rcd-last-async-buffer (&rest args)
  (let ((last-buffer (last-buffer))
	(current-buffer (current-buffer)))
  (message "Last buffer: %s, current buffer: %s" last-buffer current-buffer)))

I get this message:

Last buffer: *Completions*, current buffer: *Messages* [2 times]

and I was inspecting `&rest args' and did not get any variables
sent. My expectations were different, for example, that the hook would
give me the buffer name at least through a function invoked, or
alternatively by sending it as argument. 

If I cannot find last buffer created by M-& then I would need to list
buffers and again, how do I find the last one created if they are not
created one after the other really... the next empty number will be
filled with new async buffer.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:04                     ` Jean Louis
@ 2021-03-26  7:18                       ` Eli Zaretskii
  2021-03-26  7:28                       ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26  7:18 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 26 Mar 2021 10:04:54 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
> 
> (defun rcd-async-shell-command (command &rest args)
>   "Remembers last async shell command on `C-c l'"
>   (interactive)
>   (let* ((shell-command-buffer-name-async (concat "RCD Async: " 
> (format-time-string "%T")))
>          (last-buffer shell-command-buffer-name-async))
>     (global-set-key (kbd "C-c l") `(lambda () 
>                                      (interactive)
>                                      (switch-to-buffer ,last-buffer)))
>     (apply #'async-shell-command command args)))
> 
> (rcd-async-shell-command "gimp") → works, I can find last buffer with C-c l
> 
> (global-set-key (kbd "M-&") 'rcd-async-shell-command) → not working, as when I 
> press M-& I get funcall-interactively: Wrong number of arguments: (lambda 
> (command &rest args) "Remembers last async shell command on `C-c l'" 
> (interactive) (let* ((shell-command-buffer-name-async (concat "RCD Async: " 
> (format-time-string "%T"))) (last-buffer shell-command-buffer-name-async)) 
> (global-set-key (kbd "C-c l") (list 'lambda nil '(interactive) (list 
> 'switch-to-buffer last-buffer))) (apply #'async-shell-command command
> args))), 0
> 
> That would be simplest solution, but I cannot see to what "Wrong
> number of arguments" relate exactly.

Ask yourself 2 questions:

 . How many arguments does this function expect?
 . How many arguments are provided by the interactive call via "M-&"?

The discrepancy between these two is what causes the error.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:09                     ` Eli Zaretskii
@ 2021-03-26  7:25                       ` Jean Louis
  2021-03-26  7:31                         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26  7:56                         ` Eli Zaretskii
  0 siblings, 2 replies; 58+ messages in thread
From: Jean Louis @ 2021-03-26  7:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2021-03-26 10:09]:
> > Date: Fri, 26 Mar 2021 10:01:31 +0300
> > From: Jean Louis <bugs@gnu.support>
> > Cc: help-gnu-emacs@gnu.org
> > 
> > Please look here:
> > https://lists.gnu.org/archive/html/help-gnu-emacs/2021-03/msg00250.html
> > 
> > As maybe you can help me figure out why I cannot invoke that function
> > from a key like M-& -- as when I solve that, I will easily be able to
> > switch to last buffer with a key.
> 
> Emacs told you what's wrong: "Wrong number of arguments".  What isn't
> clear about that error message?

It is confusing as I was thinking I gave it enough arguments, but it
requires `interactive' so I copied it from original function.

Now it is solved intermittently:

(defun rcd-async-shell-command (&rest args)
  "Remembers last async shell command on `C-c l'"
  (interactive
   (list
    (read-shell-command (if shell-command-prompt-show-cwd
                            (format-message "Async shell command in `%s': "
                                            (abbreviate-file-name
                                             default-directory))
                          "Async shell command: ")
                        nil nil
			(let ((filename
			       (cond
				(buffer-file-name)
				((eq major-mode 'dired-mode)
				 (dired-get-filename nil t)))))
			  (and filename (file-relative-name filename))))
    current-prefix-arg
    shell-command-default-error-buffer))
  (let* ((shell-command-buffer-name-async (concat "RCD Async: " (format-time-string "%Y%m%d%H%M%S")))
	 (last-buffer shell-command-buffer-name-async))
    (global-set-key (kbd "C-c l") `(lambda () 
				     (interactive)
				     (switch-to-buffer ,last-buffer)))
    (apply #'async-shell-command args)))

Now I can bind it:

(global-set-key (kbd "M-&") 'rcd-async-shell-command) 

And now it works, when I wish to get the last async buffer I just
press `C-c l'.

Because buffers are named by year and time: 
(concat "RCD Async: " (format-time-string "%Y%m%d%H%M%S")

I can then make a function to browse backwards in time those async
buffers.

Jean



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:04                     ` Jean Louis
  2021-03-26  7:18                       ` Eli Zaretskii
@ 2021-03-26  7:28                       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26  7:38                         ` Jean Louis
  1 sibling, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26  7:28 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> (defun rcd-async-shell-command (command &rest args)
>   "Remembers last async shell command on `C-c l'"
>   (interactive)
>   (let* ((shell-command-buffer-name-async (concat "RCD Async: " 
> (format-time-string "%T")))
>          (last-buffer shell-command-buffer-name-async))
>     (global-set-key (kbd "C-c l") `(lambda () 
>                                      (interactive)
>                                      (switch-to-buffer ,last-buffer)))
>     (apply #'async-shell-command command args)))

(defun rcd-async-shell-command (cmd &optional args)
  (interactive)
  (let* ((buf (concat "RCD Async: " (format-time-string "%T")) )
         (last-buf buf) )
    (switch-to-buffer last-buf)
    (async-shell-command cmd args) ))

(global-set-key
 "\M-&"
 (lambda () (interactive) (rcd-async-shell-command "gimp")) )

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:25                       ` [solved]: " Jean Louis
@ 2021-03-26  7:31                         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26  7:40                           ` Jean Louis
  2021-03-26  7:56                         ` Eli Zaretskii
  1 sibling, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26  7:31 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> (defun rcd-async-shell-command (&rest args)
>   "Remembers last async shell command on `C-c l'"
>   (interactive
>    (list
>     (read-shell-command (if shell-command-prompt-show-cwd
>                             (format-message "Async shell command in `%s': "
>                                             (abbreviate-file-name
>                                              default-directory))
>                           "Async shell command: ")
>                         nil nil
> 			(let ((filename
> 			       (cond
> 				(buffer-file-name)
> 				((eq major-mode 'dired-mode)
> 				 (dired-get-filename nil t)))))
> 			  (and filename (file-relative-name filename))))
>     current-prefix-arg
>     shell-command-default-error-buffer))
>   (let* ((shell-command-buffer-name-async (concat "RCD Async: " (format-time-string "%Y%m%d%H%M%S")))
> 	 (last-buffer shell-command-buffer-name-async))
>     (global-set-key (kbd "C-c l") `(lambda () 
> 				     (interactive)
> 				     (switch-to-buffer ,last-buffer)))
>     (apply #'async-shell-command args)))

M-x hooligan-elisp-mode RET

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:28                       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-26  7:38                         ` Jean Louis
  2021-03-26  7:52                           ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26  7:38 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-26 10:29]:
> Jean Louis wrote:
> 
> > (defun rcd-async-shell-command (command &rest args)
> >   "Remembers last async shell command on `C-c l'"
> >   (interactive)
> >   (let* ((shell-command-buffer-name-async (concat "RCD Async: " 
> > (format-time-string "%T")))
> >          (last-buffer shell-command-buffer-name-async))
> >     (global-set-key (kbd "C-c l") `(lambda () 
> >                                      (interactive)
> >                                      (switch-to-buffer ,last-buffer)))
> >     (apply #'async-shell-command command args)))
> 
> (defun rcd-async-shell-command (cmd &optional args)
>   (interactive)
>   (let* ((buf (concat "RCD Async: " (format-time-string "%T")) )
>          (last-buf buf) )
>     (switch-to-buffer last-buf)
>     (async-shell-command cmd args) ))
> 
> (global-set-key
>  "\M-&"
>  (lambda () (interactive) (rcd-async-shell-command "gimp")) )

Thanks.

If gimp would be the only command to run, then I would bind it on a
key and specific gimp buffer, easy to access.

By the way, the above attempt does not work. 



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:31                         ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-26  7:40                           ` Jean Louis
  0 siblings, 0 replies; 58+ messages in thread
From: Jean Louis @ 2021-03-26  7:40 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-26 10:36]:
> M-x hooligan-elisp-mode RET

Works well here, just as M-x butterfly RET



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:17                     ` Jean Louis
@ 2021-03-26  7:47                       ` Eli Zaretskii
  2021-03-26  7:54                         ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26  7:47 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 26 Mar 2021 10:17:11 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
> 
> > Did you try writing a simple function to put on
> > buffer-list-update-hook?  Then you can in that function define a
> > buffer-local variable whose value is a simple monotonically increasing
> > counter, or even the time when the buffer was created.  Then write a
> > command to sort buffers in the order determined by that variable.
> 
> I have tried using that function, but again, how do I get the last
> buffer?

By comparing the current buffer-list with the previous one?



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:38                         ` Jean Louis
@ 2021-03-26  7:52                           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26  8:43                             ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26  7:52 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>> (defun rcd-async-shell-command (cmd &optional args)
>>   (interactive)
>>   (let* ((buf (concat "RCD Async: " (format-time-string "%T")) )
>>          (last-buf buf) )
>>     (switch-to-buffer last-buf)
>>     (async-shell-command cmd args) ))
>> 
>> (global-set-key
>>  "\M-&"
>>  (lambda () (interactive) (rcd-async-shell-command "gimp")) )
>
> Thanks.
>
> If gimp would be the only command to run, then I would bind
> it on a key and specific gimp buffer, easy to access.

Whatever you want to pass to it must be made explicit at some
point or in some form.

> By the way, the above attempt does not work.

It is your own code, cleaned up to a functional state.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:47                       ` Eli Zaretskii
@ 2021-03-26  7:54                         ` Jean Louis
  2021-03-26 11:31                           ` Eli Zaretskii
  2021-03-26 14:02                           ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 58+ messages in thread
From: Jean Louis @ 2021-03-26  7:54 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2021-03-26 10:48]:
> > Date: Fri, 26 Mar 2021 10:17:11 +0300
> > From: Jean Louis <bugs@gnu.support>
> > Cc: help-gnu-emacs@gnu.org
> > 
> > > Did you try writing a simple function to put on
> > > buffer-list-update-hook?  Then you can in that function define a
> > > buffer-local variable whose value is a simple monotonically increasing
> > > counter, or even the time when the buffer was created.  Then write a
> > > command to sort buffers in the order determined by that variable.
> > 
> > I have tried using that function, but again, how do I get the last
> > buffer?
> 
> By comparing the current buffer-list with the previous one?

My naive attempt does not show any difference, as I am doing something
wrong.

(setq last-buffer-list nil)

(defun rcd-last-async-buffer (&rest args)
  (let ((last (set-difference last-buffer-list (buffer-list))))
    (message "Last buffer: %s" last))
  (setq last-buffer-list (buffer-list)))

(add-hook 'buffer-list-update-hook 'rcd-last-async-buffer)




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:25                       ` [solved]: " Jean Louis
  2021-03-26  7:31                         ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-26  7:56                         ` Eli Zaretskii
  2021-03-26  8:55                           ` Jean Louis
  2021-03-26 10:34                           ` Jean Louis
  1 sibling, 2 replies; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26  7:56 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 26 Mar 2021 10:25:10 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
> 
> > Emacs told you what's wrong: "Wrong number of arguments".  What isn't
> > clear about that error message?
> 
> It is confusing as I was thinking I gave it enough arguments, but it
> requires `interactive' so I copied it from original function.

Command invocation doesn't give _any_ arguments at all.  The arguments
in that case must be provided by the 'interactive' form.  And in your
original code the 'interactive' form returned an empty list.

> Now it is solved intermittently:
> 
> (defun rcd-async-shell-command (&rest args)
>   "Remembers last async shell command on `C-c l'"
>   (interactive
>    (list
>     (read-shell-command (if shell-command-prompt-show-cwd
>                             (format-message "Async shell command in `%s': "
>                                             (abbreviate-file-name
>                                              default-directory))
>                           "Async shell command: ")
>                         nil nil
> 			(let ((filename
> 			       (cond
> 				(buffer-file-name)
> 				((eq major-mode 'dired-mode)
> 				 (dired-get-filename nil t)))))
> 			  (and filename (file-relative-name filename))))
>     current-prefix-arg
>     shell-command-default-error-buffer))
>   (let* ((shell-command-buffer-name-async (concat "RCD Async: " (format-time-string "%Y%m%d%H%M%S")))
> 	 (last-buffer shell-command-buffer-name-async))
>     (global-set-key (kbd "C-c l") `(lambda () 
> 				     (interactive)
> 				     (switch-to-buffer ,last-buffer)))
>     (apply #'async-shell-command args)))
> 
> Now I can bind it:
> 
> (global-set-key (kbd "M-&") 'rcd-async-shell-command) 
> 
> And now it works, when I wish to get the last async buffer I just
> press `C-c l'.

What happens if that buffer was meanwhile killed?

Personally, I find it un-Emacsy to write a wrapper command each time
you want to manipulate the results of an existing command.  Emacs
provides hooks for that very purpose, so it's best to use those
instead of inventing a new command each time you need something like
that.  Redefining a key binding each time you run an async command is
also ... inelegant.

But that's me.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:52                           ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-26  8:43                             ` Jean Louis
  2021-03-26 13:37                               ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26  8:43 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-26 10:54]:
> > By the way, the above attempt does not work.
> 
> It is your own code, cleaned up to a functional state.

I actually don't need a code, it is just that computers don't do what
I think. But I do expect computers to start understanding human needs
and doing what we need without coding.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:56                         ` Eli Zaretskii
@ 2021-03-26  8:55                           ` Jean Louis
  2021-03-26 11:18                             ` Eli Zaretskii
  2021-03-26 10:34                           ` Jean Louis
  1 sibling, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26  8:55 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2021-03-26 10:57]:
> What happens if that buffer was meanwhile killed?

If it gets killed, new buffer with same name is created. But if it
really gets killed, most probably I killed it by using the key binding
from that function, like `C-c l'. Purpose is to see output of async
command, so if there is no output to be seen that new buffer is
created does not matter.

No, it is not elegant, it is very personal.

> Personally, I find it un-Emacsy to write a wrapper command each time
> you want to manipulate the results of an existing command.  Emacs
> provides hooks for that very purpose, so it's best to use those
> instead of inventing a new command each time you need something like
> that.

Yes, I agree. 

Coming from my experience with databases, for me it would be most
usable if buffers have their creation time recorded, as that way would
be easy to find the last async buffer, or others.

In this specific example users can change the async buffer name or
Elisp programs could change last async buffer names. There is no easy
and default way how to get last buffer or last few to look into
outputs easily. It requires listing, inspecting. 

But it is terrible when there are many, as the generate-new-buffer
will create the next available number in a series and not the next
increased number compared to previous buffer.

Maybe the function `get-buffer-create' could be changed to increase
the number of newly created buffers instead of just taking some of
empty numbers in a series?

For end users I do not think that would make any difference, as the
added buffer number is not interactively influencing users.

What do you think about that change? I would not know how to do it in
C. 

> Redefining a key binding each time you run an async command is also
> ... inelegant.

Ah, definitely.




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:56                         ` Eli Zaretskii
  2021-03-26  8:55                           ` Jean Louis
@ 2021-03-26 10:34                           ` Jean Louis
  2021-03-26 11:30                             ` Eli Zaretskii
  1 sibling, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26 10:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2021-03-26 10:57]:
> What happens if that buffer was meanwhile killed?
> 
> Personally, I find it un-Emacsy to write a wrapper command each time
> you want to manipulate the results of an existing command.  Emacs
> provides hooks for that very purpose, so it's best to use those
> instead of inventing a new command each time you need something like
> that.  Redefining a key binding each time you run an async command is
> also ... inelegant.

True. It is temporary like that. 

Maybe I will be pushing last async buffer names into a list and pull
those last buffers by same key bindings as long as:

- the buffer still has process running. But the variable
  `async-current-process' is nil, and has no description.

- if buffer exists, I know how to check.

Then the key can show last async buffer, and if repeated one before
that one, with process still running, and so on.

How to discover if async buffer has current process running? 




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26  8:55                           ` Jean Louis
@ 2021-03-26 11:18                             ` Eli Zaretskii
  2021-03-26 11:26                               ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26 11:18 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 26 Mar 2021 11:55:52 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
> 
> Maybe the function `get-buffer-create' could be changed to increase
> the number of newly created buffers instead of just taking some of
> empty numbers in a series?

Perhaps as an optional behavior.  Doing that by default is usually not
what users want.

Feel free to file a feature-request bug report about such an option.

> For end users I do not think that would make any difference, as the
> added buffer number is not interactively influencing users.

You are wrong.  I use it locally to refer to the many Info buffers I
have in my sessions.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 11:18                             ` Eli Zaretskii
@ 2021-03-26 11:26                               ` Jean Louis
  2021-03-26 11:33                                 ` Eli Zaretskii
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26 11:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2021-03-26 14:18]:
> > Date: Fri, 26 Mar 2021 11:55:52 +0300
> > From: Jean Louis <bugs@gnu.support>
> > Cc: help-gnu-emacs@gnu.org
> > 
> > Maybe the function `get-buffer-create' could be changed to increase
> > the number of newly created buffers instead of just taking some of
> > empty numbers in a series?
> 
> Perhaps as an optional behavior.  Doing that by default is usually not
> what users want.

In description of `get-buffer-create' there is no mentioning of number
assigned to buffer and now I don't know if it applies there. But I see
this:

(generate-new-buffer-name NAME &optional IGNORE)

Return a string that is the name of no existing buffer based on NAME.
If there is no live buffer named NAME, then return NAME.
Otherwise modify name by appending ‘<NUMBER>’, incrementing NUMBER
(starting at 2) until an unused name is found, and then return that name.
Optional second argument IGNORE specifies a name that is okay to use (if
it is in the sequence to be tried) even if a buffer with that name exists.

> Feel free to file a feature-request bug report about such an option.

For now I solved it with this below.

> > For end users I do not think that would make any difference, as the
> > added buffer number is not interactively influencing users.
> 
> You are wrong.  I use it locally to refer to the many Info buffers I
> have in my sessions.

Sure, that is clear. I also refer to buffers like that. But how they
get assigned their number on the end like *Async Shell Command*<141>
it does not matter, so it could be 39 or 175, it does not matter.

For now I have solved it that I can browse my created async buffers
that have their corresponding process running with `C-c l' and that is
then solved personally.

;;; rcd-async.el --- Helps in reviewing output in async buffers invoked by user

;;; Commentary:
;;
;; Recommended settings:
;; (global-set-key (kbd "M-&") 'rcd-async-shell-command)
;; (global-set-key (kbd "C-c l") 'rcd-async-last-buffers)

;; Invoke `M-&' and run async command, like "gimp" or "ffmpeg",
;; etc. Work for a while in Emacs and when you wish to inspect the
;; output of running commands, invoke your key binding for
;; `rcd-async-last-buffers'

;; Invoke `C-c l' or other assigned key to review or browse last
;; invoked async commands that still have running process.

;;; Code:

(defvar rcd-async-buffer-list nil
  "Keeps the async buffer list created by RCD utilities.  New async
buffers are pushed into this list and upon inspection by
`rcd-async-last-buffers' removed from the list if they either do
not exist or do not have assigned process.")

(defvar rcd-async-buffer-inspected nil
  "Keeps the value of currently inspected buffer by `rcd-async-last-buffers'.")

(defun rcd-async-shell-command (&rest args)
  "Works as `async-shell-command' with difference to remember the
last async buffer by recording it in the list
`rcd-async-buffer-list'."
  (interactive
   (list
    (read-shell-command (if shell-command-prompt-show-cwd
                            (format-message "Async shell command in `%s': "
                                            (abbreviate-file-name
                                             default-directory))
                          "Async shell command: ")
                        nil nil
			(let ((filename
			       (cond
				(buffer-file-name)
				((eq major-mode 'dired-mode)
				 (dired-get-filename nil t)))))
			  (and filename (file-relative-name filename))))
    current-prefix-arg
    shell-command-default-error-buffer))
  (let* ((shell-command-buffer-name-async (concat "RCD Async: " (format-time-string "%Y%m%d%H%M%S")))
	 (last-buffer shell-command-buffer-name-async))
    (push last-buffer rcd-async-buffer-list)
    (apply #'async-shell-command args)))

(defun rcd-async-last-buffers ()
  "Accesses the last async buffer as invoked by
`rcd-async-shell-command'."
  (interactive)
  (rcd-async-eliminate-buffers)
  (when rcd-async-buffer-list
    (if rcd-async-buffer-inspected
	(let* ((where (member rcd-async-buffer-inspected rcd-async-buffer-list))
	       (last (car (reverse rcd-async-buffer-list)))
	       (new (elt where 1)))
	  (if (and new 
		   (not (eql where last)))
	      (progn
		(rcd-switch-to-buffer-if-exists-with-process new)
		(setq rcd-async-buffer-inspected new))
	    (let ((last (car rcd-async-buffer-list)))
 	      (setq rcd-async-buffer-inspected last)
 	      (rcd-switch-to-buffer-if-exists-with-process last))))
      (let ((last (car rcd-async-buffer-list)))
	(setq rcd-async-buffer-inspected last)
      (rcd-switch-to-buffer-if-exists-with-process last)))))

(defun rcd-async-eliminate-buffers ()
  "Eliminates async buffers from `rcd-async-buffer-list' if they do
not exist or do not have a running process."
  (let* ((list (mapcar #'rcd-buffer-exists-with-process rcd-async-buffer-list))
	 (list (delq nil list)))
    (setq rcd-async-buffer-list list)))

(defun rcd-buffer-exists-with-process (buffer)
  "Return BUFFER if BUFFER has running process and is live."
  (when (and (get-buffer-process buffer)
	     (buffer-live-p (get-buffer buffer))) ;; I probably do not need this
    buffer))

(defun rcd-switch-to-buffer-if-exists-with-process (buffer)
  "Switch to BUFFER if it has running process"
  (when (rcd-buffer-exists-with-process buffer)
    (switch-to-buffer buffer)))

(provide 'rcd-async)

;;; rcd-async.el ends here



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 10:34                           ` Jean Louis
@ 2021-03-26 11:30                             ` Eli Zaretskii
  0 siblings, 0 replies; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26 11:30 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 26 Mar 2021 13:34:22 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
> 
> How to discover if async buffer has current process running? 

Use get-buffer-process and process-status?



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:54                         ` Jean Louis
@ 2021-03-26 11:31                           ` Eli Zaretskii
  2021-03-26 14:02                           ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26 11:31 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 26 Mar 2021 10:54:07 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
> 
> > > I have tried using that function, but again, how do I get the last
> > > buffer?
> > 
> > By comparing the current buffer-list with the previous one?
> 
> My naive attempt does not show any difference, as I am doing something
> wrong.
> 
> (setq last-buffer-list nil)
> 
> (defun rcd-last-async-buffer (&rest args)
>   (let ((last (set-difference last-buffer-list (buffer-list))))
>     (message "Last buffer: %s" last))
>   (setq last-buffer-list (buffer-list)))
> 
> (add-hook 'buffer-list-update-hook 'rcd-last-async-buffer)

That hook is called for events other than buffer creation.  Are you
sure you looked at those where a buffer was created?



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 11:26                               ` Jean Louis
@ 2021-03-26 11:33                                 ` Eli Zaretskii
  2021-03-26 11:48                                   ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26 11:33 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 26 Mar 2021 14:26:13 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
> 
> > > For end users I do not think that would make any difference, as the
> > > added buffer number is not interactively influencing users.
> > 
> > You are wrong.  I use it locally to refer to the many Info buffers I
> > have in my sessions.
> 
> Sure, that is clear. I also refer to buffers like that. But how they
> get assigned their number on the end like *Async Shell Command*<141>
> it does not matter, so it could be 39 or 175, it does not matter.

Doesn't matter for your use case.  But not necessarily for others.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 11:33                                 ` Eli Zaretskii
@ 2021-03-26 11:48                                   ` Jean Louis
  2021-03-26 12:37                                     ` Eli Zaretskii
  2021-03-26 13:49                                     ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 58+ messages in thread
From: Jean Louis @ 2021-03-26 11:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2021-03-26 14:34]:
> > Date: Fri, 26 Mar 2021 14:26:13 +0300
> > From: Jean Louis <bugs@gnu.support>
> > Cc: help-gnu-emacs@gnu.org
> > 
> > > > For end users I do not think that would make any difference, as the
> > > > added buffer number is not interactively influencing users.
> > > 
> > > You are wrong.  I use it locally to refer to the many Info buffers I
> > > have in my sessions.
> > 
> > Sure, that is clear. I also refer to buffers like that. But how they
> > get assigned their number on the end like *Async Shell Command*<141>
> > it does not matter, so it could be 39 or 175, it does not matter.
> 
> Doesn't matter for your use case.  But not necessarily for others.

I wish I could understand the practical usage you describe. 

I have also buffers with numbers like *Hyperscope*<14> when handling
database entries, each new set is opened in a new buffer, but I do not
access them by number, although I could. However, what number exactly
comes there and if it is number of flower, I do not mind. maybe
somebody would be noting down on paper which number it is. That seem
more difficult. I am browsing those buffers or closing them.

For me it was important how to reach to some of those async buffers,
it is not really generally related to generation of unused numbers in
a series of existing numbers. Though I cannot see why is that so:

Example of existing buffers:

1, 2, 5, 8, and 10

Now new buffers are created: 3, 4, 6, 7, and 9.

I cannot see why is that method practical, I wish I could. When buffer
3 is created there are still unused numbers, and there is no trace for
the user to know that buffer 3 was created. There is also nothing in
the message buffer. 

Currently programmer cannot know that buffer with exact number <3> was
created when a system command is invoked by using M-&.

I was too often using M-! to run external command so that I can see
the output thereafter and pausing my Emacs work for seconds or minutes
just because I did not want to search for the *Async Shell
Command*<NUMBER> buffer where output could be found from specific
command.

Specifically for `async-shell-command' creating buffers with numbers
is not much useful as accessing those buffers is difficult.

I would rather like that buffers are named by the system command
invoked, for example:

*Async Shell Command: gimp*
*Async Shell Command: gimp*<1>
*Async Shell Command: evolution*
*Async Shell Command: geary*
*Async Shell Command: gpxsee*

as that way it would be possible to easier find the output from system
commands invoked over M-&

Jean



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 11:48                                   ` Jean Louis
@ 2021-03-26 12:37                                     ` Eli Zaretskii
  2021-03-26 20:05                                       ` Jean Louis
  2021-03-26 13:49                                     ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 1 reply; 58+ messages in thread
From: Eli Zaretskii @ 2021-03-26 12:37 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Fri, 26 Mar 2021 14:48:49 +0300
> From: Jean Louis <bugs@gnu.support>
> Cc: help-gnu-emacs@gnu.org
> 
> > > Sure, that is clear. I also refer to buffers like that. But how they
> > > get assigned their number on the end like *Async Shell Command*<141>
> > > it does not matter, so it could be 39 or 175, it does not matter.
> > 
> > Doesn't matter for your use case.  But not necessarily for others.
> 
> I wish I could understand the practical usage you describe. 

Why do you need to understand it?  Isn't it clear, up front, that
changing some old behavior runs a clear risk of breaking someone's
habits or code that relies on that behavior?

E.g., suppose that some Lisp program out there relies on the fact that
killing buffer "foo<10>" followed by creating a new buffer "foo"
yields again "foo<10"?  Is such a program not legitimate?

> Currently programmer cannot know that buffer with exact number <3> was
> created when a system command is invoked by using M-&.

Of course, he can: just scan the numbers in use, and you will know
which number will be used next.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-25 19:40   ` Jean Louis
@ 2021-03-26 13:09     ` Filipp Gunbin
  2021-03-26 13:40       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26 20:06       ` Jean Louis
  0 siblings, 2 replies; 58+ messages in thread
From: Filipp Gunbin @ 2021-03-26 13:09 UTC (permalink / raw)
  To: Help GNU Emacs

On 25/03/2021 22:40 +0300, Jean Louis wrote:

> * Filipp Gunbin <fgunbin@fastmail.fm> [2021-03-25 21:10]:
>> On 25/03/2021 17:33 +0300, Jean Louis wrote:
>>
>> > Is there way to find the last *Async Shell Command* buffer?
>> >
>> > Often I like running commands in background but there is hundreds of
>> > buffers and it would be useful to have a command to quickly change to
>> > the last one invoked.
>> >
>> > Jean
>>
>> isearch over minibuffer "future history" will give the same order as
>> *Buffer List* (latest first), so
>>
>> C-x b C-s async (possibly followed by more C-s)
>
> Yes, I could peek in the list. What I mean is to press a key and get
> latest buffer, maybe there is some internal date/time when buffers
> were created.

Something like this?

(defun my-find-latest-async-buf (pos)
  (interactive "p")
  (or pos (setq pos 0))
  (let ((b (nth pos (seq-filter (lambda (buf)
                                  (string-match (regexp-quote shell-command-buffer-name-async)
                                                (buffer-name buf)))
                                (buffer-list)))))
    (display-buffer b)))



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  8:43                             ` Jean Louis
@ 2021-03-26 13:37                               ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26 20:08                                 ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26 13:37 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>>> By the way, the above attempt does not work.
>> 
>> It is your own code, cleaned up to a functional state.
>
> I actually don't need a code, it is just that computers
> don't do what I think. But I do expect computers to start
> understanding human needs and doing what we need
> without coding.

Computers are deterministic machines, they don't understand
anything. They carry out instructions, that's all.

It is like a drilldriver. The handle can be made more
ergonomic, the machine can be cordless, brushless, yada yada
yada. It still doesn't understand anything, zip.

And if the supposed craftsman uses it in a nonchalant,
disrespectful way, contrary to its intended purpose... yeah,
you get what you get.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26 13:09     ` Filipp Gunbin
@ 2021-03-26 13:40       ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26 20:06       ` Jean Louis
  1 sibling, 0 replies; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26 13:40 UTC (permalink / raw)
  To: help-gnu-emacs

Filipp Gunbin wrote:

> (or pos (setq pos 0))

Oooh :)

But even better IMO (to avoid setq)

(let ((position (or pos 0)))
  ... )

Lisp can be soo good-looking I need a cold shower...

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 11:48                                   ` Jean Louis
  2021-03-26 12:37                                     ` Eli Zaretskii
@ 2021-03-26 13:49                                     ` Emanuel Berg via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26 13:49 UTC (permalink / raw)
  To: help-gnu-emacs

Hooks will slow down interactive feel and they are much harder
to manage than to compute <whatever> whenn - when and only
when - it is needed.

So, before one uses a hook to solve a problem like this, one
should be able to say "for reasons X & Y, this is
impossible/undesired to compute on the fly".

Compute all the time to be ready 100% of the time instantly,
when in fact 99.9% of the time when this isn't needed - much
better to compute when it is actually needed. Because that
computation is fast enough in... 99.8% of the cases.

       the best in techno-science estimations
                 brought to you by
                     esti-mate

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26  7:54                         ` Jean Louis
  2021-03-26 11:31                           ` Eli Zaretskii
@ 2021-03-26 14:02                           ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26 20:11                             ` Jean Louis
  1 sibling, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26 14:02 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> (add-hook 'buffer-list-update-hook 'rcd-last-async-buffer)

Never hook with a hooker.

Throw the hook, sure, you are within range, but so is your
opponent. That's right, time to sleep before you know it.

But you want to jab with a jabber tho because if you don't
he'll just jab all twelve rounds. Better to disturb his rhythm
and with the jab you can cross the distance and come close for
hooks and uppercuts.

The Sweet Science. Not complicated at all.

The Sweet Elisp? Same.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 12:37                                     ` Eli Zaretskii
@ 2021-03-26 20:05                                       ` Jean Louis
  2021-03-26 22:02                                         ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26 20:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

* Eli Zaretskii <eliz@gnu.org> [2021-03-26 15:38]:
> > Date: Fri, 26 Mar 2021 14:48:49 +0300
> > From: Jean Louis <bugs@gnu.support>
> > Cc: help-gnu-emacs@gnu.org
> > 
> > > > Sure, that is clear. I also refer to buffers like that. But how they
> > > > get assigned their number on the end like *Async Shell Command*<141>
> > > > it does not matter, so it could be 39 or 175, it does not matter.
> > > 
> > > Doesn't matter for your use case.  But not necessarily for others.
> > 
> > I wish I could understand the practical usage you describe. 
> 
> Why do you need to understand it?  Isn't it clear, up front, that
> changing some old behavior runs a clear risk of breaking someone's
> habits or code that relies on that behavior?

OK that is what you mean. Now is clear, of course.





^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26 13:09     ` Filipp Gunbin
  2021-03-26 13:40       ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-26 20:06       ` Jean Louis
  2021-03-26 21:17         ` Filipp Gunbin
  1 sibling, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26 20:06 UTC (permalink / raw)
  To: Help GNU Emacs

* Filipp Gunbin <fgunbin@fastmail.fm> [2021-03-26 16:10]:
> On 25/03/2021 22:40 +0300, Jean Louis wrote:
> 
> > * Filipp Gunbin <fgunbin@fastmail.fm> [2021-03-25 21:10]:
> >> On 25/03/2021 17:33 +0300, Jean Louis wrote:
> >>
> >> > Is there way to find the last *Async Shell Command* buffer?
> >> >
> >> > Often I like running commands in background but there is hundreds of
> >> > buffers and it would be useful to have a command to quickly change to
> >> > the last one invoked.
> >> >
> >> > Jean
> >>
> >> isearch over minibuffer "future history" will give the same order as
> >> *Buffer List* (latest first), so
> >>
> >> C-x b C-s async (possibly followed by more C-s)
> >
> > Yes, I could peek in the list. What I mean is to press a key and get
> > latest buffer, maybe there is some internal date/time when buffers
> > were created.
> 
> Something like this?
> 
> (defun my-find-latest-async-buf (pos)
>   (interactive "p")
>   (or pos (setq pos 0))
>   (let ((b (nth pos (seq-filter (lambda (buf)
>                                   (string-match (regexp-quote shell-command-buffer-name-async)
>                                                 (buffer-name buf)))
>                                 (buffer-list)))))
>     (display-buffer b)))

I have tried it, but error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  get-buffer(nil)
  display-buffer(nil)
  (let ((b (nth pos (seq-filter #'(lambda (buf) (string-match ... ...)) (buffer-list))))) (display-buffer b))
  my-find-latest-async-buf(1)
  funcall-interactively(my-find-latest-async-buf 1)
  call-interactively(my-find-latest-async-buf record nil)
  command-execute(my-find-latest-async-buf record)
  execute-extended-command(nil "my-find-latest-async-buf" nil)
  funcall-interactively(execute-extended-command nil "my-find-latest-async-buf" nil)
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26 13:37                               ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-26 20:08                                 ` Jean Louis
  2021-03-26 21:59                                   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26 20:08 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-26 16:38]:
> Jean Louis wrote:
> 
> >>> By the way, the above attempt does not work.
> >> 
> >> It is your own code, cleaned up to a functional state.
> >
> > I actually don't need a code, it is just that computers
> > don't do what I think. But I do expect computers to start
> > understanding human needs and doing what we need
> > without coding.
> 
> Computers are deterministic machines, they don't understand
> anything. They carry out instructions, that's all.

Fundamentally yes. However, the more or the better they are programmed
the more autonomic they may become, so that we do not need to keep
coding. That was direction of coding of 20th century, and we are now in
2021. We are late with artificial intelligence development.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26 14:02                           ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-26 20:11                             ` Jean Louis
  2021-03-26 22:00                               ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26 20:11 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-26 17:03]:
> Jean Louis wrote:
> 
> > (add-hook 'buffer-list-update-hook 'rcd-last-async-buffer)
> 
> Never hook with a hooker.
> 
> Throw the hook, sure, you are within range, but so is your
> opponent. That's right, time to sleep before you know it.

I have given up on that, it disturbed more or less. Now the idea works
well with the set of functions from today and I can browse through
async buffers which have a process attached. I will most probably
change that to be able to browse through those which are live without
process if key is invoked with a prefix.




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26 20:06       ` Jean Louis
@ 2021-03-26 21:17         ` Filipp Gunbin
  0 siblings, 0 replies; 58+ messages in thread
From: Filipp Gunbin @ 2021-03-26 21:17 UTC (permalink / raw)
  To: Help GNU Emacs

On 26/03/2021 23:06 +0300, Jean Louis wrote:

> I have tried it, but error:
>
> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>   get-buffer(nil)
>   display-buffer(nil)
...

Forgot to add non-nil check:

(defun my-find-latest-async-buf (pos)
  (interactive "p")
  (or pos (setq pos 0))
  (let ((b (nth pos (seq-filter (lambda (buf)
                                  (string-match (regexp-quote shell-command-buffer-name-async)
                                                (buffer-name buf)))
                                (buffer-list)))))
    (if b
        (display-buffer b)
      (message "No %dth async-shell buffer to display" pos))))

Filipp



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26 20:08                                 ` Jean Louis
@ 2021-03-26 21:59                                   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26 21:59 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>> Computers are deterministic machines, they don't understand
>> anything. They carry out instructions, that's all.
>
> Fundamentally yes.

By definition.

> However, the more or the better they are programmed the more
> autonomic they may become, so that we do not need to keep
> coding.

What will we then do all days?

But in the future computers will do programming as well if it
continues like that, yes.

> That was direction of coding of 20th century, and we are now
> in 2021. We are late with artificial
> intelligence development.

AI was big in the 70s as well. Because of the tree structure
and data/code blend that Lisp offers, it had an edge there.
You could traverse the trees in different ways, rotate
subtrees, and do stuff like that to, for example, make it
resemble human creativity and intuition. But boil it down, it
was just another way of carry out the same old computation.
A more elegant, cool, and inspiring way perhaps, but still.
The computer remained - a computer.

AI can excel at very simple games, for example chess, which
is well defined and easy to model.

But an AI cannot play ice hockey. It cannot run a bicycle
repair shop or chop wood. Because that's much more difficult!
Put a monitor to your brain when you play ice hockey or
repair bikes. Do the same thing when you play chess. The part
of the brain that is involved when playing chess is a joke.
Go outdoors and talk to a pretty girl. It is more involved.
Chess you can do when you get behind bars. I'm not impressed
by that. So why should I be impressed by the computer
doing it?

In the 60s-70s you could write a PhD thesis about a program
playing chess. Today that would be a big laugh. It is just
a little algorithm that plays chess. As we say, "utvecklingen
har gått framåt" (development has moved forward)

But with AI, what I've seen not so much.

I'd rather take control of the Russian subs and fire off some
nukes at my friend's houses. Ought to teach them not to borrow
my tools never to return them.

So bottom line, if you are here, there is no excuse not trying
to be the best Emacs programmer version of yourself.
Nonchalant code waiting for the AI to help - DNC.

PS. No disrespect to any AI programmer reading this.
    Because THAT involves a lot of brain activity. DS.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26 20:11                             ` Jean Louis
@ 2021-03-26 22:00                               ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26 23:28                                 ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26 22:00 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>>> (add-hook 'buffer-list-update-hook 'rcd-last-async-buffer)
>> 
>> Never hook with a hooker.
>> 
>> Throw the hook, sure, you are within range, but so is your
>> opponent. That's right, time to sleep before you know it.
>
> I have given up on that, it disturbed more or less. Now the
> idea works well with the set of functions from today and
> I can browse through async buffers which have a process
> attached. I will most probably change that to be able to
> browse through those which are live without process if key
> is invoked with a prefix.

OK, good, post the code :)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 20:05                                       ` Jean Louis
@ 2021-03-26 22:02                                         ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-03-26 23:29                                           ` Jean Louis
  0 siblings, 1 reply; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26 22:02 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>> Why do you need to understand it? Isn't it clear, up front,
>> that changing some old behavior runs a clear risk of
>> breaking someone's habits or code that relies on
>> that behavior?
>
> OK that is what you mean. Now is clear, of course.

If you write the new code all modular and neat it shouldn't
brake anything, especially nothing that's sound - neat and
modular itself.

If it does, either the new thing is bad or the previous stuff
wasn't that neat or modular, come to think of it.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26 22:00                               ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-26 23:28                                 ` Jean Louis
  2021-03-26 23:39                                   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26 23:28 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-27 01:05]:
> Jean Louis wrote:
> 
> >>> (add-hook 'buffer-list-update-hook 'rcd-last-async-buffer)
> >> 
> >> Never hook with a hooker.
> >> 
> >> Throw the hook, sure, you are within range, but so is your
> >> opponent. That's right, time to sleep before you know it.
> >
> > I have given up on that, it disturbed more or less. Now the
> > idea works well with the set of functions from today and
> > I can browse through async buffers which have a process
> > attached. I will most probably change that to be able to
> > browse through those which are live without process if key
> > is invoked with a prefix.
> 
> OK, good, post the code :)

I did, you missed it.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 22:02                                         ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-03-26 23:29                                           ` Jean Louis
  2021-03-26 23:41                                             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 58+ messages in thread
From: Jean Louis @ 2021-03-26 23:29 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-03-27 01:16]:
> Jean Louis wrote:
> 
> >> Why do you need to understand it? Isn't it clear, up front,
> >> that changing some old behavior runs a clear risk of
> >> breaking someone's habits or code that relies on
> >> that behavior?
> >
> > OK that is what you mean. Now is clear, of course.
> 
> If you write the new code all modular and neat it shouldn't
> brake anything, especially nothing that's sound - neat and
> modular itself.
> 
> If it does, either the new thing is bad or the previous stuff
> wasn't that neat or modular, come to think of it.

Maybe yes, maybe no, but what matters is that of today works well and
I can browse those active buffers with a key. In general what matters
personally is if it is useful and works.

Yet another opportunist.



^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: Finding last *Async Shell Command* buffer?
  2021-03-26 23:28                                 ` Jean Louis
@ 2021-03-26 23:39                                   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26 23:39 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

>> OK, good, post the code
>
> I did, you missed it.

Dream on - the Major of Limbo City don't make that kind
of mistake.

(symptomatic spelling mistake. let's keep the sign)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [solved]: Re: Finding last *Async Shell Command* buffer?
  2021-03-26 23:29                                           ` Jean Louis
@ 2021-03-26 23:41                                             ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 58+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-03-26 23:41 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> Maybe yes, maybe no, but what matters is that of today works
> well and I can browse those active buffers with a key.
> In general what matters personally is if it is useful
> and works.
>
> Yet another opportunist.

Here in Limbo City we don't care about stuff like that.
We write code for the sake of writing code.

And the more code we write, the more code we have to write...

Because if anything can start anew, then everything
must continue.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 58+ messages in thread

end of thread, other threads:[~2021-03-26 23:41 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-25 14:33 Finding last *Async Shell Command* buffer? Jean Louis
2021-03-25 15:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-25 15:08   ` Jean Louis
2021-03-25 20:27     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-25 20:36       ` Jean Louis
2021-03-25 20:50         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-25 20:59           ` Jean Louis
2021-03-25 21:08             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-25 21:12               ` Jean Louis
2021-03-26  5:52                 ` Robert Thorpe
2021-03-26  6:47                   ` Eli Zaretskii
2021-03-26  7:04                     ` Jean Louis
2021-03-26  7:18                       ` Eli Zaretskii
2021-03-26  7:28                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26  7:38                         ` Jean Louis
2021-03-26  7:52                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26  8:43                             ` Jean Louis
2021-03-26 13:37                               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26 20:08                                 ` Jean Louis
2021-03-26 21:59                                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26  7:17                     ` Jean Louis
2021-03-26  7:47                       ` Eli Zaretskii
2021-03-26  7:54                         ` Jean Louis
2021-03-26 11:31                           ` Eli Zaretskii
2021-03-26 14:02                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26 20:11                             ` Jean Louis
2021-03-26 22:00                               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26 23:28                                 ` Jean Louis
2021-03-26 23:39                                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26  7:01                   ` Jean Louis
2021-03-26  7:09                     ` Eli Zaretskii
2021-03-26  7:25                       ` [solved]: " Jean Louis
2021-03-26  7:31                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26  7:40                           ` Jean Louis
2021-03-26  7:56                         ` Eli Zaretskii
2021-03-26  8:55                           ` Jean Louis
2021-03-26 11:18                             ` Eli Zaretskii
2021-03-26 11:26                               ` Jean Louis
2021-03-26 11:33                                 ` Eli Zaretskii
2021-03-26 11:48                                   ` Jean Louis
2021-03-26 12:37                                     ` Eli Zaretskii
2021-03-26 20:05                                       ` Jean Louis
2021-03-26 22:02                                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26 23:29                                           ` Jean Louis
2021-03-26 23:41                                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26 13:49                                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26 10:34                           ` Jean Louis
2021-03-26 11:30                             ` Eli Zaretskii
2021-03-25 15:18   ` Jean Louis
2021-03-25 15:54     ` Skip Montanaro
2021-03-25 19:31       ` Jean Louis
2021-03-25 18:10 ` Filipp Gunbin
2021-03-25 19:40   ` Jean Louis
2021-03-26 13:09     ` Filipp Gunbin
2021-03-26 13:40       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-03-26 20:06       ` Jean Louis
2021-03-26 21:17         ` Filipp Gunbin
2021-03-25 20:05   ` Jean Louis

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.