Everytime I insert a snippet (with yasnippet) in a .tex document, I obtain a newline after the snippet. This is quite annoying for small snippets that are typically used in text style. How can I avoid that?
I read a bit about the problem (http://code.google.com/p/yasnippet/issues/detail?id=115 or http://yasnippet.googlecode.com/svn/trunk/doc/faq.html) but couldn't find a solution. Reproduce it as follows (I work with Aquamacs 2.3a on Mac OS X 10.6.8 with yasnippet version 0.6.1c):
Define ~/Library/Preferences/Aquamacs Emacs/Preferences.el to be: (require 'yasnippet) (yas/initialize) (yas/load-directory "~/Library/Preferences/Aquamacs Emacs/plugins/yasnippet-0.6.1c/snippets")
define the following snippet (call it "bm.yasnippet" [bm = boldmath]; the star * symbolizes where the cursor ends -- note that there is no newline after the snippet)
# name: \bm{}{}
# key: bm
# --
\bm{$1}*
restart Aquamacs and open a .tex file and type in bm + Tab [this should insert the snippet]
A newline is added after the snippet. This is quite inconvenient since \bm{foo}
is typically used in text style, so for example in "The vector \bm{x}
is not the null vector". A typical cause of this is that the snippet ends with a newline which is then inserted, too. However, I specifically obtain this behavior even the snippet does not end with a newline.
I can't repro it with plain Emacs. In fact, I had this exact issue, but my problem is I had require-final-newline
set to t. So Emacs was adding a newline at the end of my template.
My setup is a little more complicated but the solution for you is probably to set mode-require-final-newline
to nil and restart Emacs.
To verify this is the problem, open up the template and check for the final newline.
Thanks to the answers in Temporarly disable adding of newlines in Emacs, I'm using a function to only temporarily disable the adding of final newlines in the current buffer:
(defun disable-final-newline ()
(interactive)
(set (make-local-variable 'require-final-newline) nil))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With