From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Neil Jerram" Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: [PATCH] Single stepping through code from Emacs Date: Sat, 12 Jul 2008 20:15:36 +0100 Message-ID: <49dd78620807121215p11b1b1a1l6d72e50f7334a7ff@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1215890150 3330 80.91.229.12 (12 Jul 2008 19:15:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 12 Jul 2008 19:15:50 +0000 (UTC) To: guile-devel , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Jul 12 21:16:37 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KHkaD-00043q-0a for guile-user@m.gmane.org; Sat, 12 Jul 2008 21:16:37 +0200 Original-Received: from localhost ([127.0.0.1]:35276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KHkZK-0005kW-Qc for guile-user@m.gmane.org; Sat, 12 Jul 2008 15:15:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KHkZH-0005jW-1N for guile-user@gnu.org; Sat, 12 Jul 2008 15:15:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KHkZG-0005iO-24 for guile-user@gnu.org; Sat, 12 Jul 2008 15:15:38 -0400 Original-Received: from [199.232.76.173] (port=45151 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KHkZF-0005iA-Ko for guile-user@gnu.org; Sat, 12 Jul 2008 15:15:37 -0400 Original-Received: from wa-out-1112.google.com ([209.85.146.178]:20140) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KHkZF-0003xv-2J for guile-user@gnu.org; Sat, 12 Jul 2008 15:15:37 -0400 Original-Received: by wa-out-1112.google.com with SMTP id m34so2608422wag.10 for ; Sat, 12 Jul 2008 12:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=YV4LiNgmTWtlwvQM6SXDH5Xz88YVrbgaxE7ou2NnWiI=; b=HB2KxdlRgIr86Oxdz3B3NhGMPDvTb0JZ3Su1k+7Sy6uZQdIfa1XxNLzclL4tBnKy2F hJ3ACNNAd/q9sxZBFln6eyelGKhuRmtCpA3wnqZ7leD4v7tAJ2eo7Rt6we21gxJwKpld Is3jD6m9kZKV3pMB6p/u7TsoMp42SMpMC2p1I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=E8K4BNwIjPTn7sN0wu3PHl3EGQ8i0bCa9chSz95E6MlfjDRWOfmqnwn9iIi4PXxgkg A+fDiyUKPH54KtBbD5ZOC2gjit8Pb2m4Yxs6/XKe2qYAd3lCLSmZZrae8mX3CxDWkNxg GzR03+0mGx1lkClah7gvuAz0ELIDnJ6XP2S/Y= Original-Received: by 10.115.91.2 with SMTP id t2mr15821380wal.62.1215890136079; Sat, 12 Jul 2008 12:15:36 -0700 (PDT) Original-Received: by 10.114.197.8 with HTTP; Sat, 12 Jul 2008 12:15:36 -0700 (PDT) Content-Disposition: inline X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6646 gmane.lisp.guile.devel:7372 Archived-At: Here is a minor enhancement to Guile's Emacs support. I'll commit in a few days; let me know if you have any comments before that. Neil When you use GDS to evaluate Scheme code from Emacs, you can now use `C-u' to indicate that you want to single step through that code. See `Evaluating Scheme Code' in the manual for more details. * scheme-using.texi (Evaluating Scheme Code): Document use of `C-u' prefix with evaluation commands. * gds-scheme.el (gds-eval-region, gds-eval-expression) (gds-eval-defun, gds-eval-last-sexp): Support `C-u' prefix, meaning that user wants to single step through the code. * gds-client.scm (handle-nondebug-protocol): Add support for setting a trap on code that is about to be evaluated. --- NEWS | 6 ++++++ doc/ref/scheme-using.texi | 8 ++++++++ emacs/gds-scheme.el | 28 +++++++++++++++------------- ice-9/gds-client.scm | 10 ++++++++-- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 2c93494..b12cbbc 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,12 @@ Changes in 1.8.6 (since 1.8.5) ** New convenience function `scm_c_symbol_length ()' +** Single stepping through code from Emacs + +When you use GDS to evaluate Scheme code from Emacs, you can now use +`C-u' to indicate that you want to single step through that code. See +`Evaluating Scheme Code' in the manual for more details. + * Bugs fixed ** Internal `scm_i_' functions now have "hidden" linkage with GCC/ELF diff --git a/doc/ref/scheme-using.texi b/doc/ref/scheme-using.texi index 59cc0e6..a8a2568 100644 --- a/doc/ref/scheme-using.texi +++ b/doc/ref/scheme-using.texi @@ -842,6 +842,14 @@ region contains a balanced expression, or try to expand the region so that it does; it uses the region exactly as it is. @end table +If you type @kbd{C-u} before one of these commands, GDS will +immediately pop up a Scheme stack buffer, showing the requested +evaluation, so that you can single step through it. (This is achieved +by setting a @code{} trap at the start of the requested +evaluation; see @ref{Source Traps} for more on how those work.) The +Scheme stack display, and the options for continuing through the code, +are described in the next two sections. + @node Displaying the Scheme Stack @subsection Displaying the Scheme Stack diff --git a/emacs/gds-scheme.el b/emacs/gds-scheme.el index bc3a20b..ed3874f 100755 --- a/emacs/gds-scheme.el +++ b/emacs/gds-scheme.el @@ -279,7 +279,7 @@ region's code." (setq line (count-lines (point-min) (point)))) (cons line column))) -(defun gds-eval-region (start end) +(defun gds-eval-region (start end &optional debugp) "Evaluate the current region." (interactive "r") (or gds-client @@ -289,24 +289,26 @@ region's code." (port-name (gds-port-name start end)) (lc (gds-line-and-column start))) (let ((code (buffer-substring-no-properties start end))) - (gds-send (format "eval (region . %S) %s %S %d %d %S" + (gds-send (format "eval (region . %S) %s %S %d %d %S %s" (gds-abbreviated code) (if module (prin1-to-string module) "#f") port-name (car lc) (cdr lc) - code) + code + (if debugp '(debug) '(none))) gds-client)))) -(defun gds-eval-expression (expr &optional correlator) +(defun gds-eval-expression (expr &optional correlator debugp) "Evaluate the supplied EXPR (a string)." - (interactive "sEvaluate expression: \nP") + (interactive "sEvaluate expression: \ni\nP") (or gds-client (gds-auto-associate-buffer) (call-interactively 'gds-associate-buffer)) (set-text-properties 0 (length expr) nil expr) - (gds-send (format "eval (%S . %S) #f \"Emacs expression\" 0 0 %S" + (gds-send (format "eval (%S . %S) #f \"Emacs expression\" 0 0 %S %s" (or correlator 'expression) (gds-abbreviated expr) - expr) + expr + (if debugp '(debug) '(none))) gds-client)) (defconst gds-abbreviated-length 35) @@ -325,19 +327,19 @@ region's code." (concat (substring code 0 (- gds-abbreviated-length 3)) "...") code)) -(defun gds-eval-defun () +(defun gds-eval-defun (&optional debugp) "Evaluate the defun (top-level form) at point." - (interactive) + (interactive "P") (save-excursion (end-of-defun) (let ((end (point))) (beginning-of-defun) - (gds-eval-region (point) end)))) + (gds-eval-region (point) end debugp)))) -(defun gds-eval-last-sexp () +(defun gds-eval-last-sexp (&optional debugp) "Evaluate the sexp before point." - (interactive) - (gds-eval-region (save-excursion (backward-sexp) (point)) (point))) + (interactive "P") + (gds-eval-region (save-excursion (backward-sexp) (point)) (point) debugp)) ;;;; Help. diff --git a/ice-9/gds-client.scm b/ice-9/gds-client.scm index 4db4f82..960015a 100755 --- a/ice-9/gds-client.scm +++ b/ice-9/gds-client.scm @@ -352,7 +352,7 @@ Thanks!\n\n" ((eval) (set! last-lazy-trap-context #f) - (apply (lambda (correlator module port-name line column code) + (apply (lambda (correlator module port-name line column code flags) (with-input-from-string code (lambda () (set-port-filename! (current-input-port) port-name) @@ -380,7 +380,13 @@ Thanks!\n\n" (+ n 1)))) ;; Another complete expression read; add ;; it to the list. - (loop (cons x exprs) (read))))) + (begin + (if (and (pair? x) + (memq 'debug flags)) + (install-trap (make + #:expression x + #:behaviour gds-debug-trap))) + (loop (cons x exprs) (read)))))) (lambda (key . args) (write-form `(eval-results ,correlator -- 1.4.4.4