b37114b4d5804f8125d3951efde6a1b9d39610d1
- Author
- Marc Cornellà <hello@mcornella.com>
- Committer
- Marc Cornellà <hello@mcornella.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/emacs/emacs.plugin.zsh b/plugins/emacs/emacs.plugin.zsh
2index 0b602d12adf738e30f0be3603ab02e8efe87fa53..027c7550f4c0b2c3d3b31f940f69080efe889925 100644
3--- a/plugins/emacs/emacs.plugin.zsh
4+++ b/plugins/emacs/emacs.plugin.zsh
5@@ -9,57 +9,55 @@
6 # - You can share opened buffered across opened frames.
7 # - Configuration changes made at runtime are applied to all frames.
8
9-
10-if "$ZSH/tools/require_tool.sh" emacsclient 24 2>/dev/null ; then
11- export EMACS_PLUGIN_LAUNCHER="$ZSH/plugins/emacs/emacsclient.sh"
12-
13- # set EDITOR if not already defined.
14- export EDITOR="${EDITOR:-${EMACS_PLUGIN_LAUNCHER}}"
15-
16- alias emacs="$EMACS_PLUGIN_LAUNCHER --no-wait"
17- alias e=emacs
18- # open terminal emacsclient
19- alias te="$EMACS_PLUGIN_LAUNCHER -nw"
20-
21- # same than M-x eval but from outside Emacs.
22- alias eeval="$EMACS_PLUGIN_LAUNCHER --eval"
23- # create a new X frame
24- alias eframe='emacsclient --alternate-editor "" --create-frame'
25-
26- # Emacs ANSI Term tracking
27- if [[ -n "$INSIDE_EMACS" ]]; then
28- chpwd_emacs() { print -P "\033AnSiTc %d"; }
29- print -P "\033AnSiTc %d" # Track current working directory
30- print -P "\033AnSiTu %n" # Track username
31-
32- # add chpwd hook
33- autoload -Uz add-zsh-hook
34- add-zsh-hook chpwd chpwd_emacs
35- fi
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+# Require emacs version to be minimum 24
59+autoload -Uz is-at-least
60+is-at-least 24 "${${(Az)"$(emacsclient --version 2>/dev/null)"}[2]}" || return 0
61+
62+# Path to custom emacsclient launcher
63+export EMACS_PLUGIN_LAUNCHER="${0:A:h}/emacsclient.sh"
64+
65+# set EDITOR if not already defined.
66+export EDITOR="${EDITOR:-${EMACS_PLUGIN_LAUNCHER}}"
67+
68+alias emacs="$EMACS_PLUGIN_LAUNCHER --no-wait"
69+alias e=emacs
70+# open terminal emacsclient
71+alias te="$EMACS_PLUGIN_LAUNCHER -nw"
72+
73+# same than M-x eval but from outside Emacs.
74+alias eeval="$EMACS_PLUGIN_LAUNCHER --eval"
75+# create a new X frame
76+alias eframe='emacsclient --alternate-editor "" --create-frame'
77+
78+# Emacs ANSI Term tracking
79+if [[ -n "$INSIDE_EMACS" ]]; then
80+ chpwd_emacs() { print -P "\033AnSiTc %d"; }
81+ print -P "\033AnSiTc %d" # Track current working directory
82+ print -P "\033AnSiTu %n" # Track username
83+
84+ # add chpwd hook
85+ autoload -Uz add-zsh-hook
86+ add-zsh-hook chpwd chpwd_emacs
87 fi
88
89-## Local Variables:
90-## mode: sh
91-## End:
92+# Write to standard output the path to the file
93+# opened in the current buffer.
94+function efile {
95+ local cmd="(buffer-file-name (window-buffer))"
96+ local file="$("$EMACS_PLUGIN_LAUNCHER" --eval "$cmd" | tr -d \")"
97+
98+ if [[ -z "$file" ]]; then
99+ echo "Can't deduce current buffer filename." >&2
100+ return 1
101+ fi
102+
103+ echo "$file"
104+}