diff options
author | Zhiming Wang <zmwangx@gmail.com> | 2014-12-14 10:40:25 -0800 |
---|---|---|
committer | Zhiming Wang <zmwangx@gmail.com> | 2014-12-22 18:01:03 -0800 |
commit | f23add066558de8261528b9866e9c45542daa754 (patch) | |
tree | 05900e84ec2c29e214cd941613dd99e64b3f24ed | |
parent | ae798440800bfab9537387a4ec3aed97f3982e86 (diff) | |
download | my_new_personal_website-f23add066558de8261528b9866e9c45542daa754.tar.xz my_new_personal_website-f23add066558de8261528b9866e9c45542daa754.zip |
20141214 Speeding up Emacs with emacsclient
-rw-r--r-- | source/_posts/2014-12-14-speeding-up-emacs-with-emacsclient.md | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/_posts/2014-12-14-speeding-up-emacs-with-emacsclient.md b/source/_posts/2014-12-14-speeding-up-emacs-with-emacsclient.md new file mode 100644 index 00000000..2baeaf25 --- /dev/null +++ b/source/_posts/2014-12-14-speeding-up-emacs-with-emacsclient.md @@ -0,0 +1,29 @@ +--- +layout: post +title: "Speeding up Emacs with emacsclient" +date: 2014-12-14 10:06:02 -0800 +comments: true +categories: +--- +Emacs is notorious for its loading time. For me, this is especially annoying when I'm editing LaTeX files — AUCTeX takes about five seconds to load, and once I exit Emacs (especially after a quick edit), all that work is wasted, and next time I want to do some quick editing with that same LaTeX file — sorry, another five seconds. + +This problem can be solved by "using that same Emacs", i.e., running Emacs in server mode, then connecting to the server via `emacsclient`. Below is my script, which I call `emc`, to make `emacsclient` more user-friendly. `emc` opens a file (given as `$1`) on the server, launching one on its way if none is detected. Note that I used `-cqt` for `emacsclient`. The `-c` option is `--create-frame`, i.e., create a new frame (in the current tty, for instance) instead of using the existing frame (in another tty, for instance); this allows for multiple frames accross different ttys. The `-q` option is for `--quiet`, suppressing messages like "Waiting for Emacs..." The `-t` option is for `--tty`, or equivalently, the familiar `-nw` option of `emacs`. Note that `emacsclient` requires a filename, so my script prompts for one if `$1` is empty. + +``` bash emc +if [[ -n $1 ]]; then + file=$1 +else + while [[ -z ${file} ]]; do + read -p 'filename: ' file + done +fi +emacsclient -cqt "${file}" 2>/dev/null || { emacs --daemon; emacsclient -cqt "${file}"; } +``` + +Note that using `emacsclient` has the additional benefit that the same buffer is simultaneously updated accross different ttys (See screenshot, where I opened the current post in two different ttys). This way, you won't face the nasty "file changed on disk" problem when you accidentally edited the same file in another tty session. + +![screen shot of multiple copies of the same buffer](http://i.imgur.com/9KxEWKq.png) + +By the way, remember to re-configure your other programs that uses an external editor. For instance, change `$EDITOR` to `emacsclient -cqt` in your `env`, and `core.editor` to `emacsclient -cqt` in your `~/.gitconfig`. + +I just started using `emacsclient`, so the above script might be buggy in certain edge cases. I'll report when I run into issues. |