all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Debugging functions with lexical-binding
@ 2011-05-28 13:50 Helmut Eller
  2011-05-30  4:13 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Helmut Eller @ 2011-05-28 13:50 UTC (permalink / raw)
  To: emacs-devel

What are the commands to inspect local variables of lexical functions?

E.g. if we have code like

;; -*- lexical-binding: t -*- 
(defun foo (x y) (debug nil x y) y)

and call (foo 1 2) we end up in the debugger.  Usually one can just type
"e y" to see the value of y, but with lexical binding that doesn't work.
So what is the replacement?

[BTW, the debugger now enters recursively if an error occurs during
debugger-eval-expression.  That's almost certainly undesirable,
especially as there is no easy way to jump out of the recursive
evaluation.  Pressing C-M-c reduces one level of recursive edit but puts
the *Backtrace* buffer in fundamental-mode which is IMO also wrong.]

Helmut




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Debugging functions with lexical-binding
  2011-05-28 13:50 Debugging functions with lexical-binding Helmut Eller
@ 2011-05-30  4:13 ` Stefan Monnier
  2011-05-31  7:11   ` Helmut Eller
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2011-05-30  4:13 UTC (permalink / raw)
  To: Helmut Eller; +Cc: emacs-devel

> What are the commands to inspect local variables of lexical functions?

M-x esp RET

> So what is the replacement?

Currently the only replacement is in cconv.el near the beginning of the file:

;; TODO: (not just for cconv but also for the lexbind changes in general)
;; - let (e)debug find the value of lexical variables from the stack.

> [BTW, the debugger now enters recursively if an error occurs during
> debugger-eval-expression.

AFAIK there's been no change in this area for as far back as I remember.

> That's almost certainly undesirable, especially as there is no easy
> way to jump out of the recursive evaluation.

There was no such way, indeed, but as you note below there now is.

> Pressing C-M-c reduces one level of recursive edit but puts the
> *Backtrace* buffer in fundamental-mode which is IMO also wrong.]

Yup, the *Backtrace* buffer's content and major-mode are not properly
saved&restored upon entry to and exit from the debugger.  Patch welcome,


        Stefan



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Debugging functions with lexical-binding
  2011-05-30  4:13 ` Stefan Monnier
@ 2011-05-31  7:11   ` Helmut Eller
  2011-05-31 15:25     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Helmut Eller @ 2011-05-31  7:11 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

* Stefan Monnier [2011-05-30 04:13] writes:

>> What are the commands to inspect local variables of lexical functions?
>
> M-x esp RET

That's too cryptic for me.  What do you mean?

>> Pressing C-M-c reduces one level of recursive edit but puts the
>> *Backtrace* buffer in fundamental-mode which is IMO also wrong.]
>
> Yup, the *Backtrace* buffer's content and major-mode are not properly
> saved&restored upon entry to and exit from the debugger.  Patch welcome,

Below is a simple patch.  It only restores the content but not buffer
local variables.

Helmut


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: debug.patch --]
[-- Type: text/x-diff, Size: 1688 bytes --]

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2011-05-30 12:23:56 +0000
+++ lisp/ChangeLog	2011-05-31 07:08:41 +0000
@@ -1,3 +1,11 @@
+2011-05-31  Helmut Eller  <eller.helmut@gmail.com>
+
+	Try to deal with recursive debuggers and C-M-c.
+
+	* debug.el (debug): Restore the previous content of the
+	*Backtrace* buffer when we exit with C-M-c.  Restoring buffer
+	local variables would be annoyingly difficult.
+
 2011-05-30  Leo Liu  <sdl.web@gmail.com>
 
 	* net/rcirc.el (rcirc-debug-buffer): Use visible buffer name.

=== modified file 'lisp/emacs-lisp/debug.el'
--- lisp/emacs-lisp/debug.el	2011-03-20 03:53:45 +0000
+++ lisp/emacs-lisp/debug.el	2011-05-31 06:45:28 +0000
@@ -120,6 +120,7 @@
 	  (debug-on-quit nil)
 	  (debugger-buffer (get-buffer-create "*Backtrace*"))
 	  (debugger-old-buffer (current-buffer))
+	  (debugger-previous-contents nil)
 	  (debugger-step-after-exit nil)
           (debugger-will-be-back nil)
 	  ;; Don't keep reading from an executing kbd macro!
@@ -181,6 +182,7 @@
 		  (when (eq 'lambda (car-safe (cadr (backtrace-frame 4))))
 		    (backtrace-debug 5 t)))
                 (pop-to-buffer debugger-buffer)
+		(setq debugger-previous-contents (buffer-string))
 		(debugger-mode)
 		(debugger-setup-buffer debugger-args)
 		(when noninteractive
@@ -215,7 +217,7 @@
 	      ;; erase it (and maybe hide it) but keep it alive.
 	      (with-current-buffer debugger-buffer
 		(erase-buffer)
-		(fundamental-mode)
+		(insert debugger-previous-contents)
 		(with-selected-window (get-buffer-window debugger-buffer 0)
                   (when (and (window-dedicated-p (selected-window))
                              (not debugger-will-be-back))


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Debugging functions with lexical-binding
  2011-05-31  7:11   ` Helmut Eller
@ 2011-05-31 15:25     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2011-05-31 15:25 UTC (permalink / raw)
  To: Helmut Eller; +Cc: emacs-devel

>>> What are the commands to inspect local variables of lexical functions?
>> M-x esp RET
> That's too cryptic for me.  What do you mean?

ESP = Extra Sensorial Perception, also known as psychic, mind-reader, ...
I.e. it was just a bad joke.

>>> Pressing C-M-c reduces one level of recursive edit but puts the
>>> *Backtrace* buffer in fundamental-mode which is IMO also wrong.]
>> Yup, the *Backtrace* buffer's content and major-mode are not properly
>> saved&restored upon entry to and exit from the debugger.  Patch welcome,
> Below is a simple patch.  It only restores the content but not buffer
> local variables.

Thanks.  I've installed it into trunk.  I've also added an additional
patch to save&restore the major mode.


        Stefan



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-31 15:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-28 13:50 Debugging functions with lexical-binding Helmut Eller
2011-05-30  4:13 ` Stefan Monnier
2011-05-31  7:11   ` Helmut Eller
2011-05-31 15:25     ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.