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

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

Re: [solved]: Re: Finding last *Async Shell Command* buffer?


From: Eli Zaretskii
Subject: Re: [solved]: Re: Finding last *Async Shell Command* buffer?
Date: Fri, 26 Mar 2021 10:56:51 +0300

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



reply via email to

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