home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / DOS / TEKST / AURORA2 / COMPRESS.AML < prev    next >
Text File  |  1995-04-28  |  3KB  |  106 lines

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