From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#37540: Bug 37540: [PATCH] Wishlist: Allow edebug-specs to signal arbitrary error strings on syntax errors in macros. Date: Tue, 14 Jan 2020 20:14:13 +0000 Message-ID: <20200114201413.GA8534@ACM> References: <20190928123034.GA9181@ACM> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="28911"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) To: 37540@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jan 14 21:15:21 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1irSas-0006sM-R6 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 Jan 2020 21:15:18 +0100 Original-Received: from localhost ([::1]:45550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irSar-0006hM-Ly for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 Jan 2020 15:15:17 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44188) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irSag-0006hC-6U for bug-gnu-emacs@gnu.org; Tue, 14 Jan 2020 15:15:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irSac-0004ks-AZ for bug-gnu-emacs@gnu.org; Tue, 14 Jan 2020 15:15:06 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55805) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1irSac-0004ke-6n for bug-gnu-emacs@gnu.org; Tue, 14 Jan 2020 15:15:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1irSac-0005IV-1s for bug-gnu-emacs@gnu.org; Tue, 14 Jan 2020 15:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 14 Jan 2020 20:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37540 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 37540-submit@debbugs.gnu.org id=B37540.157903286420296 (code B ref 37540); Tue, 14 Jan 2020 20:15:02 +0000 Original-Received: (at 37540) by debbugs.gnu.org; 14 Jan 2020 20:14:24 +0000 Original-Received: from localhost ([127.0.0.1]:33542 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1irSZz-0005HI-TF for submit@debbugs.gnu.org; Tue, 14 Jan 2020 15:14:24 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:39008 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1irSZt-0005H5-EA for 37540@debbugs.gnu.org; Tue, 14 Jan 2020 15:14:21 -0500 Original-Received: (qmail 55323 invoked by uid 3782); 14 Jan 2020 20:14:16 -0000 Original-Received: from acm.muc.de (p4FE15B53.dip0.t-ipconnect.de [79.225.91.83]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 14 Jan 2020 21:14:13 +0100 Original-Received: (qmail 8748 invoked by uid 1000); 14 Jan 2020 20:14:13 -0000 Content-Disposition: inline In-Reply-To: <20190928123034.GA9181@ACM> X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:174578 Archived-At: Hello Emacs and Eli. On Sat, Sep 28, 2019 at 12:30:34 +0000, Alan Mackenzie wrote: > 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)? , to which Eli's response was to request me to wait until the emacs-27 release branch had been cut. That has now happened. So, are there any objections to me now committing this patch (current version below, including a documentation amendment), plus a NEWS item, to the master branch? diff --git a/doc/lispref/edebug.texi b/doc/lispref/edebug.texi index 8be8307c75..cfef5c12d1 100644 --- a/doc/lispref/edebug.texi +++ b/doc/lispref/edebug.texi @@ -1362,6 +1362,11 @@ Specification List is primarily used to generate more specific syntax error messages. See @ref{Backtracking}, for more details. Also see the @code{let} example. +@item &error +@code{&error} should be followed by a string, an error message, in the +edebug-spec; it aborts the instrumentation, displaying the message in +the minibuffer. + @item @var{other-symbol} @cindex indirect specifications Any other symbol in a specification list may be a predicate or an diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index b8d2fb5beb..a57c48f1f9 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -1714,6 +1714,7 @@ edebug-match-specs (cl-macrolet-body . edebug-match-cl-macrolet-body) (¬ . edebug-match-¬) (&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. @@ -1847,6 +1848,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. @@ -2216,6 +2225,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).