summaryrefslogtreecommitdiff
path: root/plugins/emacs
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/emacs')
-rw-r--r--plugins/emacs/emacs.plugin.zsh7
-rwxr-xr-xplugins/emacs/emacsclient.sh30
2 files changed, 26 insertions, 11 deletions
diff --git a/plugins/emacs/emacs.plugin.zsh b/plugins/emacs/emacs.plugin.zsh
index a3f0085a8..c102a5a1e 100644
--- a/plugins/emacs/emacs.plugin.zsh
+++ b/plugins/emacs/emacs.plugin.zsh
@@ -10,7 +10,7 @@
# - Configuration changes made at runtime are applied to all frames.
-if "$ZSH/tools/require_tool.sh" emacs 23 2>/dev/null ; then
+if "$ZSH/tools/require_tool.sh" emacs 24 2>/dev/null ; then
export EMACS_PLUGIN_LAUNCHER="$ZSH/plugins/emacs/emacsclient.sh"
# set EDITOR if not already defined.
@@ -18,15 +18,14 @@ if "$ZSH/tools/require_tool.sh" emacs 23 2>/dev/null ; then
alias emacs="$EMACS_PLUGIN_LAUNCHER --no-wait"
alias e=emacs
+ # open terminal emacsclient
+ alias te="$EMACS_PLUGIN_LAUNCHER -nw"
# same than M-x eval but from outside Emacs.
alias eeval="$EMACS_PLUGIN_LAUNCHER --eval"
# create a new X frame
alias eframe='emacsclient --alternate-editor "" --create-frame'
- # to code all night long
- alias emasc=emacs
- alias emcas=emacs
# Write to standard output the path to the file
# opened in the current buffer.
diff --git a/plugins/emacs/emacsclient.sh b/plugins/emacs/emacsclient.sh
index 625201a16..26b28d495 100755
--- a/plugins/emacs/emacsclient.sh
+++ b/plugins/emacs/emacsclient.sh
@@ -1,12 +1,28 @@
#!/bin/sh
-# get list of available X windows.
-x=`emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null`
+_emacsfun()
+{
+ # get list of emacs frames.
+ frameslist=`emacsclient --alternate-editor '' --eval '(frame-list)' 2>/dev/null | egrep -o '(frame)+'`
-if [ -z "$x" ] || [ "$x" = "nil" ] ;then
- # Create one if there is no X window yet.
- emacsclient --alternate-editor "" --create-frame "$@"
+ if [ "$(echo "$frameslist" | sed -n '$=')" -ge 2 ] ;then
+ # prevent creating another X frame if there is at least one present.
+ emacsclient --alternate-editor "" "$@"
+ else
+ # Create one if there is no X window yet.
+ emacsclient --alternate-editor "" --create-frame "$@"
+ fi
+}
+
+
+# adopted from https://github.com/davidshepherd7/emacs-read-stdin/blob/master/emacs-read-stdin.sh
+# If the second argument is - then write stdin to a tempfile and open the
+# tempfile. (first argument will be `--no-wait` passed in by the plugin.zsh)
+if [ "$#" -ge "2" -a "$2" = "-" ]
+then
+ tempfile="$(mktemp emacs-stdin-$USER.XXXXXXX --tmpdir)"
+ cat - > "$tempfile"
+ _emacsfun --no-wait $tempfile
else
- # prevent creating another X frame if there is at least one present.
- emacsclient --alternate-editor "" "$@"
+ _emacsfun "$@"
fi