速度突破裸配置/emacs -Q的极限:emacs启动时间只够你眨眼?

棒!你这个是编辑器大集成啊 我用chemacs管理好几套不同的emacs配置,需求是输入doom就启动doom-emacs,输入space就启动spacemacs ,诸如此类。 所以目测还得自己倒腾一番…

1 个赞

好奇,请问一下 native-comp 和 dump 有啥副作用?

native-comp 必须安装gccjit等工具链,编译会占用大量CPU资源,第一次启动、安装或者更新包时会造成卡顿;dumper 只能相对固定的包,更新包后要重新dump。使用起来都不够自然顺畅,对于需要更新包的同学不够友好。如果环境很固定也不更新包就无所谓了。

2 个赞

没什么技巧啊,快捷键唤醒alfred,直接在搜索框输入e,然后RET就可以了 :rofl:如果要设置alfred workflow的话,可以参考一下我的这个帖子

对啊,我也觉得这个时间挺不准的。那能不能设置个函数可以计算emacs刚启动到界面显示的时间呢?

我现在还没配什么包,貌似还能hook整个init-file作弊一下 ,估计之后包多了就不管用了:joy:

另外,顺便请教一下大佬,我抄了你的“环境变量”的作业,shell的设置也放在.zshenv里,也却掉了-i参数,加了exec-path-from-shell包之后,emacs-init-time的多了2秒多……还有什么办法可以加快这个包吗?听说emacs-mac能自动继承环境变量,但我用的是gui emacs-plus,不知道能不能也自动继承环境变量?

time emacs -e kill-emacs

另一种方法,不用这个包,自己设置

应该看0.73s这个时间吗

谢谢提供两种方法,第二种方法试过了,还是不行。第一种我以前也试过,当时可能配置没写好就不起作用,我再试试。 :handshake:

看最后的数字

先安装 exec-path-from-shell ,再从 cache-path-from-shell 下载 cache-path-from-shell.el 然后在~/.emacs 的最开头的位置加上 (注意一定是最开头的位置)

我觉得这个蛮准的

关于 exec-path-from-shell, 分享一个替代做法。
因为环境变量不会经常变,其实可以把当前的环境变量存下来
printenv > ~/.emacs.d/env

然后读取这个文件

;; Load env
(defconst my-env-file (concat user-emacs-directory "env"))
(when (and (or (display-graphic-p)
               (daemonp))
           (file-exists-p my-env-file))
  (defun my-load-envvars-file (file &optional noerror)
    "Read and set envvars from FILE.
If NOERROR is non-nil, don't throw an error if the file doesn't exist or is
unreadable. Returns the names of envvars that were changed."
    (if (not (file-readable-p file))
        (unless noerror
          (signal 'file-error (list "Couldn't read envvar file" file)))
      (let (envvars environment)
        (with-temp-buffer
          (save-excursion
            (insert "\n")
            (insert-file-contents file))
          (while (re-search-forward "\n *\\([^#= \n]*\\)=" nil t)
            (push (match-string 1) envvars)
            (push (buffer-substring
                   (match-beginning 1)
                   (1- (or (save-excursion
                             (when (re-search-forward "^\\([^= ]+\\)=" nil t)
                               (line-beginning-position)))
                           (point-max))))
                  environment)))
        (when environment
          (setq process-environment
                (append (nreverse environment) process-environment)
                exec-path
                (if (member "PATH" envvars)
                    (append (split-string (getenv "PATH") path-separator t)
                            (list exec-directory))
                  exec-path)
                shell-file-name
                (if (member "SHELL" envvars)
                    (or (getenv "SHELL") shell-file-name)
                  shell-file-name))
          envvars))))

  (my-load-envvars-file my-env-file))

每次改变环境变量之后更新环境变量文件即可。做法来自 https://www.reddit.com/r/emacs/comments/f8xwau/hack_replace_execpathfromshell/

3 个赞

明白了 谢谢 :pray:

我看别人都是用benchmark-init,就没试过这个 :rofl:

感谢分享 :pray:

去掉 -i 参数,exec-path-from-shell 初始化只读取.zshenv 的环境变量,速度应该很快才对。多2秒肯定不正常。检查下你的zsh配置,尤其是.zshenv文件。

1 个赞

还可以试试esup

emacs --daemon 的启动用emacsclient 启动怎么让自定义配置生效,我自定义配置的字体实际上改的很大,正常启动没问题,但是用emacsclient启动自定义的字体就没了。

字体配置在daemon和terminal下是不起效的。你需要把字体配置部分加入after-make-frame-functions或者default-frame-alist

1 个赞

谢谢,根据你说的方式,daemon现在可以。。 :grin:

大佬,麻烦帮我看看环境变量 :pray:也没多少东西,不知道哪里出问题了……

export PATH/usr/local/bin:/usr/bin:/bin

忘记加引号了吧。。