From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.devel Subject: Re: Proposing new function for basic editing Date: Tue, 06 Feb 2024 08:14:28 +0000 Message-ID: <878r3yxb4r.fsf@posteo.net> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18931"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Pedro Andres Aranda Gutierrez Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Feb 06 09:15:31 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 1rXGc4-0004by-Ny for ged-emacs-devel@m.gmane-mx.org; Tue, 06 Feb 2024 09:15:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXGbE-00018n-GR; Tue, 06 Feb 2024 03:14:36 -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 1rXGbC-00018b-VE for emacs-devel@gnu.org; Tue, 06 Feb 2024 03:14:34 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rXGbB-0007kM-0c for emacs-devel@gnu.org; Tue, 06 Feb 2024 03:14:34 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id DD76E240029 for ; Tue, 6 Feb 2024 09:14:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1707207269; bh=QD1ZlGbs5+27F73CS/xFXd+CkSe9gq9tnVYNyE9WHZg=; h=From:To:Cc:Subject:Autocrypt:OpenPGP:Date:Message-ID:MIME-Version: Content-Type:From; b=WscRAeztMBIvAX+LDJ9u4okfsipuGKAT8NZr3WtkllgoXIYr5i4AF4zcy7AottspM hywJIUZ1oGP+F6CBwWZDV0okGIIZTETy/b14iqLV2c2ZPjeb4ImzXnhSuVLPJO8CHY NigUEc5lBiEW9gmA3ZlNYi1EIaGr+OV2y1tw0W5pZGXVGq3TXKaKXamwLBDUB1+QNd v1H8Mq0X1DTE000miLaCp9NSYFLP8FPw8gspGvPr8FEAHk0FnCvowXU9uNOwNJyycd dP46wixL07L38DrA8qqdIb7hYbM8awKtxWgE0x5CiTCQ6RpuFVH1siHK+ViW2+E5ae aHzkHMrnXxTAQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TTbd13Mmmz6tyy; Tue, 6 Feb 2024 09:14:29 +0100 (CET) In-Reply-To: (Pedro Andres Aranda Gutierrez's message of "Tue, 6 Feb 2024 08:05:33 +0100") Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM OpenPGP: id=7126E1DE2F0CE35C770BED01F2C3CC513DB89F66; url="https://keys.openpgp.org/vks/v1/by-fingerprint/7126E1DE2F0CE35C770BED01F2C3CC513DB89F66"; preference=signencrypt Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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:315916 Archived-At: 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