mrr@mrsoft.Newport.RI.US (Mark Rinfret) (08/18/90)
Enclosed with this message are a couple of quick hacks I cooked up this weekend. I often find myself adding or removing a level of nesting from a block of code. The usual approach was to insert/delete blanks on a line-by-line basis. The enclosed ARexx scripts can be used with CygnusEd Professional to shift a selected block of text left or right by one tab stop. They're pretty crude, but so far they seem to do the job. Enjoy! /************************************************************************ * left-shift-block.ced * * This ARexx program for CygnusEd Pro moves the selected block left * one tab position. * * Author: Mark R. Rinfret, August 1990 * ************************************************************************/ /* Allow CygnusEd to pass status variables */ options results /* Tell ARexx to talk to CygnusEd */ address 'rexx_ced' cr = '0A'x /* Is a block marked? */ status 69 if result = -1 then do okay1 "No block marked for left-shift-block!" exit end beginLine = result + 1 /* Get current line number. */ status 57 endLine = result + 1 if endLine < beginLine then do temp = endLine endLine = beginLine beginLine = temp end saveBegin = beginLine status 7 /* Get the tab picture string. */ tabString = result firstTab = pos('T',tabString,1) /* Find first tab position. */ /* copy block */ /* copy (unmark) the block */ newLine = "" do while beginLine <= endLine jumpto beginLine 1 status 55 /* Get contents of current line. */ oldLine = result crPos = pos('0A'x, oldLine) /* Line contains newline char? */ if crPos > 0 then do oldLine = delstr(oldLine, crPos, 1) end if length(oldLine) > 0 then do LeftShiftLine() /* newLine gets the result */ delete to eol /* Delete old line of text. */ text newLine /* Replace with new line of text. */ end beginLine = beginLine + 1 end exit /* LeftShiftLine - shift a line left one tab position. * Global variables used: * firstTab - first tab stop position * oldLine - string containing original line * newLine - string to receive result */ LeftShiftLine: procedure expose firstTab oldLine newLine /* Watch out for zero-length strings. */ oldLineLength = length(oldLine) if oldLineLength = 0 then do newLine = "" return 0 end /* Search for first non-blank character or tab stop. */ blanks = 0 spacePos = 1 do spacePos = 1 to oldLineLength if spacePos > firstTab | substr(oldLine,spacePos,1) ~= " " then do blanks = spacePos - 1 leave spacePos end end /* If the original line has embedded tabs, get cheap 'n dirty. Just * delete the first tab we see. Actually, to do this with precision, * we should find the last tab that occurs before the first non-white * character and delete it. That approach would support variable tab * settings more accurately. An exercise for the reader... :-) */ tabFound = pos('09'X, oldLine) if tabFound > 0 & tabFound < blanks then do newLine = delstr(oldLine,tabFound,1) return 0 end /* There's a (remote) possibility that we've found a line of blanks. */ if blanks > 0 then do newLine = delstr(oldLine, 1, blanks) end else do newLine = oldLine end return 0 --------------------------------------------------------------------------- /************************************************************************ * right-shift-block.ced * * This ARexx program for CygnusEd Pro moves the selected block right * one tab position. This script uses a very simplistic approach, simply * inserting a tab character at the beginning of each line in the block. * CED will automatically substitute spaces for the tab, if you have that * feature enabled. * * Author: Mark R. Rinfret, August 1990 * ************************************************************************/ /* Allow CygnusEd to pass status variables */ options results /* Tell ARexx to talk to CygnusEd */ address 'rexx_ced' tab = '09'x /* Is a block marked? */ status 69 if result = -1 then do okay1 "No block marked for right-shift-block!" exit end beginLine = result + 1 saveBegin = beginLine /* Get current line number. */ status 57 endLine = result + 1 if endLine < beginLine then do temp = endLine endLine = beginLine beginLine = temp end do while beginLine <= endLine jumpto beginLine text tab beginLine = beginLine + 1 end exit -- ################################################################# # Mark R. Rinfret, MRSoft Home: 401-846-7639 # # mrr@mrsoft, galaxia!mrsoft!mrr Work: 401-849-9930 x301 # #################################################################