3

I used to run Emacs on Linux using Emacsclient, it is really easy and great experience:

emacs --daemon
emacsclient

When I work on a Windows machine, Emacs starts very slow. It seems there's no default support for emacsclient. So I decide to use the use-package package to reduce Emacs startup time. Since there're several packages, I'd like to know which cost the most startup time, and load it with use-package.

If I am not in the right direction, please correct me.

legends2k
  • 207
  • 3
  • 11
Nick
  • 4,423
  • 4
  • 24
  • 41
  • Which Windows package are you using? In the one I'm using there's a `emacsclient.exe`. – legends2k Jan 06 '15 at 10:06
  • @legends2k I'm using emacs form `Chocolatey`, a `apt-get` like package management tool for Windows. I use it to install many opensource or free software. There's a `emacsclient.exe` too. How do you use it? Emacs doesn't support `daemon` on Windows. – Nick Jan 06 '15 at 10:39
  • Related questions have already been discussed at length: [What can I do to speed up my start-up?](http://emacs.stackexchange.com/questions/2286/what-can-i-do-to-speed-up-my-start-up), [How can I troubleshoot a very slow Emacs?](http://emacs.stackexchange.com/questions/5359/how-can-i-troubleshoot-a-very-slow-emacs/5438#5438). – Dan Jan 06 '15 at 13:40

2 Answers2

5

Since you said you are already using use-package, you can turn on its own verbose option that reports how long each package takes to load.

Use customize-option use-package-verbose or put this in your init file:

(setq use-package-verbose t)

Then restart Emacs and check your *Messages* buffer. The output will look something like:

Loading package dash...done (0.015s)
Loading package ido...done (0.109s)
Loading package company...done (0.125s)
Loading package elisp-slime-nav...done (0.047s)
Loading package smart-mode-line...done (0.046s)

By default times are reported that are longer than 0.01 seconds. You can change this threshold too, see use-package-minimum-reported-time.

glucas
  • 20,175
  • 1
  • 51
  • 83
1

This is based on Emacs 24.4.1 (KAEL) on Windows 7 from the emacs-w64 project, but should work on other releases of the same major version. Add this to your .emacs:

(load "server")
(unless (server-running-p) (server-start))

which will run the server if it's not running; taken from here. If you're using cygwin/msys/msys2 then you could add this to your .bashrc:

edit_file() {
        emacsclient -nqa "runemacs.exe" $1 &
}

alias edit=edit_file

or do the equivalent in a batch script for cmd. Now all you've to do is

edit 1.txt   # will start the server, if it's not running
edit 2.txt   # will send a request to the server to open this file

The explanation part is that emacsclient would run runemacs.exe if a server is not running; -q would be to silence it's success message. -n is to not wait for server to return; if not for -n, you should clean up the buffer using server-edit and not the usual kill-buffer.

One additional point is that, if you want to use emacsclient.exe from GUI instead of CLI/TUI then use emacsclientw.exe.

legends2k
  • 207
  • 3
  • 11
  • Error: file name or argument required. (I downloaded Emacs-w64 from your list, the same error occured.) (Thank you.) – Nick Jan 06 '15 at 12:10
  • What shell did you try it on, bash or cmd? Also what command gave you that error? – legends2k Jan 06 '15 at 13:21
  • I run it with the native Windows `PowerShell`, and `bash`, both failed with the same error: `file name or argument required.` – Nick Jan 06 '15 at 13:23
  • Try this `emacsclient -nqa "runemacs.exe" &` on bash, is it working? – legends2k Jan 06 '15 at 13:25
  • This post does not answer OP's stated question about startup time. If the OP can post a separate question on emacsclient for Windows, this answer would make more sense there. – Dan Jan 06 '15 at 13:42
  • @Dan Perhaps, but start up is made faster by running Emacs as a server and calling subsequent edits from the client. This is one possible solution, no? – legends2k Jan 06 '15 at 13:51
  • Right, but OP seems to be aware of emacsclient conceptually (it's not clear if he found a way to get it on Windows). I'm not taking issue with the content of your answer; I'm merely pointing out that the answer is a mismatch for the question as currently stated (figure out what takes so long at startup). – Dan Jan 06 '15 at 13:58