Programmer's WorkBench (pwb.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Macro Example: Expanding Text Abbreviations
                                             Up Contents Index Back
─────Programmer's WorkBench─────────────────────────────────────────────────
 
     The macros below implement a "template" mechanism that you can use
     to expand abbreviations or insert boilerplate text such as a
     standard function header.
 
     The SelWord macro selects the word at the cursor, much like double-
     clicking a word does. This is useful by itself. However, in this
     example, it is used as part of the Expand macro.
 
          ;  Select the current word
          SelWord:= Pword ->eof Mword Arg Meta Pword =>  \
                    :>eof Mword Pword Arg Meta Pword
 
     The Expand macro deletes the word at the cursor and executes it.
     If the word is defined as a PWB function or a macro, PWB performs
     the specified action. In the following example, it is assigned to
     the ALT+T key.
 
          ;  Delete the current word and execute it
          Expand := SelWord Lasttext Cancel Lastselect Meta Sdelete  \
                    Lasttext Execute
          Expand :Alt+T
 
     To use Expand, type the abbreviation and press ALT+T.
 
     With Expand, many text macros can be defined for use as shorthand,
     but only one key is needed to expand them all. For example, with
     the following text macros:
 
          ;  Simple text expansion
          prog := "program"
          ex   := "example"
 
     type 'ex', ALT+T, ' prog', ALT+T to get 'example program'.
 
     You can define a text macro in terms of another so that one
     abbreviation can be used for more than one expansion:
 
          ;  Expand 'cmd' once to get 'command', Expand twice
          ;  to get 'command line'
          cmd    := "command"
          command:= "command line"
 
     Expand is not limited to text macros. It can be used to execute
     any macro or PWB function. For example, the following macro
     expands to the contents of a file──a good technique for large
     boilerplate text:
 
          Header := Arg "$INIT:header.txt" Paste
 
     The following macro could form the basis of a complete C
     programming template package. It expands the 'for' keyword into
     the outline of a for loop and positions the cursor at the first
     enclosed statement.
 
          ;  Expand the skeleton of a C 'for' loop
          for := "for (;;) {"   Begline Down Linsert  "}" Left  \
                 Linsert Tab ";" Left
 
     When Expand is used on the word 'for', it yields the text:
 
          for (;;) {
               ;
          }
 
     After expansion, the cursor is on the statement in the block.
                                    -♦-