RSS / Atom

Reflow using Text::Autoformat

2005-10-01 , ,

Filladapt mode is good but the Perl module [Text::Autoformat]( is better at reflowing text for email. I cobbled together the following elisp to make that easy.

   (defun rel-autoformatter (begin end rightmargin)
      "Run Text::Autoformat on region"
      (shell-command-on-region begin end
       (format "perl -MText::Autoformat -e 'autoformat({all=>1,right=>%d})'" rightmargin) t t )
      (message "done."))
   (defun rel-autoformat (begin end)
      Text::Autoformat on region, RFC recommended right margin of 72"
      (interactive "r")
      (rel-autoformatter begin end 72))
   (defun rel-autoformat-quote (begin end)
      "Text::Autoformat on region, right margin of 60, suitable for quoting replies"
      (interactive "r")
      (rel-autoformatter begin end 60))
   (global-set-key (kbd "C-c f f") 'rel-autoformat)
   (global-set-key (kbd "C-c f q") 'rel-autoformat-quote)

It might be nice to handle parameters other than right margin- and do it in a cleaner way than explicitly specifying them. I doubt I’ll get around to it since Text::Autoformat usually does the right thing for me with just the margin hint.


Commenting is closed for this article.