home *** CD-ROM | disk | FTP | other *** search
/ Bila Vrana / BILA_VRANA.iso / 028A / AUROR.ZIP / EXAMPLE.AML < prev    next >
Text File  |  1996-07-17  |  14KB  |  522 lines

  1. //--------------------------------------------------------------------
  2. // EXAMPLE.AML
  3. // AML examples and code fragments (C), 1993-1996 by nuText Systems
  4. //
  5. // This file is not an executable macro. It contains AML examples and
  6. // code fragments which can be used in other macro files.
  7. //--------------------------------------------------------------------
  8.  
  9. // Example 1 ---------------------------------------------------------
  10.  
  11. // mark the entire file - assign to the <f12> key
  12. key <f12>
  13.   markline 1 (getlines)
  14. end
  15.  
  16.  
  17. // Example 2 ---------------------------------------------------------
  18.  
  19. // block marking without having the cursor resize the mark
  20.  
  21. // mark line
  22. key <alt l>
  23.   markline
  24.   stopmark    // stopmark closes the mark
  25. end
  26.  
  27. // mark character
  28. key <alt a>
  29.   markchar
  30.   stopmark
  31. end
  32.  
  33. // mark column
  34. key <alt b>
  35.   markcolumn
  36.   stopmark
  37. end
  38.  
  39.  
  40. // Example 3 ---------------------------------------------------------
  41.  
  42. // block copy without moving the mark
  43. key <alt c>
  44.   undobegin                // group together as one undoable operation
  45.   copymark curr_mark 'T'   // create temp copy of original mark
  46.   oldmark = usemark 'T'    // use the temp mark
  47.   copyblock2               // copy marked text (moves the mark also)
  48.   destroymark              // destroy the temp mark
  49.   usemark oldmark          // switch back to the original mark
  50.   undoend
  51. end
  52.  
  53.  
  54. // Example 4 ---------------------------------------------------------
  55.  
  56. // automark example - creates a temporary paragraph mark if
  57. // no mark exists
  58.  
  59. // begin automark
  60. function begauto
  61.   if not mark? then        // if no mark exists...
  62.     _am = ON               // set a flag
  63.     markpara               // mark the current paragraph
  64.   end
  65. end
  66.  
  67. // end automark
  68. function endauto
  69.   if _am then              // if flag was set..
  70.     _am = OFF            // unset flag
  71.     destroymark            // destroy the temporary mark
  72.   end
  73. end
  74.  
  75. // usage example (indent a block)
  76. key <shift f8>
  77.   begauto
  78.   shiftblock 1
  79.   endauto
  80. end
  81.  
  82.  
  83. // Example 5 ---------------------------------------------------------
  84.  
  85. // Repeat Last Find with wrap around
  86. function findlastw
  87.  
  88.   variable search_str, options
  89.  
  90.   // get last find string
  91.   history_str = gethiststr "_find"
  92.  
  93.   // do the search
  94.   if not search2 history_str '' TRUE then
  95.  
  96.     // not found, wrap to top or bottom
  97.     if (splitstr '' history_str ref search_str ref options ) >= 2 and
  98.        (pos 'r' options) then
  99.       row (getlines)
  100.       col getlinelen + 1
  101.     else
  102.       gotopos 1 1
  103.     end
  104.  
  105.     // repeat the search
  106.     search2 history_str
  107.   end
  108. end
  109.  
  110. // usage example
  111. key <ctrl l>  findlastw
  112.  
  113.  
  114. // Example 6 ---------------------------------------------------------
  115.  
  116. // change the left and right cursor keys to wrap to the previous or
  117. // next line
  118.  
  119. // cursorleft with wrap
  120. key <left>
  121.   if getcol == 1 then             // wrap if at column 1
  122.     if up then                    // ..and not at first line
  123.       col getlinelen + 1
  124.     end
  125.   else
  126.     left
  127.   end
  128. end
  129.  
  130. // cursorright with wrap
  131. key <right>
  132.   if getcol > getlinelen then     // wrap if at end-of-line
  133.     if down then                  // ..and not at last line
  134.       col 1
  135.     end
  136.   else
  137.     right
  138.   end
  139. end
  140.  
  141.  
  142. // Example 7 ---------------------------------------------------------
  143.  
  144. // change the <del> key to delete a block if marked, otherwise
  145. // delete a character
  146.  
  147. key <del>
  148.   if mark? then
  149.     deleteblock      // delete block if it exists,
  150.   else
  151.     delchar2         // otherwise delete a character
  152.   end
  153. end
  154.  
  155.  
  156. // Example 8 ---------------------------------------------------------
  157.  
  158. // find the word at the cursor - assigned to <ctrl f11>
  159. key <ctrl f11>
  160.   wordstr = getword           // get word using the default charset
  161.   if wordstr then
  162.     search2 wordstr           // find the word
  163.   else
  164.     say "no word at the cursor" 'b'
  165.   end
  166. end
  167.  
  168.  
  169. // Example 9 ---------------------------------------------------------
  170.  
  171. // emulate the QEdit 'GetPrev' command:  copies characters from
  172. // the line above the current line - assigned to <alt 4> key.
  173. key <alt 4>
  174.   if getrow > 1 then                         // if after first line...
  175.     writetext (getchar (getcol) getrow - 1)  // get char and write it
  176.   end
  177. end
  178.  
  179.  
  180. // Example 10 --------------------------------------------------------
  181.  
  182. // emulation of Brief-style <home> and <end> keys. These keys should
  183. // be placed in the 'edit' object.
  184.  
  185. // brief <home> key emulation
  186. key <home>
  187.   col 1                                      // goto column 1
  188.   smark                                      // cua marking
  189.   keycode = getkey                           // get next key
  190.   if keycode == <home> then                  // <home> pressed 2nd time?
  191.     row (getviewtop)                         // goto to page top
  192.     smark                                    // cua marking
  193.     keycode = getkey                         // get next key
  194.     if keycode == <home> then                // <home> pressed 3rd time?
  195.       row 1                                  // goto to top of file
  196.       smark                                  // cua marking
  197.     else
  198.       queuekey keycode                       // execute key normally
  199.     end
  200.   else
  201.     queuekey keycode                         // execute key normally
  202.   end
  203. end
  204.  
  205. // brief <end> key emulation (br)
  206. key <end>
  207.   col getlinelen + 1                         // goto end-of-line
  208.   smark                                      // cua marking
  209.   keycode = getkey                           // get next key
  210.   if keycode == <end> then                   // <end> pressed 2nd time?
  211.     row (getviewbot)                         // goto to page bottom
  212.     smark                                    // cua marking
  213.     keycode = getkey                         // get next key
  214.     if keycode == <end> then                 // <end> pressed 3rd time?
  215.       row (getlines)                         // goto to bottom of file
  216.       smark                                  // cua marking
  217.     else
  218.       queuekey keycode                       // execute key normally
  219.     end
  220.   else
  221.     queuekey keycode                         // execute key normally
  222.   end
  223. end
  224.  
  225.  
  226. // Example 11 --------------------------------------------------------
  227.  
  228. // shows how to 'double-up' key usage for some keys by testing
  229. // for the <shift> key
  230.  
  231. key <alt k>
  232.   if shiftkey? then      // <alt shift k>
  233.     :
  234.   else                   // <alt k>
  235.     :
  236.   end
  237. end
  238.  
  239.  
  240. // Example 12 --------------------------------------------------------
  241.  
  242. // prompts the user for the name of a program and passes the word
  243. // at the cursor to it as the first parameter.
  244.  
  245. key <shift f12>
  246.   parm = getword _CSetB                  // get word using charset CSetB
  247.   if parm then
  248.     program = ask "Program to execute"   // prompt user for program
  249.     if program then                      // program entered?
  250.       run program + ' ' + parm  "ck"     // concatenate program with word
  251.     end                                  //   and execute it
  252.   else
  253.     say "no word at the cursor" 'b'      // no word found at the cursor
  254.   end
  255. end
  256.  
  257.  
  258. // Example 13 --------------------------------------------------------
  259.  
  260. // strip leading or trailing spaces from a string
  261.  
  262. // return string 'charstring' without leading spaces
  263. function stripl (charstring)
  264.   return charstring [posnot ' ' charstring : -1]
  265. end
  266.  
  267. // return string 'charstring' without trailing spaces
  268. function stript (charstring)
  269.   return charstring [1 : posnot ' ' charstring 'r']
  270. end
  271.  
  272.  
  273. // Example 14 --------------------------------------------------------
  274.  
  275. // attach 'properties' to a string value in the current object
  276.  
  277. // set a property
  278. function setprop (string prop value)
  279.   this [string + '-' + prop] = value
  280. end
  281.  
  282. // get a property
  283. function getprop (string prop)
  284.   this [string + '-' + prop]
  285. end
  286.  
  287. // delete a property
  288. function delprop (string prop)
  289.   destroyvar string + '-' + prop
  290. end
  291.  
  292.  
  293. // Example 15 --------------------------------------------------------
  294.  
  295. // modify the save-as prompt to change