unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Efficient edebug-instrumented predicate?
@ 2021-10-04 14:18 Arthur Miller
  0 siblings, 0 replies; only message in thread
From: Arthur Miller @ 2021-10-04 14:18 UTC (permalink / raw)
  To: emacs-devel

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

I would like to have a reliable and efficient predicate to test whether a
function has been intrumented for edebug or not.

As I have seen in the code, there is no such currently. Suggested patch is
refactored out of 'edebug-remove-intrumentation', but it seems to be slightly
inneficiet since it will try to strip all edebug instrumentation from a
function.

Helpful.el includes a different test based on entries added by edebug wrapper,
but I am not sure how reliable it is to use it since it can change internally?

#+begin_src emacs-lisp
(defun helpful--edebug-p (sym)
  "Does function SYM have its definition patched by edebug?"
  (let ((fn-def (indirect-function sym)))
    ;; Edebug replaces function source code with a sexp that has
    ;; `edebug-enter', `edebug-after' etc interleaved. This means the
    ;; function is interpreted, so `indirect-function' returns a list.
    (when (and (consp fn-def) (consp (cdr fn-def)))
      (-let [fn-end (-last-item fn-def)]
        (and (consp fn-end)
#+end_src

Such predicate is useful for eventual tooling.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Edebug-Instrumented-Predicate.patch --]
[-- Type: text/x-patch, Size: 933 bytes --]

From e60011d5bf7273955ef0bad0c2550d06405bc59f Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
Date: Mon, 4 Oct 2021 15:18:37 +0200
Subject: [PATCH 1/2] Edebug Instrumented Predicate

* lisp/emacs-lisp/edebug.el (edebug-instrumented-p): New function.
---
 lisp/emacs-lisp/edebug.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index 4f3c05baa9..a37d37163e 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -4562,6 +4562,10 @@ edebug-remove-instrumentation
   (message "Removed edebug instrumentation from %s"
            (mapconcat #'symbol-name functions ", ")))
 
+(defun edebug-instrumented-p (function)
+  "Whether FUNCTION has been instrumented for edebug."
+  (and (get function 'edebug) (or (functionp function) (macrop function))
+       (edebug--unwrap*-symbol-function function)))
 \f
 ;;; Obsolete.
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-10-04 14:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 14:18 Efficient edebug-instrumented predicate? Arthur Miller

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).