Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Emacs start-up faster?

I use Emacs v. 22 (the console version, either remotely with PuTTY or locally with Konsole) as my primary text editor on Linux. It takes a while to load up each time I start it though, probably almost a second, although I never timed it. I tend to open and close Emacs a lot, because I'm more comfortable using the Bash command-line for file/directory manipulation and compiling.

How can I speed up the start-up time?

like image 576
Paul Avatar asked Apr 22 '09 19:04

Paul


People also ask

How do I use Emacs daemon?

One easy way to start the Emacs daemon is via “Settings > Session and Startup > Application Autostart”. You can also place an init script to place in /etc/init. d/emacsd.

What is Emacs client?

EmacsClient allows one to open a file for editing in an already running Emacs. Because it doesn't start a new Emacs instance at each invocation, you can set up EmacsClient as the default editor, e.g. in the environment variable EDITOR or VISUAL.


2 Answers

Others have covered using gnuserve and emacsclient, and I'd suggest compiling within emacs (being able to jump to compilation errors is a win).

But, specifically speeding up the .emacs can be done by:

  1. Byte compiling the .emacs file, which you can do automatically by using this snippet of code

  2. Replacing as many of the (require 'package) statements with autoloaded functionality. This will delay loading of lisp until it's actually required. Using this technique allowed me to speed up my startup from >6 seconds to <1. This takes a little bit of work because not all libraries come properly marked autoload.

  3. Removing code/functionality you no longer use.

  4. Try running emacs with the option --no-site-file to avoid loading unnecessary packages in the site installation site-start.el.

  5. If you are really serious, you can roll your own emacs with your favorite functionality already loaded. This, of course, means it's more involved to make changes to what you have in your .emacs because it's a part of the binary. Follow the link for information on how to use dump-emacs.

  6. Buy a faster computer and/or faster disk.

How to determine what your .emacs loads

Now, how do you find out what your .emacs loads? With the goal to remove the functionality, or to delay it? Check your *Messages* buffer, which contains lines like:

 Loading /home/tjackson/.emacs.tjackson.el (source)... Loading /home/tjackson/installed/emacs/lisp/loaddefs.el (source)...done Loading /user/tjackson/.elisp/source/loaddefs.el (source)...done Loading autorevert...done Loading /home/tjackson/.emacs.tjackson.el (source)...done 

If you'll notice, the Loading statements can nest: the first .emacs.tjackson.el ends with ... and the last line shows the .emacs.tjackson.el load is ...done. All those other files are loaded from inside my .emacs.tjackson.el file. All the other loads are atomic.

Note: If you have a large .emacs, it's possible that the *Messages* buffer will lose some of the messages because it only keeps a fixed amount of information. You can add this setting early on to your .emacs to keep all the messages around:

(setq message-log-max t) 

Note: It the 'load command will suppress the messages if its fourth argument nomessage is non-nil, so remove any such invocations (or, advise 'load and force the fourth argument to be nil).

like image 63
Trey Jackson Avatar answered Oct 06 '22 01:10

Trey Jackson


In addition to Adam Rosenfield's solution, I recommend to use Emacs in server mode. You may add (server-start) to your dotemacs, and run emacsclient instead of emacs whenever you want to open file in Emacs. That way you have to pay the loading cost of Emacs only once, after then clients pop up immediately.

Edit

You're right, v22 does not create a new frame. Create a shell script that do the trick:

#!/bin/bash # Argument: filename to open in new Emacs frame /usr/bin/emacsclient -e '(let ((default-directory "`pwd`/")) (select-frame (make-frame)) (find-file "'$1'"))' 

Edit 2

In v24+, you can do emacsclient -c to create a new frame.

like image 42
viam0Zah Avatar answered Oct 06 '22 00:10

viam0Zah