.emacs Edit to Always Start Emacs in Terminal Mode?
Solution 1
You can't do this in the .emacs
file. By the time that file is being parsed, the "chosen" emacs binary is already running.
You can install the emacs-nox
package as one commenter suggests, or create an alias in your shell so that "emacs" is always treated as "emacs -nw".
Randy
Solution 2
I'm using a bash alias instead of .emacs to do that.
Add this line to your ~/.bashrc.
alias emacs='emacs -nw'
Solution 3
There is any easy way to solve the problem in general that has nothing to do with emacs at all and will work for any program that can choose between running in the console vs X:
unset DISPLAY
Of course you may not want to put that in your configuration file to be applied globally to all your shell sessions, so if you want it to apply to only emacs, then either call it from the command line like this:
DISPLAY= emacs
note the space!!! if you leave the space out it means you're setting the DISPLAY to emacs instead of setting DISPLAY to nothing... this command is a shorthand for:
DISPLAY=; emacs
So either use the above from the command line(s) or put that in a wrapper script that would look something like this:
#!/bin/bash
unset DISPLAY
exec emacs
I recommend the exec there because it will replace your wrapper script with emacs; to see the difference between the two you can run:
pstree -p
Solution 4
When I was first setting up a "emacs -nw" alias for emacs in windows I got stuck in a situation where I thought tototoshi's explanation hadn't worked. Yet all that was required was a restart of my terminal. Therefore, i think its worth mentioning that in windows (at least) if you are using emacs within the git bash terminal to create the .bashrc file and add "alias emacs='emacs -nw" to it (as tototoshi mentions) you have to close and reopen your terminal for it to work.
templatetypedef
I love teaching, learning, and that really great feeling you get when you finally understand something.
Updated on June 06, 2022Comments
-
templatetypedef about 2 years
I use emacs as my editor-of-choice, and since I'm doing a lot of work in a terminal I always run emacs as
emacs -nw
so that it runs in the terminal instead of in a window.
I'd like to just run
emacs
and have it know that it should run in a terminal. My question is - how do I edit my.emacs
file so that this is the default behavior? -
cristobalito over 13 years+1 for the alias suggestion - defo the way to go in this case
-
templatetypedef over 13 yearsThanks for the detailed answer! I'll try that out.
-
aculich over 13 yearsbtw: I am curious- why do you WANT to always run emacs in a console if you are running in an X environment?
-
Kim Gräsman over 9 yearsemacs-nox11-* on FreeBSD. Just what I was looking for, thanks!
-
Thomas over 7 yearsThat third command with a semicolon is NOT the same as the second command. If you add the semicolon it sets DISPLAY to empty in the current shell as well as in the emacs child process. Without the semicolon it only applies to emacs. With semicolon it's destructive.
-
Thomas over 7 yearsWhy would you want a billion windows open? Also I do all my coding work inside 'screen', which doesn't make sense with X. @aculich