all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Detachable shells in Emacs?
@ 2012-08-25 23:47 Sean McAfee
  2012-08-26  0:05 ` Pascal J. Bourguignon
  2012-08-26  2:02 ` Stefan Monnier
  0 siblings, 2 replies; 11+ messages in thread
From: Sean McAfee @ 2012-08-25 23:47 UTC (permalink / raw)
  To: help-gnu-emacs

At my workplace, I often invoke commands in my Emacs shell buffer that
take quite a long time to finish--sometimes quite a bit longer than I
originally expected.  For example, on Friday afternoon I might find that
the command that's been running for an hour is going to continue for
several more.  I'd like to head home for the day, but I'm interested in
all of the output, and I don't want to interrupt the program to start it
over, perhaps because it's making changes on a remote server and
interrupting it could leave things in a weird state.

What I'd like is to be able to detach the shell process running in the
buffer, like the GNU screen program allows me to do, and resume it
later.  I tried the direct approach of simply running screen instead of
bash in the shell buffer, but screen won't have that: it complains
"Clear screen capability required" and exits immediately.  I scanned the
various options to screen to see if there was a way to invoke it in a
relatively feature-free mode that doesn't support multiple concurrent
windows, but didn't see anything relevant.

I could run screen inside an Emacs terminal buffer, but I prefer
shell-mode in general for various reasons.

Does anyone have any thoughts?  I feel I could probably contrive
something useful with enough time, but I wanted to see if any
approximately equivalent solutions already exist.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
  2012-08-25 23:47 Detachable shells in Emacs? Sean McAfee
@ 2012-08-26  0:05 ` Pascal J. Bourguignon
  2012-09-07 20:04   ` Sean McAfee
  2012-09-14  0:56   ` Sean McAfee
  2012-08-26  2:02 ` Stefan Monnier
  1 sibling, 2 replies; 11+ messages in thread
From: Pascal J. Bourguignon @ 2012-08-26  0:05 UTC (permalink / raw)
  To: help-gnu-emacs

Sean McAfee <eefacm@gmail.com> writes:

> What I'd like is to be able to detach the shell process running in the
> buffer, like the GNU screen program allows me to do, and resume it
> later.  I tried the direct approach of simply running screen instead of
> bash in the shell buffer, but screen won't have that: it complains
> "Clear screen capability required" and exits immediately.  I scanned the
> various options to screen to see if there was a way to invoke it in a
> relatively feature-free mode that doesn't support multiple concurrent
> windows, but didn't see anything relevant.
>
> I could run screen inside an Emacs terminal buffer, but I prefer
> shell-mode in general for various reasons.
>
> Does anyone have any thoughts?  I feel I could probably contrive
> something useful with enough time, but I wanted to see if any
> approximately equivalent solutions already exist.

Do the reverse.
Run emacs inside screen, not screen inside emacs.

You can do it after the fact:

- launch screen,
- in screen, use emacsclient -t to open an emacs frame in screen,
- close the GUI emacs frames with C-x 5 0
- detach screen
- log out

then you can:

- log in
- screen -r -x 
- M-x make-frame-on-display RET :0.0 RET

 
-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
  2012-08-25 23:47 Detachable shells in Emacs? Sean McAfee
  2012-08-26  0:05 ` Pascal J. Bourguignon
@ 2012-08-26  2:02 ` Stefan Monnier
  2012-08-27 19:09   ` Neal Becker
       [not found]   ` <mailman.7694.1346094589.855.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 11+ messages in thread
From: Stefan Monnier @ 2012-08-26  2:02 UTC (permalink / raw)
  To: help-gnu-emacs

> What I'd like is to be able to detach the shell process running in the
> buffer, like the GNU screen program allows me to do, and resume it
> later.

Just leave your Emacs running and then connect to it with emacsclient
when you want to see the result.


        Stefan


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
  2012-08-26  2:02 ` Stefan Monnier
@ 2012-08-27 19:09   ` Neal Becker
       [not found]   ` <mailman.7694.1346094589.855.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Neal Becker @ 2012-08-27 19:09 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier wrote:

>> What I'd like is to be able to detach the shell process running in the
>> buffer, like the GNU screen program allows me to do, and resume it
>> later.
> 
> Just leave your Emacs running and then connect to it with emacsclient
> when you want to see the result.
> 
> 
>         Stefan

Not a choice if you started emacs via e.g., ssh.

I really miss this feature.  Turn running emacs into a daemon.  I'll bet it's 
not that hard to implement this.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
       [not found]   ` <mailman.7694.1346094589.855.help-gnu-emacs@gnu.org>
@ 2012-08-27 19:47     ` Lowell Gilbert
  2012-09-09 16:06       ` David Combs
  2012-08-28  3:58     ` Barry Margolin
  1 sibling, 1 reply; 11+ messages in thread
From: Lowell Gilbert @ 2012-08-27 19:47 UTC (permalink / raw)
  To: help-gnu-emacs

Neal Becker <ndbecker2@gmail.com> writes:

> Stefan Monnier wrote:
>
>>> What I'd like is to be able to detach the shell process running in the
>>> buffer, like the GNU screen program allows me to do, and resume it
>>> later.
>> 
>> Just leave your Emacs running and then connect to it with emacsclient
>> when you want to see the result.
>> 
>> 
>>         Stefan
>
> Not a choice if you started emacs via e.g., ssh.
>
> I really miss this feature.  Turn running emacs into a daemon.  I'll bet it's 
> not that hard to implement this.

You can always use emacs' daemon option (which has been around for a few
years now), but as far as I can see, you need to start it that way up
front. Stefan Monnier's approach seems to allow you to detach from a
running emacs started without that option.

I use the daemon mode quite often; in fact, these days I rarely run
emacs without it.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
       [not found]   ` <mailman.7694.1346094589.855.help-gnu-emacs@gnu.org>
  2012-08-27 19:47     ` Lowell Gilbert
@ 2012-08-28  3:58     ` Barry Margolin
  1 sibling, 0 replies; 11+ messages in thread
From: Barry Margolin @ 2012-08-28  3:58 UTC (permalink / raw)
  To: help-gnu-emacs

In article <mailman.7694.1346094589.855.help-gnu-emacs@gnu.org>,
 Neal Becker <ndbecker2@gmail.com> wrote:

> Stefan Monnier wrote:
> 
> >> What I'd like is to be able to detach the shell process running in the
> >> buffer, like the GNU screen program allows me to do, and resume it
> >> later.
> > 
> > Just leave your Emacs running and then connect to it with emacsclient
> > when you want to see the result.
> > 
> > 
> >         Stefan
> 
> Not a choice if you started emacs via e.g., ssh.
> 
> I really miss this feature.  Turn running emacs into a daemon.  I'll bet it's 
> not that hard to implement this.

Actually, it is. Just like you can't start a shell, do a bunch of things 
in it, and then turn it into a screen session. You have to run the shell 
within screen in the first place.

I suppose Emacs could do it by ALWAYS daemonizing itself when it starts 
up, and doing an implicit emacsclient.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
  2012-08-26  0:05 ` Pascal J. Bourguignon
@ 2012-09-07 20:04   ` Sean McAfee
  2012-09-08  2:08     ` Neil T. Dantam
  2012-09-14  0:56   ` Sean McAfee
  1 sibling, 1 reply; 11+ messages in thread
From: Sean McAfee @ 2012-09-07 20:04 UTC (permalink / raw)
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
> Sean McAfee <eefacm@gmail.com> writes:
>> What I'd like is to be able to detach the shell process running in the
>> buffer, like the GNU screen program allows me to do, and resume it
>> later.

> Do the reverse.
> Run emacs inside screen, not screen inside emacs.
>
> You can do it after the fact:
>
> - launch screen,
> - in screen, use emacsclient -t to open an emacs frame in screen,
> - close the GUI emacs frames with C-x 5 0
> - detach screen
> - log out
>
> then you can:
>
> - log in
> - screen -r -x 
> - M-x make-frame-on-display RET :0.0 RET

Very nice!  But it doesn't quite get me where I want to be.  I work from
home occasionally, and so I'd like to be able to leave Emacs running at
the office and resume working on it remotely, on my laptop, over an ssh
tunnel.  But when I try to create a frame on my laptop's display, using
"localhost:10.0" as the display, I get "X11 connection rejected because
of wrong authentication."

Anyway, I guess this has become more of an X11 and/or ssh problem than
an Emacs problem.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
  2012-09-07 20:04   ` Sean McAfee
@ 2012-09-08  2:08     ` Neil T. Dantam
  0 siblings, 0 replies; 11+ messages in thread
From: Neil T. Dantam @ 2012-09-08  2:08 UTC (permalink / raw)
  To: help-gnu-emacs


> I work from home occasionally, and so I'd like to be able to leave
> Emacs running at the office and resume working on it remotely, on my
> laptop, over an ssh tunnel.  But when I try to create a frame on my
> laptop's display, using "localhost:10.0" as the display, I get "X11
> connection rejected because of wrong authentication."

Likely, the XAUTHORITY used by emacs does not know how to talk to the
X connection forward by ssh.  I've had this problem when GDM makes
some random XAUTHORITY file under /var, which emacs will also use,
while SSH puts everything in ~/.Xauthority.  The following script is
what I use to forward emacs frames through SSH:

    #!/bin/sh

    #### Create a new emacs frame on $DISPLAY, setting xauthority properly

    ### Merge the xauth entry for $DISPLAY into emacs's xauthority
    # scrub out localhost from display, or xauth doesn't list it
    SCRUBBED_DISPLAY=`echo $DISPLAY | sed -e 's/^localhost:/:/'`
    if [ -n "$SCRUBBED_DISPLAY" ]; then
        CURRENT_XAUTH=`xauth list $SCRUBBED_DISPLAY`
        emacsclient -e "(shell-command \"xauth add $CURRENT_XAUTH\")" > /dev/null
    fi

    ### New emacs frame
    exec emacsclient -e "(make-frame-on-display  \"$DISPLAY\")"


-ntd





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
  2012-08-27 19:47     ` Lowell Gilbert
@ 2012-09-09 16:06       ` David Combs
  2012-09-11 17:56         ` Lowell Gilbert
  0 siblings, 1 reply; 11+ messages in thread
From: David Combs @ 2012-09-09 16:06 UTC (permalink / raw)
  To: help-gnu-emacs

In article <44lih0p16h.fsf@be-well.ilk.org>,
Lowell Gilbert  <lgusenet@be-well.ilk.org> wrote:
>Neal Becker <ndbecker2@gmail.com> writes:
>
>> Stefan Monnier wrote:
>>
>>>> What I'd like is to be able to detach the shell process running in the
>>>> buffer, like the GNU screen program allows me to do, and resume it
>>>> later.
>>> 
>>> Just leave your Emacs running and then connect to it with emacsclient
>>> when you want to see the result.
>>> 
>>> 
>>>         Stefan
>>
>> Not a choice if you started emacs via e.g., ssh.
>>
>> I really miss this feature.  Turn running emacs into a daemon.  I'll bet it's 
>> not that hard to implement this.
>
>You can always use emacs' daemon option (which has been around for a few
>years now), but as far as I can see, you need to start it that way up
>front. Stefan Monnier's approach seems to allow you to detach from a
>running emacs started without that option.
>
>I use the daemon mode quite often; in fact, these days I rarely run
>emacs without it.

It'd be really useful to *lots* of us (I think) if, right here in
this very thread, you guys could followup with posts that could
later be put together into a tutorial on emacs-as-daemon:

. What benefits come from deamonizing emacs -- what kinds of
  things can you do (easily) only when emacs is sitting there
  as a daemon.

. a little ascii picture (or instructions for drawing one 
  on paper) of how the thing works, how it's used.

. (Note: in both emacs and elisp *info* tbl of contents, no mention
   of either daemon or demon.)

. How to it up as a daemon.

. How to actually use it in one of its uses.


Thanks so much!

Looks like a pretty cool feature, but I have ZERO idea of how
(or why) I'd use it, benefit from it.

Also, an explanation of what's behind this statement:

   >
   >I use the daemon mode quite often; in fact, these days I rarely run
   >emacs without it.


THANK YOU!

David




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
  2012-09-09 16:06       ` David Combs
@ 2012-09-11 17:56         ` Lowell Gilbert
  0 siblings, 0 replies; 11+ messages in thread
From: Lowell Gilbert @ 2012-09-11 17:56 UTC (permalink / raw)
  To: help-gnu-emacs

dkcombs@panix.com (David Combs) writes:

> . (Note: in both emacs and elisp *info* tbl of contents, no mention
>    of either daemon or demon.)
>

The node is called "Emacs Server" and includes the basic description:
"once an Emacs server is started, you can use a shell command called
`emacsclient' to connect to the Emacs process and tell it to visit a
file."

If that was hard to find, then you probably would be helped more by
learning about "Info-search", which is bound to 's' in Info mode.

> In article <44lih0p16h.fsf@be-well.ilk.org>,
> Lowell Gilbert  <lgusenet@be-well.ilk.org> wrote:
>>
>>You can always use emacs' daemon option (which has been around for a few
>>years now), but as far as I can see, you need to start it that way up
>>front. Stefan Monnier's approach seems to allow you to detach from a
>>running emacs started without that option.
>>
>>I use the daemon mode quite often; in fact, these days I rarely run
>>emacs without it.
>
> It'd be really useful to *lots* of us (I think) if, right here in
> this very thread, you guys could followup with posts that could
> later be put together into a tutorial on emacs-as-daemon:
>
> . What benefits come from deamonizing emacs -- what kinds of
>   things can you do (easily) only when emacs is sitting there
>   as a daemon.

There are lots of things that are useful about it. A big one for me is
being to able to open up windows from the same emacs; e.g., I can log
into work from home and connect to the same emacs instance that I left
at the office. Commands that open editors for you (anything for which
you set the EDITOR environment variable or its like) will use the
existing emacs rather than starting up a new process.

Beyond that, I'll let you read the documentation first and see what's
still unclear after that.

Good luck.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Detachable shells in Emacs?
  2012-08-26  0:05 ` Pascal J. Bourguignon
  2012-09-07 20:04   ` Sean McAfee
@ 2012-09-14  0:56   ` Sean McAfee
  1 sibling, 0 replies; 11+ messages in thread
From: Sean McAfee @ 2012-09-14  0:56 UTC (permalink / raw)
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> Sean McAfee <eefacm@gmail.com> writes:
>> What I'd like is to be able to detach the shell process running in the
>> buffer, like the GNU screen program allows me to do, and resume it
>> later.

> - launch screen,
> - in screen, use emacsclient -t to open an emacs frame in screen,
> - close the GUI emacs frames with C-x 5 0
> - detach screen
> - log out
>
> then you can:
>
> - log in
> - screen -r -x 
> - M-x make-frame-on-display RET :0.0 RET

OK, this works great now, although I need to use the ssh-wrangling
script provided by Neil to manifest the window.  Thanks!

What's especially nifty is that I can start the screen session
containing the text-mode frame required to keep Emacs alive when all of
the graphical frames are deleted using a terminal-emulator buffer within
Emacs itself.  It lends an Ouroboros-like quality to the proceedings.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-09-14  0:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-25 23:47 Detachable shells in Emacs? Sean McAfee
2012-08-26  0:05 ` Pascal J. Bourguignon
2012-09-07 20:04   ` Sean McAfee
2012-09-08  2:08     ` Neil T. Dantam
2012-09-14  0:56   ` Sean McAfee
2012-08-26  2:02 ` Stefan Monnier
2012-08-27 19:09   ` Neal Becker
     [not found]   ` <mailman.7694.1346094589.855.help-gnu-emacs@gnu.org>
2012-08-27 19:47     ` Lowell Gilbert
2012-09-09 16:06       ` David Combs
2012-09-11 17:56         ` Lowell Gilbert
2012-08-28  3:58     ` Barry Margolin

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.