hunter.png The Bug Hunter https://travis-ci.org/Malabarba/elisp-bug-hunter.svg?branch=master

Automatically debug and bisect your init (.emacs) file!

The Bug Hunter is an Emacs library that finds the source of an error or unexpected behavior inside an elisp configuration file (typically init.el or .emacs).

hunter-screencast.gif

Usage Examples

Automated error hunting

If your Emacs init file signals an error during startup, but you don’t know why, simply issue

M-x bug-hunter-init-file RET e

and The Bug Hunter will find it for you. Note that your init.el (or .emacs) must be idempotent for this to work.

Interactive hunt

If Emacs starts up without errors but something is not working as it should, invoke the same command, but choose the interactive option:

M-x bug-hunter-init-file RET i

The Bug Hunter will start a separate Emacs instance several times, and then it will ask you each time whether that instance presented the problem you have. After doing this about 5–12 times, you’ll be given the results.

Assertion hunt

The Bug Hunter can also find your issue based on an assertion. Essentially, if you can write a code snippet that returns non-nil when it detects the issue, just provide this snippet as the assertion and the Bug Hunter will do the rest.

For example, let’s say there’s something in your init file that’s loading the cl library, and you don’t want that. You know you’re not loading it yourself, but how can you figure out which external package is responsible for this outrage?

M-x bug-hunter-init-file RET a (featurep 'cl) RET

That’s it! You’ll be given a nice buffer reporting the results:

cl-example.png

  • Are you getting obscure errors when trying to open “.tex” files?
    • Don’t despair! Just use (and (find-file "dummy.tex") nil) as the assertion.
  • Did ox-html stop working due to some arcane misconfiguration?
    • Just write an assertion that does an export and checks the result.
  • Does some random command suddenly bind itself to C-j and you can’t figure out why?
    • (eq (key-binding "\n") 'unwanted-command) is the assertion for you!

Finally, you can also use bug-hunter-file to hunt in other files.

Installation

The Bug Hunter is available from GNU Elpa to all Emacs versions since 24.1. To install, just issue

M-x package-install RET bug-hunter

init.org and other literate-style configs

Some people (me included) like to organize their init files by writting it in org-mode instead of Emacs-Lisp. This usually involves adding something like this to init.el,

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Maybe some code up here ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'org)
(org-babel-tangle-file "~/.emacs.d/org-init.org"
                       "~/.emacs.d/org-init.el")
(load "~/.emacs.d/org-init.el")

At first, this makes the Bug-Hunter essentially useless, for it will do the hunting in init.el instead of the much more extensive org-init.el. The name of the second file (org-init.el) will vary, but the point is the same. But fear not! There’s a simple solution:

  1. If you have any code above the call to org-babel-tangle-file, copy that to the top of org-init.el (or whatever is the name of your tangled file). This includes that (require 'org) over there.
  2. Invoke M-x bug-hunter-file (instead of bug-hunter-init-file). It will ask you which file to debug, and you need to point it to your tangled output file org-init.el.


hunter.png The Bug Hunter https://travis-ci.org/Malabarba/elisp-bug-hunter.svg?branch=master

自动调试和平分您的init(.emacs)文件!

Bug Hunter是一个找到错误源的Emacs库   或者Elisp配置文件中的意外行为(通常为    init.el .emacs

Usage Examples

自动误差狩猎

如果您的Emacs init文件在启动过程中发出错误信号,但是没有   知道为什么,简单地发行

M-x bug-hunter-init-file RET e
恶作剧猎人会为你找到它。请注意,您的 init.el   (或 .emacs )必须是幂等的,才能正常工作。

互动狩猎

如果Emacs没有错误启动,但是不能正常工作   应该调用相同的命令,但选择交互式选项:

M-x bug-hunter-init-file RET i

Bug Hunter将会多次启动一个单独的Emacs实例   那么每次都会问你是否提供了这个实例   你有问题大概5-12次之后,你会被给予   结果。

断言追捕

Bug Hunter也可以根据断言找到您的问题。   基本上,如果你可以编写一个返回非零的代码片段   它检测到问题,只是提供这个代码段作为断言和   Bug猎人将会休息。

例如,假设你的init文件有一些东西   加载 cl 库,你不想要。你你知道   没有自己加载,但是你如何找出哪个外部的   包裹是否对这种愤怒负责?

M-x bug-hunter-init-file RET a (featurep 'cl) RET

就是这样!你会得到一个很好的缓冲区来报告结果:

  • Are you getting obscure errors when trying to open .tex files?
    • Don’t despair! Just use (and (find-file "dummy.tex") nil) as the assertion.
  • Did ox-html stop working due to some arcane misconfiguration?
    • Just write an assertion that does an export and checks the result.
  • Does some random command suddenly bind itself to C-j and you can’t figure out why?
    • (eq (key-binding "\n") 'unwanted-command) is the assertion for you!
最后,您还可以使用 bug-hunter-file 来搜索其他文件。

Installation

Bug Hunter可从 GNU Elpa 获取到所有Emacs版本,因为    24.1 。要安装,只需发布​​

M-x package-install RET bug-hunter

init.org and other literate-style configs

有些人(包括我)喜欢组织他们的init文件   将其写入 org-mode 而不是Emacs-Lisp。这通常涉及到   添加这样的东西到 init.el

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Maybe some code up here ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'org)
(org-babel-tangle-file "~/.emacs.d/org-init.org"
                       "~/.emacs.d/org-init.el")
(load "~/.emacs.d/org-init.el")
首先,这使得Bug-Hunter基本上没用,因为它会的   在 init.el 中进行狩猎,而不是更广泛    org-init.el 。第二个文件的名称( org-init.el )将有所不同,   但要点是一样的。但不要害怕!有一个简单的解决方案:

  1. If you have any code above the call to org-babel-tangle-file, copy that to the top of org-init.el (or whatever is the name of your tangled file). This includes that (require 'org) over there.
  2. Invoke M-x bug-hunter-file (instead of bug-hunter-init-file). It will ask you which file to debug, and you need to point it to your tangled output file org-init.el.




相关问题推荐