emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ruijie Yu via "General discussions about Org-mode." <emacs-orgmode@gnu.org>
To: Ypo <ypuntot@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Help using org-entities or arternatives.
Date: Tue, 09 May 2023 19:48:58 +0800	[thread overview]
Message-ID: <sdvlehxbtdi.fsf@netyu.xyz> (raw)
In-Reply-To: <a91c151d-a21f-7ff5-673e-deba6dc5e2e1@gmail.com>


Ypo <ypuntot@gmail.com> writes:

> Hi
>
> Is it possible to, each time I write "...." to be subsituted by "[...]" ?
>
> I can't do it using abbrev, and I don't know how to do it using org-entities.
>
> I use it to yank quotes, for example, I write:
>
>  "Like other editors, Emacs has commands to search for occurrences of a string. ....There are also commands that do the same thing, but
>  search for patterns instead of fixed strings."
>
> And I would like to get, automatically:
>
>  "Like other editors, Emacs has commands to search for occurrences of a string. [...] There are also commands that do the same thing, but
>  search for patterns instead of fixed strings."
>
> Best regards

Not necessarily Org-specific, but here's my idea, untested:

```emacs-lisp
(defun my/yank-subst-ellipses ()
  (interactive)
  (let* ((start (point-marker))
         (_ (insert (current-kill 0)))
         (end (point-marker)))
    (save-match-data
      ;; Play around with this regexp
      (while (re-search-forward (rx "...") end t)
        ;; And this replacement text
        (replace-match "[...]")))))
```

Then, since Org sets C-y as `org-yank', make an advice with it.  I am
not confident in this portion at all, but here goes nothing ;)

```emacs-lisp
(require 'cl-lib)
(advice-add
 #'org-yank :around
 (lambda (org-yank &optional arg)
   (cl-letf (((symbol-function 'yank)
              (symbol-function 'my/yank-subst/ellipses)))
     (funcall org-yank arg))))
```

-- 
Best,


RY


  reply	other threads:[~2023-05-09 12:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 11:32 Help using org-entities or arternatives Ypo
2023-05-09 11:48 ` Ruijie Yu via General discussions about Org-mode. [this message]
2023-05-13 16:43   ` Ypo

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.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sdvlehxbtdi.fsf@netyu.xyz \
    --to=emacs-orgmode@gnu.org \
    --cc=ruijie@netyu.xyz \
    --cc=ypuntot@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/org-mode.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).