Temporarily disable adding newlines in Emacs

I have included require-final-newline because I usually want Emacs to add new lines to my files where it is missing. But there are some cases where I want Emacs to delete a new line (for example, when editing yasnippet, which should not generate a new line, see emacs + latex + yasnippet: why are new lines inserted after the snippet? ).

Is there a way to achieve this temporary (like turning on a mode or something else) without changing .emacs and restarting Emacs?

+2
source share
3 answers

In addition to what @eldrich mentioned, you can set its value locally in this buffer. Put something like this on the mode hook to disable it for the given mode:

 (defun foo () (set (make-local-variable 'require-final-newline) nil)) (add-hook 'some-mode-hook 'foo) 
+2
source

Everything that is installed in the .emacs file can be changed on the fly. For variables, such as require-final-newline , this is simply a matter of changing the variable. For example, you can enter the following code and then use Cx e to evaluate it.

 (setq require-final-newline (not require-final-newline)) 

Then it can be connected as a keyboard shortcut if you want it.

 (defun toggle-final-newline (interactive) (setq require-final-newline (not require-final-newline))) (global-set-key (kbd "Cc f") 'toggle-final-newline) 
+2
source

I think it should be:

 (defun toggle-final-newline () (interactive) (setq require-final-newline (not require-final-newline))) (global-set-key (kbd "Cc f") 'toggle-final-newline) 
0
source

All Articles