customizing emacs with perl: Text::Autoformat

11 views
Skip to first unread message

Joe Brenner

unread,
Aug 14, 2009, 8:43:06 PM8/14/09
to emacs-perl-...@googlegroups.com

Here's a nice simple trick. If you don't like the way emacs is
formatting your text, one solution is to use an external program
to do it via "shell-command-on-region":

I was just writing a line of text with some embedded right angle
brackets in it: '>>'. The line was getting long but there's a bug with
M-q ("fill-paragraph") in emacs (at least in MH-Letter-mode). It takes
a line like this:

Right, that's probably a harder one: '>>' looks like it's part of a heredoc.

And wraps it like:

Right, that's probably a harder one: '>>' looks like it's part of a
>>heredoc.

Apparently it gets confused and thinks the angles indicate text quoted
from a previous reply... The way I want this to wrap is like so:

Right, that's probably a harder one: '>>' looks like it's part of
a heredoc.

And that is exactly what this does (but you do need to select the text
first, before doing a "M-oM-f"):

(defun doom-run-text-autoformat-on-region (start end)
"Format the region using Text::Autoformat."
(interactive "r")
(let ( (command
(format
"perl -MText::Autoformat -e'autoformat {right=> %d, all=>1}'"
fill-column)) )
(shell-command-on-region start end command nil t "*error*")
))
(global-set-key "\M-o\M-f" 'doom-run-text-autoformat-on-region)

Reply all
Reply to author
Forward
0 new messages