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)
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 lastsetq`.