unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Zachary Kanfer <zkanfer@gmail.com>
To: Juri Linkov <juri@linkov.net>
Cc: ruijie@netyu.xyz, Eli Zaretskii <eliz@gnu.org>,
	monnier@iro.umontreal.ca, 62892@debbugs.gnu.org,
	mardani29@yahoo.es
Subject: bug#62892: proposal to extend mark-sexp to go forward and backward on command
Date: Fri, 28 Apr 2023 01:28:09 -0400	[thread overview]
Message-ID: <CAFXT+ROcOy8GR1a7mjPFBvhpiJbVqwTo-xMAn8c=jEw2XVB8Ww@mail.gmail.com> (raw)
In-Reply-To: <86ttx19ot4.fsf@mail.linkov.net>

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

I made some minor changes below. Alongside my suggestions are explanations
as to why. This is a hard command to describe!

> (defun mark-sexp (&optional arg allow-extend)
>  "Set mark ARG sexps from point or move mark ARG sexps.

Mark can be moved ARG steps. Press C-M-@ C-M-@ C-u 3 C-M-@. There will be
five total sexps marked. I'm hoping this explains that case as well, and
giving an intuition for what this command does ("move mark ARG steps").

> When invoked interactively without a prefix argument and no active
> region, mark moves one sexp forward.

I moved this first, both because I suspect it's the most common use case,
but also because it's the the simplest to understand.

> When invoked interactively without a prefix argument, and region
> is active, mark moves one sexp away from point (i.e., forward
> if mark is at or after point, back if mark is before point), thus
> extending the region by one sexp.
> 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.

Moved this earlier to keep the entire interactive block together.

> When the region is active, the direction the region is extended
> depends on the relative position of mark and point. This means the
> direction can be changed by pressing \\[exchange-point-and-mark]
> before this command..

I moved this to a separate section to simplify the earlier parts, and to
call out that this is possible whenever the region is active.

> When called from Lisp with ALLOW-EXTEND omitted or nil, mark is
> set ARG (defaulting to 1) sexps from point.

Removed extra m from "omitted".

> This command assumes point is not in a string or comment."

Altogether, the docstring with my suggestions looks like:

> (defun mark-sexp (&optional arg allow-extend)
>  "Set mark ARG sexps from point or move mark ARG sexps.
> 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 from point (i.e., forward
> if mark is at or after point, back if mark is before point), thus
> extending the region by one sexp.
> 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.
> When the region is active, the direction the region is extended
> depends on the relative position of mark and point. This means the
> direction can be changed by pressing \\[exchange-point-and-mark]
> before this command.
> When called from Lisp with ALLOW-EXTEND omitted or nil, mark is
> set ARG (defaulting to 1) sexps from point.
> This command assumes point is not in a string or comment."

This is a complicated command, for sure -- which is partially why I want
simple functions to mark sexps forward and backward: to not have to think
about different cases. Can we fork off a discussion about those functions?
Having simple functions allows the user to do what they want without having
to learn complex nuance.

On Thu, Apr 27, 2023 at 2:14 PM Juri Linkov <juri@linkov.net> wrote:

> > 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.
>
> mark-sexp has a counterpart mark-word that has almost the same
> implementation and docstring.  So this could be fixed in both places.
>

[-- Attachment #2: Type: text/html, Size: 5728 bytes --]

  reply	other threads:[~2023-04-28  5:28 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-17  2:25 bug#62892: proposal to extend mark-sexp to go forward and backward on command Zachary Kanfer
2023-04-17  3:06 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-20  5:25   ` Zachary Kanfer
2023-04-20  7:16     ` Eli Zaretskii
2023-04-21  5:04       ` Zachary Kanfer
2023-04-21  6:07         ` Eli Zaretskii
2023-04-21  7:24           ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-21  9:51           ` Visuwesh
2023-04-21 13:10   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-23  5:33     ` Zachary Kanfer
2023-04-25 22:26       ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-04-26  4:41         ` Zachary Kanfer
2023-04-26  6:28           ` Eli Zaretskii
2023-04-27  2:37             ` Zachary Kanfer
2023-04-27 12:25               ` Eli Zaretskii
2023-04-27 18:12                 ` Juri Linkov
2023-04-28  5:28                   ` Zachary Kanfer [this message]
2023-05-06  8:49                   ` Eli Zaretskii
2023-04-28 17:04       ` Juri Linkov
2023-04-28 19:28         ` Drew Adams
2023-05-04  4:48           ` Zachary Kanfer
2023-05-08 12:28             ` Zachary Kanfer
2023-05-18  3:17               ` Zachary Kanfer
2023-05-18  6:52                 ` Eli Zaretskii
2023-05-21  5:46                   ` Zachary Kanfer
2023-05-21  5:58                     ` Eli Zaretskii
2023-05-21 14:31                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-21 14:39                         ` Eli Zaretskii
2023-05-21 14:54                           ` Eli Zaretskii
2023-05-21 14:56                         ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-21 15:11                           ` Eli Zaretskii
2023-05-21 15:41                             ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-22 22:02                 ` Richard Stallman
2023-05-23 14:11                   ` Zachary Kanfer
2023-05-25 22:32                     ` Richard Stallman
2023-05-26  6:06                       ` Eli Zaretskii
2023-05-31  3:23                         ` Zachary Kanfer
2023-05-31 12:01                           ` Eli Zaretskii
2023-06-01  3:54                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-01  6:32                               ` Eli Zaretskii
2023-05-03  6:10         ` Zachary Kanfer
2023-05-03 17:29           ` Juri Linkov
2023-04-17  7:11 ` Juri Linkov

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='CAFXT+ROcOy8GR1a7mjPFBvhpiJbVqwTo-xMAn8c=jEw2XVB8Ww@mail.gmail.com' \
    --to=zkanfer@gmail.com \
    --cc=62892@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=juri@linkov.net \
    --cc=mardani29@yahoo.es \
    --cc=monnier@iro.umontreal.ca \
    --cc=ruijie@netyu.xyz \
    /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 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).