all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: 37540@debbugs.gnu.org
Subject: bug#37540: [PATCH] Wishlist: Allow edebug-specs to signal arbitrary error strings on syntax errors in macros.
Date: Sat, 28 Sep 2019 12:30:34 +0000	[thread overview]
Message-ID: <20190928123034.GA9181@ACM> (raw)

Hello, Emacs.

I think it would be a good idea to allow edebug-specs to signal syntax
errors with arbitrary strings, like:

     ("`" &error "Too deeply nested backquotes")

.  The motivation is to complete the correction in bug #31090, which
fixed edebug's handling of nested backquotes in macros.

The problem with that fix is it doesn't handle triply nested backquotes
(without , or ,@ between them) at all well.  There is a fundamental
structure clash between backquote's nesting and Lisp's nesting of
parentheses.

The pragmatic solution is simply to ban triply nested backquotes (i.e.
three `s without ,s or ,@s between them) from edebug instrumentation.
However, this really needs a mechanism to output an error message
string.  There is currently no such mecahanism in edebug.

The following patch implements an &error mechanism in edebug.el, and
illustrates its use in the case which motivated it.

Any objections to committing this patch (together with the needed
amendments to documentation and NEWS)?




diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el
index 717026995a..73257f1568 100644
--- a/lisp/emacs-lisp/edebug.el
+++ b/lisp/emacs-lisp/edebug.el
@@ -1683,6 +1683,7 @@ edebug-match-specs
                 (cl-macrolet-body . edebug-match-cl-macrolet-body)
 		(&not . edebug-match-&not)
 		(&key . edebug-match-&key)
+		(&error . edebug-match-&error)
 		(place . edebug-match-place)
 		(gate . edebug-match-gate)
 		;;   (nil . edebug-match-nil)  not this one - special case it.
@@ -1816,6 +1817,14 @@ edebug-match-&key
                            (car (cdr pair))))
 		 specs))))
 
+(defun edebug-match-&error (cursor specs)
+  ;; Signal an error, using the following string in the spec as argument.
+  (setq edebug-gate t)
+  (let* ((error-string (car specs)))
+    (if (stringp error-string)
+        (edebug-no-match cursor error-string)
+      (error "String expected after &error in edebug-spec"))))
+
 
 (defun edebug-match-gate (_cursor)
   ;; Simply set the gate to prevent backtracking at this level.
@@ -2185,6 +2194,8 @@ backquote-form
 
 (def-edebug-spec nested-backquote-form
   (&or
+   ("`" &error "Triply nested backquotes (without commas \"between\" them) \
+are too difficult to instrument")
    ;; Allow instrumentation of any , or ,@ contained within the (\, ...) or
    ;; (\,@ ...) matched on the next line.
    ([&or "," ",@"] backquote-form)


-- 
Alan Mackenzie (Nuremberg, Germany).





             reply	other threads:[~2019-09-28 12:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-28 12:30 Alan Mackenzie [this message]
2019-09-28 13:42 ` bug#37540: [PATCH] Wishlist: Allow edebug-specs to signal arbitrary error strings on syntax errors in macros Eli Zaretskii
2019-09-28 20:34   ` Alan Mackenzie
2019-09-29  6:18     ` Eli Zaretskii
2020-01-16 14:47   ` Stefan Kangas
2020-01-16 20:57     ` Alan Mackenzie
2020-01-14 20:14 ` bug#37540: Bug 37540: " Alan Mackenzie
2020-01-17 22:01   ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190928123034.GA9181@ACM \
    --to=acm@muc.de \
    --cc=37540@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.