abo-abo / lispy

Short and sweet LISP editing
http://oremacs.com/lispy/
1.2k stars 132 forks source link

Debugging elisp with `lispy-eval` #543

Open haqle314 opened 4 years ago

haqle314 commented 4 years ago

I'm just wondering if the backtrace produced by lispy-eval can be improved.

For example, evaluating the expression (+ 1 ""), with debug-on-error bound to t, produces the following backtraces:

Evaluated with lispy-eval

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p "")
  signal(wrong-type-argument (number-or-marker-p ""))
  lispy--eval-elisp("(+ 1 \"\")")
  lispy--eval(nil)
  lispy-eval(1)
  funcall-interactively(lispy-eval 1)
  call-interactively(lispy-eval)
  (cond ((lispy--edebug-commandp) (call-interactively lispy--edebug-command)) ((and (bound-and-true-p macrostep-mode) (setq lispy--compat-cmd (lookup-key macrostep-keymap (this-command-keys)))) (call-interactively lispy--compat-cmd)) ((and (bound-and-true-p magit-blame-mode) (setq lispy--compat-cmd (lookup-key magit-blame-mode-map (this-command-keys)))) (call-interactively lispy--compat-cmd)) ((region-active-p) (call-interactively 'lispy-eval)) ((lispy--in-string-or-comment-p) (setq this-command 'self-insert-command) (call-interactively 'self-insert-command)) ((or (lispy-left-p) (lispy-right-p) (and (lispy-bolp) (or (looking-at lispy-outline-header) (looking-at lispy-outline)))) (call-interactively 'lispy-eval)) (t (setq this-command 'self-insert-command) (call-interactively 'self-insert-command)))
  special-lispy-eval()
  funcall-interactively(special-lispy-eval)
  call-interactively(special-lispy-eval nil nil)
  command-execute(special-lispy-eval)

Evaluated with eval-expression

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p "")
  +(1 "")
  eval((+ 1 "") t)
  eval-expression((+ 1 "") nil nil 127)
  funcall-interactively(eval-expression (+ 1 "") nil nil 127)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

When evaluated with lispy-eval, you can still see the error. But unlike eval-expression, you can't see that the error was signaled by +. In a more complicated expression, this makes the backtrace pretty useless.