The context
I'm storing all my custom defined yasnippet snippets in an Org file (see below)
$ cat ~/.emacs.d/snippets/snippets.org
#+PROPERTY: header-args:yasnippet :mkdirp yes
#+begin_src yasnippet :tangle ~/.emacs.d/snippets/org-mode/a
# key: a
# --
a foo bar
#+end_src
#+begin_src yasnippet :tangle ~/.emacs.d/snippets/org-mode/b
# key: b
# --
b foo bar
#+end_src
The problem
When tangling any code block present in the Org file shown above (i.e. snippet definition) a newline is inserted at the end of the last line which is causing yasnippet insert a newline whenever a snippet is triggered. I don't want a newline to be inserted whenever an snippet is triggered since newlines are unnecessarily added to my files and I manually have to delete them.
The behavior of yasnippet of adding newlines after an snippet expansion is mentioned in the FAQ file located in the yasnippet master branch repository
If there is a newline at the end of a snippet definition file, YASnippet will add a newline when expanding that snippet.
Additional context
It is worth mentioning that this problem is not present when creating a new snippet with yas-new-snippet
since the variable require-final-newline
is set to nil
in the opened buffer.
The behavior present in the buffers which are opened after yas-new-snippet
has been executed is set by yasnippet
itself.
$ grep -R 'require-final-newline' ~/repos/yasnippet
...
~/repos/yasnippet/yasnippet.el: (set (make-local-variable 'require-final-newline) nil)
~/repos/yasnippet/yasnippet.el: (set (make-local-variable 'require-final-newline) nil)
...
The question
- Is there a way to change the behavior of tangling so that a newline is not inserted at the end of the file?
- What other workarounds could I try to overcome this issue? I was thinking in executing a function that iterates over all files in my custom snippets directory and delete the last character if and only if it is a newline.