如何在“.emacs"中查找错误?还是“init.el"? [英] How to find a bug in ".emacs" or "init.el"?

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

问题描述

有时当我打开 Emacs 时,Emacs 初始化失败.
那是因为 .emacsinit.el 文件有错误.(我的错误通常来自于输入错误.)

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

我想在 .emacsinit.el 中找到错误.有没有办法做到这一点?

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

推荐答案

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

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

要注释掉文本区域(例如,您选择的连续行),我推荐 comment-region(我绑定到 Cx C-;).使用数字前缀 arg 它使用许多 ; 注释字符.使用普通前缀 arg (C-u) 它取消注释该区域而不是注释它.

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.

您也可以使用命令行开关--debug-init 启动Emacs.这将导致调试器在 Emacs 启动期间引发错误时打开,包括在加载您的 init 文件时.调试器回溯会告诉您哪个评估引发了错误(调用了哪个函数),它会显示哪个函数调用了引发错误的函数,哪个函数调用了那个函数,等等.

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.

当您知道哪个函数是问题时,如果需要,您可以通过将 (debug-on-entry 'THE-FUNCTION) 放在 init 文件的开头附近来调试它的评估.这将在输入函数时打开调试器,而不是仅显示引发错误时发生的情况.然后,您可以使用 d (或 c 跳过一个步骤)单步调试调试器,看看到底出了什么问题.

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.

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

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.

一如既往,Emacs 手册是您的朋友.例如,参见 Emacs 手册中的节点 Checklist 和 Elisp 手册中的节点 Invoking the Debugger.

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.

还有另一个调试器,称为 edebug,手册中也对此进行了说明.有些人喜欢它而不是 debug.(我更喜欢debug.)两者都很好.

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.

如果您加载了 Emacs Lisp 源文件而不是它们的字节编译版本,则使用调试器通常会提供更多信息.如果您开始使用调试器调查特定问题,您可能希望首先加载有问题的 *.el(而不是 *.elc)文件.

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天全站免登陆