emacs + latex + yasnippet: Why are newlines inserted after a snippet?

眉间皱痕 提交于 2019-12-06 01:33:10

问题


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):

  1. 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")

  2. 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}*
    
  3. restart Aquamacs and open a .tex file and type in bm + Tab [this should insert the snippet]

  4. 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.


回答1:


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.




回答2:


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))



回答3:


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...




回答4:


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.



来源:https://stackoverflow.com/questions/7619640/emacs-latex-yasnippet-why-are-newlines-inserted-after-a-snippet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!