mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-17 19:30:10 +00:00
08da19e3fd
Revert cab1ac6e68
The change from the above commit breaks opening a new emacs frame if
there isn't a existing frame open.
When emacs is running in daemon mode, there will always be a frame
associated with the daemon, even if there are no visible frames.
The lisp function `frame-list`, will always return 1 frame.
```
emacsclient --eval '(frame-list)'
(#<frame F1 0xa3c680>)
```
When an real frame is open, two frames are reported by the `frame-list`
function.
```
emacsclient --eval '(frame-list)'
(#<frame F1 0xa3c680> #<frame emacs Prelude - ~/oh-my-zsh/plugins/emacs/emacsclient.sh 0xf50e10>)
```
See:
https://emacs.stackexchange.com/questions/44537/extra-frame-in-visible-frame-list-when-started-in-daemon-mode-is-causing-prob
https://emacs.stackexchange.com/questions/18859/dont-let-the-daemon-frame-make-a-file-visible
28 lines
915 B
Bash
Executable file
28 lines
915 B
Bash
Executable file
#!/bin/sh
|
|
|
|
_emacsfun()
|
|
{
|
|
# get list of emacs frames.
|
|
frameslist=`emacsclient --alternate-editor '' --eval '(frame-list)' 2>/dev/null | egrep -o '(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
|
|
_emacsfun "$@"
|
|
fi
|