5 When your InitFile has a bug, or when you load external files that cause |
5 When your InitFile has a bug, or when you load external files that cause |
6 errors, the bug is often hard to find, because the Emacs Lisp reader does not |
6 errors, the bug is often hard to find, because the Emacs Lisp reader does not |
7 know about line numbers and files – it just knows an error happened, and |
7 know about line numbers and files – it just knows an error happened, and |
8 that’s it. |
8 that’s it. |
9 |
9 |
10 You have several options: |
10 ** Binary Search. |
11 |
11 |
12 * Binary Search – select half of the file in a region, and M-x eval-region. |
12 Select half of the file in a region, and M-x eval-region. Depending on whether |
13 Depending on whether that causes the error or not, split this half or the |
13 that causes the error or not, split this half or the other half again, and |
14 other half again, and repeat. |
14 repeat. |
15 |
15 |
16 * Simplified Binary Search – add (error “No error until here”) in the |
16 ** Elisp. |
17 middle of your file. If you get the error “No error until here” when |
|
18 reloading the file, move the expression towards the back of the file, |
|
19 otherwise towards the front of the file. |
|
20 |
17 |
21 * Use a keyboard macro that moves forward one expression (sexp) and |
18 - Use a keyboard macro that moves forward one expression (sexp) and evaluates |
22 evaluates it. |
19 it. |
|
20 - Try C-x check-parens. |
|
21 - Set (setq debug-on-error t). |
23 |
22 |
24 * Try the command line switch --debug-init. |
23 ** CLI. |
25 |
24 |
26 * Should n’t (setq debug-on-error t) help? |
25 $ emacs --no-init-file --no-site-file --debug-init |
27 |
26 |
28 * Try check-parens. |
27 ** Simplified Binary Search. |
|
28 |
|
29 Add (error “No error until here”) in the middle of your file. If you get the |
|
30 error “No error until here” when reloading the file, move the expression |
|
31 towards the back of the file, otherwise towards the front of the file. |
29 |
32 |
30 * Using edebug. |
33 * Using edebug. |
31 |
34 |
32 The main entry point is ‘M-x edebug-defun’ (also on ‘C-u C-M-x’). Use it |
35 The main entry point is ‘M-x edebug-defun’ (also on ‘C-u C-M-x’). Use it |
33 instead of `C-x C-e’ or ‘C-M-x’ to evaluate a ‘defun’ and instrument it for |
36 instead of `C-x C-e’ or ‘C-M-x’ to evaluate a ‘defun’ and instrument it for |