Reputation: 6692
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.
Upvotes: 7
Views: 3039
Reputation: 31
I had a similar issue with a few snippets, one of that was \frac{}{} which I use quite often. The snippet version of frac that I use is not the one bundled with yasnippets.
The issue was that I edited some of the snippets in VIM and when you save the file, VIM automatically appends a newline to it. To resolve it I had to remove the newline in a different editor e.g. emacs.
Upvotes: 0
Reputation: 13
the reason why u got a new line is that your snippet has space or tab at the end. Ctrl+e and Ctrl+k to kill them will make it works, nearly 1 hour to figure it out...
Upvotes: 1
Reputation: 604
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))
Upvotes: 1
Reputation: 17707
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.
Upvotes: 8