I usually want my Emacs windows, including those opened via emacsclient
, to be opened using the full screen height. It turns out that Emacs has a command line option for this:
emacs --fullheight
Now, for emacsclient
this option doesn’t exist, so how can we solve this? Looking around the web, I found this answer on Emacs StackExchange that explained how to do this from within Emacs (see also the fullscreen
option on the corresponding page in the Emacs manual). Combined with this answer on StackOverflow that shows how to use the -F/--frame-parameters
option of emacsclient
I managed to open a full-height Emacs client window:
emacsclient --create-frame --frame-parameters="'(fullscreen . fullheight)"
Most of the time I open new Emacs (-client) windows using the button in Ubuntu’s/Gnome shell’s dock. So how do we incorporate the aforementioned options in the relevant .desktop
file? Before explaining how I did this, I have to mention that I don’t use a pre-packaged version of Emacs. As of this writing Emacs v27.2 is the latest official release, but I have been compiling Emacs from source for about two years now. About a month ago I compiled Emacs from the emacs-28
branch 1, which contains what will become Emacs v28. In this branch the .desktop
files used by Gnome for its list of applications (including the icons/launchers that end up in the Gnome shell dock) have received some love. For example, the emacsclient.desktop
file now opens a regular Emacs at first launch, but subsequent clicks on the icon will launch an Emacs client window. Right-clicking on the icon shows an option called “New Instance”, which will do as it says: launch a new Emacs instance. Well done Emacs maintainers! This perfectly fits my workflow, where most of the time I want to open a client window, but sometimes want to open a new Emacs instance (e.g. when I don’t want to clutter my regular workspaces).
So, getting back to the fullheight
topic, editing the emacsclient.desktop
file seemed like the way to go. Given that I compile Emacs from source and do not install it system-wide (I used the --prefix=/home/$USER/.local
option when running ./configure
), the .desktop
files can be found in ~/.local/share/applications
. This is the contents of the emacsclient.desktop
file before I edited it:
[Desktop Entry] Name=Emacs (Client) GenericName=Text Editor Comment=Edit text MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++; Exec=sh -c "if [ -n \\"\\$*\\" ]; then exec emacsclient --alternate-editor= --display=\\"\\$DISPLAY\\" \\"\\$@\\"; else exec emacsclient --alternate-editor= --create-frame; fi" %F Icon=emacs Type=Application Terminal=false Categories=Development;TextEditor; StartupNotify=true StartupWMClass=Emacs Keywords=emacsclient; Actions=new-window;new-instance; [Desktop Action new-window] Name=New Window Exec=/home/lennart/.local/bin/emacsclient --alternate-editor= --create-frame %F [Desktop Action new-instance] Name=New Instance Exec=emacs %F
After my edits, this is the contents of the file:
[Desktop Entry] Name=Emacs (Client) GenericName=Text Editor Comment=Edit text MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++; Exec=sh -c "if [ -n \\"\\$*\\" ]; then exec emacsclient --alternate-editor= --frame-parameters=\\"'(fullscreen . fullheight)\\" --display=\\"\\$DISPLAY\\" \\"\\$@\\"; else exec emacsclient --alternate-editor= --create-frame --frame-parameters=\\"'(fullscreen . fullheight)\\"; fi" %F Icon=emacs Type=Application Terminal=false Categories=Development;TextEditor; StartupNotify=true StartupWMClass=Emacs Keywords=emacsclient; Actions=new-window;new-instance; [Desktop Action new-window] Name=New Window Exec=/home/lennart/.local/bin/emacsclient --alternate-editor= --create-frame --frame-parameters="'(fullscreen . fullheight)" %F [Desktop Action new-instance] Name=New Instance Exec=emacs --fullheight %F
The diff is:
@@ -3,7 +3,7 @@ GenericName=Text Editor Comment=Edit text MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++; -Exec=sh -c "if [ -n \\"\\$*\\" ]; then exec emacsclient --alternate-editor= --display=\\"\\$DISPLAY\\" \\"\\$@\\"; else exec emacsclient --alternate-editor= --create-frame; fi" %F +Exec=sh -c "if [ -n \\"\\$*\\" ]; then exec emacsclient --alternate-editor= --frame-parameters=\\"'(fullscreen . fullheight)\\" --display=\\"\\$DISPLAY\\" \\"\\$@\\"; else exec emacsclient --alternate-editor= --create-frame --frame-parameters=\\"'(fullscreen . fullheight)\\"; fi" %F Icon=emacs Type=Application Terminal=false @@ -15,8 +15,8 @@ [Desktop Action new-window] Name=New Window -Exec=/home/lennart/.local/bin/emacsclient --alternate-editor= --create-frame %F +Exec=/home/lennart/.local/bin/emacsclient --alternate-editor= --create-frame --frame-parameters="'(fullscreen . fullheight)" %F [Desktop Action new-instance] Name=New Instance -Exec=emacs %F +Exec=emacs --fullheight %F
One final note: for those who don’t use the Emacs client, there is also the emacs.desktop
file, with the same icon. You can find out which one is in your Gnome shell dock by running:
gsettings get org.gnome.shell favorite-apps
which returns a list like this:
['org.gnome.Terminal.desktop', 'thunderbird.desktop', 'firefox.desktop', 'emacsclient.desktop']
If you’d like to edit this variable manually, you can use either dconf-editor
to edit org/gnome/shell/favorite-apps
, or set it directly:
gsettings set org.gnome.shell favorite-apps "['org.gnome.Terminal.desktop', 'thunderbird.desktop', 'firefox.desktop', 'emacs.desktop']"
Note, the order of the list matters!