I am using org-mode to generate my PDF report. Each time the tex is generated, emacs asks me
Buffer hw1.tex<2> does not end in newline. Add one? (y or n) y
How can I get rid of this message and just add a new line automatically?
I tried setting mode-require-final-newline and require-final-newline to t, But this didn't change anything.
EDIT: I also tried setting mode-require-final-newline and require-final-newline to nil, and even though I can check that their value changed (via C-h v), the problem still persists.
Following the advice of the comments, I added a hook to change the value of those variables:
(add-hook 'org-mode-hook (lambda () (setq require-final-newline nil) (setq mode-require-final-newline nil)))
But again the problem persists.
EDIT:
Also, I think I found the command responsible for this:
(el-get 'sync my-packages)
, so I suspect some package I installed is missing with my configuration.
Here is the list of the packages I installed using el-get:
auctex
auto-complete
autopair
color-theme-solarized
cdlatex-mode
ecb
ein
elpy
expand-region
flycheck
folding
gnuplot-mode
helm
helm-descbinds
jedi
js2-mode
jump-char
key-chord
latex-preview-pane
lua-mode
magit
markdown-mode
matlab-mode
multiple-cursors
;nxhtml
nyan-mode
org-mode
outshine
popup
popwin
pyenv
pydoc-info
scss-mode
yaml-mode
yasnippet
Thanks!
[The following solution was tested with no user configuration -- i.e., Emacs -Q -- using Emacs 24.5.1. Try loading Emacs with no user configuration and then add the solution and test. Then try it with a full user configuration -- if it doesn't work with a full user configuration, it may be necessary to bisect and comment out code until the culprit is found. It would probably be easier to just word-search the user-configuration for require-final-newline
.]
As of the last stable public release of Emacs bearing version number 24.5.1, the default value of require-final-newline
is nil
. The doc-string of that variable states (in part) that "Certain major modes set this locally to the value obtained from mode-require-final-newline
." The function basic-save-buffer
in the library files.el
checks the value of require-final-newline
(among other criteria) when making a decision to prompt the user with (and require-final-newline (y-or-n-p (format "Buffer %s does not end in newline. Add one? " (buffer-name))))
. When enabling org-mode
with no user configuration -- e.g., Emacs -Q -- the value of require-final-newline
is set locally in the buffer as t
. The PARENT mode of org-mode
is outline-mode
; and the PARENT mode of outline-mode
is text-mode
. text-mode
when enabled contains a line of code that looks like this: (set (make-local-variable 'require-final-newline) mode-require-final-newline)
. The variable mode-require-final-newline
is defined in the library files.el
, and the default value is t
.
Now that we have done our due diligence, we can approach the problem from a couple of different angles. We could change the global value of mode-require-final-newline
by changing it from t
to nil
: (setq mode-require-final-newline nil)
. Or, we could keep the new user-configuration buffer-local relating to org-mode
:
(defun my-org-mode-config-fn ()
(setq require-final-newline nil))
(add-hook 'org-mode-hook 'my-org-mode-config-fn)