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?
-
Check your
.emacsfile to see if you're loading unnecessary packages. Loading packages can take a significant amount of time. For example, you might only want to load thephp-modepackage if you're editing a PHP file. You can do that by installing a hook procedure, although I'm not certain of the details.Also make sure that any packages you're loading are compiled (
.elcfiles). You can compile anelispfile by runningemacs -batch -f batch-byte-compile thefile.elCompiled packages load much faster than uncompiled packages.
-
This doesn't answer the question, but is kind of relevant
I don't know how to make it start faster, but there are a few things I could suggest:
for most things you do on the command line, you can do them in emacs:
- compile: M-x compile, then type the command you use
- my experience is only with C++, but with g++ you can press C-x ` to jump to lines that the compiler complains about
- run shell commands: M-!, dumps output into a buffer
- interactive shell: M-x shell
alternatively, you could run emacs like this:
emacs file.ext &- which opens emacs in the background so you can still use the shell ( this works best with putty and X forwarding with something like Xming)
-
Don't close Emacs every time you want to use the shell. Use Ctrl-Z to move Emacs to the background and the
fgcommand in Bash to move it back to the foreground. -
"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."
You're describing the way an editor like vim is used like. Shoot in&out. Emacs is usually kept open, and mostly all is done from "within it". hiena already answered what would be the correct approach here.
Damien Pollet : Instead of quitting emacs, you could just suspend it, with C-z, then wake it back with fg…ldigas : @Damien Pollet - (confused), ... uhmm, yes, I'm aware of that. I didn't feel repeating what's already been said, so I just pointed to hiena's post. -
In addition to Adam Rosenfield's solution, I recommend to use Emacs in server mode. You may add
(server-start)to your dotemacs, and runemacsclientinstead ofemacswhenever 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'"))'Colin : I'm struggling with this solution - I have the server started up, but I can't seem to get emacsclient to start a new frame. Apparently my version of emacs doesn't support the "-c" or "-t" options. Any suggestions?Török Gábor : Yes, `-c` and `-t` only works in Emacs 23. I extended my answer with a workaround for you.Gregory : emacs --daemon is only supported in v23 and beyond. Plus it doesn't start correctly if it finds errors with your ~/.emacs which it may find when you move to this new version for the first time :) -
I would have to check my customization, but there is a package called gnuserve or emacsclient. It migrates a lot so you will have to google for it.
It runs one emacs session in the background. Any further sessions of emacs are essentially just new frames of that session. One advatage is quick startup times for your later sessions.
-
Emacs is designed to run "all the time" (or at least for long periods of time), thus starting and stopping Emacs several times during a day is not recommended.
I would suggest using screen. Screen is a terminal multiplexer, giving you an unlimited virtual terminals in one terminal.
After installing simply write "screen emacs" in your terminal. Emacs will start as usual, but pressing "c-a c" (that is press ctrl-a and then c) will open a new virtual terminal. You can get back to emacs by pressing "c-a c-a" (that's two times ctrl-a).
You can even detach from the running screen session, the key sequence is "c-a d".
Re-attach to the session by issuing "screen -R" and you will be back where you left. This enables you to start an emacs session at work, detach, go home, and re-attach from home.
I've been running Emacs like this for months in a row.
Here's the official web site: http://www.gnu.org/software/screen/ but try googling for screen tutorials and howtos
-
Others have covered using
gnuserveandemacsclient, 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:
Byte compiling the .emacs file, which you can do automatically by using this snippet of code
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 markedautoload.Removing code/functionality you no longer use.
Try running emacs with the option
--no-site-fileto avoid loading unnecessary packages in the site installationsite-start.el.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
.emacsbecause it's a part of the binary. Follow the link for information on how to usedump-emacs.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
Loadingstatements can nest: the first.emacs.tjackson.elends with...and the last line shows the.emacs.tjackson.elload is...done. All those other files are loaded from inside my.emacs.tjackson.elfile. 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.emacsto keep all the messages around:(setq message-log-max t)Note: It the
'loadcommand will suppress the messages if its fourth argumentnomessageis non-nil, so remove any such invocations (or, advise'loadand force the fourth argument to benil). -
One of
M-x shell M-x eshell M-x term M-x ansi-termshould meet your command-line needs from within Emacs.
You can also use
M-!(akaM-x shell-command) to execute a one-liner without dropping to the shell. -
A couple of tips:
Use autoloads
Using autoload saves you from loading libraries until you use them. For example:
(if (locate-library "ediff-trees") (autoload 'ediff-trees "ediff-trees" "Start an tree ediff" t))Compile your .emacs
Gives you a slight speed increase although there are pitfalls if you work with version control and your .emacs is newer than .emacs.elc. One common trick is:
(defun autocompile nil "compile itself if ~/.emacs" (interactive) (require 'bytecomp) (let ((dotemacs (expand-file-name "~/.emacs"))) (if (string= (buffer-file-name) (file-chase-links dotemacs)) (byte-compile-file dotemacs)))) (add-hook 'after-save-hook 'autocompile)Learn to love emacs server.
Running emacs as a server means never having to close it down. However I note your still using emacs22. emacs23 supports multi-tty which makes it a lot easier to run emacs in one screen session and then bring up new windows in another terminal. I use emacs to edit mail for my mail client (mutt) and emacsclient is fantastic for these sort of quick edits.
stsquad : That odd numbering is due to Stackoverflow and not the actual text. How very odd.Jouni K. Seppänen : It's a Markdown feature: you need to indent paragraphs within list items, otherwise it thinks each numbered line is its own ordered list and helpfully renumbers it starting from 1. I fixed your formatting. -
One thing that others haven't mentioned is to include the elisp libraries you use as part of the dumped Emacs to move the library loading time from Emacs startup to Emacs build. It is not for the faint-hearted, but if you load several libraries in
.emacsit could win you a few seconds of startup time. -
One thing that helped me reduce the load time of my
.emacs, in addition toautoload(as others have suggested), is eval-after-load. In the following example, delaying the call tosql-set-productsaves you from having to loadsqlin your.emacs, making the exisitingsqlautoloads more effective.(eval-after-load "sql" '(progn (sql-set-product 'mysql) (setq sql-mysql-options '("-C" "-t" "-f" "-n")) (setq sql-sqlite-program "sqlite3") ))Of course, for some packages there will be a hook available that you can do the same thing, but sometimes there isn't, or else this way just proves easier to think about.
-
+1 for all of the people who said some combination of "run emacs once on bootup and then just use server, or create more windows."
Alternatively: ed is the standard unix editor! ed is fast, small, and weeds out the weenies!
sorry.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.