/************************************************************************ * 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' cr = '0A'x 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 0 status 55 /* Remove the newline at the end of the result. */ theLine = substr(result,1,length(result)-1); delete to eol /* Push the text over with a tab. If tab-to-spaces conversion is enabled, * this still works fine. */ text tab || theLine 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 | tabFound = 1) 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