I'd like to run my Emacs in daemon mode, and then use emacsclient
to actually display things. However, if I run emacsclient filename
, it shows up in the terminal, which isn't what I want; I instead have to pass it the -c
option.
However, that option always creates a new frame, which isn't what I want - I'd rather just have one frame, and have stuff open in a new buffer in the same frame if it already exists; otherwise, it should make me a new frame. However, I'm not sure how to do this.
Additionally, I want that one frame to be maximized, which I usually achieve my starting Emacs with the -mm
option; how would I ensure that a frame made by emacsclient
is also maximized?
The following script does the following:
#!/bin/bash
# Selected options for "emacsclient"
#
# -c Create a new frame instead of trying to use the current
# Emacs frame.
#
# -e Evaluate the FILE arguments as ELisp expressions.
#
# -n Don't wait for the server to return.
#
# -t Open a new Emacs frame on the current terminal.
#
# Note that the "-t" and "-n" options are contradictory: "-t" says to
# take control of the current text terminal to create a new client frame,
# while "-n" says not to take control of the text terminal. If you
# supply both options, Emacs visits the specified files(s) in an existing
# frame rather than a new client frame, negating the effect of "-t".
# check whether an Emacs server is already running
pgrep -l "^emacs$" > /dev/null
# otherwise, start Emacs server daemon
if [ $? -ne 0 ]; then
emacs --daemon
fi
# return a list of all frames on $DISPLAY
emacsclient -e "(frames-on-display-list \"$DISPLAY\")" &>/dev/null
# open frames detected, so open files in current frame
if [ $? -eq 0 ]; then
emacsclient -n -t "$@"
# no open frames detected, so open new frame
else
emacsclient -n -c "$@"
fi
Edit: fixed expansion of positional arguments (2017-12-31).
For having every new frame maximized, you could add this to your .emacs:
(modify-all-frames-parameters '((fullscreen . maximized))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With