Search code examples
emacslatexelisptemplate-engine

Emacs lisp, skeleton-mode: Prevent trailing newline


I am using this code for inserting \emph{..} blocks into latex:

(define-skeleton mylatex-emph-skeleton "\emph{_}"
  nil "\\emph{" _ "}")

As an undired side effect however, it also inserts a newline at the end of the skeleton. E.g. if I select emphasized in

This is emphasized text.

and press my hotkey, I end up with

This is \emph{emphasized}
text.

instead of

This is \emph{emphasized} text.

Can I prevent this? Note that the newline only gets inserted, there is text after the insertion point, so it is not as easy as deleting the character after the closing }.


Solution

  • Set skeleton-end-newline to nil to change the behavior of all skeletons.

    Modify skeleton-end-hook to check which skeleton is being expanded and inserting newline as desired if you want to change the behavior of a specific skeleton.