(let ((buffer (or (loop for buffer being the buffers
if (with-current-buffer buffer
(eq major-mode 'shell-mode))
return buffer)
(error "No shell buffers!"))))
;; Issue a "cd" command in buffer that sends that shell
;; to the starting buffer's default-directory
This works great most of the time, but once I started an asynchronous
shell command after moving around in dired, and when I did M-x c'mere,
my routine tried to send a cd to the *Async Shell Command* buffer.
What's the best way to distinguish asynchronous shell command buffers
from interactive shell buffers?
Why not just look for the buffer named "*shell*"?
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
> Why not just look for the buffer named "*shell*"?
Because I often have multiple shell buffers open--none of which are
necessarily named "*shell*"--and I only want to target the
most-recently-accessed one.
mode-name ?
It would be "Shell" for things started with "shell" and "Fundamental" for things done with shell-command
> mode-name ?
>
> It would be "Shell" for things started with "shell" and "Fundamental" for things done with shell-command
I hadn't known of that variable, but a quick test shows that its value
is also "Shell" in the buffer *Async Shell Command* after a
shell-command of "ls &".
If COMMAND ends in ampersand, execute it asynchronously.The output appears in the buffer `*Async Shell Command*'.That buffer is in shell mode.
Sean McAfee <eef...@gmail.com> writes:
> What's the best way to distinguish asynchronous shell command buffers
> from interactive shell buffers?
Digging into simple.el, the only difference I could find between
asynchronous and interactive shell buffers is that the former have
process sentinels associated with them when they're running; after they
finish, they of course have no process at all. That led me to write:
(defun is-interactive-shell-buffer (buffer)
(and (with-current-buffer buffer
(eq major-mode 'shell-mode))
(let ((proc (get-buffer-process buffer)))
(and proc (not (process-sentinel proc))))))
I guess this solution could fail if an interactive shell buffer ever had
a process sentinel for some reason, but it seems OK for now.
Indeed, there are very few differences between them. Another way to
distinguish them is to look at the buffer's history: if you never type
in async-shell-command buffers, then the input history should be empty
in those buffers. E.g. maybe checking (eq (point-min)
comint-last-input-start) will do the trick.
Another way is to check (string-match "Async" (buffer-name)).
Stefan
Aren't those methods a bit tacky? I feel like there should be a
better way.
I barely know anything about comint/shell-mode but how about a
buffer-local variable which indicates whether or not the process is
running asynchronously?