2

In Emacs, is there a way control where the cursor/point gets placed in abbrev-mode expansion?

You know, something like this?

("orgfootnote" "[fn:: %?]" nil 0)
incandescentman
  • 6,168
  • 3
  • 46
  • 86
  • This is emacs so of course something can be done! Could you elaborate a bit more on where the cursor ends up now and where you would like it to end up? Also, double check and make sure you know which abbrev mode you are using as there are a couple of them for emacs. – Eric Johnson Mar 13 '13 at 09:21

3 Answers3

3

Abbrev do not offer this feature themselves, but they offer enough hooks to do it externally. E.g.

(define-skeleton my-orgfootnote "Docstring." nil
  "fn::" _ "]")

and then use an abbrev like

("orgfootnote" "" 'my-orgfootnote)
Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
Stefan
  • 27,908
  • 4
  • 53
  • 82
2

If you mean the builtin abbrev feature then here's my take on the problem. With this deafdvice if you have an abbrev containing the string @@ then after exapnsion the cursor will be placed at that position in the expanded text where the @@ occurs.

 (defadvice expand-abbrev (after my-expand-abbrev activate)
   ;; if there was an expansion
   (if ad-return-value
       ;; start idle timer to ensure insertion of abbrev activator
       ;; character (e.g. space) is finished
       (run-with-idle-timer 0 nil
                            (lambda ()
                              ;; if there is the string "@@" in the
                              ;; expansion then move cursor there and
                              ;; delete the string
                              (let ((cursor "@@"))
                                (if (search-backward cursor last-abbrev-location t)
                                    (delete-char (length cursor))))))))
Tom
  • 7,515
  • 7
  • 38
  • 54
  • Tom FYI I have referenced your comment in a recent video: https://www.youtube.com/watch?v=2ONNXDlN3RU&t=1020s – Edman Apr 10 '21 at 16:12
1

If you need to fill out a template, then abbrev is the wrong facility. I highly recommend yasnippet. abbrev is very useful for correcting frequent typos though.

event_jr
  • 17,467
  • 4
  • 47
  • 62