* Distinguishing between interactive and asynchronous shell buffers
@ 2011-02-21 0:02 Sean McAfee
2011-02-21 2:43 ` Barry Margolin
2011-02-22 21:18 ` Sean McAfee
0 siblings, 2 replies; 9+ messages in thread
From: Sean McAfee @ 2011-02-21 0:02 UTC (permalink / raw)
To: help-gnu-emacs
I find that dired is a much better way of navigating around a large
directory hierarchy than staying in my shell buffer and issuing lots of
cd/ls commands. To bring my shell buffer to a directory I've located
with dired, I wrote an interactive command
bring-last-shell-buffer-to-this-directory (aliased to "c'mere") which
locates the most-recently-used shell buffer like this:
(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?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Distinguishing between interactive and asynchronous shell buffers
2011-02-21 0:02 Distinguishing between interactive and asynchronous shell buffers Sean McAfee
@ 2011-02-21 2:43 ` Barry Margolin
2011-02-22 0:24 ` Sean McAfee
2011-02-22 21:18 ` Sean McAfee
1 sibling, 1 reply; 9+ messages in thread
From: Barry Margolin @ 2011-02-21 2:43 UTC (permalink / raw)
To: help-gnu-emacs
In article <m2y65ajluo.fsf@gmail.com>, Sean McAfee <eefacm@gmail.com>
wrote:
> I find that dired is a much better way of navigating around a large
> directory hierarchy than staying in my shell buffer and issuing lots of
> cd/ls commands. To bring my shell buffer to a directory I've located
> with dired, I wrote an interactive command
> bring-last-shell-buffer-to-this-directory (aliased to "c'mere") which
> locates the most-recently-used shell buffer like this:
>
> (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, barmar@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 ***
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Distinguishing between interactive and asynchronous shell buffers
2011-02-21 2:43 ` Barry Margolin
@ 2011-02-22 0:24 ` Sean McAfee
2011-02-22 0:50 ` Perry Smith
[not found] ` <mailman.7.1298335846.7153.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 9+ messages in thread
From: Sean McAfee @ 2011-02-22 0:24 UTC (permalink / raw)
To: help-gnu-emacs
Barry Margolin <barmar@alum.mit.edu> writes:
> In article <m2y65ajluo.fsf@gmail.com>, Sean McAfee <eefacm@gmail.com>
> wrote:
>> What's the best way to distinguish asynchronous shell command buffers
>> from interactive shell buffers?
> 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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Distinguishing between interactive and asynchronous shell buffers
2011-02-22 0:24 ` Sean McAfee
@ 2011-02-22 0:50 ` Perry Smith
[not found] ` <mailman.7.1298335846.7153.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 9+ messages in thread
From: Perry Smith @ 2011-02-22 0:50 UTC (permalink / raw)
To: GNU Emacs List
On Feb 21, 2011, at 6:24 PM, Sean McAfee wrote:
> Barry Margolin <barmar@alum.mit.edu> writes:
>> In article <m2y65ajluo.fsf@gmail.com>, Sean McAfee <eefacm@gmail.com>
>> wrote:
>>> What's the best way to distinguish asynchronous shell command buffers
>>> from interactive shell buffers?
>
>> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Distinguishing between interactive and asynchronous shell buffers
[not found] ` <mailman.7.1298335846.7153.help-gnu-emacs@gnu.org>
@ 2011-02-22 18:48 ` Sean McAfee
2011-02-22 19:59 ` Perry Smith
0 siblings, 1 reply; 9+ messages in thread
From: Sean McAfee @ 2011-02-22 18:48 UTC (permalink / raw)
To: help-gnu-emacs
Perry Smith <pedzsan@gmail.com> writes:
>>> In article <m2y65ajluo.fsf@gmail.com>, Sean McAfee <eefacm@gmail.com>
>>> wrote:
>>>> What's the best way to distinguish asynchronous shell command buffers
>>>> from interactive shell buffers?
> 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 &".
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Distinguishing between interactive and asynchronous shell buffers
2011-02-22 18:48 ` Sean McAfee
@ 2011-02-22 19:59 ` Perry Smith
0 siblings, 0 replies; 9+ messages in thread
From: Perry Smith @ 2011-02-22 19:59 UTC (permalink / raw)
To: GNU Emacs List
[-- Attachment #1: Type: text/plain, Size: 1336 bytes --]
On Feb 22, 2011, at 12:48 PM, Sean McAfee wrote:
> Perry Smith <pedzsan@gmail.com> writes:
>>>> In article <m2y65ajluo.fsf@gmail.com>, Sean McAfee <eefacm@gmail.com>
>>>> wrote:
>>>>> What's the best way to distinguish asynchronous shell command buffers
>>>>> from interactive shell buffers?
>
>> 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 &".
Hmm... your are right:
> If COMMAND ends in ampersand, execute it asynchronously.
> The output appears in the buffer `*Async Shell Command*'.
> That buffer is in shell mode.
bummer.
So, my (oh dear, I just walked into an awful pun) advice at this point
is to look at "advice" in the lisp manual. I've never used it but
it seems to allow you to wrap a function with some extra code. In
that code, maybe set a buffer local variable that you could later test.
The other alternatives would be not to use & for shell-commands or look
at mode-name first. If it is shell then look at the buffers name and
if it isn't "Async ... whatever", then its an interactive shell buffer.
Sorry to be so vague.
pedz
[-- Attachment #2: Type: text/html, Size: 2773 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Distinguishing between interactive and asynchronous shell buffers
2011-02-21 0:02 Distinguishing between interactive and asynchronous shell buffers Sean McAfee
2011-02-21 2:43 ` Barry Margolin
@ 2011-02-22 21:18 ` Sean McAfee
2011-02-23 16:03 ` Stefan Monnier
1 sibling, 1 reply; 9+ messages in thread
From: Sean McAfee @ 2011-02-22 21:18 UTC (permalink / raw)
To: help-gnu-emacs
Following myself up...
Sean McAfee <eefacm@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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Distinguishing between interactive and asynchronous shell buffers
2011-02-22 21:18 ` Sean McAfee
@ 2011-02-23 16:03 ` Stefan Monnier
2011-02-23 18:28 ` Deniz Dogan
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2011-02-23 16:03 UTC (permalink / raw)
To: help-gnu-emacs
> 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:
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Distinguishing between interactive and asynchronous shell buffers
2011-02-23 16:03 ` Stefan Monnier
@ 2011-02-23 18:28 ` Deniz Dogan
0 siblings, 0 replies; 9+ messages in thread
From: Deniz Dogan @ 2011-02-23 18:28 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
2011/2/23 Stefan Monnier <monnier@iro.umontreal.ca>:
>> 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:
>
> 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)).
>
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?
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-02-23 18:28 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-21 0:02 Distinguishing between interactive and asynchronous shell buffers Sean McAfee
2011-02-21 2:43 ` Barry Margolin
2011-02-22 0:24 ` Sean McAfee
2011-02-22 0:50 ` Perry Smith
[not found] ` <mailman.7.1298335846.7153.help-gnu-emacs@gnu.org>
2011-02-22 18:48 ` Sean McAfee
2011-02-22 19:59 ` Perry Smith
2011-02-22 21:18 ` Sean McAfee
2011-02-23 16:03 ` Stefan Monnier
2011-02-23 18:28 ` Deniz Dogan
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.