From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: [solved]: Re: Finding last *Async Shell Command* buffer? Date: Fri, 26 Mar 2021 14:26:13 +0300 Message-ID: References: <87k0puihrd.fsf@robertthorpeconsulting.com> <838s6aqtlv.fsf@gnu.org> <8335wiqrek.fsf@gnu.org> <831rc2qi35.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4285"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.6 (2021-03-06) Cc: help-gnu-emacs@gnu.org To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 26 12:33:03 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 1lPki7-00010q-CL for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 26 Mar 2021 12:33:03 +0100 Original-Received: from localhost ([::1]:53698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPki6-0007Ry-Ct for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 26 Mar 2021 07:33:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPkem-0005oF-4R for help-gnu-emacs@gnu.org; Fri, 26 Mar 2021 07:29:36 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:53255) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPke5-0006SJ-9A; Fri, 26 Mar 2021 07:29:35 -0400 Original-Received: from localhost ([::ffff:41.210.143.10]) (AUTH: PLAIN securesender, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000027ECE.00000000605DC570.0000699A; Fri, 26 Mar 2021 04:28:48 -0700 Mail-Followup-To: Eli Zaretskii , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <831rc2qi35.fsf@gnu.org> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:128616 Archived-At: * Eli Zaretskii [2021-03-26 14:18]: > > Date: Fri, 26 Mar 2021 11:55:52 +0300 > > From: Jean Louis > > 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 ‘’, 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