]> code.delx.au - gnu-emacs-elpa/blob - packages/bug-hunter/README.org
78c622e7e7d41057a950e42330bab989b1473fb6
[gnu-emacs-elpa] / packages / bug-hunter / README.org
1 #+OPTIONS: toc:nil num:nil
2 #+TITLE: [[file:hunter.png]] The Bug Hunter [[https://travis-ci.org/Malabarba/elisp-bug-hunter][file:https://travis-ci.org/Malabarba/elisp-bug-hunter.svg?branch=master]]
3
4
5 The Bug Hunter is an Emacs library that finds the source of an error
6 or unexpected behavior inside an elisp configuration file (typically
7 ~init.el~ or ~.emacs~).
8
9 [[file:hunter-screencast.gif]]
10
11 * Usage Examples
12
13 ** Automated error hunting
14 If your Emacs init file signals an error during startup, but you don’t
15 know why, simply issue
16 #+BEGIN_SRC text
17 M-x bug-hunter-init-file RET e
18 #+END_SRC
19 and The Bug Hunter will find it for you. Note that your ~init.el~
20 (or ~.emacs~) must be idempotent for this to work.
21
22 ** Interactive hunt
23
24 If Emacs starts up without errors but something is not working as it
25 should, invoke the same command, but choose the interactive option:
26 #+BEGIN_SRC text
27 M-x bug-hunter-init-file RET i
28 #+END_SRC
29 The Bug Hunter will start a separate Emacs instance several times, and
30 then it will ask you each time whether that instance presented the
31 problem you have. After doing this about 5--12 times, you’ll be given
32 the results.
33
34 ** Assertion hunt
35
36 The Bug Hunter can also find your issue based on an assertion.
37 Essentially, if you can write a code snippet that returns non-nil when
38 it detects the issue, just provide this snippet as the assertion and
39 the Bug Hunter will do the rest.
40
41 For example, let’s say there’s something in your init file that’s
42 loading the ~cl~ library, and you don’t want that. You /know/ you’re
43 not loading it yourself, but how can you figure out which external
44 package is responsible for this outrage?
45
46 #+BEGIN_SRC text
47 M-x bug-hunter-init-file RET a (featurep 'cl) RET
48 #+END_SRC
49
50 *That’s it!* You’ll be given a nice buffer reporting the results:
51
52 [[file:cl-example.png]]
53 - Are you getting obscure errors when trying to open /“.tex”/ files?
54 - Don’t despair! Just use ~(find-file "dummy.tex")~ as the assertion.
55 - Did ~ox-html~ stop working due to some arcane misconfiguration?
56 - Just write an assertion that does an export and checks the result.
57 - Does some random command suddenly bind itself to ~C-j~ and you can’t figure out why?
58 - ~(eq (key-binding "\n") 'unwanted-command)~ is the assertion for you!
59
60 Finally, you can also use ~bug-hunter-file~ to hunt in other files.
61
62 * Installation
63 The Bug Hunter is available from [[https://elpa.gnu.org/packages/bug-hunter.html][GNU Elpa]] to all Emacs versions since
64 ~24.1~. To install, just issue
65
66 #+BEGIN_SRC text
67 M-x package-install RET bug-hunter
68 #+END_SRC
69
70 * init.org and other literate-style configs
71
72 Some people (me included) like to organize their init files by
73 writting it in ~org-mode~ instead of Emacs-Lisp. This usually involves
74 adding something like this to ~init.el~,
75 #+BEGIN_SRC emacs-lisp
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77 ;;; Maybe some code up here ;;;
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79 (require 'org)
80 (org-babel-tangle-file "~/.emacs.d/org-init.org"
81 "~/.emacs.d/org-init.el")
82 (load "~/.emacs.d/org-init.el")
83 #+END_SRC
84
85 At first, this makes the Bug-Hunter essentially useless, for it will
86 do the hunting in ~init.el~ instead of the much more extensive
87 ~org-init.el~. The name of the second file (~org-init.el~) will vary,
88 but the point is the same. But fear not! There’s a simple solution:
89
90 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.
91 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~.