简体   繁体   English

Elisp:如果启动时出错,是否可以自动打开Emacs初始化文件?

[英]Elisp: possible to automatically open Emacs init file if error at start-up?

Here's the idea: if I restart Emacs after making a change to my Emacs init file, it would be very convenient if, in the event of an error at start-up, Emacs automatically opened my init file for editing 这是一个主意:如果我在更改了Emacs初始化文件后重新启动Emacs,如果启动时发生错误,Emacs自动打开我的初始化文件进行编辑,那将非常方便。

For example, if there's an error at start-up, Emacs could show the error/debug message in one window and my init file in the other window. 例如,如果在启动时出现错误,Emacs可以在一个窗口中显示错误/调试消息,而在另一个窗口中显示我的初始化文件。

I'm new to Emacs Lisp and am not familiar with error-handling procedures. 我是Emacs Lisp的新手,也不熟悉错误处理过程。 Are there any error-handling mechanisms/settings that could be useful? 是否有任何有用的错误处理机制/设置? (Am honestly not sure where to even start with this one, hence the lack of any experimental code in this post...) (坦白地说,我不确定从哪里开始,因此本文中缺少任何实验代码...)

If you really want to do that, you can try this: 如果您确实想这样做,可以尝试以下方法:

Wrap the contents of your init file in this, where CONTENTS is your originaly init file, and FILE is the absolute name (ie, location) of your init file: 在其中包装您的init文件的内容,其中CONTENTS是您的原始init文件,而FILE是您的init文件的绝对名称(即位置):

(condition-case err
     (progn
        (setq debug-on-error  t)
        CONTENTS
     )
  (error (find-file FILE)
         (error "*INIT ERROR*: %s" (error-message-string err))))

Or perhaps a little better: Put what is in your init file now in another file - called ORIG-INIT here (again, an absolute file name), and use this as the (only) content of your init file: 也许更好一点:现在将您的init文件中的内容放到另一个文件中,这里称为ORIG-INIT(同样是绝对文件名),并将其用作init文件的(唯一)内容:

(condition-case err
     (progn (setq debug-on-error  t)
            (load-file ORIG-INIT))
  (error (find-file ORIG-INIT)
         (error "*INIT ERROR*: %s" (error-message-string err))))

Actually, I normally have one emacs open with the .emacs file. 实际上,我通常使用.emacs文件打开一个emacs。 Then I open and close a new emacs every time I've made changes. 然后,每次进行更改后,我都会打开和关闭一个新的emacs。 Not as cool, I know, but then even your cursor will be where you were working. 我知道,它不那么酷,但是即使您的光标也会在您工作的地方。

Another thing I do is just edit a piece of code in a scrap buffer ( scratch or a newly made temporary file) and execute it using Cx Ce (while standing at the end of the expression). 我要做的另一件事就是在scrap缓冲区( scratch缓冲区或新创建的临时文件)中编辑一段代码,并使用Cx Ce(位于表达式的末尾)执行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM