longlines-mode

Posted on Tue 16 June 2009 in misc

I use a fantastic little Firefox add-on called It's all Text to spawn an Emacs client when editing text boxes. However up until recently I kept having problems with formatting of my posts. Even though HTML doesn't really care about white space most blog software tends to treat them as though they mean something. This can lead to some ugly formatting because hidden HTML elements still count towards auto-fill-mode when flowing text. Yes I can turn off auto-fill mode but then lines wrap at the full width of my emacs window.

Enter longlines-mode which still wraps the text pleasingly on my display but only puts the real "hard returns" in the final text. As a bonus it even shows me the real returns as special glyphs.

; I don't want all text-mode stuff to be auto-fill as editing text
; boxes can screw with the formatting (especially if html is involved)
(add-hook 'text-mode-hook
          '(lambda ()
             (if (string-match "itsalltext" (buffer-file-name))
                 (progn
                   (message "enabling long lines for itsalltext")
                   (longlines-mode 1)
                   (longlines-show-hard-newlines))
               (turn-on-auto-fill))))

I can finally remove the horrible /r /n gobbling hack in my blog script and post code snippets formatted the way I want them :-)