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

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

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


From: Jean Louis
Subject: [solved]: Re: Finding last *Async Shell Command* buffer?
Date: Fri, 26 Mar 2021 10:25:10 +0300
User-agent: Mutt/2.0.6 (2021-03-06)

* 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



reply via email to

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