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: Proposing new function for basic editing Date: Tue, 6 Feb 2024 08:05:33 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000d93af30610b13566" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38605"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Feb 06 08:07:03 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 1rXFXq-0009tE-FE for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Feb 2024 08:07:02 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXFWy-0003hd-2V; Tue, 06 Feb 2024 02:06:08 -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 1rXFWv-0003h9-GU for emacs-devel@gnu.org; Tue, 06 Feb 2024 02:06:05 -0500 Original-Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rXFWr-0003pb-8Q for emacs-devel@gnu.org; Tue, 06 Feb 2024 02:06:05 -0500 Original-Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5608f7fd83cso1175587a12.0 for ; Mon, 05 Feb 2024 23:06:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707203159; x=1707807959; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=rxlh2P+hcgyym+Bn1CR6+tVpM/n48+rX+GAA8SVIhgY=; b=kh4dbbMJrfrxTO+odNPH1G+YSxST+JPfWA4CScDOvvOl1YjEALnUZJ1YMBVYufVajL +CBoQwRd7v4erStKY7reb9mY+VHLFjiD21NpseLLCqs12PJJQ/YdoNkbulYVG3502MHJ 3i8XacAvYJbwPPo6PMkLAS4ykVdLnn3G1rzEpHKuBFl0K3Tp0bfl6lxaZkcgONrhyZm2 UW1+VDQo2Gg1a4q9fJlFwAjoa+UvFsr11Ly6qDmkyw1YlN0AA5WH/76xlZFv5ThpsFUr QeN2WrVeHrel7wPGOK3YD4TiqOtivXtjCiXLz8wWRTDGUmFbgKPzKStVeMYmct1bJgk9 Fr6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707203159; x=1707807959; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rxlh2P+hcgyym+Bn1CR6+tVpM/n48+rX+GAA8SVIhgY=; b=IeAWwtXtIyNkbdCzayqWOUucg8zSMlllMeSemKI9JMtrSptMNo6PVlU3zTRtzYB4Po F5u0fDlpLlbs7fllywE8DKCiMq9+0bc22nlsQAvBqIgdPTlsMB8CIvv4c5y78l0bhENp IjJaUN4YiR95nExin6+YtFgkErHgoCBt3s9DVwjNuITBjIpoNEof4F7glwHvM6lEr70h o0H7+hvwruV4i1JRvHH+DrBmJOMoriALzJS1wDKCArt9Nhwbw/fY8/fMa09SNHyJkYHz mJwSIMQInsqf2Xf+wbWuKyc1r0VC0uDoROGf2wN3dbBlb4ms5PrFEdztxf+6QOViBIO+ EzrQ== X-Gm-Message-State: AOJu0Yw+Ng3xyTyfBci7vINDouxJ1i5rllw3+WsuuDlm4QxP/vkIq1VO dtG92kowxifCu7g9X5mpBBrodtSmZvQDV6vXb8Id4W3kE+DXjLifnVf2KZRhZ/pSWGeBx/INXdY +vmvLRSfXRWUuIgoIJyi7TdAKsO8RB9vpN2c= X-Google-Smtp-Source: AGHT+IF+oEg8UwcPygBLq73HAgSF0tUxld1Bsw0XpHzCni/b8/rssoKwQs1nTo61dKH795aUR8Ad/h3e0F1Xfp8U7To= X-Received: by 2002:aa7:da0d:0:b0:55f:92f4:15b5 with SMTP id r13-20020aa7da0d000000b0055f92f415b5mr900200eds.23.1707203158947; Mon, 05 Feb 2024 23:05:58 -0800 (PST) Received-SPF: pass client-ip=2a00:1450:4864:20::533; envelope-from=paaguti@gmail.com; helo=mail-ed1-x533.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:315914 Archived-At: --000000000000d93af30610b13566 Content-Type: text/plain; charset="UTF-8" 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. 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 (progn (insert before) (if put-after (insert after) ; put point after both strings (save-excursion (insert after)))))) ; put point between strings --- cut here --- 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 --000000000000d93af30610b13566 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,
I really don't know if this is useful for more= people or it's just me. In the elisp=C2=A0I write, I have ended up mor= e than once wrapping the point or the active region with two strings.
=

I normally use a yasnippet for this, so I really don= 9;t use elisp ;-)=C2=A0

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-p= oint (before after &optional put-after)
=C2=A0 "Insert `before&= #39; before mark or region,
`after' after mark or region and
put = mark after `after' if `put-after' is not nil"
=C2=A0 (if (u= se-region-p)
=C2=A0 =C2=A0 =C2=A0 (with-restriction (region-beginning) (= region-end)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Insert `before' before re= gion
=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= (point-max))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; Insert `after' after re= gion
=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 after inserted string
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (save-excursion (insert after)))) ; put = point after region
=C2=A0 =C2=A0 (progn
=C2=A0 =C2=A0 =C2=A0 (insert= before)
=C2=A0 =C2=A0 =C2=A0 (if put-after
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (insert after) ; put point after both strings
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 (save-excursion (insert after)))))) ; put point between strin= gs
--- cut here ---

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
<= br>
Headaches with a Juju log:
unit-basic-16: 09:17:36 = WARNING juju.worker.uniter.operation we should run a leader-deposed hook he= re, but we can't yet

--000000000000d93af30610b13566--