From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Sausner Newsgroups: gmane.emacs.bugs Subject: bug#52003: Unexpected advising behavior due to recursive implementation Date: Sat, 20 Nov 2021 16:13:32 +0000 Message-ID: <9f9a3c25-c473-ce45-9293-9754b8bcc113@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8656"; mail-complaints-to="usenet@ciao.gmane.io" To: 52003@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 20 18:05:37 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1moTny-0001w4-Jq for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 20 Nov 2021 18:05:34 +0100 Original-Received: from localhost ([::1]:50058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1moTnx-0006v5-EB for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 20 Nov 2021 12:05:33 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moTnT-0006rw-P4 for bug-gnu-emacs@gnu.org; Sat, 20 Nov 2021 12:05:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60282) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1moTnT-0000N7-GS for bug-gnu-emacs@gnu.org; Sat, 20 Nov 2021 12:05:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1moTnT-0003vr-BD for bug-gnu-emacs@gnu.org; Sat, 20 Nov 2021 12:05:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Daniel Sausner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 20 Nov 2021 17:05:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 52003 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.163742787115034 (code B ref -1); Sat, 20 Nov 2021 17:05:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Nov 2021 17:04:31 +0000 Original-Received: from localhost ([127.0.0.1]:43590 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1moTmx-0003uP-7M for submit@debbugs.gnu.org; Sat, 20 Nov 2021 12:04:31 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:59934) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1moSzn-0002ND-76 for submit@debbugs.gnu.org; Sat, 20 Nov 2021 11:13:46 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moSzj-0007jZ-Lh for bug-gnu-emacs@gnu.org; Sat, 20 Nov 2021 11:13:42 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:47759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moSzh-0002KQ-1M for bug-gnu-emacs@gnu.org; Sat, 20 Nov 2021 11:13:39 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 0B621240101 for ; Sat, 20 Nov 2021 17:13:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1637424814; bh=aqf2PTwggHzepUIPDVeBjwgg5Bt56LsPaxWoHpIy6OA=; h=To:From:Subject:Date:From; b=RwcFT+d+UwAFQEUk65bKcRpiGlOwIXs4nMIdkmU64Ycfy/nASei4iXKPyXb9bI/k7 l+fnA/rndeOHE1HxUOJ88D2qb+lusr8H8WSaU0CELf1sXuHM4usIJTYMKO63WO6TQY 0XvMNS37MIHF9AFHq0+f4VhTnc3JydjpbN73XEA8zKNPVrVH6H69B8H38XY1vNOe55 b4u6nI45++udcdlLFksNhK2mNFrzb2PkpOcSo/HfR8+uNvZcA703DlojZTGnw8cynk nJT6xpihvgaoLBQt5ksnCpSjtoHkeaQXtM3yYvagTGV5lNwUpcxnloUes1enGCSOiy Ejlv9RjE4pktA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4HxJVj3Vqrz9rxN for ; Sat, 20 Nov 2021 17:13:33 +0100 (CET) Content-Language: de-DE Received-SPF: pass client-ip=185.67.36.66; envelope-from=daniel.sausner@posteo.de; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 20 Nov 2021 12:04:30 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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.io gmane.emacs.bugs:220513 Archived-At: Hi, I stumbled [1] on an issue that seems to affect several functions [2] in lisp/emacs-lisp/lisp.el. For the sake of brevity I'll sketch it only for forward-sexp but the problematic code is effectively duplicated and was introduced with a commit [3] about one year ago. Here's the problem: Since the commit any advice on the function forward-sexp will effectively be called twice before the actual code runs in interactive mode. In non-interactive mode everthing is as expected however. The reason is the introduction of an error message if no forward/backward sexp is found. This is implemented in a way that the functions calls itself immediately again and scans for errors: (defun forward-sexp (&optional arg interactive)   "..."   (interactive "^p\nd")   (if interactive       (condition-case _           (forward-sexp arg nil)              <-- Recursion         (scan-error (user-error (if (> arg 0)                                     "No next sexp"                                   "No previous sexp"))))     (or arg (setq arg 1))     (if forward-sexp-function         (funcall forward-sexp-function arg)       (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))       (if (< arg 0) (backward-prefix-chars))))) In my (very) humble opinion that method of error catching was an unfortunate choice in that regard, that it makes the advising very counter-intuitive. I'm far from a lisp expert but my feeling is that the condition-case should only wrap the calls where things can actually go wrong. If there is interest, I'd be happy to provide a patch :-) Best regards, Daniel [1] https://github.com/emacs-evil/evil/issues/1541 [2] On a first glimpse at least: forward-sexp, forward-list, down-list, kill-sexp in that particular file. [3] Commit: df0f32f04850e7ed106a225addfa82f1b5b91f45 Author:     Mattias Engdegård AuthorDate: Fri Sep 18 12:49:33 2020 +0200 Commit:     Mattias Engdegård CommitDate: Wed Sep 23 16:31:18 2020 +0200 Don't signal scan-error when moving by sexp interactively