d8ed8f669a51078f85ff3ada8bc7a738b2156b8b

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #650 from tristan0x/emacs

Emacs

Diff

 1diff --git a/plugins/emacs/emacs.plugin.zsh b/plugins/emacs/emacs.plugin.zsh
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..a3f0085a826ba7817e47bc46f814fb931bd9011e
 4--- /dev/null
 5+++ b/plugins/emacs/emacs.plugin.zsh
 6@@ -0,0 +1,56 @@
 7+# Emacs 23 daemon capability is a killing feature.
 8+# One emacs process handles all your frames whether
 9+# you use a frame opened in a terminal via a ssh connection or X frames
10+# opened on the same host.
11+
12+# Benefits are multiple
13+# - You don't have the cost of starting Emacs all the time anymore
14+# - Opening a file is as fast as Emacs does not have anything else to do.
15+# - You can share opened buffered across opened frames.
16+# - Configuration changes made at runtime are applied to all frames.
17+
18+
19+if "$ZSH/tools/require_tool.sh" emacs 23 2>/dev/null ; then
20+    export EMACS_PLUGIN_LAUNCHER="$ZSH/plugins/emacs/emacsclient.sh"
21+
22+    # set EDITOR if not already defined.
23+    export EDITOR="${EDITOR:-${EMACS_PLUGIN_LAUNCHER}}"
24+
25+    alias emacs="$EMACS_PLUGIN_LAUNCHER --no-wait"
26+    alias e=emacs
27+
28+    # same than M-x eval but from outside Emacs.
29+    alias eeval="$EMACS_PLUGIN_LAUNCHER --eval"
30+    # create a new X frame
31+    alias eframe='emacsclient --alternate-editor "" --create-frame'
32+
33+    # to code all night long
34+    alias emasc=emacs
35+    alias emcas=emacs
36+
37+    # Write to standard output the path to the file
38+    # opened in the current buffer.
39+    function efile {
40+        local cmd="(buffer-file-name (window-buffer))"
41+        "$EMACS_PLUGIN_LAUNCHER" --eval "$cmd" | tr -d \"
42+    }
43+
44+    # Write to standard output the directory of the file
45+    # opened in the the current buffer
46+    function ecd {
47+        local cmd="(let ((buf-name (buffer-file-name (window-buffer))))
48+                     (if buf-name (file-name-directory buf-name)))"
49+
50+        local dir="$($EMACS_PLUGIN_LAUNCHER --eval $cmd | tr -d \")"
51+        if [ -n "$dir" ] ;then
52+            echo "$dir"
53+        else
54+            echo "can not deduce current buffer filename." >/dev/stderr
55+            return 1
56+        fi
57+    }
58+fi
59+
60+## Local Variables:
61+## mode: sh
62+## End:
63diff --git a/plugins/emacs/emacsclient.sh b/plugins/emacs/emacsclient.sh
64new file mode 100755
65index 0000000000000000000000000000000000000000..38d419813f8e21d37feb6f032ee250abdc4bf748
66--- /dev/null
67+++ b/plugins/emacs/emacsclient.sh
68@@ -0,0 +1,12 @@
69+#!/bin/sh
70+
71+# get list of available X windows.
72+x=`emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null`
73+
74+if [ -z "$x" ] ;then
75+    # Create one if there is no X window yet.
76+    emacsclient --alternate-editor "" --create-frame "$@"
77+else
78+    # prevent creating another X frame if there is at least one present.
79+    emacsclient --alternate-editor "" "$@"
80+fi