unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Pedro Andres Aranda Gutierrez <paaguti@gmail.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Proposing new function for basic editing
Date: Tue, 06 Feb 2024 08:14:28 +0000	[thread overview]
Message-ID: <878r3yxb4r.fsf@posteo.net> (raw)
In-Reply-To: <CAO48Bk-KmVVhPF=MLTjpqLmmaM+=-3H8_boK+cA05t9aWPXCWQ@mail.gmail.com> (Pedro Andres Aranda Gutierrez's message of "Tue, 6 Feb 2024 08:05:33 +0100")

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 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



  reply	other threads:[~2024-02-06  8:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06  7:05 Proposing new function for basic editing Pedro Andres Aranda Gutierrez
2024-02-06  8:14 ` Philip Kaludercic [this message]
2024-02-06 10:34   ` Pedro Andres Aranda Gutierrez
2024-02-06  8:25 ` Adam Porter
2024-02-06  9:16   ` Pedro Andres Aranda Gutierrez
2024-02-06 17:29     ` 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=878r3yxb4r.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=emacs-devel@gnu.org \
    --cc=paaguti@gmail.com \
    /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).