2011-04-13 15:34:51 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-09-28 08:10:43 +00:00
|
|
|
emacsfun() {
|
|
|
|
local frames="$(emacsclient --alternate-editor "" -n -e "(length (frame-list))" 2>/dev/null)"
|
2011-10-10 16:04:13 +00:00
|
|
|
|
2021-09-28 08:10:43 +00:00
|
|
|
# Only create another X frame if there isn't one present
|
|
|
|
if [ -z "$frames" -o "$frames" -lt 2 ]; then
|
|
|
|
emacsclient --alternate-editor "" --create-frame "$@"
|
|
|
|
return $?
|
|
|
|
fi
|
|
|
|
|
|
|
|
emacsclient --alternate-editor "" "$@"
|
2016-06-17 10:12:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# 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)
|
2021-09-28 08:10:43 +00:00
|
|
|
if [ $# -ge 2 -a "$2" = "-" ]; then
|
|
|
|
tempfile="$(mktemp --tmpdir emacs-stdin-$USERNAME.XXXXXXX 2>/dev/null \
|
|
|
|
|| mktemp -t emacs-stdin-$USERNAME)" # support BSD mktemp
|
|
|
|
cat - > "$tempfile"
|
|
|
|
emacsfun --no-wait "$tempfile"
|
|
|
|
return $?
|
2011-04-13 15:34:51 +00:00
|
|
|
fi
|
2021-09-28 08:10:43 +00:00
|
|
|
|
|
|
|
emacsfun "$@"
|