Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.6: Format text via a Service and emacs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Format text via a Service and emacs
Authored by: d1taylor on Oct 28, '09 08:29:13AM

You're making this WAYYY too hard, chaps. Just use the "fmt" command on the command line. As an added bonus, you can specify how wide you want your lines to be too. For example:

fmt -w70

does what you want without the overhead of loading the emacs behemoth. Turns out that fmt can do a lot more if you read up on it. Try "man fmt" to get some of its slick tricks.



[ Reply to This | # ]
10.6: Format text via a Service and emacs
Authored by: 1amzave on Oct 28, '09 08:58:58AM
Additionally...
tmp=/tmp/emacsmail`date "+%s"`.txt
...would probably be cleaner via mktemp (1), and for this:
cat /dev/stdin | tr '\r' '\n' > $tmp
cat (1) reads stdin by default, so 'cat /dev/stdin' is redundant, though tr (1) also reads stdin by default, so the 'cat' is not actually needed (though if your system has it, 'mac2unix' may also be a slightly clearer way of achieving the same thing as that particular invocation of tr). In combination with fmt (1) as mentioned above, there should actually be no need for temporary file at all, obviating the 'mktemp' as well, and the script basically becomes a one-liner, perhaps just piping mac2unix into fmt (and maybe back into unix2mac again if you want carriage returns instead of line feeds).

I think the more fundamental hint here though is the mechanism of having text-manipulation scripts available as a service (and as mentioned, possibly with a quick hotkey) which is a cool idea that could allow lots of similarly-handy things.

[ Reply to This | # ]
10.6: Format text via a Service and emacs
Authored by: renaud on Jan 18, '10 04:34:46AM
You're making this WAYYY too hard, chaps. Just use the "fmt" command on the command line.
fmt is a nice formatting tool, but it won't do everything emacs does. For example, I don't believe that fmt would format a list like this:
- This is the first item of a list.

- This is the second item, in which the second line is properly
  indented.
Edited on Jan 18, '10 04:35:13AM by renaud


[ Reply to This | # ]