From: Jean Louis <bugs@gnu.support>
To: Eli Zaretskii <eliz@gnu.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: [solved]: Re: Finding last *Async Shell Command* buffer?
Date: Fri, 26 Mar 2021 14:26:13 +0300 [thread overview]
Message-ID: <YF3E1Zb3+gRkSASA@protected.localdomain> (raw)
In-Reply-To: <831rc2qi35.fsf@gnu.org>
* 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
next prev parent reply other threads:[~2021-03-26 11:26 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YF3E1Zb3+gRkSASA@protected.localdomain \
--to=bugs@gnu.support \
--cc=eliz@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).