From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zachary Kanfer Newsgroups: gmane.emacs.bugs Subject: bug#62892: proposal to extend mark-sexp to go forward and backward on command Date: Wed, 3 May 2023 02:10:01 -0400 Message-ID: References: <86jzxwuedr.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000a995c505fac3e876" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32019"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Ruijie Yu , Stefan Monnier , 62892@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed May 03 08:11:25 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 1pu5i0-0008AZ-RQ for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 03 May 2023 08:11:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pu5hg-0005P0-BS; Wed, 03 May 2023 02:11:04 -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 1pu5hf-0005Os-6Y for bug-gnu-emacs@gnu.org; Wed, 03 May 2023 02:11: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 1pu5he-0001h5-TC for bug-gnu-emacs@gnu.org; Wed, 03 May 2023 02:11:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pu5he-0004tC-AA for bug-gnu-emacs@gnu.org; Wed, 03 May 2023 02:11:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Zachary Kanfer Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 03 May 2023 06:11: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.168309422118742 (code B ref 62892); Wed, 03 May 2023 06:11:02 +0000 Original-Received: (at 62892) by debbugs.gnu.org; 3 May 2023 06:10:21 +0000 Original-Received: from localhost ([127.0.0.1]:45478 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pu5gy-0004sE-KT for submit@debbugs.gnu.org; Wed, 03 May 2023 02:10:21 -0400 Original-Received: from mail-oo1-f49.google.com ([209.85.161.49]:51303) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pu5gw-0004ry-GY for 62892@debbugs.gnu.org; Wed, 03 May 2023 02:10:19 -0400 Original-Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-54c905139deso1196922eaf.2 for <62892@debbugs.gnu.org>; Tue, 02 May 2023 23:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683094212; x=1685686212; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bwCAsRIH0WeqT9phLuUdfotGLQ27xk7rrbpWRM1J8iM=; b=ZinAuL3qriFSEVKnur0UefM0umTevNoWIApJGzdJfY/e3FN2BJWOy1NAfrZBBA0XkT 3LPBqWLlcziDug9RfzG9iCytASlvUiO8w+XJxh1Whqrz0UnxufshaZZcQJw2L8u504Lz wvkh8GwoGAdrEsIsCMZa2MsfJcb5U7Dj67sG6uKJhogK9vs3piyVvrLXrsATsq4wOeWu Y7xcc4g56NrpjMc4bQ6/+ux9Y+pnFlHXFSNC47qRPCrpubQ/Lh3sKv3r7lutdUUX0pKG PUmR+eh7cug+5LP/+Pg4zLUjI+7zqd1So5A6vh+tpvTU7Zzs5qhZVq6hs6pZd+lMm8yX +bAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683094212; x=1685686212; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bwCAsRIH0WeqT9phLuUdfotGLQ27xk7rrbpWRM1J8iM=; b=hRXRsRe//5kPuoXgYDoPdOBbCHErAJsVCT/KzC60sEp0wPfwkZZQjsf0qYNemRqsjT yfQOpzvfzb4fUSLGfYR9pusdafx4qPB/3CgQt78qYa+3Rq/TivKwlTasQ85lE0S3XD7x aW2C5qzxwu/nwKW/yAJFNtaRDDdlfsO5bvMrjau64oWlfbAMCosaZFoLXC/4fUidR9Sq H5gMSolvkkSaoWiHW7IW3aK52YjPFBr7dKi1oTueGamVgaZu+wk50/8rqexpYesQZhJ+ aoZH/EwEIYv30b7FdUPDHN1vT7IksozZqxKX1Xs9Ln/3xCNkcx8VoB+VIjtG62pn+u2T OpFg== X-Gm-Message-State: AC+VfDwk4w/TawUkGs9eS8YcJo1FOmS574z4vN7Yc4LKPNK7w1W0Lpvz Zky53OLnAU55qFJ0IkvsVDPq/e2cqsuI32wOn0Q= X-Google-Smtp-Source: ACHHUZ7RMp4ZkuV4nbrPlmLyqS43y5lSV8lvCuVjweqbAFdP2qqRpEZD016GJB/kF/dHrrFxolSeoXWx7RrHeubfY6s= X-Received: by 2002:a54:4590:0:b0:38e:c8a8:f233 with SMTP id z16-20020a544590000000b0038ec8a8f233mr9021650oib.25.1683094212546; Tue, 02 May 2023 23:10:12 -0700 (PDT) In-Reply-To: <86jzxwuedr.fsf@mail.linkov.net> 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:260965 Archived-At: --000000000000a995c505fac3e876 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > Thanks for the patch. It would be nice to have such commands > even not bound to default keys, so the users are free to bind > them to any keys. That's my hope, unless sufficiently good default keys can be found. I like C-M-space and C-M-S-space, which are both currently bound to mark-sexp, but changing the default keys is not trivially done. > So looks like the best place to define the helper is simple.el, > before mark-word. Sure! I'll get a patch out for this. > Another variant is to use a single argument JUMPFORM like > in 'isearch-yank-internal' that allows not to leak the > prefix argument to the helper function: This is tempting. The downside I'm seeing to this -- which I'll think more about to see if I can get around it -- is that we don't know if we need to call JUMPFORM from point or mark. We can do it from both, something like: (defun mark--helper (fn-to-find-new-mark) "Extend region by calling FN-TO-FIND-NEW-MARK. The MOVE-FN should take a numeric argument, and move that many items forward (negative means backward). NUMBER-OF-THINGS is the number of additional things to move." (if (use-region-p) (let* ((beginning-of-region (region-beginning)) (end-of-region (region-end)) (at-end-of-region (=3D end-of-region (point))) (move-from-front (save-excursion (goto-char beginning-of-region) (funcall fn-to-find-new-mark) (point))) (move-from-end (save-excursion (goto-char end-of-region) (funcall fn-to-find-new-mark) (point))) (new-beginning-of-region (min beginning-of-region move-from-front)) (new-end-of-region (max end-of-region move-from-end))) (goto-char (if at-end-of-region new-end-of-region new-beginning-of-region)) (set-mark (if at-end-of-region new-beginning-of-region new-end-of-region))) (progn (push-mark (save-excursion (funcall fn-to-find-new-mark) (point))) (activate-mark)))) Downsides include: 1. We have to call the function twice each time. This doesn't seem like such a big deal unless it's expensive or has side effects -- neither of which should be the case. 2. The current implementation errors when there are no more objects to mark. This doesn't. I think we probably could error if we don't change the region. 3. I'm not 100% convinced this will always do the right thing. I would like to be. 4. I'm not sure going to one argument is worth it. The two arguments seem pretty simple; changing to one argument might add more complexity than it removes. On Fri, Apr 28, 2023 at 1:07=E2=80=AFPM Juri Linkov wrote= : > > Attached is a patch with a few updates: > > Thanks for the patch. It would be nice to have such commands > even not bound to default keys, so the users are free to bind > them to any keys. > > > I'm not exactly sure of the best place to put the helper function, nor > > exactly how the different lisp files in Emacs work together. There's no > > provide statement; are all the files in lisp/emacs-lisp loaded at the > same > > time? If so, I'll make the other relevant functions (for marking word, > > defun, page, paragraph, line, and char). > > Let's see: > - mark-sexp and mark-defun are defined in emacs-lisp/lisp.el > - mark-page in textmodes/page.el > - mark-paragraph in textmodes/paragraphs.el > - mark-word in simple.el > > So looks like the best place to define the helper is simple.el, > before mark-word. > > > +(defun mark--helper (move-fn number-of-things) > > A nicer name would be 'mark-thing' as a reference to thingatpt.el. > > > + "Use MOVE-FN to move NUMBER-OF-THINGS things, extending region over > them. > > + > > +The MOVE-FN should take a numeric argument, and move that many > > +items forward (negative means backward). > > + > > +NUMBER-OF-THINGS is the number of additional things to move." > > Another variant is to use a single argument JUMPFORM like > in 'isearch-yank-internal' that allows not to leak the > prefix argument to the helper function: > > (defun isearch-yank-char (&optional arg) > (isearch-yank-internal (lambda () (forward-char arg) (point)))) > --000000000000a995c505fac3e876 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> Thanks for the patch.= =C2=A0 It would be nice to have such commands
>=20 even not bound to default keys, so the users are free to bind
> = them to any keys.

That's my = hope, unless sufficiently good default keys can be found. I like C-M-space = and C-M-S-space, which are both currently bound to mark-sexp, but changing = the default keys is not trivially done.

> So looks = like the best place to define the helper is simple.el,
> before mark-= word.

Sure! I'll get a patch out for this.

> Another variant is to use a single argument JUMP= FORM like
> in 'isearch-yank-internal' that allows not to lea= k the
> prefix argument to the helper function:

<= div>This is tempting. The downside I'm seeing to this -- which I'll= think more about to see if I can get around it -- is that we don't kno= w if we need to call JUMPFORM from point or mark.

= We can do it from both, something like:

(defun mar= k--helper (fn-to-find-new-mark)
=C2=A0 "Extend region by calling FN= -TO-FIND-NEW-MARK.

The MOVE-FN should take a numeric argument, and m= ove that many
items forward (negative means backward).

NUMBER-OF-= THINGS is the number of additional things to move."
=C2=A0 (if (use= -region-p)
=C2=A0 =C2=A0 =C2=A0 (let* ((beginning-of-region (region-begi= nning))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(end-of-region (= region-end))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(at-end-of-= region (=3D end-of-region (point)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0(move-from-front (save-excursion (goto-char beginning-of-regio= n)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 (funcall fn-to-find-new-mark)
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (point)))=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(move-from-end (save-excur= sion (goto-char end-of-region)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (funcall fn-to-find-new-mark)
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (point)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(new-begin= ning-of-region (min beginning-of-region move-from-front))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(new-end-of-region (max end-of-region mov= e-from-end)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (goto-char (if at-end-of-regio= n
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0new-end-of-region
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0new-beginning-of-region))
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 (set-mark (if at-end-of-region
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 new-beginning-of-re= gion
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 new-end-of-region)))
=C2=A0 =C2=A0 (progn (push-mark (save-excursion=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (funcall fn-to-find-new-mark)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (point)))
=C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(activate-mark))))

<= div>Downsides include:

1. We have to call the func= tion twice each time. This doesn't seem like such a big deal unless it&= #39;s expensive or has side effects -- neither of which should be the case.=
2. The current implementation errors when there are no more obje= cts to mark. This doesn't. I think we probably could error if we don= 9;t change the region.
3. I'm not 100% convinced this will al= ways do the right thing. I would like to be.
4. I'm not sure = going to one argument is worth it. The two arguments seem pretty simple; ch= anging to one argument might add more complexity than it removes.
=

On Fri, Apr 28, 2023 at 1:07=E2= =80=AFPM Juri Linkov <juri@linkov.net= > wrote:
= > Attached is a patch with a few updates:

Thanks for the patch.=C2=A0 It would be nice to have such commands
even not bound to default keys, so the users are free to bind
them to any keys.

> I'm not exactly sure of the best place to put the helper function,= nor
> exactly how the different lisp files in Emacs work together. There'= ;s no
> provide statement; are all the files in lisp/emacs-lisp loaded at the = same
> time? If so, I'll make the other relevant functions (for marking w= ord,
> defun, page, paragraph, line, and char).

Let's see:
- mark-sexp and mark-defun are defined in emacs-lisp/lisp.el
- mark-page in textmodes/page.el
- mark-paragraph in textmodes/paragraphs.el
- mark-word in simple.el

So looks like the best place to define the helper is simple.el,
before mark-word.

> +(defun mark--helper (move-fn number-of-things)

A nicer name would be 'mark-thing' as a reference to thingatpt.el.<= br>
> +=C2=A0 "Use MOVE-FN to move NUMBER-OF-THINGS things, extending r= egion over them.
> +
> +The MOVE-FN should take a numeric argument, and move that many
> +items forward (negative means backward).
> +
> +NUMBER-OF-THINGS is the number of additional things to move."
Another variant is to use a single argument JUMPFORM like
in 'isearch-yank-internal' that allows not to leak the
prefix argument to the helper function:

=C2=A0 (defun isearch-yank-char (&optional arg)
=C2=A0 =C2=A0 (isearch-yank-internal (lambda () (forward-char arg) (point))= ))
--000000000000a995c505fac3e876--