From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: [solved]: Re: Finding last *Async Shell Command* buffer? Date: Fri, 26 Mar 2021 10:56:51 +0300 Message-ID: <8335wiqrek.fsf@gnu.org> References: <87k0puihrd.fsf@robertthorpeconsulting.com> <838s6aqtlv.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3222"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 26 08:57:19 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lPhLK-0000kF-DQ for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 26 Mar 2021 08:57:18 +0100 Original-Received: from localhost ([::1]:56762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPhLJ-0000vy-Fa for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 26 Mar 2021 03:57:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPhKt-0000ti-6b for help-gnu-emacs@gnu.org; Fri, 26 Mar 2021 03:56:51 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:45785) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPhKs-0007SQ-Vg for help-gnu-emacs@gnu.org; Fri, 26 Mar 2021 03:56:50 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4869 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lPhKr-0003WR-5D for help-gnu-emacs@gnu.org; Fri, 26 Mar 2021 03:56:50 -0400 In-Reply-To: (message from Jean Louis on Fri, 26 Mar 2021 10:25:10 +0300) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128607 Archived-At: > Date: Fri, 26 Mar 2021 10:25:10 +0300 > From: Jean Louis > 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.