You are not logged in.
Pages: 1
UPDATE: The solution is to install the package "emacs-nox" to replace "emacs". This way, the GUI is never used.
I'm starting to use emacs more and more as my main editor, but I would like to know how to make it always run in the terminal. I currently launch it as "emacs -nw" because I created a bash alias that runs it like that when I type "emacs".
The problem is I can't run "sudo emacs" and get it to run in the terminal. I even edited the root user's .bashrc to have the same emacs='emacs -nw' alias. No luck.
Another problem is that I can't set it as the default editor in my .bashrc. I use midnight commander for file management, and it looks for the default bash editor when I choose to edit a text file. If I set the default editor as "emacs", even when I have an alias set for emacs to run emacs -nw, the program still launches its GUI mode. Attempting to set "EDITOR emacs -nw" returns an error.
How can I get emacs to always launch in the terminal, even when running "sudo emacs"?
Last edited by Allamgir (2009-07-26 00:57:14)
дɭɭɑӎɠїɾ
Offline
Why not create an alias that consists of:
alias semacs='sudo emacs -nw'
Can't help with default editor problem.
Offline
pacman -Rcsn emacs && pacman -Sy vim
Joking aside, you can as a last resort create a script that would just run emacs -nw, then you can call that script every time...
Last edited by moljac024 (2009-07-25 18:39:17)
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...
Offline
I would suggest you the same thing Ashren did. About the EDITOR environment variable, try adding this to your bashrc
EDITOR="emacs -nw"
It may be the case that you want to run emacs in a terminal, but another one, not the one you're using. In this case, you can use (replace xterm with the terminal you use):
xterm -e emacs -nw
(lambda ())
Offline
Yeah, and after this setting, you can toogle the state of Options/Configuration/Other Options/Use internal editor/viewer box in Midnight Commander.
Offline
What I'm trying to do is make it so emacs is started when I choose to edit a file from midnight commander, and that emacs with the file is started in the same terminal window.
After putting EDITOR="emacs -nw" or even EDITOR="urxvtc -e emacs -nw", midnight commander just blinks when I try to edit a file (I set midnight commander to not use the internal editor).
Setting the editor to nano or vim works fine. I was considering just using vim for editing files from mc (usually config files), but I use emacs for things like LaTeX, and the switching of keybindings throws me off. Nano has kind of similar keybindings to emacs, but I'd really like to have the power of emacs (plus I have a few customizations in my .emacs).
Also, is there a way to create an alias for a two-word command? For example:
alias sudo emacs='sudo emacs -nw'
I know that doesn't work, but is there a way to get that desired results? semacs just seems a little weird for some reason.
Last edited by Allamgir (2009-07-25 20:03:30)
дɭɭɑӎɠїɾ
Offline
It's weird, I've tried with vim and it works for me, so the emacs can't... Why is emacs special in this handling, hm. it's a great work to solve
Offline
This is weird...
EDITOR=emacs mc # works
EDITOR="emacs -nw" mc # doesn't work
EDITOR="emacsclient" mc # works
EDITOR="emacsclient -c -a emacs" mc # doesn't work
From this, I guess that only one word EDITOR variables can be used with mc.
(lambda ())
Offline
Maybe emacs --daemon and then emacsclient -t will work better for you. This will only work with emacs 23.
I have the following in my .bashrc and it work with yaourt. I haven't tried with MC.
# set Emacsclient as yaourt's default editor
export EDITOR="emacsclient -t"
-Rasmus
Arch x64 on Thinkpad X200s/W530
Offline
Try the emacs-nox package
Offline
I think it's a bug in mc.
Some one who uses vim and has gvim installed could test it for me? Try running
EDITOR=gvim mc # this should work
and then
EDITOR="vim -g" # but this one shouldn't
I think it's a problem with how mc handles the EDITOR variable. You can see in "my_system" definition (utilsunix.c, line 128) that mc calls execl or execlp, but I the way it's calling it, it won't work if your EDITOR variable has more than one "word". I did this 3 little C program to test it:
#include <unistd.h>
int main(int argc, char *argv[])
{
execlp("sh", "sh", "emacs -nw", (char *)NULL);
return 0;
}
#include <unistd.h>
int main(int argc, char *argv[])
{
execl("sh", "sh", "-c", "emacs -nw", (char *)NULL);
return 0;
}
#include <unistd.h>
int main(int argc, char *argv[])
{
execlp("sh", "sh", "-c", "emacs -nw", (char *)NULL);
return 0;
}
The two first won't work (these are the two ways mcedit calls the EDITOR variable). The last one will work, it was just I test I did.
(lambda ())
Offline
Try the emacs-nox package
Yes! It works! Thank you!
The problem is that emacs defaults to its GUI mode and requires options to be run in the cli, unlike VIM which defaults to CLI. It must be a limitation of setting the EDITOR in .bashrc that options cannot be used (unless there's another way I'm not aware of), and even if it works, midnight commander gets confused because it's not a one word command.
Installing emacs-nox fixed it. Now running "emacs" runs the program in the cli.
дɭɭɑӎɠїɾ
Offline
But I think it still won't work if you need to pass some argument to call your editor, so I'm reporting a bug upstream.
(lambda ())
Offline
Ticket #1425 (closed defect: fixed)
External editor won't open if there are spaces in EDITOR variable
http://www.midnight-commander.org/ticket/1425
When version 4.7 is released, this shouldn't be a problem anymore.
(lambda ())
Offline
The problem is I can't run "sudo emacs" and get it to run in the terminal. I even edited the root user's .bashrc to have the same emacs='emacs -nw' alias. No luck.
I know you've found a solution to your problem; however, adding
alias sudo='sudo '
to your ~/.bashrc will allow expansion of aliases following sudo. (This is a feature of BASH: if an alias ends in a space, an alias following it in a command will also be expanded. I'm not certain, but I suppose that this only works for a single following alias.)
In other words, try this:
$ alias sudo='sudo '
$ alias emacs='emacs -nw'
Then, running sudo emacs will essentially run sudo emacs -nw.
Note: Credit for this information goes to one or more sources on these forums.
#!/vim/rocks
Offline
I bet this is actually a bug.
If you're using zsh, you can use global aliases and I guess it should work if you put it after sudo:
alias -g emacs='emacs -nw'
(lambda ())
Offline
Pages: 1