Ypo <ypun...@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