Thoughts on Perl and Emacs, technology and writing

Emacs and External Processes

Emacs has some nice facilities for interacting with external
processes. Recently I was working with an extremely long line with no
spaces that I wanted to split into lines of 72 characters. I banged
this out in about 20 seconds:

M-| (shell-command-on-region)
perl -e '$_=<>;s/(.{72})/$1\n/g;print'

Now,

Maybe I could have written this to a file and run perl on it using
the shell

Related

3 Responses

where the items in [] are keypresses. The regex is pretty much the same as what you have there in perl, except with more backslashes, and the “ctrl-q ctrl-j” thing is needed to get a newline into the replacement text.

Also, you could shorten your perl like this:

perl -pe ‘s/(.{72})/$1\n/g’

Lastly, I assume you used a prefix arg on your M-| too, since that would cause the perl output to replace the region directly.

[…] One thing that isn’t well highlighted (so to speak) is how well ediff drills down on the exact change. It doesn’t just say “this line is different to this line”, it focuses on the exact change within the line. You can easily see here the tags that have been added to an old revision of one of my earlier posts. […]