[Back to tal main page]

tal - Examples

This page is supposed to give you an idea of how the different options offered by tal work together and what tal can do for you. Most examples on this page were generated using tal release 1.5, but so far the specifications have not changed. Please do refer to the manual page that comes with the tal distribution. This page serves only as an illustration.

Example #1

Objective: Align backslashes in long macro definition

Input:

#define HANDLE_KEYSTROKE \ kp = readcmd(); \ if ( kp.action == cmAnimInc \ || kp.action == cmAnimDec) { \ step = ani_adjust_speed (kp.action); \ } \ else { \ if (kp.action == cmAnimSwDir) { \ dir_up = !dir_up; \ turning = TRUE; \ goto dir_change; \ } \ else { \ if (!dir_up) \ view->vmove(1); \ DELAYSYNC; \ V_Pan (0); \ view->display(); \ writestatusline(); \ return kp; \ } \ } Command: tal

Output:

#define HANDLE_KEYSTROKE \ kp = readcmd(); \ if ( kp.action == cmAnimInc \ || kp.action == cmAnimDec) { \ step = ani_adjust_speed (kp.action); \ } \ else { \ if (kp.action == cmAnimSwDir) { \ dir_up = !dir_up; \ turning = TRUE; \ goto dir_change; \ } \ else { \ if (!dir_up) \ view->vmove(1); \ DELAYSYNC; \ V_Pan (0); \ view->display(); \ writestatusline(); \ return kp; \ } \ } Explanation: ---

Example #2

Objective: Repair broken comment box

Input:

/***************************************************/ /* some text and so on */ /* */ /* even more text */ /* foo, bar. bar bar. */ /* */ /***************************************************/ Command: tal -p 0

Output:

/***************************************************/ /* some text and so on */ /* */ /* even more text */ /* foo, bar. bar bar. */ /* */ /***************************************************/ Explanation: The "-p 0" option turns padding off. If we hadn't done that, tal would have placed the closing comment tags one space away from the box. In vim, you may want to define a mapping for box repair that has "-p 0" set.
Since tal works with any trailing characters, it can be used to repair every possible box in any programming language, even to align trailing characters that the author didn't think of!

Note: tal is not designed for drawing boxes! It can only repair them for you. In order to draw boxes, or comment out/in regions of code, please use cor.pl (comment out region), a little script written in Perl. Called with "-l C -b", it will draw a C comment box for you. Look at the author's .vimrc for hints on how to install it in yours. Kevin McCarthy hacked it up to improve on the drawing of boxes (cor-kmc.txt). Recently, boxes has become available, a fast, general, freely configurable box drawing program.


Example #3

Objective: Generate leading dots for an index

Input:

Heading One. SubHeading. FooBar. BarFoo. Heading Two. Salamo. BratBrat. FettFett. Command: tal -k 40 -c .

Output:

Heading One............................. SubHeading........................... FooBar............................... BarFoo............................... Heading Two............................. Salamo............................... BratBrat............................. FettFett............................. Explanation: The option "-k 40" specifies the ending column. We now have exactly 40 characters in width. "-c ." sets the fill character to be a dot, so the space between the trailer (also a dot) and the headings is filled up by more dots. Padding is also added, but in the form of dots, so we don't care.
The next step in the generation of our index would be to add page numbers after the dots. :-)

Example #4

Objective: Beautify a to-do list

Input:

Reshape corporate culture DONE. Gain substantial market share done. Analyze competitor's product Done. Improve shareholder value Assign more funds to research department done. Command: tal -i -p 5

Output:

Reshape corporate culture DONE. Gain substantial market share DONE. Analyze competitor's product DONE. Improve shareholder value Assign more funds to research department DONE. Explanation: Now it's easier to see which tasks are already done. :-) "-i" is used because we need to ignore case. This example was generated using tal version 1.9.

Example #5

Objective: Show how the "-m" option works

Input:

<!-- foo1 bar1 --> <!-- foo2 bar2 --> <!-- foo3 bar3 --> <!-- foo4 bar4 --> Command: tal -m 28

Output:

<!-- foo1 bar1 --> <!-- foo2 bar2 --> <!-- foo3 bar3 --> <!-- foo4 bar4 --> Explanation: "-m" specifies the maximum length we want a line to reach (our screen or printout width, usually). Without "-m", the comments would have been aligned behind bar3. However, the bar3 line is 30 characters long, so it is not considered in the auto-detection ("-m 28" < 30).
Note that trailers are not aligned at column 28! This is just a threshold to exclude lines from the auto-detection. Note also that line "bar2", being initally longer than 28 characters, is properly adjusted. What counts is output length, not input length.
Examples of sensible values for "-m" are 80 for regular terminal windows or 86 for two-on-one printing with a2ps.

Example #6

Objective: Show how to influence trailer length (-f and -l (ell) options)

Input:

/* foo foo foo bar */ /* moo moo moo bar */ /* yabba dabba door */ /* ho ho bar */ /* no bar */ 1. Command: tal

Output:

/* foo foo foo ba r */ /* moo moo moo ba r */ /* yabba dabba doo r */ /* ho ho ba r */ /* no ba r */ 2. Command: tal -l 2

Output:

/* foo foo foo bar */ /* moo moo moo bar */ /* yabba dabba door */ /* ho ho bar */ /* no bar */ 3. Command: tal -l 6

Output:

/* foo foo foo ba r */ /* moo moo moo ba r */ /* yabba dabba doo r */ /* ho ho ba r */ /* no ba r */ 4. Command: tal -l 6 -f

Output:

/* foo foo foo bar */ /* moo moo moo bar */ /* yabba dabba door */ /* ho ho bar */ /* no bar */ Explanation: This is supposed to illustrate how the -f and -l (ell) options work together. All lines in our input example have the common trailer 'r */'. That is because all lines end in 'o bar */' except one ending in 'door */'.
So the result of command #1 is natural. But: You probably wanted to align the closing comment tags only! This is done with command #2.
However, -l (ell) only takes effect if no other trailer is more frequent. Thus, if we tried to set the preferred trailer length to six (as we do in command #3), we only get a trailer of four characters, because it is more frequent.
In order to force tal to use the six character trailer, we use command #4, which includes the -f option. Of course, this leaves the 'door' line untouched.
It may be a good idea to include '-l 2' with your vim mapping if you edit a lot of C code.

As of version 1.9, it is also possible to specify the trailer directly by means of the "-e" option, a more direct approach than using "-f". "-f" is cooler, though. :-)


tal © 1997 by Thomas Jensen <public(at)thomasjensen.com>
Page created November 30, 1997, last updated: 05/25/99. All rights reserved.