Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open a file in an emacs buffer while in emacs terminal

Tags:

bash

emacs

Suppose I am in terminal in Emacs (M-x term), and I list the following files in current directory:

text_code.R

Now I am in bash-3.2$ (terminal) and hope to open this .R file in another Emacs buffer and then edit. Is there a way to do it? This might be a trivial question, for I am a newbie to Linux and Emacs. Thanks in advance!

like image 743
alittleboy Avatar asked Sep 21 '12 02:09

alittleboy


2 Answers

Remember that in Term Mode you can type C-c C-f to open a file (just like C-x C-f outside Term Mode). The prompt will already be on your current directory, so you just have to start typing the name of the file and autocomplete it with TAB.

like image 122
Juancho Avatar answered Oct 20 '22 17:10

Juancho


I don't know the official procedure for what you want to do, but here is a procedure that works:

  1. Either tell emacs to run as a daemon (Ref: EmacsAsDaemon) or in emacs start daemon via M-x server-start.

  2. In the term, a command like emacsclient -n filename will start editing the specified file in the current window. Note, emacsclient also has a -c, --create-frame option to edit in a new frame. You probably will want to use a -n option as above, so you can continue using your term, after selecting it from the buffers list in another pane or frame.

  3. If you start the daemon via M-x server-start in emacs, the daemon will terminate when you exit from emacs. If you set it up via reference mentioned above, use kill-emacs or save-buffers-kill-emacs commands or shell command emacsclient -e '(kill-emacs)' to stop it, as mentioned in part 6 of reference.

like image 43
James Waldby - jwpat7 Avatar answered Oct 20 '22 18:10

James Waldby - jwpat7