emacs plugin tweak to open buffer from stdin (#5126)
Diff
1diff --git a/plugins/emacs/emacsclient.sh b/plugins/emacs/emacsclient.sh
2index 625201a16bbd106b6dcb2e5489e63c480391f58c..d61ebb15b38d76c2652394f9ebb68c7cf10d40ff 100755
3--- a/plugins/emacs/emacsclient.sh
4+++ b/plugins/emacs/emacsclient.sh
5@@ -1,12 +1,27 @@
6 #!/bin/sh
7 8-# get list of available X windows.
9-x=`emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null`
10+function _emacsfun
11+{
12+ # get list of available X windows.
13+ x=`emacsclient --alternate-editor '' --eval '(x-display-list)' 2>/dev/null`
1415-if [ -z "$x" ] || [ "$x" = "nil" ] ;then
16- # Create one if there is no X window yet.
17- emacsclient --alternate-editor "" --create-frame "$@"
18+ if [ -z "$x" ] || [ "$x" = "nil" ] ;then
19+ # Create one if there is no X window yet.
20+ emacsclient --alternate-editor "" --create-frame "$@"
21+ else
22+ # prevent creating another X frame if there is at least one present.
23+ emacsclient --alternate-editor "" "$@"
24+ fi
25+}
26+
27+
28+# adopted from https://github.com/davidshepherd7/emacs-read-stdin/blob/master/emacs-read-stdin.sh
29+# If the second argument is - then write stdin to a tempfile and open the
30+# tempfile. (first argument will be `--no-wait` passed in by the plugin.zsh)
31+if [[ $# -ge 2 ]] && [[ "$2" == - ]]; then
32+ tempfile="$(mktemp emacs-stdin-$USER.XXXXXXX --tmpdir)"
33+ cat - > "$tempfile"
34+ _emacsfun --no-wait $tempfile
35 else
36- # prevent creating another X frame if there is at least one present.
37- emacsclient --alternate-editor "" "$@"
38+ _emacsfun "$@"
39 fi