4
  1. I have a screenrc file but I am finding some conflicts when I run emacs inside screen. For e.g, moving across buffers in emacs, Ctrl-right arrow/left arrow, instead of moving back and forth sends some characters into the buffers such as 5C, 5D etc. This problem exists even when I invoke screen without any screenrc file. But at least the other conflicts were not there. But I would be very grateful if someone could tell me how to fix this ?

  2. Since I have my own bindings in my screenrc file and I want to continue using it, so I was thinking that I will keep my screenrc file but when I want to start emacs in a new screen, I will not use my screenrc. Is there any way to while invoking screen to not to use screenrc ? Till now I have been managing by renaming my screenrc file to something else when starting emacs.

  3. Is there any way in which emacs itself can work as screen, as in I am using screen so that my emacs session does not terminate whenever the remote ssh session goes down. I found some documentation regarding emacs client and emacs server but could not understand much. I would appreciate if someone could tell how to save sessions inside emacs and restore them so that I dont need to use screen for emacs if its possible, as in one should be able to restore the emacs process again.

1
  • 2
    May I suggest that you post three separate questions next time, to allow people to get credit for answering (only) one of them, and to make it easier to search for each of them?
    – Thomas
    Jul 10 '11 at 16:27
9

I only have input on your question #3.

As of emacs 23, emacs has a daemon mode which for me has obviated the need to run emacs inside screen. On my first login after a boot, I start emacs --daemon in a terminal. This starts emacs in the background. Then, whenever I need to use emacs, I either run emacsclient -nc to get an X window to my emacs session, or emacsclient -t to get a terminal session.

Multiple clients can coexist happily. I routinely run an X client on my workstation screen at work, an X client through ssh login from home, and a terminal client on my phone. All talking to the same emacs process, with all my buffers and other state intact. And should my ssh connection on my phone die, I can just continue where I left off after logging in again.

I don't know enough about keybindings in screen to help you with your first two questions.

5
  • Thanks a lot for that emacs client thing. Now I dont need screen anymore for emacs. At least it wont conflict with the emacs key bindings :-)
    – pineapple
    Jul 11 '11 at 18:19
  • How does this solve the problem of persistent sessions? If the shell in which you originally invoke emacs --daemon happens to be exited (for example, a random broken pipe for that ssh connection), then upon re-connecting, the original emacs session won't be available. Previously opened buffers will not be in the client sessions, etc. Isn't this virtually the entire use case for running emacs inside screen? I'm missing how this addresses it. It seems like you'd have to run emacs --daemon inside a screen session to ensure it was persistent, which defeats the purpose.
    – ely
    Mar 20 '17 at 18:37
  • @ely If your emacs becomes unavailable after a client shell exits for whatever reason, your emacs is buggy. I just tested, and this works for me: logged in; emacs --daemon; emacsclient -t; do stuff; log out; log back in; emacsclient -t; see previous stuff; log in on alternate terminal; kill -9 the shell with emacsclient; log in again; emacsclient -t; my stuff is still there. Mar 21 '17 at 13:28
  • I think you're misunderstanding. What if the shell running emacs --daemon goes down. If that shell stays up, then I can log in and out of other shells, each of which is only bothering with emacsclient, and it works as you say. But if the connection to the original shell dies, the shell within which emacs --daemon is executed, then the daemon and all clients go with it. How would you persist the running daemon across different log ins? Background is not enough. You'd have to run it with nohup or something, which is the bad way of doing what you should use screen or tmux for.
    – ely
    Mar 21 '17 at 14:07
  • @ely It wouldn't be much of a daemon if it needed help from nohup, screen or tmux. Not needing that is the point of --daemon. emacs --daemon properly detaches from the terminal and reparents to pid 1. It has no dependency on its originating shell. I tried, in my previous comment, to show a sequence in which I indeed exit the shell from which I started the daemonized emacs, but perhaps that was not clear. For me, emacs --daemon works exactly the way you claim it can't. Calling something a daemon and not having it survive the invoking shell would be stupid. So the devs didn't do that. Mar 28 '17 at 10:37
8

1) This has to do with the way in which Emacs interpets escape sequences sent by the terminal. This is fun stuff! You should configure your input-decode-map, e.g., by defining the following function in your .emacs file:

(defun terminal-init-screen ()
  "Terminal initialization function for GNU screen."
  (when (boundp 'input-decode-map)
    (define-key input-decode-map "^[[1;5C" [(control right)])
    (define-key input-decode-map "^[[1;5D" [(control left)])))

(Note that the ^[ in the above example is not a caret followed by an opening bracket, it's a single escape character which you type like this: C-q ESC.)

This function is magically called by Emacs running inside screen.

2) You can invoke screen with its -c option, to specify a different file than the default .screenrc. So if you have special configurations for screen that you only want to be applied when you run Emacs inside screen, you could put them in a file .emacs-screenrc, and run emacs inside screen like so:

screen -c .emacs-screenrc emacs

Note that this file could be empty.

3) Managing sessions in emacs can sometimes be tedious. Off the shelf, Emacs provides desktop save mode which I personally don't use, but I've read mixed reports on it. You might want to give it a try. A good overview over alternative approaches can be found on the Emacs wiki.

An alternative to session management in the first place is to run Emacs as a server and connect to it with emacsclient. I don't know which documentation you saw, but GNU's official Emacs documentation is usually very good. Have a look at it:

http://www.gnu.org/software/libtool/manual/emacs/Emacs-Server.html#Emacs-Server

3

For #1

Try invoking emacs like so from inside screen:

TERM=xterm emacs -nw somefile

CTRL+arrow should now work as intented

0

Another way to have part of 3) is to use tramp: with tramp you can use the Emacs running on your computer to edit a file on your server. Just open /ssh:user@host:/path/to/remote/file

This can also be used for other "remote" use for example

  • /sudo::/etc/bla for editing using sudo,
  • /ftp:user@host:/path/to/remote/file to edit remote file using ftp...

tramp will reopen the ssh connection when needed, and you can even use tramp to run program on the remote host (VCS stuff for example).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.