如何让Emacs重新加载我在.emacs中更新的所有定义而不重新启动Emacs?


当前回答

如果你碰巧在Emacs内部打开了一个shell,你还可以这样做:

. ~/.emacs

这样可以节省一些按键。

其他回答

在init文件中定义它,并通过M-x reload-user-init-file调用

(defun reload-user-init-file()
  (interactive)
  (load-file user-init-file))

这里有一个快速和简单的方法来快速测试您的配置。您还可以在特定的lisp末尾使用C-x C-e来单独执行某些函数。

C-x C-e runs the command eval-last-sexp (found in global-map), which is an interactive compiled Lisp function. It is bound to C-x C-e. (eval-last-sexp EVAL-LAST-SEXP-ARG-INTERNAL) Evaluate sexp before point; print value in the echo area. Interactively, with prefix argument, print output into current buffer. Normally, this function truncates long output according to the value of the variables ‘eval-expression-print-length’ and ‘eval-expression-print-level’. With a prefix argument of zero, however, there is no such truncation. Such a prefix argument also causes integers to be printed in several additional formats (octal, hexadecimal, and character). If ‘eval-expression-debug-on-error’ is non-nil, which is the default, this command arranges for all errors to enter the debugger.

解决方案

M-(加载user-init-file)


笔记

你在Eval: prompt中输入它(包括括号) User-init-file是一个保存~/的变量。Emacs值(指向配置文件路径) (load)是(load-file)的较短、较旧且非交互式的版本;它不是一个Emacs命令(要在M-x中输入),而仅仅是一个Elisp函数


结论

M-: > M-x

尽管M-x eval-buffer可以工作,但是在切换和其他类似的事情上可能会遇到问题。更好的方法可能是“标记”或突出显示.emacs文件中的新内容(如果只是瞎折腾,甚至可以标记缓冲区),然后是M-x eval-region。

如果你碰巧在Emacs内部打开了一个shell,你还可以这样做:

. ~/.emacs

这样可以节省一些按键。