如何让Emacs更快启动?

时间:2022-01-09 20:47:05

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.

我使用Emacs v.22(控制台版本,远程使用PuTTY或本地使用Konsole)作为Linux上的主要文本编辑器。每次启动它都需要一段时间才能加载,可能差不多一秒钟,尽管我从来没有计时。我倾向于打开和关闭Emacs很多,因为我更习惯使用Bash命令行进行文件/目录操作和编译。

How can I speed up the start-up time?

如何加快启动时间?

17 个解决方案

#1


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.

除了Adam Rosenfield的解决方案,我建议在服务器模式下使用Emacs。你可以添加(server-start)到你的dotemacs,并在你想在Emacs中打开文件时运行emacsclient而不是emacs。这样,您只需支付一次Emacs的装载成本,然后客户端立即弹出。

Edit

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

你是对的,v22不会创建一个新的框架。创建一个执行技巧的shell脚本:

#!/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'"))'

#2


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

其他人已经介绍过使用gnuserve和emacsclient,我建议在emacs中进行编译(能够跳转到编译错误是一种胜利)。

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

但是,特别是加速.emacs可以通过以下方式完成:

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

    字节编译.emacs文件,您可以使用此代码段自动执行此操作

  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.

    用自动加载的功能替换尽可能多的(require'包)语句。这将延迟加载lisp直到它实际需要。使用这种技术,我可以将启动速度从> 6秒加速到<1。这需要一些工作,因为并非所有库都标记为自动加载。

  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.

    尝试使用选项--no-site-file运行emacs,以避免在站点安装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.

    如果您真的很认真,可以使用已加载的喜爱功能滚动自己的emacs。当然,这意味着更多地参与更改.emacs中的内容,因为它是二进制文件的一部分。请访问该链接以获取有关如何使用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:

现在,您如何找到.emacs加载的内容?目标是删除功能,还是延迟它?检查* Messages *缓冲区,其中包含以下行:

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.

如果你注意到,Loading语句可以嵌套:第一个.emacs.tjackson.el以...结尾,最后一行显示.emacs.tjackson.el加载完成。所有其他文件都是从我的.emacs.tjackson.el文件中加载的。所有其他负载都是原子的。

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:

注意:如果你有一个大的.emacs,* Messages *缓冲区可能会丢失一些消息,因为它只保留一定数量的信息。您可以尽早将此设置添加到.emacs以保留所有消息:

(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).

注意:'load命令将在第四个参数nomessage为非nil时禁止消息,因此删除任何此类调用(或者,建议'加载并强制第四个参数为nil)。

#3


Don't close Emacs every time you want to use the shell. Use Ctrl-Z to move Emacs to the background and the fg command in Bash to move it back to the foreground.

每次要使用shell时都不要关闭Emacs。使用Ctrl-Z将Emacs移动到后台,使用Bash中的fg命令将其移回前台。

#4


A couple of tips:

一些提示:

  1. 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))
    
  2. Compile your .emacs

    编译你的.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:

    如果你使用版本控制并且你的.emacs比.emacs.elc更新,那么你可以稍微提高速度。一个常见的技巧是:

    (defun autocompile nil
      "compile itself if ~/.emacs"
      (interactive)
      (require 'bytecomp)
      (let ((dotemacs (file-truename user-init-file)))
        (if (string= (buffer-file-name) (file-chase-links dotemacs))
          (byte-compile-file dotemacs))))
    
    (add-hook 'after-save-hook 'autocompile)
    
  3. Learn to love emacs server.

    学会爱上emacs服务器。

    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.

    将emacs作为服务器运行意味着永远不必关闭它。但是我注意到你仍在使用emacs22。 emacs23支持multi-tty,这使得在一个屏幕会话中运行emacs,然后在另一个终端中启动新窗口变得更加容易。我使用emacs编辑邮件客户端(mutt)的邮件,emacsclient非常适合这些快速编辑。

#5


One of

M-x shell
M-x eshell
M-x term
M-x ansi-term

should meet your command-line needs from within Emacs.

应该满足您在Emacs内的命令行需求。

You can also use M-! (aka M-x shell-command) to execute a one-liner without dropping to the shell.

你也可以使用M-! (又名M-x shell-command)执行单行程而不会掉到shell中。

#6


Check your .emacs file 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 the php-mode package if you're editing a PHP file. You can do that by installing a hook procedure, although I'm not certain of the details.

检查.emacs文件以查看是否正在加载不必要的包。加载包可能会花费大量时间。例如,如果您正在编辑PHP文件,则可能只想加载php模式包。你可以通过安装一个钩子程序来做到这一点,虽然我不确定细节。

Also make sure that any packages you're loading are compiled (.elc files). You can compile an elisp file by running

还要确保编译的所有软件包都已编译(.elc文件)。您可以通过运行来编译elisp文件

emacs -batch -f batch-byte-compile thefile.el

Compiled packages load much faster than uncompiled packages.

编译包的加载速度比未编译的包快得多。

#7


"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."

“我倾向于打开和关闭emacs,因为我更习惯使用bash命令行进行文件/目录操作和编译。”

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.

你正在描述像vim这样的编辑器的使用方式。拍摄进出。 Emacs通常保持开放状态,大部分都是从“内部”完成的。希恩已经回答了这里正确的做法。

#8


The fastest way is to profile your .emacs. I cut down my load time from >3s to 1s in 5 minutes after I found that 4 particular lines in my .emacs were taking up more than 80% of the load time.

最快的方法是分析您的.emacs。在我发现我的.emacs中的4条特定线占用了超过80%的加载时间后,我在5分钟内将加载时间从> 3s减少到1s。

#9


One thing that helped me reduce the load time of my .emacs, in addition to autoload (as others have suggested), is eval-after-load. In the following example, delaying the call to sql-set-product saves you from having to load sql in your .emacs, making the exisiting sql autoloads more effective.

除了自动加载(正如其他人建议的那样)之外,有助于减少我的.emacs加载时间的一件事是eval-after-load。在下面的示例中,延迟对sql-set-product的调用可以使您不必在.emacs中加载sql,从而使现有的sql自动加载更有效。

(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.

当然,对于某些软件包,会有一个可用的钩子,你可以做同样的事情,但有时候没有,或者这种方式证明更容易思考。

#10


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.

Emacs旨在“始终”(或至少长时间)运行,因此不建议在一天内多次启动和停止Emacs。

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).

安装完成后,只需在终端中输入“screen emacs”即可。 Emacs将照常启动,但按“c-a c”(即按ctrl-a然后按c)将打开一个新的虚拟终端。你可以按“c-a c-a”(这是ctrl-a的两次)回到emacs。

You can even detach from the running screen session, the key sequence is "c-a d".

您甚至可以从正在运行的屏幕会话中分离,键序列是“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.

通过发出“screen -R”重新附加到会话,您将返回到您离开的位置。这使您可以在工作,分离,回家和从家中重新连接时启动emacs会话。

I've been running Emacs like this for months in a row.

我连续几个月一直在运行这样的Emacs。

Here's the official web site: http://www.gnu.org/software/screen/ but try googling for screen tutorials and howtos

这是官方网站:http://www.gnu.org/software/screen/但是尝试谷歌搜索屏幕教程和howtos

#11


You can use benchmark-init to profile your Emacs startup. It will keep track of what modules are being loaded and how much time is spent on each. The results can be presented either in a tabulated form or as a tree. The tree makes it easier to track who loads what, which can be helpful when you load a package with a lot of dependencies, and the tabulated form helps you quickly find where most of the time is being spent.

您可以使用benchmark-init来配置您的Emacs启动。它将跟踪正在加载的模块以及每个模块花费的时间。结果可以以表格形式或树形式呈现。树可以更容易地跟踪谁加载了什么,这在加载具有大量依赖关系的包时会很有帮助,并且列表形式可以帮助您快速找到大部分时间花在哪里。

Once you have these results try to figure out if all of the modules have to be loaded all the time or if you can perhaps load some of them on-demand. For instance, in my configuration I only load Emacs extensions that are specific to certain modes when that mode is actually activated since most of the time I only use a small subset of them in a session. eval-after-load and mode hooks will be your friends here.

获得这些结果后,尝试确定是否必须始终加载所有模块,或者是否可以按需加载其中一些模块。例如,在我的配置中,我只加载特定于某些模式的Emacs扩展,当该模式实际被激活时,因为大多数时候我只在会话中使用它们的一小部分。 eval-after-load和mode hooks将成为你的朋友。

By applying this method my Emacs starts in 3-4 seconds and I have close to 200 extensions installed. Most of the time is spent loading Helm, which I always load since it replaces find-file and other core functions that are always needed, and CEDET, since I use the latest version and it has to be loaded before Emacs tries to load the older built-in version.

通过应用此方法,我的Emacs在3-4秒内启动,并且我安装了近200个扩展。大部分时间用于加载Helm,我总是加载它,因为它取代了总是需要的find-file和其他核心功能,以及CEDET,因为我使用最新版本并且必须在Emacs尝试加载旧版本之前加载它内置版本。

#12


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 .emacs it could win you a few seconds of startup time.

其他人没有提到的一件事是包含你用作转储Emacs的一部分的elisp库,以便将库加载时间从Emacs启动移动到Emacs构建。它不适合胆小的人,但如果你在.emacs中加载几个库,它可以赢得你几秒钟的启动时间。

#13


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:

    对于您在命令行上执行的大多数操作,您可以在emacs中执行以下操作:

    • compile: M-x compile, then type the command you use
    • 编译:M-x编译,然后键入您使用的命令

    • my experience is only with C++, but with g++ you can press C-x ` to jump to lines that the compiler complains about
    • 我的经验只适用于C ++,但使用g ++,你可以按C-x`跳转到编译器抱怨的行

    • run shell commands: M-!, dumps output into a buffer
    • 运行shell命令:M- !,将输出转储到缓冲区

    • interactive shell: M-x shell
    • 交互式shell:M-x shell

  • alternatively, you could run emacs like this:

    或者,您可以像这样运行emacs:

    • emacs file.ext &
    • 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)
    • 它在后台打开emacs,所以你仍然可以使用shell(这最适合使用putty和X转发,比如Xming)

#14


I had around 120sec start time. I was able to find the fix installing this:

我有大约120秒的开始时间。我能找到安装此修复程序:

https://github.com/dholm/benchmark-init-el put on top of your init.el

https://github.com/dholm/benchmark-init-el放在你的init.el之上

(let ((benchmark-init.el "~/.emacs.d/el-get/benchmark-init/benchmark-init.el"))
  (when (file-exists-p benchmark-init.el)
    (load benchmark-init.el)))

then once your emacs started, run:

然后,一旦你的emacs启动,运行:

M-x benchmark-init/show-durations-tree

On my side the problem was 127 secs in tramp-loaddefs

在我这边,tramp-loaddefs中的问题是127秒

I fixed it by adding

我通过添加来修复它

127.0.0.1  host.does.not.exist

to /etc/hosts and that made my startup fast

到/ etc / hosts,这让我的创业很快

see more here: https://github.com/emacs-helm/helm/issues/1045

在这里看到更多:https://github.com/emacs-helm/helm/issues/1045

another thing that maybe helpful to you: https://www.emacswiki.org/emacs/ProfileDotEmacs

另一件可能对你有帮助的事情:https://www.emacswiki.org/emacs/ProfileDotEmacs

#15


I was trying to solve the same problem, when I came across this question here. I just wanted to add that the problem for me was not because of the load time of emacs lisp packages, but the fact that the host did not have a fully resolved hostname

当我在这里遇到这个问题时,我试图解决同样的问题。我只是想补充说,问题对我来说不是因为emacs lisp软件包的加载时间,而是因为主机没有完全解析的主机名

To check your package load time do

要检查你的包加载时间吗

M-x emacs-init-time

For me it was 0.3 seconds, and yet the load time was extremely high. After changing my hostname correctly, it fixed the problem.

对我来说这是0.3秒,然而加载时间非常高。正确更改主机名后,它修复了问题。

To configure your fully resolved hostname edit /etc/hostname, and /etc/hostsfile with:

要配置完全解析的主机名,请编辑/ etc / hostname和/ etc / hosts文件:

127.0.0.1       localhost localhost.localdomain
192.168.0.2   hostname hostname.domain

#16


Try using the https://github.com/jwiegley/use-package macro to define your package loads and customizations. It handles deferred loading of packages for you, making it relatively easy to get good startup times even in the presence of large numbers of configured packages. I have almost 100 packages referenced in my .emacs, but my startup time is under 2 seconds on Linux, and 2.2s on the Mac.

尝试使用https://github.com/jwiegley/use-package宏来定义包加载和自定义。它为您处理延迟加载包,使得即使在存在大量配置包的情况下也可以相对容易地获得良好的启动时间。我的.emacs中引用了近100个软件包,但我在Linux上的启动时间不到2秒,在Mac上的启动时间不到2.2秒。

#17


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.

我必须检查我的自定义,但有一个名为gnuserve或emacsclient的包。它迁移了很多,所以你必须谷歌为它。

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会话。 emacs的任何进一步会话基本上只是该会话的新帧。一个优点是您以后的会话的快速启动时间。

#1


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.

除了Adam Rosenfield的解决方案,我建议在服务器模式下使用Emacs。你可以添加(server-start)到你的dotemacs,并在你想在Emacs中打开文件时运行emacsclient而不是emacs。这样,您只需支付一次Emacs的装载成本,然后客户端立即弹出。

Edit

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

你是对的,v22不会创建一个新的框架。创建一个执行技巧的shell脚本:

#!/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'"))'

#2


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

其他人已经介绍过使用gnuserve和emacsclient,我建议在emacs中进行编译(能够跳转到编译错误是一种胜利)。

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

但是,特别是加速.emacs可以通过以下方式完成:

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

    字节编译.emacs文件,您可以使用此代码段自动执行此操作

  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.

    用自动加载的功能替换尽可能多的(require'包)语句。这将延迟加载lisp直到它实际需要。使用这种技术,我可以将启动速度从> 6秒加速到<1。这需要一些工作,因为并非所有库都标记为自动加载。

  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.

    尝试使用选项--no-site-file运行emacs,以避免在站点安装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.

    如果您真的很认真,可以使用已加载的喜爱功能滚动自己的emacs。当然,这意味着更多地参与更改.emacs中的内容,因为它是二进制文件的一部分。请访问该链接以获取有关如何使用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:

现在,您如何找到.emacs加载的内容?目标是删除功能,还是延迟它?检查* Messages *缓冲区,其中包含以下行:

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.

如果你注意到,Loading语句可以嵌套:第一个.emacs.tjackson.el以...结尾,最后一行显示.emacs.tjackson.el加载完成。所有其他文件都是从我的.emacs.tjackson.el文件中加载的。所有其他负载都是原子的。

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:

注意:如果你有一个大的.emacs,* Messages *缓冲区可能会丢失一些消息,因为它只保留一定数量的信息。您可以尽早将此设置添加到.emacs以保留所有消息:

(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).

注意:'load命令将在第四个参数nomessage为非nil时禁止消息,因此删除任何此类调用(或者,建议'加载并强制第四个参数为nil)。

#3


Don't close Emacs every time you want to use the shell. Use Ctrl-Z to move Emacs to the background and the fg command in Bash to move it back to the foreground.

每次要使用shell时都不要关闭Emacs。使用Ctrl-Z将Emacs移动到后台,使用Bash中的fg命令将其移回前台。

#4


A couple of tips:

一些提示:

  1. 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))
    
  2. Compile your .emacs

    编译你的.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:

    如果你使用版本控制并且你的.emacs比.emacs.elc更新,那么你可以稍微提高速度。一个常见的技巧是:

    (defun autocompile nil
      "compile itself if ~/.emacs"
      (interactive)
      (require 'bytecomp)
      (let ((dotemacs (file-truename user-init-file)))
        (if (string= (buffer-file-name) (file-chase-links dotemacs))
          (byte-compile-file dotemacs))))
    
    (add-hook 'after-save-hook 'autocompile)
    
  3. Learn to love emacs server.

    学会爱上emacs服务器。

    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.

    将emacs作为服务器运行意味着永远不必关闭它。但是我注意到你仍在使用emacs22。 emacs23支持multi-tty,这使得在一个屏幕会话中运行emacs,然后在另一个终端中启动新窗口变得更加容易。我使用emacs编辑邮件客户端(mutt)的邮件,emacsclient非常适合这些快速编辑。

#5


One of

M-x shell
M-x eshell
M-x term
M-x ansi-term

should meet your command-line needs from within Emacs.

应该满足您在Emacs内的命令行需求。

You can also use M-! (aka M-x shell-command) to execute a one-liner without dropping to the shell.

你也可以使用M-! (又名M-x shell-command)执行单行程而不会掉到shell中。

#6


Check your .emacs file 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 the php-mode package if you're editing a PHP file. You can do that by installing a hook procedure, although I'm not certain of the details.

检查.emacs文件以查看是否正在加载不必要的包。加载包可能会花费大量时间。例如,如果您正在编辑PHP文件,则可能只想加载php模式包。你可以通过安装一个钩子程序来做到这一点,虽然我不确定细节。

Also make sure that any packages you're loading are compiled (.elc files). You can compile an elisp file by running

还要确保编译的所有软件包都已编译(.elc文件)。您可以通过运行来编译elisp文件

emacs -batch -f batch-byte-compile thefile.el

Compiled packages load much faster than uncompiled packages.

编译包的加载速度比未编译的包快得多。

#7


"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."

“我倾向于打开和关闭emacs,因为我更习惯使用bash命令行进行文件/目录操作和编译。”

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.

你正在描述像vim这样的编辑器的使用方式。拍摄进出。 Emacs通常保持开放状态,大部分都是从“内部”完成的。希恩已经回答了这里正确的做法。

#8


The fastest way is to profile your .emacs. I cut down my load time from >3s to 1s in 5 minutes after I found that 4 particular lines in my .emacs were taking up more than 80% of the load time.

最快的方法是分析您的.emacs。在我发现我的.emacs中的4条特定线占用了超过80%的加载时间后,我在5分钟内将加载时间从> 3s减少到1s。

#9


One thing that helped me reduce the load time of my .emacs, in addition to autoload (as others have suggested), is eval-after-load. In the following example, delaying the call to sql-set-product saves you from having to load sql in your .emacs, making the exisiting sql autoloads more effective.

除了自动加载(正如其他人建议的那样)之外,有助于减少我的.emacs加载时间的一件事是eval-after-load。在下面的示例中,延迟对sql-set-product的调用可以使您不必在.emacs中加载sql,从而使现有的sql自动加载更有效。

(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.

当然,对于某些软件包,会有一个可用的钩子,你可以做同样的事情,但有时候没有,或者这种方式证明更容易思考。

#10


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.

Emacs旨在“始终”(或至少长时间)运行,因此不建议在一天内多次启动和停止Emacs。

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).

安装完成后,只需在终端中输入“screen emacs”即可。 Emacs将照常启动,但按“c-a c”(即按ctrl-a然后按c)将打开一个新的虚拟终端。你可以按“c-a c-a”(这是ctrl-a的两次)回到emacs。

You can even detach from the running screen session, the key sequence is "c-a d".

您甚至可以从正在运行的屏幕会话中分离,键序列是“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.

通过发出“screen -R”重新附加到会话,您将返回到您离开的位置。这使您可以在工作,分离,回家和从家中重新连接时启动emacs会话。

I've been running Emacs like this for months in a row.

我连续几个月一直在运行这样的Emacs。

Here's the official web site: http://www.gnu.org/software/screen/ but try googling for screen tutorials and howtos

这是官方网站:http://www.gnu.org/software/screen/但是尝试谷歌搜索屏幕教程和howtos

#11


You can use benchmark-init to profile your Emacs startup. It will keep track of what modules are being loaded and how much time is spent on each. The results can be presented either in a tabulated form or as a tree. The tree makes it easier to track who loads what, which can be helpful when you load a package with a lot of dependencies, and the tabulated form helps you quickly find where most of the time is being spent.

您可以使用benchmark-init来配置您的Emacs启动。它将跟踪正在加载的模块以及每个模块花费的时间。结果可以以表格形式或树形式呈现。树可以更容易地跟踪谁加载了什么,这在加载具有大量依赖关系的包时会很有帮助,并且列表形式可以帮助您快速找到大部分时间花在哪里。

Once you have these results try to figure out if all of the modules have to be loaded all the time or if you can perhaps load some of them on-demand. For instance, in my configuration I only load Emacs extensions that are specific to certain modes when that mode is actually activated since most of the time I only use a small subset of them in a session. eval-after-load and mode hooks will be your friends here.

获得这些结果后,尝试确定是否必须始终加载所有模块,或者是否可以按需加载其中一些模块。例如,在我的配置中,我只加载特定于某些模式的Emacs扩展,当该模式实际被激活时,因为大多数时候我只在会话中使用它们的一小部分。 eval-after-load和mode hooks将成为你的朋友。

By applying this method my Emacs starts in 3-4 seconds and I have close to 200 extensions installed. Most of the time is spent loading Helm, which I always load since it replaces find-file and other core functions that are always needed, and CEDET, since I use the latest version and it has to be loaded before Emacs tries to load the older built-in version.

通过应用此方法,我的Emacs在3-4秒内启动,并且我安装了近200个扩展。大部分时间用于加载Helm,我总是加载它,因为它取代了总是需要的find-file和其他核心功能,以及CEDET,因为我使用最新版本并且必须在Emacs尝试加载旧版本之前加载它内置版本。

#12


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 .emacs it could win you a few seconds of startup time.

其他人没有提到的一件事是包含你用作转储Emacs的一部分的elisp库,以便将库加载时间从Emacs启动移动到Emacs构建。它不适合胆小的人,但如果你在.emacs中加载几个库,它可以赢得你几秒钟的启动时间。

#13


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:

    对于您在命令行上执行的大多数操作,您可以在emacs中执行以下操作:

    • compile: M-x compile, then type the command you use
    • 编译:M-x编译,然后键入您使用的命令

    • my experience is only with C++, but with g++ you can press C-x ` to jump to lines that the compiler complains about
    • 我的经验只适用于C ++,但使用g ++,你可以按C-x`跳转到编译器抱怨的行

    • run shell commands: M-!, dumps output into a buffer
    • 运行shell命令:M- !,将输出转储到缓冲区

    • interactive shell: M-x shell
    • 交互式shell:M-x shell

  • alternatively, you could run emacs like this:

    或者,您可以像这样运行emacs:

    • emacs file.ext &
    • 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)
    • 它在后台打开emacs,所以你仍然可以使用shell(这最适合使用putty和X转发,比如Xming)

#14


I had around 120sec start time. I was able to find the fix installing this:

我有大约120秒的开始时间。我能找到安装此修复程序:

https://github.com/dholm/benchmark-init-el put on top of your init.el

https://github.com/dholm/benchmark-init-el放在你的init.el之上

(let ((benchmark-init.el "~/.emacs.d/el-get/benchmark-init/benchmark-init.el"))
  (when (file-exists-p benchmark-init.el)
    (load benchmark-init.el)))

then once your emacs started, run:

然后,一旦你的emacs启动,运行:

M-x benchmark-init/show-durations-tree

On my side the problem was 127 secs in tramp-loaddefs

在我这边,tramp-loaddefs中的问题是127秒

I fixed it by adding

我通过添加来修复它

127.0.0.1  host.does.not.exist

to /etc/hosts and that made my startup fast

到/ etc / hosts,这让我的创业很快

see more here: https://github.com/emacs-helm/helm/issues/1045

在这里看到更多:https://github.com/emacs-helm/helm/issues/1045

another thing that maybe helpful to you: https://www.emacswiki.org/emacs/ProfileDotEmacs

另一件可能对你有帮助的事情:https://www.emacswiki.org/emacs/ProfileDotEmacs

#15


I was trying to solve the same problem, when I came across this question here. I just wanted to add that the problem for me was not because of the load time of emacs lisp packages, but the fact that the host did not have a fully resolved hostname

当我在这里遇到这个问题时,我试图解决同样的问题。我只是想补充说,问题对我来说不是因为emacs lisp软件包的加载时间,而是因为主机没有完全解析的主机名

To check your package load time do

要检查你的包加载时间吗

M-x emacs-init-time

For me it was 0.3 seconds, and yet the load time was extremely high. After changing my hostname correctly, it fixed the problem.

对我来说这是0.3秒,然而加载时间非常高。正确更改主机名后,它修复了问题。

To configure your fully resolved hostname edit /etc/hostname, and /etc/hostsfile with:

要配置完全解析的主机名,请编辑/ etc / hostname和/ etc / hosts文件:

127.0.0.1       localhost localhost.localdomain
192.168.0.2   hostname hostname.domain

#16


Try using the https://github.com/jwiegley/use-package macro to define your package loads and customizations. It handles deferred loading of packages for you, making it relatively easy to get good startup times even in the presence of large numbers of configured packages. I have almost 100 packages referenced in my .emacs, but my startup time is under 2 seconds on Linux, and 2.2s on the Mac.

尝试使用https://github.com/jwiegley/use-package宏来定义包加载和自定义。它为您处理延迟加载包,使得即使在存在大量配置包的情况下也可以相对容易地获得良好的启动时间。我的.emacs中引用了近100个软件包,但我在Linux上的启动时间不到2秒,在Mac上的启动时间不到2.2秒。

#17


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.

我必须检查我的自定义,但有一个名为gnuserve或emacsclient的包。它迁移了很多,所以你必须谷歌为它。

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会话。 emacs的任何进一步会话基本上只是该会话的新帧。一个优点是您以后的会话的快速启动时间。