From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pedro Andres Aranda Gutierrez Newsgroups: gmane.emacs.devel Subject: Re: Proposing new function for basic editing Date: Tue, 6 Feb 2024 11:34:14 +0100 Message-ID: References: <878r3yxb4r.fsf@posteo.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000002b4d0c0610b42064" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27172"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Philip Kaludercic Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Feb 06 11:35:22 2024 Return-path: Envelope-to: ged-emacs-devel@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 1rXInR-0006nd-Kg for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Feb 2024 11:35:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXImq-0004cx-LV; Tue, 06 Feb 2024 05:34:44 -0500 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 1rXImp-0004ci-Nz for emacs-devel@gnu.org; Tue, 06 Feb 2024 05:34:43 -0500 Original-Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rXImn-0000Wy-S3 for emacs-devel@gnu.org; Tue, 06 Feb 2024 05:34:43 -0500 Original-Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5605c7b0ca2so2569723a12.3 for ; Tue, 06 Feb 2024 02:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707215680; x=1707820480; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Qk0LcelsdjSeG1hFZxc3Xh90KUZlGkU6DA2PMs0J+k8=; b=F+3T4D32DSrT5DAvfaeJssnCChlaO+699kmlMdZU7vHG1SC6PQAM7GmNkMAGIGCAjh G0I9cIhwi4nKXxD5lqV0LXuUQCIBSaaR+TkJU0d/dXX1r79dH4v/XLHQjSBmzMK2M0z/ P4QHYGBhAVKYulZJXEd2DlJBpMvY8LvMrvrzjAgWjj0Je4wXI11MuKJA92bdjDDyo9J2 Gzi0yBniG1bMkngJE37jZds1Q99kD2laIAn7I+0/LviEn14QgrNAMHin/ODikluvdTT8 L58fPzzocTZlseFi54g0T+qU568x55V7Tt1I7Eh1z9C9tRv7frZLJm8YqvUwp7rg9cXi VvXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707215680; x=1707820480; 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=Qk0LcelsdjSeG1hFZxc3Xh90KUZlGkU6DA2PMs0J+k8=; b=wDIYOqmPSKcvkWyfpmP5DlAY3C6mw7+9H6z6yBueARbTDhHKBRf9U28wx+HaJzPgw4 iONRVCRRBZbRnE4eu1dQUhgYQRi0drGIX7YjfKhxjpOc5lhWH1wbFVpWB3OpiuhE1+Qd KaBf7j4jJy0J5sUsd7KFxKbA+cgyTr5emRGAwbLQeVRXyiVEPE+ywxh+1PVCaSVUlf7h a/0mulbg1kFx21mgqOyGkl2BIJK4/EbnRpNDg+L93ay183Ttyf5bAaI1VMrleCGvUwUY nP874d0snFBlwKCNLqHcUWpEC9nh/7D+E3PhlboMNXHFGaxCVG1QDrEa+64mzvzMdU3L bxVg== X-Gm-Message-State: AOJu0YyBvvRrZyKYLhtaKJL3rino9VrR8YvBseUxwW72uvWvAHCCyh69 X2PJbgjbHFqAxNnWg2Ug4XbAxOC8oR+1BMTO0AIMCZtVzzdJyDWExZ6Rw6WMV+G29TOjaLPomgE UUSLquJ7CnXyOWBnBj9tvXxAj1KPfROb94vQ= X-Google-Smtp-Source: AGHT+IFrI+sH/pLJO8l3iEl2lNdPlZVhyQDYBM+lJH0JLGQPkoorAaAeWrjrKryLwECsGD2Ej43uQGG18CiKwgomQjA= X-Received: by 2002:aa7:de04:0:b0:55e:f9c4:3525 with SMTP id h4-20020aa7de04000000b0055ef9c43525mr1401425edv.30.1707215680128; Tue, 06 Feb 2024 02:34:40 -0800 (PST) In-Reply-To: <878r3yxb4r.fsf@posteo.net> Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=paaguti@gmail.com; helo=mail-ed1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:315925 Archived-At: --0000000000002b4d0c0610b42064 Content-Type: text/plain; charset="UTF-8" Hi Philip, thanks for the comments. I'll look at wrapping anything approach when time permits... Meanwhile, following your comment, I'd propose something like --- cut here --- (defun surround-region-or-point (before after &optional put-after) "Insert `before' before mark or region, `after' after mark or region and put mark after `after' if `put-after' is not nil" ;; insert the first string before the mark or region-beginning (if (use-region-p) (with-restriction (region-beginning) (region-end) ;; Insert `before' before region (goto-char (point-min)) (insert before) (goto-char (point-max))) (insert before)) ;; Insert the second string after the point or mark (if put-after (insert after) ; put point after second string (save-excursion (insert after)))) ; put point before second string --- cut here --- Wouldn't it serve a couple of scenarios? Best, /PA On Tue, 6 Feb 2024 at 09:14, Philip Kaludercic wrote: > Pedro Andres Aranda Gutierrez writes: > > > Hi, > > I really don't know if this is useful for more people or it's just me. In > > the elisp I write, I have ended up more than once wrapping the point or > the > > active region with two strings. > > There are certainly some cases where less generic code like this was > written, e.g. in rcirc we have `rcirc-format'. > > > I normally use a yasnippet for this, so I really don't use elisp ;-) > > > > But when I need this for a package, I end up replicating the following > > function where I need it: > > > > --- cut here --- > > (defun surround-region-or-point (before after &optional put-after) > > "Insert `before' before mark or region, > > `after' after mark or region and > > put mark after `after' if `put-after' is not nil" > > (if (use-region-p) > > (with-restriction (region-beginning) (region-end) > > ;; Insert `before' before region > > (goto-char (point-min)) > > (insert before) > > (goto-char (point-max)) > > ;; Insert `after' after region > > (if put-after > > (insert after) ; put point after inserted string > > (save-excursion (insert after)))) ; put point after region > > Can't you pull this code out of the if > > > (progn > > ... and then drop the progn? > > > (insert before) > > (if put-after > > (insert after) ; put point after both strings > > (save-excursion (insert after)))))) ; put point between strings > > --- cut here --- > > Also interesting, if you want to be generic, why not use an approach > like `isearch-forward-thing-at-point' and allow wrapping anything that > defines `bounds-of-thing-at-point'? > > > I was wondering if it would make sense to have this in the emacs lisp > > library once and for good. > > > > Best, /PA > -- Fragen sind nicht da, um beantwortet zu werden, Fragen sind da um gestellt zu werden Georg Kreisler Headaches with a Juju log: unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run a leader-deposed hook here, but we can't yet --0000000000002b4d0c0610b42064 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Philip,

thanks for the comments. I&#= 39;ll look at wrapping anything approach when time permits...
Mea= nwhile, following your comment, I'd propose something like=C2=A0
<= div>
--- cut here ---
(defun surround-region-or-poi= nt (before after &optional put-after)
=C2=A0 "Insert `before= 9; before mark or region,
`after' after mark or region and
put ma= rk after `after' if `put-after' is not nil"
=C2=A0 ;; inser= t the first string before the mark or region-beginning
=C2=A0 (if (use-r= egion-p)
=C2=A0 =C2=A0 =C2=A0 (with-restriction (region-beginning) (regi= on-end)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Insert `before' before region=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (goto-char (point-min))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 (insert before)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (goto-char (po= int-max)))
=C2=A0 =C2=A0 (insert before))
=C2=A0 ;; Insert the second= string after the point or mark
=C2=A0 (if put-after
=C2=A0 =C2=A0 = =C2=A0 (insert after) ; put point after second string
=C2=A0 =C2=A0 (sav= e-excursion (insert after)))) ; put point before second string
--- cut here ---

Wouldn't it serve a couple = of scenarios?

Best, /PA

=
On Tue= , 6 Feb 2024 at 09:14, Philip Kaludercic <philipk@posteo.net> wrote:
Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
> Hi,
> I really don't know if this is useful for more people or it's = just me. In
> the elisp I write, I have ended up more than once wrapping the point o= r the
> active region with two strings.

There are certainly some cases where less generic code like this was
written, e.g. in rcirc we have `rcirc-format'.

> I normally use a yasnippet for this, so I really don't use elisp ;= -)
>
> But when I need this for a package, I end up replicating the following=
> function where I need it:
>
> --- cut here ---
> (defun surround-region-or-point (before after &optional put-after)=
>=C2=A0 =C2=A0"Insert `before' before mark or region,
> `after' after mark or region and
> put mark after `after' if `put-after' is not nil"
>=C2=A0 =C2=A0(if (use-region-p)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(with-restriction (region-beginning) (region= -end)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Insert `before' before region<= br> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char (point-min))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(insert before)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char (point-max))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; Insert `after' after region >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if put-after
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(insert after) ; put po= int after inserted string
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(save-excursion (insert after)= ))) ; put point after region

Can't you pull this code out of the if

>=C2=A0 =C2=A0 =C2=A0(progn

... and then drop the progn?

>=C2=A0 =C2=A0 =C2=A0 =C2=A0(insert before)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(if put-after
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(insert after) ; put point aft= er both strings
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(save-excursion (insert after)))))) ;= put point between strings
> --- cut here ---

Also interesting, if you want to be generic, why not use an approach
like `isearch-forward-thing-at-point' and allow wrapping anything that<= br> defines `bounds-of-thing-at-point'?

> I was wondering if it would make sense to have this in the emacs lisp<= br> > library once and for good.
>
> Best, /PA


--
Fragen sind nicht da, um bea= ntwortet zu werden,
Fragen sind da um gestellt zu werden
= Georg Kreisler

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should ru= n a leader-deposed hook here, but we can't yet

--0000000000002b4d0c0610b42064--