emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master e07cf69: Change Edebug's behavior-changing hooks to


From: Gemini Lasswell
Subject: [Emacs-diffs] master e07cf69: Change Edebug's behavior-changing hooks to variables
Date: Sun, 22 Oct 2017 15:03:10 -0400 (EDT)

branch: master
commit e07cf691decf01dc3cbe19a413708570b95bc41b
Author: Gemini Lasswell <address@hidden>
Commit: Gemini Lasswell <address@hidden>

    Change Edebug's behavior-changing hooks to variables
    
    * lisp/emacs-lisp/edebug.el (edebug-after-instrumentation-functions)
    (edebug-new-definition-functions): Deleted.
    (edebug-after-instrumentation-function)
    (edebug-new-definition-function): New variables.
    (edebug-behavior-alist): Update docstring.
    (edebug-read-and-maybe-wrap-form1, edebug-make-form-wrapper): Use new
    variables.
    
    * lisp/emacs-lisp/testcover.el (testcover-start)
    (testcover-this-defun): Use `edebug-after-instrumentation-function' and
    `edebug-new-definition-function'.
    (testcover-after-instrumentation): Return passed form.
    (testcover-init-definition): Use argument instead of `edebug-def-name'.
    
    * doc/lispref/edebug.texi (Edebug Options): Replace descriptions of
    `edebug-after-instrumentation-functions' and 
`edebug-new-definition-functions'
    with `edebug-after-instrumentation-function' and
    `edebug-new-definition-function'.
---
 doc/lispref/edebug.texi      | 23 +++++++++--------------
 etc/NEWS                     |  6 +++---
 lisp/emacs-lisp/edebug.el    | 37 +++++++++++++++++++------------------
 lisp/emacs-lisp/testcover.el | 23 +++++++++--------------
 4 files changed, 40 insertions(+), 49 deletions(-)

diff --git a/doc/lispref/edebug.texi b/doc/lispref/edebug.texi
index 94d6148..651bfac 100644
--- a/doc/lispref/edebug.texi
+++ b/doc/lispref/edebug.texi
@@ -1705,23 +1705,18 @@ instrumented definition to the key of the new entry, 
and Edebug will
 call the new functions in place of its own for that definition.
 @end defopt
 
address@hidden edebug-new-definition-functions
-An abnormal hook run by Edebug after it wraps the body of a definition
-or closure.  After Edebug has initialized its own data, each function
address@hidden edebug-new-definition-function
+A function run by Edebug after it wraps the body of a definition
+or closure.  After Edebug has initialized its own data, this function
 is called with one argument, the symbol associated with the
 definition, which may be the actual symbol defined or one generated by
-Edebug. This hook may be used to set the @code{edebug-behavior}
+Edebug.  This function may be used to set the @code{edebug-behavior}
 symbol property of each definition instrumented by Edebug.
-
-By default @code{edebug-new-definition-functions} contains
address@hidden which prints a message each time a
-definition is instrumented.  If you are instrumenting a lot of code
-and find the messages excessive, remove
address@hidden
 @end defopt
 
address@hidden edebug-after-instrumentation-functions
-An abnormal hook run by Edebug after it instruments a form.
-Each function is called with one argument, a form which has
-just been instrumented by Edebug.
address@hidden edebug-after-instrumentation-function
+To inspect or modify Edebug's instrumentation before it is used, set
+this variable to a function which takes one argument, an instrumented
+top-level form, and returns either the same or a replacement form,
+which Edebug will then use as the final result of instrumentation.
 @end defopt
diff --git a/etc/NEWS b/etc/NEWS
index 267d988..5c6c0b7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -71,9 +71,9 @@ directories in the destination.
 
 +++
 *** The runtime behavior of Edebug's instrumentation can be changed
-using the new variable 'edebug-behavior-alist' and the new abnormal
-hooks 'edebug-after-instrumentation-functions' and
-'edebug-new-definition-functions'. Edebug's behavior can be changed
+using the new variables 'edebug-behavior-alist',
+'edebug-after-instrumentation-function' and
+'edebug-new-definition-function'. Edebug's behavior can be changed
 globally or for individual definitions.
 
 ** Enhanced xterm support
diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index 77523de..0e8f77e 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -1065,16 +1065,17 @@ circular objects.  Let `read' read everything else."
 (defvar edebug-error-point nil)
 (defvar edebug-best-error nil)
 
-;; Hooks which may be used to extend Edebug's functionality.  See
+;; Functions which may be used to extend Edebug's functionality.  See
 ;; Testcover for an example.
-(defvar edebug-after-instrumentation-functions nil
-  "Abnormal hook run on code after instrumentation for debugging.
-Each function is called with one argument, a form which has just
-been instrumented for Edebugging.")
-
-(defvar edebug-new-definition-functions '(edebug-announce-definition)
-  "Abnormal hook run after Edebug wraps a new definition.
-After Edebug has initialized its own data, each hook function is
+(defvar edebug-after-instrumentation-function #'identity
+  "Function to run on code after instrumentation for debugging.
+The function is called with one argument, a FORM which has just
+been instrumented for Edebugging, and it should return either FORM
+or a replacement form to use in its place.")
+
+(defvar edebug-new-definition-function #'edebug-new-definition
+  "Function to call after Edebug wraps a new definition.
+After Edebug has initialized its own data, this function is
 called with one argument, the symbol associated with the
 definition, which may be the actual symbol defined or one
 generated by Edebug.")
@@ -1087,9 +1088,9 @@ Each definition instrumented by Edebug will have a
 the instrumented code is running, Edebug will look here for the
 implementations of `edebug-enter', `edebug-before', and
 `edebug-after'.  Edebug's instrumentation may be used for a new
-purpose by adding an entry to this alist and a hook to
-`edebug-new-definition-functions' which sets `edebug-behavior'
-for the definition.")
+purpose by adding an entry to this alist, and setting
+`edebug-new-definition-function' to a function which sets
+`edebug-behavior' for the definition.")
 
 (defun edebug-read-and-maybe-wrap-form ()
   ;; Read a form and wrap it with edebug calls, if the conditions are right.
@@ -1189,8 +1190,7 @@ for the definition.")
 
             ;; Not a defining form, and not edebugging.
             (t (edebug-read-sexp)))))
-      (run-hook-with-args 'edebug-after-instrumentation-functions result)
-      result)))
+      (funcall edebug-after-instrumentation-function result))))
 
 (defvar edebug-def-args) ; args of defining form.
 (defvar edebug-def-interactive) ; is it an emacs interactive function?
@@ -1383,13 +1383,14 @@ expressions; a `progn' form will be returned enclosing 
these forms."
                 edebug-offset-list
                 edebug-top-window-data
                 ))
-      (put edebug-def-name 'edebug-behavior 'edebug)
-      (run-hook-with-args 'edebug-new-definition-functions edebug-def-name)
+
+      (funcall edebug-new-definition-function edebug-def-name)
       result
       )))
 
-(defun edebug-announce-definition (def-name)
-  "Announce Edebug's processing of DEF-NAME."
+(defun edebug-new-definition (def-name)
+  "Set up DEF-NAME to use Edebug's instrumentation functions."
+  (put def-name 'edebug-behavior 'edebug)
   (message "Edebug: %s" def-name))
 
 
diff --git a/lisp/emacs-lisp/testcover.el b/lisp/emacs-lisp/testcover.el
index 3628968..797cc68 100644
--- a/lisp/emacs-lisp/testcover.el
+++ b/lisp/emacs-lisp/testcover.el
@@ -193,12 +193,9 @@ If BYTE-COMPILE is non-nil, byte compile each function 
after instrumenting."
           testcover-module-constants nil
           testcover-module-1value-functions nil
           testcover-module-potentially-1value-functions nil)
-    (cl-letf ((edebug-all-defs t)
-              (edebug-after-instrumentation-functions)
-              (edebug-new-definition-functions))
-      (add-hook 'edebug-after-instrumentation-functions 
'testcover-after-instrumentation)
-      (add-hook 'edebug-new-definition-functions 'testcover-init-definition)
-      (remove-hook 'edebug-new-definition-functions 
'edebug-announce-definition)
+    (let ((edebug-all-defs t)
+          (edebug-after-instrumentation-function 
#'testcover-after-instrumentation)
+          (edebug-new-definition-function #'testcover-init-definition))
       (eval-buffer buf)))
   (when byte-compile
     (dolist (x (reverse edebug-form-data))
@@ -210,12 +207,9 @@ If BYTE-COMPILE is non-nil, byte compile each function 
after instrumenting."
 (defun testcover-this-defun ()
   "Start coverage on function under point."
   (interactive)
-  (cl-letf ((edebug-all-defs t)
-            (edebug-after-instrumentation-functions)
-            (edebug-new-definition-functions))
-    (add-hook 'edebug-after-instrumentation-functions 
'testcover-after-instrumentation)
-    (add-hook 'edebug-new-definition-functions 'testcover-init-definition)
-    (remove-hook 'edebug-new-definition-functions 'edebug-announce-definition)
+  (let ((edebug-all-defs t)
+        (edebug-after-instrumentation-function 
#'testcover-after-instrumentation)
+        (edebug-new-definition-function #'testcover-init-definition))
     (eval-defun nil)))
 
 (defun testcover-end (filename)
@@ -231,11 +225,12 @@ If BYTE-COMPILE is non-nil, byte compile each function 
after instrumenting."
 
 (defun testcover-after-instrumentation (form)
   "Analyze FORM for code coverage."
-  (testcover-analyze-coverage form))
+  (testcover-analyze-coverage form)
+  form)
 
 (defun testcover-init-definition (sym)
   "Mark SYM as under test coverage."
-  (message "Testcover: %s" edebug-def-name)
+  (message "Testcover: %s" sym)
   (put sym 'edebug-behavior 'testcover))
 
 (defun testcover-enter (func _args body)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]