mrr@mrsoft.Newport.RI.US (Mark Rinfret) (08/23/90)
A few days ago, I posted a couple of CED macros for right/left shifting of a selected block. To my dismay, I discovered that in editing out some debug stuff, I really botched up the right-shift-block macro. I've since discovered a minor glitch in the left-shift-block macro which shows up when you're using real tabs (vs. tabs = spaces). Included is a repost of the macros. Please accept my apologies. Mark /************************************************************************ * 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 | 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 -------------------------------------------------------------------------- /************************************************************************ * 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 -------------------------------------------------------------------------- -- ################################################################# # Mark R. Rinfret, MRSoft Home: 401-846-7639 # # mrr@mrsoft, galaxia!mrsoft!mrr Work: 401-849-9930 x301 # #################################################################