home *** CD-ROM | disk | FTP | other *** search
-
- // ───────────────────────────────────────────────────────────────────
- // The Aurora Editor v2.0
- // Copyright 1993-1995 nuText Systems. All Rights Reserved Worldwide.
- //
- // Entab macro (does not used builtin entab, can be customized)
- //
- // Converts spaces to tabs in the current file. The conversion is
- // limited to a marked block if it exists in the current file. The
- // current value of the _TabWidth config variable is used for the
- // conversion.
- //
- // (Note: this macro will run faster if undo is disabled)
- // ───────────────────────────────────────────────────────────────────
-
- // compile time macros and function definitions
- include bootpath "define.aml"
-
- // declare variables which are referenced before
- // they're assigned a value
- var space_total
- var tab_total
- var line_total
- var progress_line
- var lastline
-
- if not objtype? "edit" then
- msgbox "Edit windows only!"
- return
- end
-
- width = _TabWidth
- tabchar = char 9
-
- // setup search string for 2 or more spaces, quote chars, and tabs
- search_str = "{ #}|['\"" + tabchar + ']'
- search_opt = if mark? and getmarkbuf == getcurrbuf then
- "xb"
- else
- 'x'
- end
-
- // group together as one undoable operation and save cursor position
- undobegin
- pushcursor
-
- // search for 2 or more spaces, quote chars, and tabs
- // using reg expressions
- spaces = find search_str search_opt + "g*"
-
- while spaces do
-
- if getchar <> ' ' then
-
- // if the file already contains tabs, undo what's been done,
- // display a message, and return
- if getchar == tabchar then
- popcursor
- undoend
- undo
- msgbox "File or block already contains tabs - expand tabs first"
- return
-
- // if quote characters are found, skip the rest of the line
- else
- col MAX_COL
- end
-
- else
-
- if line_total then
- // if this is a new line, set spaces-removed to zero
- if getrow <> lastline then
- line_total = 0
- end
- end
-
- // get the distance to the next tab stop
- dist_to_tab = width - (getcol + line_total - 1) mod width
-
- // ..if greater than the number of spaces, go to next tabstop
- if dist_to_tab > spaces then
- right dist_to_tab
-
- // ..otherwise add up totals, delete spaces, and insert tabchar
- else
- space_total = space_total + dist_to_tab
- line_total = line_total + dist_to_tab - 1
- tab_total = tab_total + 1
- delchar dist_to_tab
- instext tabchar
- lastline = getrow
-
- // show progress
- if lastline >= progress_line then
- progress_line = progress_line + 150
- say "Entab [" + lastline + ']'
- end
- end
- end
-
- // repeat find
- spaces = find search_str search_opt
- end
-
- popcursor
- undoend
-
- // display totals
- msgbox (thousands tab_total) + " tabs added, " +
- (thousands space_total) + " spaces removed." "Entab"
-
-
-