home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / tools / aurora21 / compress.aml < prev    next >
Text File  |  1995-08-10  |  3KB  |  105 lines

  1. /* ------------------------------------------------------------------ */
  2. /* Macro:        COMPRESS.AML                                         */
  3. /* Written by:   nuText Systems                                       */
  4. /*                                                                    */
  5. /* Description:  This macro prompts the user for a search string and  */
  6. /*               hides all lines (via folding) in which the search    */
  7. /*               string is not found. The first fold might not        */
  8. /*               contain the search string.                           */
  9. /*                                                                    */
  10. /*               This macro is similar to the 'Find Occurrences'      */
  11. /*               function, but also allows you to edit the            */
  12. /*               occurrences 'in place'. The folds can be removed     */
  13. /*               later by selecting 'Destroy All Folds' from the Fold */
  14. /*               menu (<alt 0> using Aurora keydefs).                 */
  15. /*                                                                    */
  16. /* Usage:        Select this macro from the Macro List (on the Macro  */
  17. /*               menu), or run it from the macro picklist <shift f12> */
  18. /* ------------------------------------------------------------------ */
  19.  
  20.   include bootpath "define.aml"
  21.  
  22.   // prompt the user for the search string in multi-string format
  23.   string_and_opt = ask "[string/birswx] Display occurrences of"  "_find"
  24.   if not string_and_opt then
  25.     return
  26.   end
  27.  
  28.   // add the search string to _find history buffer
  29.   addhistory "_find" string_and_opt
  30.  
  31.   var search_string
  32.   var options
  33.   var o
  34.  
  35.   // parse the search multi-string
  36.   n = splitstr '' string_and_opt
  37.                ref search_string  ref options  ref o
  38.  
  39.   // initialize search options
  40.   if n >= 2 then
  41.     if n > 2 then
  42.       options = o
  43.     end
  44.   else
  45.     options = _SearchOpt
  46.   end
  47.   if pos 'g' options then
  48.     options = sub 'g' '' options
  49.   end
  50.   options = options + '*'
  51.  
  52.   // initialize last line number and fold-count
  53.   lastline = 1
  54.   count = 0
  55.  
  56.   // group undo, and use a temporary mark
  57.   undobegin
  58.   oldmark = usemark 'T'
  59.  
  60.   // save cursor position and move the cursor to the top of the file
  61.   pushcursor
  62.   gotopos 1 1
  63.  
  64.   // do for all lines where the search string is found
  65.   while find  search_string options  do
  66.     thisline = getrow
  67.  
  68.     // fold the lines from the last line to the current line
  69.     if thisline > lastline then
  70.       markline lastline thisline - 1
  71.       foldblock
  72.       count = count + 1
  73.     end
  74.  
  75.     lastline = thisline
  76.     col MAX_COL
  77.   end
  78.  
  79.   // fold the last block, if applicable
  80.   if count then
  81.     if getlines > lastline then
  82.       markline lastline (getlines)
  83.       foldblock
  84.     end
  85.   end
  86.  
  87.   // restore the cursor position
  88.   popcursor
  89.  
  90.   // destroy the temp mark and use the default mark
  91.   destroymark
  92.   usemark oldmark
  93.  
  94.   // end of undo group
  95.   undoend
  96.  
  97.   // display the number of lines where the search string is found
  98.   display
  99.   if count then
  100.     say count + " lines found"
  101.   else
  102.     say "'" + string_and_opt + "'" + " not found" 'b'
  103.   end
  104.  
  105.