Though many people says Emacs is an “Operating System”, it is not and still need to interactive with other programs
I’ve talked about how to call other programs from eshell, dired, and view files according to mime types within dired. Besides that, the 2 programs I use most is a terminal emulator and Firefox.
Most Emacs users know the basic of VIM because it’s a waste of time waiting for Emacs to start just to change one or two lines of a config file. A better way than learning VIM is to config your Emacs to do things quickly
There are two solutions for this, with nearly the same mechinesm: turn the running Emacs as a server and connect to it from the outside world. Emacsserv/emacsclient comes with the official GNU Emacs and there’s a standalone package called gnuserv. The later is more powerful that it could connect from other machines through TCP/IP and works with XEmacs too. It is very useful with tramp, especially in the same LAN. I’ve used it before and it’s really handy. However my current network connection is not good for that kind of usage so I’m using the official emacsserv/emacsclient now.
To start it is simple: just add
(server-start))
to your Emacs config file. The noninteractive line makes sure the server only starts on an interactive Emacs. I have some scripts calling Emacs and I don’t want them to start another instance of Emacs and confuse the clients about which server to connect.
It is easy to use in the terminal, just call emacsclient with the file you want to edit. One important option is “—no-wait” which tells the shell or caller don’t wait for the end of the editing.
I have
emacsclient –no-wait $@
as my ~/bin/e so I can call it with less key presses. This not only works for files, if you give it a directory as the argument, like “e .”, Emacs will show the dired buffer with the current directory.
And I have
emacsclient $@
as my ~/bin/e_wait and EDITOR and VISUAL point to it.
And in Firefox, there is a web developer entension that could call external editors for viewing page source, the “e” shell fits quite well here.
It can do more than that, like use Emacs to handle “mailto:” within firefox.
Sometimes want to jump to the current Emacs directory in the buffer? this function
"Copy current directory to `kill-ring’ prefixed with ‘cd ‘."
(interactive)
(if (consp comint-completion-addsuffix)
(kill-new (concat "cd " (subst-char-in-string ?/ (string-to-char
(car comint-completion-addsuffix)) default-directory)))
(kill-new (concat "cd " default-directory))
)
)
helps me alot. I bind it to “C-c g d” and I can paste the directory with “cd” to the terminal.
Post a Comment
You could use <code type="name"> to get your code colorized