如何在“.emacs”中找到一个错误或“init.el” [英] How to find a bug in ".emacs" or "init.el"?

查看:265
本文介绍了如何在“.emacs”中找到一个错误或“init.el”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,当我打开Emacs时,Emacs的初始化失败。

这是因为 .emacs init.el 文件有一个错误。 (我的错误通常来自于错误的)。



我想在 .emacs init.el 。有没有办法这样做?

解决方案

要找出你的init文件的哪一部分(〜 /.emacs )导致您看到的行为, bisect 您的init文件递归:首先注释一半,看看哪一半是负责任的,然后3/4,看看哪个季度负责,...



要注释一个文本区域(例如您选择的行的继承),我推荐注释区域(我绑定到 Cx C - ; )。使用数字前缀arg,它使用许多; 注释字符。使用简单的前缀arg( Cu )将取消注释该区域,而不是对其进行注释。



您还可以启动Emacs使用命令行开关 - debug-init 。这将导致调试器在Emacs启动期间出现错误时打开,包括在您的init文件加载时。调试器回溯告诉您哪个评估引发了错误(哪个函数被调用),并显示哪个函数称为引发错误的函数,哪个函数称为该函数,依此类推。



当您知道哪个功能是问题时,如果需要,可以通过将(调试输入'THE-FUNCTION)'调试其评估在你的初始化文件的开始附近。这将在输入函数时打开调试器,而不是仅显示出现错误时发生的情况。然后,您可以使用 d (或 c 跳过一步),查看调试器,看看是什么



如果您希望从某个断点开始执行该函数,则将定义该函数的源代码复制到您的init文件中,然后插入(debug)在您要调试器打开的位置。



与往常一样,Emacs手册是您的朋友。请参阅Emacs手册中的节点清单,并在Elisp手册中调用调试器节点。



另外还有一个调试器,叫做$ code> edebug ,这也是在手册中记载的。有些人喜欢它 debug 。 (我更喜欢 debug 。)两者都不错。



如果你加载了Emacs,使用调试器通常会更有说服力Lisp源文件而不是字节编译版本。如果您使用调试器开始调查特定问题,您可能需要先加载 *。el (不是 *。elc )文件。


Sometimes when I open Emacs, Emacs initialization fail.
That is because .emacs or init.el files have a bug. (My bugs often come from just mistyping.)

I want to find the bug in .emacs or init.el. Is there any way to do this?

解决方案

To find out what part of your init file (~/.emacs) is causing the behavior you see, bisect your init file recursively: First comment-out half, to see which half is responsible, then 3/4, to see which quarter is responsible,...

To comment out a region of text (e.g. succession of lines that you have selected), I recommend comment-region (which I bind to C-x C-;). With a numeric prefix arg it uses that many ; comment chars. With a plain prefix arg (C-u) it uncomments the region instead of commenting it.

You can also start Emacs with the command-line switch --debug-init. This will cause the debugger to open when an error is raised during Emacs startup, including while your init file is loaded. The debugger backtrace tells you which evaluation raised the error (which function was called), and it shows you which function called the function where the error was raised, which function called that one, and so on.

When you know which function is the problem, if you need to you can debug its evaluation by putting (debug-on-entry 'THE-FUNCTION) near the start of your init file. That will open the debugger when the function is entered instead of just showing what happened when the error was raised. You can then step through the debugger using d (or c to skip through a step), to see just what went wrong.

If you prefer to step through the function starting at some breakpoint, then copy the source code that defines the function to your init file, and insert (debug) at the position where you want the debugger to open.

As always, the Emacs manuals are your friends. See, for instance, node Checklist in the Emacs manual and node Invoking the Debugger in the Elisp manual.

There is another debugger also, called edebug, which is also documented in the manuals. Some people prefer it to debug. (I prefer debug.) Both are good.

Using the debugger is generally more informative if you have loaded Emacs Lisp source files rather than their byte-compiled versions. If you start investigating a particular problem using the debugger, you might want to first load the *.el (not *.elc) file(s) in question.

这篇关于如何在“.emacs”中找到一个错误或“init.el”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆