Emacs + latex + yasnippet: Why are new lines inserted after the fragment?

Each time I insert a fragment (with yasnippet) in a .tex document, I get a new line after the fragment. This is pretty annoying for small snippets that are commonly used in text style. How can i avoid this?

I read a little about the problem (http://code.google.com/p/yasnippet/issues/detail?id=115 or http://yasnippet.googlecode.com/svn/trunk/doc/faq.html ), but could not find a solution. Play it like this (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: (yasnippet required) (Yash / initialization) (yas / load-directory "~ / Library / Preferences / Aquamacs Emacs / plugins / yasnippet-0.6. 1c / snippets ")

  • define the next fragment (name it "bm.yasnippet" [bm = boldmath], the star * symbolizes where the cursor ends, - note that there is no new line after the fragment)

    # name: \bm{}{} # key: bm # -- \bm{$1}* 
  • restart Aquamacs and open the .tex file and type bm + Tab [this should insert a snippet]

  • A new line is added after the fragment. This is rather inconvenient, since \bm{foo} usually used in a text style, therefore, for example, in "Vector \bm{x} not a zero vector." A typical reason for this is that the fragment ends with a new line, which is then inserted. However, I specifically get this behavior, even the fragment does not end with a newline.

+4
source share
4 answers

I cannot play it using simple Emacs. Actually, I had this exact problem, but my problem is that I had require-final-newline set to t. Therefore, Emacs added a new line 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 that this is a problem, open the template and check the final new line.

+6
source

Thanks to Temporarly's answers to disable adding newlines in Emacs , I use the function only to temporarily disable adding the last lines of a newline in the current buffer:

 (defun disable-final-newline () (interactive) (set (make-local-variable 'require-final-newline) nil)) 
0
source

the reason why you have a new line is because your fragment has a space or tab at the end. Ctrl + e and Ctrl + k to kill them will make it work, almost 1 hour to figure it out ...

0
source

I had a similar problem with several fragments, one of which was \ frac {} {}, which I use quite often. The fragmented version of frac that I use is not the one associated with yasnippets.

The problem was that I edited some fragments in VIM, and when you save the file, VIM automatically adds a new line to it. To solve this problem, I had to delete a new line in another editor, for example. Emacs

0
source

All Articles