2020-09-20 A simple trick with Textern and require-final-newline

I have been using the Textern add-on for Firefox for quite some time now. What it does is it lets you press some key combination while being focused on a textarea element and start editing it in an editor of your choice. Of course, the editor of my choice is Emacs (well actually, Firefox thinks it’s emacsclient, of course). However, there was one thing that annoyed me. By default, Emacs sets require-final-newline to t in text mode and the modes derived from it, like Markdown mode (well, actually it sets it to mode-require-final-newline, which is t by default, but that’s another story). This is good when editing actual text files (which I want to end with a newline), but bad when editing a one-line chat message using Emacs via Textern.

Of course, this is Emacs, so it turns out that it is actually very easy to fix. What I did was this: I configured Textern to use textern.md as the temporary file extension, and added this to my init.el:

(add-hook
 'markdown-mode-hook
 (lambda ()
   (when (string-match "\\.textern\\.md$" (buffer-file-name))
     (setq require-final-newline nil))))

And that’s it! The cool bit is that it only took me five minutes of work, and I didn’t even have to restart Emacs to benefit from this little improvement.

CategoryEnglish, CategoryBlog, CategoryEmacs