Fast emacs?

78 views
Skip to first unread message

kj

unread,
May 17, 2009, 5:05:57 PM5/17/09
to


For ***years*** I've been looking for a solution to this problem,
and I'm truly amazed that I have yet to find it: how to get a
fast-starting version of emacs. The problem is that I have a big
.emacs file and a big Emacs desktop, which means that my Emacs takes
forever to start. This is fine most of the time, but occasionally
I want a fast-starting emacs session (e.g. when I run "sudo emacs"
to edit a superuser-owned config file), and it's infuriating to
wait for emacs to go through a lengthy and useless song-and-dance...

I just can't believe there is no way around this. (Other than, of
course, using vi.)

Note that using the emacsclient is no solution, because this requires
that a version of Emacs be already running, which often defeats
the purpose (not only do I have to wait another eternity for this
new Emacs session to start, but then I have to start the server in
the new session).

Any words of wisdom would be much appreciated!

TIA!

Kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.

Anselm Helbig

unread,
May 17, 2009, 5:39:30 PM5/17/09
to
Hi!

> For ***years*** I've been looking for a solution to this problem,
> and I'm truly amazed that I have yet to find it: how to get a
> fast-starting version of emacs. The problem is that I have a big
> .emacs file and a big Emacs desktop, which means that my Emacs takes
> forever to start. This is fine most of the time, but occasionally
> I want a fast-starting emacs session (e.g. when I run "sudo emacs"
> to edit a superuser-owned config file), and it's infuriating to
> wait for emacs to go through a lengthy and useless song-and-dance...
>
> I just can't believe there is no way around this. (Other than, of
> course, using vi.)
>
> Note that using the emacsclient is no solution, because this requires
> that a version of Emacs be already running, which often defeats
> the purpose (not only do I have to wait another eternity for this
> new Emacs session to start, but then I have to start the server in
> the new session).
>
> Any words of wisdom would be much appreciated!

Emacs has tons of functionality baked in right from the start, yet its
startup time is reasonably fast if you don't have customizations. So,
learning from core emacs means learning how to start up fast. There
are lots of possible improvements you can make:

- don't use `require', use autoloads:
http://www.emacswiki.org/emacs/AutoLoad
Magic comments can help, see (info "(elisp) Autoload")
Use `update-autoloads-from-directories' to automatically generate
the autoloads for you.

- for stuff that can only be configured once a library is loaded, use
`eval-after-load'.

- make a new emacs image with all your favourite libraries already
loaded: http://www.emacswiki.org/emacs/DumpingEmacs

- start emacs as part of system startup with the --daemon switch:
http://www.emacswiki.org/emacs/EmacsAsDaemon

- byte-compile the libraries you use; consider byte-compiling your
.emacs if it is huge

- remove extensions you don't use

- measure the progress you make: use the lisp function benchmark-run,
or `time' on the command line. Try adding (kill-emacs) at the end
of your .emacs file to get meaningful results for this.

My init file has 1677 lines, emacs starts in 2.3 seconds (hot
cache). Hmmm... this could be improved. 8-)

Happy tuning!

Anselm


--
Anselm Helbig
mailto:anselm.helb...@googlemail.com

Michael Ekstrand

unread,
May 17, 2009, 6:12:03 PM5/17/09
to
kj <so...@987jk.com.invalid> writes:
> For ***years*** I've been looking for a solution to this problem,
> and I'm truly amazed that I have yet to find it: how to get a
> fast-starting version of emacs. The problem is that I have a big
> .emacs file and a big Emacs desktop, which means that my Emacs takes
> forever to start. This is fine most of the time, but occasionally
> I want a fast-starting emacs session (e.g. when I run "sudo emacs"
> to edit a superuser-owned config file), and it's infuriating to
> wait for emacs to go through a lengthy and useless song-and-dance...
>
> I just can't believe there is no way around this. (Other than, of
> course, using vi.)

I frequently use Zile in that context. Bare-bones editor with Emacs
keybindings. Great for the odd config file edit from a terminal.

- Michael

--
mouse, n: A device for pointing at the xterm in which you want to type.

Jason Rumney

unread,
May 17, 2009, 8:16:46 PM5/17/09
to
On May 18, 5:05 am, kj <so...@987jk.com.invalid> wrote:
>  The problem is that I have a big
> .emacs file and a big Emacs desktop, which means that my Emacs takes
> forever to start.  This is fine most of the time, but occasionally
> I want a fast-starting emacs session (e.g. when I run "sudo emacs"
> to edit a superuser-owned config file), and it's infuriating to
> wait for emacs to go through a lengthy and useless song-and-dance...

emacs -Q

Giorgos Keramidas

unread,
May 17, 2009, 9:13:27 PM5/17/09
to
On Sun, 17 May 2009 23:39:30 +0200, Anselm Helbig <anselm.helb...@googlemail.com> wrote:
>> Note that using the emacsclient is no solution, because this requires
>> that a version of Emacs be already running, which often defeats
>> the purpose (not only do I have to wait another eternity for this
>> new Emacs session to start, but then I have to start the server in
>> the new session).
>>
>> Any words of wisdom would be much appreciated!

> - don't use `require', use autoloads:
> http://www.emacswiki.org/emacs/AutoLoad

> - for stuff that can only be configured once a library is loaded, use
> `eval-after-load'.

> - make a new emacs image with all your favourite libraries already
> loaded: http://www.emacswiki.org/emacs/DumpingEmacs

> - start emacs as part of system startup with the --daemon switch:
> http://www.emacswiki.org/emacs/EmacsAsDaemon

> - byte-compile the libraries you use; consider byte-compiling your
> .emacs if it is huge

> - remove extensions you don't use

> - measure the progress you make: use the lisp function benchmark-run,
> or `time' on the command line. Try adding (kill-emacs) at the end
> of your .emacs file to get meaningful results for this.

All good points :)

I use all of (1) autoloading, (2) --daemon mode for most of my quick
editing sessions, (3) I keep trimming my configuration from stuff I have
not used for months, and (4) fire up 1-2 different instances besides the
background daemon process: one for Gnus-only stuff, and maybe another
one for IRC windows.

Another neat thing to do is install a light-weight clone like `mg' and
use that for very basic editing. I even went so far as to import mg in
my own copy of the FreeBSD src/ tree and attach it to the normal build
process, so my laptop's custom FreeBSD version now includes:

$ which mg
/usr/bin/mg

This way even when my full Emacs installation is not available (i.e. in
single user mode) I can use a lean and fast editor with very familiar
key bindings.

There are packages for `mg' and other mini clones of Emacs in the
package collection of most UNIX-like systems today, so installing one of
them is another thing that may be useful to consider.

kj

unread,
May 17, 2009, 10:51:24 PM5/17/09
to
In <7a909198-c1e9-4ac1...@u9g2000pre.googlegroups.com> Jason Rumney <jason...@gmail.com> writes:

>On May 18, 5:05=A0am, kj <so...@987jk.com.invalid> wrote:
>> =A0The problem is that I have a big


>> .emacs file and a big Emacs desktop, which means that my Emacs takes

>> forever to start. =A0This is fine most of the time, but occasionally


>> I want a fast-starting emacs session (e.g. when I run "sudo emacs"
>> to edit a superuser-owned config file), and it's infuriating to
>> wait for emacs to go through a lengthy and useless song-and-dance...

>emacs -Q

I've gotten some very useful ideas in this thread (thanks Anselm,
Michael, and Giorgios), but this one actually blew me away. In
all my years using emacs (decades really) I never knew of this
command-line switch. In fact, after rummaging through the man page
and the emacs docs, I was not able to find it. But it works like
gangbusters. Thanks!

kynn

B. T. Raven

unread,
May 17, 2009, 11:38:50 PM5/17/09
to
kj wrote:
> In <7a909198-c1e9-4ac1...@u9g2000pre.googlegroups.com> Jason Rumney <jason...@gmail.com> writes:
>
>> On May 18, 5:05=A0am, kj <so...@987jk.com.invalid> wrote:
>>> =A0The problem is that I have a big
>>> .emacs file and a big Emacs desktop, which means that my Emacs takes
>>> forever to start. =A0This is fine most of the time, but occasionally
>>> I want a fast-starting emacs session (e.g. when I run "sudo emacs"
>>> to edit a superuser-owned config file), and it's infuriating to
>>> wait for emacs to go through a lengthy and useless song-and-dance...
>
>> emacs -Q
>
> I've gotten some very useful ideas in this thread (thanks Anselm,
> Michael, and Giorgios), but this one actually blew me away. In
> all my years using emacs (decades really) I never knew of this
> command-line switch. In fact, after rummaging through the man page
> and the emacs docs, I was not able to find it. But it works like
> gangbusters. Thanks!
>
> kynn

Just like the spaghetti sauce "it's in theya":

C-h r m intial options

Dirk-Jan C. Binnema

unread,
May 18, 2009, 1:43:53 AM5/18/09
to help-gn...@gnu.org

> > Note that using the emacsclient is no solution, because this requires
> > that a version of Emacs be already running, which often defeats
> > the purpose (not only do I have to wait another eternity for this
> > new Emacs session to start, but then I have to start the server in
> > the new session).

Well, maybe you'd need to take another look at emacs --daemon ;-) I have
run it when my (X) *session* starts (no need for tricks to put it in
system startup scripts). Emacs starts within a cpl of seconds (1000 line
.emacs).

Then for the rest of the day I use emacsclient -c; lightning fast.

With emacs --daemon all the trimming, autoloading etc becomes much less
important.

Best wishes,
Dirk.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C


Tim X

unread,
May 18, 2009, 4:15:16 AM5/18/09
to
"Dirk-Jan C. Binnema" <djcb...@gmail.com> writes:

>> > Note that using the emacsclient is no solution, because this requires
>> > that a version of Emacs be already running, which often defeats
>> > the purpose (not only do I have to wait another eternity for this
>> > new Emacs session to start, but then I have to start the server in
>> > the new session).
>
> Well, maybe you'd need to take another look at emacs --daemon ;-) I have
> run it when my (X) *session* starts (no need for tricks to put it in
> system startup scripts). Emacs starts within a cpl of seconds (1000 line
> .emacs).
>
> Then for the rest of the day I use emacsclient -c; lightning fast.
>
> With emacs --daemon all the trimming, autoloading etc becomes much less
> important.
>
> Best wishes,
> Dirk.

Emacs daemon mode is great, but only available with emacs 23.

However, another point I wanted to mention. There is no need to do sudo
emacs to edit a file as root. You can do this from within your normal
running emacs using tramp. 'su' will work too.

Tim


--
tcross (at) rapttech dot com dot au

Jean Magnan de Bornier

unread,
May 18, 2009, 4:54:13 AM5/18/09
to
"Dirk-Jan C. Binnema" <djcb...@gmail.com> wrote :

| > > Note that using the emacsclient is no solution, because this requires
| > > that a version of Emacs be already running, which often defeats
| > > the purpose (not only do I have to wait another eternity for this
| > > new Emacs session to start, but then I have to start the server in
| > > the new session).
>
| Well, maybe you'd need to take another look at emacs --daemon ;-) I have
| run it when my (X) *session* starts (no need for tricks to put it in
| system startup scripts). Emacs starts within a cpl of seconds (1000 line
| .emacs).
>
| Then for the rest of the day I use emacsclient -c; lightning fast.
>
| With emacs --daemon all the trimming, autoloading etc becomes much less
| important.

Hi,
I just tried that Dirk, it seems emacsclient doesn't read my .Xresources
files then; is this expected?

tia,
--
Jean

Bernardo

unread,
May 18, 2009, 7:03:09 AM5/18/09
to emacs help
> Hi!
>
>> For ***years*** I've been looking for a solution to this problem,
>> and I'm truly amazed that I have yet to find it: how to get a
>> fast-starting version of emacs. The problem is that I have a big
>> .emacs file and a big Emacs desktop, which means that my Emacs takes
>> forever to start. This is fine most of the time, but occasionally
>> I want a fast-starting emacs session (e.g. when I run "sudo emacs"
>> to edit a superuser-owned config file), and it's infuriating to
>> wait for emacs to go through a lengthy and useless song-and-dance...
>>
>> I just can't believe there is no way around this. (Other than, of
>> course, using vi.)
>>
>> Note that using the emacsclient is no solution, because this requires
>> that a version of Emacs be already running, which often defeats
>> the purpose (not only do I have to wait another eternity for this
>> new Emacs session to start, but then I have to start the server in
>> the new session).
>>
>> Any words of wisdom would be much appreciated!

this one is pretty good cure for a fat desktop file

,----[ C-h v desktop-restore-eager ]
| desktop-restore-eager is a variable defined in `desktop.el'.
| Its value is 5
|
| Documentation:
| Number of buffers to restore immediately.
| Remaining buffers are restored lazily (when Emacs is idle).
| If value is t, all buffers are restored immediately.
|
| You can customize this variable.
|
| This variable was introduced, or its default value was changed, in
| version 22.1 of Emacs.
`----

ken

unread,
May 18, 2009, 7:29:33 AM5/18/09
to emacs help

>>> For ***years*** I've been looking for a solution to this problem,
>>> and I'm truly amazed that I have yet to find it: how to get a
>>> fast-starting version of emacs. The problem is that I have a big
>>> .emacs file and a big Emacs desktop, which means that my Emacs takes
>>> forever to start. This is fine most of the time, but occasionally
>>> I want a fast-starting emacs session (e.g. when I run "sudo emacs"
>>> to edit a superuser-owned config file), and it's infuriating to
>>> wait for emacs to go through a lengthy and useless song-and-dance...
>>>
>>> ....

It should speed things up quite a bit to byte compile a major part of
your ~/.emacs as another file which is then loaded on start-up.


Drew Adams

unread,
May 18, 2009, 2:05:02 PM5/18/09
to kj, help-gn...@gnu.org
> >emacs -Q

>
> In all my years using emacs (decades really) I never knew of this
> command-line switch. In fact, after rummaging through the man page
> and the emacs docs, I was not able to find it.

In releases of Emacs prior to 22, you can use `emacs -q --no-site-file'. It does
the same thing as does `emacs -Q' in Emacs 22 and later.

Jean Magnan de Bornier

unread,
May 20, 2009, 6:04:42 AM5/20/09
to
"Dirk-Jan C. Binnema" <djcb...@gmail.com> wrote :

| > > Note that using the emacsclient is no solution, because this requires


| > > that a version of Emacs be already running, which often defeats
| > > the purpose (not only do I have to wait another eternity for this
| > > new Emacs session to start, but then I have to start the server in
| > > the new session).
>
| Well, maybe you'd need to take another look at emacs --daemon ;-) I have
| run it when my (X) *session* starts (no need for tricks to put it in
| system startup scripts). Emacs starts within a cpl of seconds (1000 line
| .emacs).
>
| Then for the rest of the day I use emacsclient -c; lightning fast.
>
| With emacs --daemon all the trimming, autoloading etc becomes much less
| important.

Hi all,

emacs --daemon is really great!

However I wonder what's the best place to write the command; I'm running a
linux box with xorg started by "startx".
A first try was to write "emacs --daemon" in ~/.xsession, but then if I
leave my x session and enter another one, it aks a new emacs start and
that causes trouble.
I have then written "emacs --daemon" in my ~/.zshenv, and it starts all
right, but then opening a zsh shell also make it attempt to start the
daemon again!

I probably miss something very straightforward!

Thanks for any help,
--
Jean

Jean Magnan de Bornier

unread,
May 20, 2009, 9:24:41 AM5/20/09
to
Jean Magnan de Bornier <je...@bornier.net> wrote :

| However I wonder what's the best place to write the command; I'm running a
| linux box with xorg started by "startx".
| A first try was to write "emacs --daemon" in ~/.xsession, but then if I
| leave my x session and enter another one, it aks a new emacs start and
| that causes trouble.
| I have then written "emacs --daemon" in my ~/.zshenv, and it starts all
| right, but then opening a zsh shell also make it attempt to start the
| daemon again!

Well I ended writing a zsh script (lauched in .xsession) to check if an
emacs server is running, and lauching the server only if there isn't any.
bye,
--
Jean

thierry....@gmail.com

unread,
May 20, 2009, 12:54:22 PM5/20/09
to help-gn...@gnu.org
Hi,

If you use gentoo,
you will find a gentoo package called emacs-daemon.
It start emacs --daemon as a service.
Even if you don't use gentoo, it should be easy to make it working in
another linux.
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France

Jean Magnan de Bornier

unread,
May 21, 2009, 2:20:39 AM5/21/09
to
thierry....@gmail.com wrote :

| If you use gentoo,
| you will find a gentoo package called emacs-daemon.
| It start emacs --daemon as a service.
| Even if you don't use gentoo, it should be easy to make it working in
| another linux.

No, I am not (anymore) a gentoo user.
When using a system-wide emacs daemon, I imagine that all user
customizations are only loaded with emacsclient, while if started as a
user emacs daemon loads the config.
So I still wonder what is the best way (I'm the only user).

Cheers,
--
Jean (near Aix-en-Provence :-) )

Pascal J. Bourguignon

unread,
May 21, 2009, 5:49:22 AM5/21/09
to
Jean Magnan de Bornier <je...@bornier.net> writes:

I just launch emacs interactively once, and then on use emacsclient
(or just open from one of the emacs frames).


Of notable interest, when I change of workstation but still want to go
on working in the same emacs session, is:

laptop$ xhost +maincomputer
laptop$ ssh -X myself@maincomputer
maincomputer$ emacsclient --eval "(make-frame-on-display \"$DISPLAY\")"

which will open a frame on the X server in laptop from the emacs
running on maincomputer.


Since I don't log-out every day, I get usually emacs uptimes as long
as the computer uptimes (ie _months_). It wouldn't matter if my
.emacs needed five minutes to load...

--
__Pascal Bourguignon__

Christian Herenz

unread,
May 21, 2009, 6:04:52 AM5/21/09
to
kj schrieb:

>(e.g. when I run "sudo emacs"
> to edit a superuser-owned config file)

hm... this can be done with tramp mode, right?

greets,
Christian

Hugo Heden

unread,
May 21, 2009, 6:13:43 AM5/21/09
to Jean Magnan de Bornier, help-gn...@gnu.org
On Wed, May 20, 2009 at 3:24 PM, Jean Magnan de Bornier <je...@bornier.net> wrote:
Jean Magnan de Bornier <je...@bornier.net> wrote :

 [snip]
 

Well I ended writing a zsh script (lauched in .xsession) to check if an
emacs server is running, and lauching the server only if there isn't any.
bye,
--

I do something similar (but using bash). I have a script that is *not* intended to be launched in some init-file. Instead, the user invokes the script when he wants to use emacs. The script starts the emacs-daemon if not already started, and then invokes the client.

I am not completely sure it covers all your requirements, but it works very well for me.

See http://hugoheden.wordpress.com/2009/03/21/invoking-emacs-daemon-and-client-easily/

 

Jean

Lennart Borgman

unread,
May 21, 2009, 6:29:12 AM5/21/09
to Hugo Heden, help-gn...@gnu.org, Jean Magnan de Bornier
On Thu, May 21, 2009 at 12:13 PM, Hugo Heden <hugo...@gmail.com> wrote:
> On Wed, May 20, 2009 at 3:24 PM, Jean Magnan de Bornier <je...@bornier.net>

> wrote:
>>
>> Jean Magnan de Bornier <je...@bornier.net> wrote :
>
>  [snip]

>
>>
>> Well I ended writing a zsh script (lauched in .xsession) to check if an
>> emacs server is running, and lauching the server only if there isn't any.
>> bye,
>> --
>
> I do something similar (but using bash). I have a script that is *not*
> intended to be launched in some init-file. Instead, the user invokes the
> script when he wants to use emacs. The script starts the emacs-daemon if not
> already started, and then invokes the client.

For that purpose you may also instead patch emacsclient. I have done
that in EmacsW32. Those patches are written to work on all platforms
(but I have no idea if they do at the moment).


thierry....@gmail.com

unread,
May 21, 2009, 11:08:52 AM5/21/09
to help-gn...@gnu.org
Jean Magnan de Bornier <je...@bornier.net> writes:

> thierry....@gmail.com wrote :
>
> | If you use gentoo,
> | you will find a gentoo package called emacs-daemon.
> | It start emacs --daemon as a service.
> | Even if you don't use gentoo, it should be easy to make it working in
> | another linux.
>
> No, I am not (anymore) a gentoo user.
> When using a system-wide emacs daemon, I imagine that all user
> customizations are only loaded with emacsclient, while if started as a
> user emacs daemon loads the config.

No you use a symlink for each user and each user will have his own init
file (.emacs) loaded.
The daemon in /etc/init.d is called emacs but the one i start is a
symlink of emacs called emacs.thierry that use the .emacs of user
thierry.

> So I still wonder what is the best way (I'm the only user).
>
> Cheers,

--

David Kastrup

unread,
Aug 2, 2009, 11:28:16 AM8/2/09
to
kj <so...@987jk.com.invalid> writes:

> For ***years*** I've been looking for a solution to this problem,
> and I'm truly amazed that I have yet to find it: how to get a
> fast-starting version of emacs. The problem is that I have a big
> .emacs file and a big Emacs desktop, which means that my Emacs takes
> forever to start. This is fine most of the time, but occasionally
> I want a fast-starting emacs session (e.g. when I run "sudo emacs"
> to edit a superuser-owned config file),

C-x C-f /sudo::/etc/fstab RET

--
David Kastrup

Richard Riley

unread,
Aug 2, 2009, 4:34:45 PM8/2/09
to
David Kastrup <d...@gnu.org> writes:

I use this which is great. Open the file in normal mode, and then C-x
C-r to switch to root privs.

,----
| (defun find-alternative-file-with-sudo ()
| "Open current buffer as root!"
| (interactive)
| (when buffer-file-name
| (find-alternate-file
| (concat "/sudo:root@localhost:"
| buffer-file-name))))
|
| (global-set-key (kbd "C-x C-r") 'find-alternative-file-with-sudo)
`----

Cecil Westerhof

unread,
Oct 13, 2009, 4:50:45 AM10/13/09
to

Nice one. Only the first time I use it, it take some time. When I do it
a second time, it is quit fast.

Teemu Likonen

unread,
Oct 13, 2009, 9:17:45 AM10/13/09
to
On 2009-10-13 10:50 (+0200), Cecil Westerhof wrote:

> David Kastrup <d...@gnu.org> writes:
>> C-x C-f /sudo::/etc/fstab RET
>
> Nice one. Only the first time I use it, it take some time. When I do
> it a second time, it is quit fast.

With Emacs 22 it's slow first time. Fortunately with Emacs 23 /sudo: and
/su: are always fast.

Cecil Westerhof

unread,
Oct 16, 2009, 6:28:00 AM10/16/09
to
Teemu Likonen <tlik...@iki.fi> writes:
>>> C-x C-f /sudo::/etc/fstab RET
>>
>> Nice one. Only the first time I use it, it take some time. When I do
>> it a second time, it is quit fast.
>
> With Emacs 22 it's slow first time. Fortunately with Emacs 23 /sudo: and
> /su: are always fast.

That explains it. The system I tried it on was still running 22.3.1. I
tried it on another system with 23 and there was no delay.

Reply all
Reply to author
Forward
0 new messages