I suspect that even for many hardcore emacs users it is something other than emacs
.
The $EDITOR environment variable determines which editor is run to change the contents of files by various unix commands1. Until a few weeks ago, my $EDITOR and $P4EDITOR variables were both set to vi. Why?
Starting my emacs takes a few seconds on a local server and up to a minute on a remote server (because of X). I could use emacsclient
which connects to an already running emacs. I would also have to change my work habits and access remote servers using tramp. Doing that would be inconvenient and a better solution for me is to start a stripped-down emacs-in-a-terminal.
The first thing to do is to set up a simple file which loads your basic configuration. I call this one basic-emacs.el.
basic-emacs.el
(add-to-list 'load-path (expand-file-name "~/emacs-files")) (require 'my-defaults) (require 'my-utils)
Then set your EDITOR variables in .bashrc
for example.
.bashrc
EDITOR='emacs -nw -q --load ~/emacs-files/basic-emacs.el' P4EDITOR=$EDITOR export EDITOR P4EDITOR
- The q flag prevents emacs from loading your .emacs
- The nw flag runs emacs in a terminal
1. e.g. crontab -e
Because I always have emacs running, my $EDITOR = emacsclient.
Yes, emacsclient. That is a very nice solution. I still think it would not work well for me as I often (unfortunately) have multiple emacs instances running using different perforce shadows.
Jared: If you have many Emacs open, just
M-x server-start
in the one you want “active” and open files via emacsclient with.
Hi Johan,
Unfortunately, all of them are active too, depending on which p4 client I’m using. Ideally I would prefer it just to be one session but I haven’t figured a way to do that. Maybe merging the p4 clients would be easier.
I also use something other than emacs as my $EDITOR, although I often choose jed/xjed instead of vi but have indeed been known to choose vi.
With respect to emacsclient, I find gnuclient/gnuserv much nicer although it doesn’t have the -a option which I do miss.
How did you know my $EDITOR was unset! 🙂
+1 for basic-emacs.el idea. Previously I was either:
1) defaulting to vi or nano
2) trying to install qemacs or other mini-sized emacs clones
3) using /sudo::root@localhost:/
when working with system files.
Also, the emacsclient and gnuclient ideas are great. I use the latter all the time in Windows for quickly editing the clipboard, raising the Frame, etc.
As an aside, perhaps you should explore the “auto-magic” directory ${HOME}/.emacs.d and startup file ${HOME}/.emacs.d/init.el, instead of your example directory or ${HOME}/.emacs.
Lastly, I am following your blog posts via Planet Emacsen and Google Reader, and each blog post has the same title “A Curious Programmer: Jared” instead of the blog post title like “Emacs users, what is your $EDITOR?” This might be a problem you have to correct on your side.
@éric – Hi, I hadn’t heard of gnuclient/gnuserv previously but the emacswiki says that as of Emacs 22.1 emacsclient has all of the same features. Why do you find gnuclient/gnuserv better?
@piyo – Hi Piyo. Thanks for your comment. I knew *your* $EDITOR wasn’t set!
When you’re talking about the “auto-magic” directory, .emacs.d, how is that better than ~/emacs-files? Is it because it reads .emacs.d/init.el?
And thanks for letting me know about the title problem. I’ll have a look to see if I can do something about that.
Cheers
I also tend to run one emacs per-project for my day to day editing.
However I also run one with “-server” which is used as a server for my
emacsclients which are called for editing text boxes or commit
messages. With emacs-23 and muti-tty it’s also very useful on my
mail server where I keep one running in a screen session and it can be
invoked in other terminals for editing mails.
> When you’re talking about the “auto-magic” directory, .emacs.d, how is that better than ~/emacs-files? Is it because it reads .emacs.d/init.el?
For your specific example, it makes no difference whether if it is in .emacs.d or emacs-files, since your settings force the reading of only basic-emacs.el. init.el will not be read, because of -q.
I suppose I was suggesting a tip for organizing your emacs files. If you’ve taken the leap from .emacs to .emacs.d/init.el (especially if you are using version-control), it should be easy just to stick basic-emacs.el in that same directory.
Also, regarding the comment about emacsclient vs gnuclient, I use gnuclient over emacsclient. With the following conditions of using Windows and starting emacsclientw with –alternate-editor switch, it launches a new emacs (because you specify emacs), however if I use that switch in collaboration with –eval, the parameter to be eval will be misinterpreted to be a filename. This works perfectly in gnuclient, so gnuclient FTW.
@Alex – Hi Alex, is this specifically with perforce? In which case how do you get the file to open in the emacs session with the appropriate client?
@Piyo – My regular .emacs is pretty empty is it just requires files in ~/emacs-files/ containing my customizations, similar to as described here. (I notice you left a comment saying you also do something similar). I keep the files under control using RCS which has been working well for me.
And thanks for the tip on gnuclient. Does this work on gnu emacs as well as xemacs?
@Jared
I think you misunderstand slight. The emacsclient sessions are just for ad-hoc edits and use the emacs server that is always running on my desktop. I’ve never used Perforce but I assume P4EDITOR is the editor run when doing a commit message.
I then open a number of separate emacs processes for each project I’m actively working on. I mainly do this as each project typically has it’s own make invocation.
The one downside is that an emacsclient sessions don’t have access to the buffers in the other emacsen which you may want if you want to include comments from code your editing. But maybe you want to commit into Perforce from vc-mode?
@Alex
Ah, that makes more sense now, thanks.
The stripped down emacs has the same problem you describe – it can’t access the other buffers either. The perforce emacs module I’m using can only submit all of the files in a directory at the same time which isn’t normally the way I like to work.
I used to use multiple emacs sessions simultaneously too but I always got confused about which one I was using to work on which project (I always open and close loads of new frames with C-x 5). However, I have a solution to the different make invocation problem which I’ll probably write about next time.
[…] 13, 2009 by Jared Alex Bennee left a comment on my dollar editor post: I then open a number of separate emacs processes for each project I’m actively […]
On my development systems I use emacsclient, because emacs is always running.
On other systems, especially servers, I use zile. It’s small, fast, and most importantly it’s in the debian/ubuntu repos.
Zile isn’t installed on the servers I work on (and no, I can’t install it, even in $HOME), but yes, that looks like a nice alternative to my stripped down emacs if it is available.
I have EDITOR set to vim. emacsclient isn’t really a solution for me since I’m often on remote machines via ssh editing config files (yes, I know about tramp). Also, I like vim better for editing config files because it knows about the syntax of the configuration files for many services I use (like postfix or openssh) and thus helps me avoid silly spelling mistakes in their configuration files. Plus, I think it helps train my brain to switch between the two extremely different editing philosophies all the time. 🙂
Hi afoo. You say you know about tramp… what is the problem with it if you prefer using vim over ssh?
And surely there can’t be any widely used configuration file that doesn’t have an emacs mode… 😉
[…] initialization. Hence it could be safely set as the $EDITOR on Mac or Linux (See Jared’s post What is your $EDITOR?). The same is true with emacs 23 running in –daemon mode, and now we have the added flexibility to […]
Liked this setup for opening “emacs -nw” within ipython shell using %edit