smtfmt utility was written to replace the
fmt standard filter. It can be used to format plain text,
most conveniently within textedit or other windows that use
the same widget.
At first its most valuable feature was that it did not discard special characters (characters with a code larger than 127, such as accented characters). Since that time many other features have been added.
smtfmt is a simple filter program, that is, it reads the
text from the standard input and it sends the formatted result to
standard output. It does not accept parameters in the usual way (i.e.
no command line parameters), instead, it is designed to read control
sequences from input text lines beginning with the @@
keyword followed by white space. The first control sequence you want
to try is @@ help, which yields the following result:
Control lines have the form: @@ option_1 option_2 ... option_n
where option_i is one of the following:
lm<n> Set left margin to <n>
flm<n> Set left margin in the first line to <n>
rm<n> Set right margin to <n>
fmt<n> Switch formatting on (<n>=1, default) or off (<n>=0)
arm<n> Switch automatic right margin on (<n>=1, default)
or off (<n>=0) (only has effect if formatting is off)
mp<n> Multiple paragraphs on (<n>=1, default) or off (<n>=0)
ju<n> Switch both-side justifying on (<n>=1) or off (<n>=0, default)
lp<n> Switch left-hand padding on (<n>=1) or off (<n>=0, default)
rp<n> Switch right-hand padding on (<n>=1) or off (<n>=0, default)
!<cmd> Filter the result with command <cmd> (no more options are
allowed in the line after !<cmd>)
Usually, the input consists of a control line followed by the text to
be formatted, as seen in the following example, which formats the text
with a left margin of four spaces and a right margin set to 30,
justifying the output lines on both the left and the right side:
@@ lm4 rm30 ju1 ``Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise.''The result looks like this:
``Never imagine yourself
not to be otherwise than
what it might appear to
others that what you were
or might have been was not
otherwise than what you
had been would have
appeared to them to be
otherwise.''
~/.text_extras_menu file:
"Smart Format" smtfmtTo invoke the formatter, write the necessary control line (beginning with
@@, only needed if default options aren't
satisfactory) in front of the text to be formatted, and then select
the text together with the control line so that the control line is
the first line of the selection. Press the right-hand mouse button and
select Smart Format.
n
spaces will precede each line in the formatted text.
n characters. Note that this
is not possible in case of words that themselves are longer than the
right margin would allow.
n=1 (the default) means that formatting should take
place. By formatting I mean that the input text is broken into output
lines so that the output lines are as long as possible but not longer
than the prescribed limit.
n=0 will generate the output so that an input line is
transformed into one output line. Might be useful when combined with
the lp or rp options, for example.
n=0, default), the right margin will be
determined by the longest input line. Only effective when combined
with fmt0.
n=1, default), empty lines in the input
text are interpreted as paragraph separators. If n=0 is
used (multiple paragraphs off), the whole input text is regarded as
one single paragraph.
n=1), both the left and the right side of
the output text is aligned to the margin by inserting enough space
characters between the words of the line. The default setting is that
this should not take place (n=0).
> ") is inserted in front of
the output lines if the switch is on. Default setting is no padding.
<") is appended to the
output lines if the switch is on. Default setting is no padding.
<cmd>. Formatting is switched off by default when
using this filtering. The whole part of the control line after the
exclamation mark is considered as <cmd>, so this
must be the last option in the control line.
Example 1: Count the number of lines (words, characters) in the input:
@@ !wcExample 2: Discard all words but the last in each input line and display the result in alphabetical order. Display each word only once:
@@ !awk '{ print $NF }' | sort | uniq
Example 3: Number the lines:
@@ !awk '{ printf "%5d %s\n", ++line_number, $0 }'