1

I have the following line in my .init.el

(ansi-term "/usr/bin/bash")

, because I usually like to have a terminal running in my emacs. The problem is that sometimes I don't, for instance, when I just do some quick edit, like when I git commit. In this case, exiting emacs involves prompts about running processes, and usually I like these safety warnings. I know I can create an alias something along the lines of

alias emax='emacs --eval "(ansi-term \"/usr/bin/bash\")"'

This leaves the normal emacs command unchanged and everything would be fine, if I only start emacs from terminals. If I want to start it from the "Start" menu however, then I'm out of luck again.

So, the question is, is there some clever mechanism, where emacs usually starts with an ansi-term, but somehow knows, when I don't want one. One such possibility would be creating something like a custom emax.desktop file, but I'd also have to use the alias above and I'd like to avoid maintaining code in two different places.

So hopefully this question is understandable. I'm open to any linuxy hints, but simpler is better of course.

  • You could turn emax into a bash script that execs emacs with the appropriate arguments, and then have a desktop shortcut to that script. – nispio Apr 13 '16 at 16:51
  • 3
    Why not use emacsclient for things like git commit? – npostavs Apr 13 '16 at 18:57
2

Paste this script into bash and you are ready to roll:

#!/bin/bash
EMAX_DIR=/usr/local/bin
EMAX=$EMAX_DIR/emax
mkdir -p $EMAX_DIR
cat > $EMAX <<EOF
#!/bin/bash
exec emacs \$* --eval "(ansi-term \"/usr/bin/bash\")"
EOF
chmod +x $EMAX
hash -r

SHORTCUT=$HOME/.local/share/applications/emacs-with-ansi-term.desktop
sed -e "s,EMAX,$EMAX," > $SHORTCUT <<EOF
[Desktop Entry]
Name=Emacs with Ansi Terminal
GenericName=Text Editor
Comment=Edit text
MimeType=text/english;text/plain;
Exec=EMAX %F
Icon=emacs
Type=Application
Terminal=false
Categories=Development;TextEditor;
StartupWMClass=Emacs
Encoding=UTF-8
Keywords=emax;emacs;Text;Editor;Terminal
EOF

This assumes that you are using a freedesktop.org-compliant desktop like GNOME. It will make the emax bash script and also create the desktop shortcut for invoking it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.