From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#62892: proposal to extend mark-sexp to go forward and backward on command Date: Thu, 27 Apr 2023 15:25:59 +0300 Message-ID: <83r0s5se94.fsf@gnu.org> References: <835y9jupgg.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31714"; mail-complaints-to="usenet@ciao.gmane.io" Cc: ruijie@netyu.xyz, monnier@iro.umontreal.ca, 62892@debbugs.gnu.org, mardani29@yahoo.es To: Zachary Kanfer , Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Apr 27 14:26:26 2023 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 1ps0he-00082Y-GC for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 27 Apr 2023 14:26:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ps0hK-000484-Od; Thu, 27 Apr 2023 08:26:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps0hH-0003yr-72 for bug-gnu-emacs@gnu.org; Thu, 27 Apr 2023 08:26:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ps0hG-0006ZP-QX for bug-gnu-emacs@gnu.org; Thu, 27 Apr 2023 08:26:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ps0hG-0007Di-5e for bug-gnu-emacs@gnu.org; Thu, 27 Apr 2023 08:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 27 Apr 2023 12:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62892 X-GNU-PR-Package: emacs Original-Received: via spool by 62892-submit@debbugs.gnu.org id=B62892.168259833927724 (code B ref 62892); Thu, 27 Apr 2023 12:26:02 +0000 Original-Received: (at 62892) by debbugs.gnu.org; 27 Apr 2023 12:25:39 +0000 Original-Received: from localhost ([127.0.0.1]:57699 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ps0gs-0007D5-Gk for submit@debbugs.gnu.org; Thu, 27 Apr 2023 08:25:39 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:60782) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ps0go-0007Cn-SX for 62892@debbugs.gnu.org; Thu, 27 Apr 2023 08:25:37 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps0gi-0006Om-EJ; Thu, 27 Apr 2023 08:25:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=nnkKydKFLjOqxm4EHYoIOZYRs3P3c8kUg9kRJSqCqoc=; b=Tv81g1KzbKe8 CvkXEbMyrWEreab4atgDSs9Oz4UBcKnyBg+CLO2u8o8Hn7dNrn1tNpjC5l8OPoWLOuJZXDI/MjskZ oolkZzWt9mxr+KMiC6tdlM4Rj3Mxprkv2hMiFWSnMM2sqxMojXkyCULP+0/K0p0msqQoGxegUJih3 83ceN9GkvmIhzOuUQ/QCr3zMvqwq+pQJljdfLCW/wvGRDdeAh/c1TJHVA7y4uKxxef3mQfNkG0A4j CvQV98WBm4x3EC74l8MNWO59ksGsc1YMmE9OEA/HMF1DM4C3mBCvh4eDd+rJIwSfO5izX3QuC3f/q nAjXMBMHpk30XZN3ugf4XQ==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ps0gh-0001ew-Ue; Thu, 27 Apr 2023 08:25:28 -0400 In-Reply-To: (message from Zachary Kanfer on Wed, 26 Apr 2023 22:37:58 -0400) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:260718 Archived-At: > From: Zachary Kanfer > Date: Wed, 26 Apr 2023 22:37:58 -0400 > Cc: mardani29@yahoo.es, ruijie@netyu.xyz, monnier@iro.umontreal.ca, > 62892@debbugs.gnu.org > > > > Worse still is the next part: > > > > > > > Interactively, if this command is repeated > > > > or (in Transient Mark mode) if the mark is active, > > > > it marks the next ARG sexps after the ones already marked. > > > > > > This says it marks sexps *after* the ones already marked. This is incorrect; if point is *after* mark, > and > > > mark is active, this function marks sexps *before* the ones already marked. > > > > I cannot reproduce this behavior, if I understand your description > > correctly. Please show a recipe, starting from "emacs -Q", to > > reproduce. > > Open Emacs with: > > emacs -Q --eval '(progn (insert "foo bar baz") (goto-char 8) (set-mark 5))' > > It will insert "foo bar baz", put point after "bar", and mark before "bar". Region contains "bar". > > Then when we run mark-sexp, we expect to mark some sexps "after the ones already marked". That's > what the docstring says. > > After running the command above to open emacs, press C-M-@ to run mark-sexp. We should see > sexps marked "after the ones already marked"; that is, we should see "bar baz" marked. But we don't. > Instead, we see that "foo bar" is highlighted. That is, we have marked sexps *before* the ones already > marked. > > > > The documentation for mark-sexp says: > > > > > > > Set mark ARG sexps from point. > > > > The place mark goes is the same place C-M- would > > > > move to with the same argument. > > > > > > This is correct but misleading. > > > > Please elaborate: how could it mislead? > > "The same argument" is the misleading part. If I call mark-sexp with no argument, sometimes that code > passes -1 to forward-sexp. So while I think I'm effectively passing a "1" to mark-sexp, instead -1 is > passed to forward-sexp. This is somewhat explained by the next part of the docstring, but not entirely. > Read with the rest of the docstring, it reinforces the belief that the command only marks sexps *after* > point. Thanks. Yes, we have a small mess on our hands here. Over the years, as features were added to this command, the doc string became more and more inaccurate. Moreover, the behavior itself is somewhat inconsistent: AFAIK this is the only command that accepts a numeric argument and yet behaves differently when invoked without an argument vs with "C-u 1". I tried to describe the behavior in the doc string as follows: (defun mark-sexp (&optional arg allow-extend) "Set mark ARG sexps from point or move mark one sexp. When called from Lisp with ALLOW-EXTEND ommitted or nil, mark is set ARG sexps from point; ARG defaults to 1. With ALLOW-EXTEND non-nil (interactively, with prefix argument), the place mark goes is the same place \\[forward-sexp] would move with the same value of ARG; if the mark is active, it moves ARG sexps from its current position, otherwise it is set ARG sexps from point; ARG defaults to 1. When invoked interactively without a prefix argument and no active region, mark moves one sexp forward. When invoked interactively without a prefix argument, and region is active, mark moves one sexp away of point (i.e., forward if mark is at or after point, back if mark is before point), thus extending the region by one sexp. Since the direction of region extension depends on the relative position of mark and point, you can change the direction by \\[exchange-point-and-mark]. This command assumes point is not in a string or comment." It is still somewhat complicated and confusing, but at least it's accurate, I think.