I'm doing this from typescript-mode-hook:

(defun disable-final-newline ()
  (setq-default mode-require-final-newline nil)
  (setq-default require-final-newline nil)
  (setq mode-require-final-newline nil)
  (setq require-final-newline nil))

I've verified that this code runs when I open a .ts file (I can see the output of a (message ...) I added to the definition of the function above). However, after I load the file, I see using C-h v that require-final-newline is set t as a buffer-local variable (the global value is nil). If I then (run-hook 'typescript-mode-hook), the variables get set buffer-local to nil as I expect, and saving the file has the behaviour I expected (not adding final newlines).

I've also tried setting these two variables as directory-local variables, without any change in behaviour.

I've searched all the code I can think of and can't find any relevant reference to these variables other than in my own code. How can I force this variable false in .ts files? (ideally by locating the code that's setting it true)

  • 2
    If you only want this in behavior in typescript mode, then you can remove the setq-default's. If indeed you ensured that the code runs, then probably the value gets set again somewhere later. You can check this by adding a (debug-on-variable-change 'require-final-newline) after that last setq`. Nov 5, 2022 at 18:10
  • The debug-on-variable-change is exactly what I was wishing for! The rest I thought I knew, but thanks for the confirmation Nov 5, 2022 at 21:16

1 Answer 1


The answer in my case turned out to be an .editorconfig file whose existence I was not aware of. It specifies:

insert_final_newline = true

@dalanicolai's suggestion to use (debug-on-variable-change 'require-final-newline) after my last setq answered this for me very quickly!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.