/* ** Outdent.ced ** ** $VER: Outdent.ced 1.0 (18.2.95) ** ** This script can outdent a line or block. It removes first white char from ** beginning of current line or each line in block if block is marked. ** Useful for editing source. ** ** This script requires CygnusEd Professional v3.5 (or later) to run. ** ** Copyright © 1995 Michael Letowski */ /* Get host */ PARSE SOURCE Com Res Called Resolved Ext Host . IF Host="REXX" THEN /* From command line */ ADDRESS "rexx_ced" /* Talk to default CEd */ OPTIONS RESULTS /* Hear it from CEd */ GV.TAB="09"X GV.LF="0A"X GV.Ops=0 /* Number of operations for Undo.ced */ 'Status CURSORMEMORYX' /* Get position of cursor in line */ Pos=RESULT 'Status LINEBUFFEROFFSET' /* Get position of line */ Pos=Pos+RESULT 'DM "Outdenting..."' 'Cut block' /* Cut marked block */ IF RESULT THEN /* There is a marked block */ CALL OutdentBlock /* Outdent block */ ELSE /* No marked block */ CALL OutdentLine /* Outdent line */ CALL SetClip(UndoClipName(),GV.Ops) /* Set data for Undo.ced */ 'Jump to byte' Pos-GV.Removed /* Move cursor to old position */ 'DM' /* Restore status line */ EXIT /* Finished */ OutdentBlock: PROCEDURE EXPOSE GV. GV.Removed=0 'Status BLOCKBUFFER' /* Get buffer */ ToOutdent=RESULT /* And store it */ IF Length(ToOutdent)=0 THEN DO /* Nothing to outdent */ 'Okay1' "No area marked." RETURN END GV.Ops=GV.Ops+1 DelPos=1 DO UNTIL DelPos=1 /* For each line... */ Char=SubStr(ToOutdent,DelPos,1) IF Char=GV.TAB | Char=" " THEN ToOutdent=DelStr(ToOutdent,DelPos,1) DelPos=Pos(GV.LF,ToOutdent,DelPos+1)+1/* Find end of a line */ END 'Text' ToOutdent /* Insert back to CED */ GV.Ops=GV.Ops+RESULT RETURN OutdentLine: PROCEDURE EXPOSE GV. 'Delete line' /* Delete current line */ GV.Ops=GV.Ops+RESULT /* Increase number of ops */ 'Status DELETELINEBUFFER' /* Get current line */ PARSE VAR RESULT First 2 Rest /* Split it */ IF First=GV.TAB | First=" " THEN DO /* Remove first char */ 'Text' Rest /* Insert rest of line */ GV.Removed=1 END ELSE DO 'Text' First||Rest /* Insert whole line */ GV.Removed=0 END GV.Ops=GV.Ops+RESULT /* Increase number of ops */ RETURN UndoClipName: 'Status FILEMEM' /* Get address of current file */ RETURN "CEDUndo."Right(D2X(RESULT),8,"0") /* Prepare unique name */