home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
epmsmp.zip
/
JUSTIFY.E
< prev
next >
Wrap
Text File
|
1996-02-06
|
7KB
|
131 lines
/****************************************************************************/
/* PJUSTIFY_MARK: REFLOW THE TEXT AND LEFT JUSTIFY , THEN RIGHT JUSTIFY */
/* */
/* Ctrl-J to initiate */
/* Operates on LINE marked text with current margin setting (not>=254) */
/* Operates on the text marked with BLOCK mark within the mark */
/* If NO MARK, operates from current line to next blank line */
/* with current margin setting (Thanks to Cristian Peter) */
/* Honors paragraph indent specification of Margin setting */
/* Does NOT right justify last line */
/* */
/* Uses a simple insert blanks starting from right end to right justify */
/* Uses some procedures from EXTPROCS.E */
/* Include 'justify.e' in main.e */
/* between include 'stdkeys.e' and include 'stdcnf.e' */
/* */
/* Patrick Leabo (LEABO at TUCVM2) 7-23-86 Initial Ver 1.00 */
/* 7-24-86 Corrected First Line bug 1.01 */
/* 7-26-86 Changed NO MARK to work to next blank line, 1.10 */
/* and BLOCK to work just in the block */
/* 8-03-86 Changed justify algorithm to space out blanks a bit 1.11 */
/* and got rid of flashing screen in block justify */
/* 12-17-86 Checked it out on E3 -- OK as is on vanilla E3 */
/* 11-28-89 Massage with brass hammer until functional under EPM; J e r r y */
/****************************************************************************/
compile if not defined(REFLOW_LIKE_PE)
const
REFLOW_LIKE_PE = 0
compile endif
def c_j=pjustify_mark() /* Use the Ctrl-J key to initiate */
defproc pjustify_mark /* First reflow the text per the mark type */
mkt = marktype() /* save some initial conditions */
plsvcol =.col;plsvline = .line;plsvcx = .cursorx;plsvcy = .cursory
if mkt = 'BLOCK' then
getmark bfirstline,blastline,firstcol,lastcol,plfileid
if lastcol - firstcol < 8 then
sayerror 'Quitting Justify - Block Mark < 8 chars wide'
stop
endif
'xcom e /q /n /h .tempo' /* move the source to a temporary file */
getfileid pltempfid ; sayerror 0 ; activatefile pltempfid
.col = firstcol ; .line = 1
copy_mark ; unmark
activatefile plfileid
call pset_mark(bfirstline,blastline,firstcol,lastcol,mkt,plfileid)
fill_mark ' ' ; unmark /* blank the source */
activatefile pltempfid
savemargins = pmargins()
'ma 'firstcol lastcol
.line = 1 ; mark_line
.line = .last ; mark_line
reflow /* reflow first */
getmark firstline,lastline,bfirstcol,blastcol,pltempfid
unmark
parcol = firstcol
'ma 'savemargins
elseif mkt = 'LINE' or mkt = '' then /* line type mark or no mark */
parse value pmargins() with firstcol lastcol parcol
if lastcol >= 254 then
sayerror 'Quitting Justify - Right Margin is 254'
stop
endif
if mkt = '' then /* no mark, look for a blank line */ /* M */
if (.line = 0) then /* o */
sayerror "Can't justify here" ; stop /* d */
else /* */
getline line
if line = '' then sayerror "Can't justify here" ; stop endif
mark_line ; call pfind_blank_line() /* b */
getline line; if line='' then up else .line=.last endif /* y */
mark_line /* */
endif /* C */
endif /* P */
reflow /* reflow first */
getmark firstline,lastline,mfirstcol,mlastcol,plfileid
else sayerror 'Character mark invalid'; stop endif
/****** this is the justify code ********/
savemargins = pmargins() ; 'ma 1 254'
if not insert_state() then insrtflg=1 ; insert_toggle else insrtflg=0 endif
oddlinetgl = 0
for i=firstline to (lastline-1)
/* if ((i = lastline) and (firstline <> lastline)) then leave endif */
if i = firstline then startcol = parcol else startcol = firstcol endif
.line = i ; begin_line
keyin '>' ; rubout /* just to get rid of trailing blanks */
end_line ; nspaces = lastcol + 1 - .col
backtab_word ; pltgl = 0
if (.col > startcol) and (nspaces > 0) then /* this does the deed */
backtab_word ;
if oddlinetgl = 0 then
backtab_word ; oddlinetgl = 1 /* start in 3rd space */
else oddlinetgl = 0;
endif
for j = nspaces to 1 by -1
if .col <= startcol then
end_line ; backtab_word
if pltgl = 0 then backtab_word ; pltgl = 1 else pltgl = 0 endif
if .col <= startcol then end_line ; backtab_word endif
endif
keyin ' ' ; backtab_word ; backtab_word
endfor
endif
endfor
'ma 'savemargins /* cleanup */
if mkt = 'BLOCK' then
call pset_mark(firstline,lastline,firstcol,lastcol,mkt,pltempfid)
activatefile plfileid
.line = bfirstline ; .col = firstcol
overlay_block ; activatefile pltempfid
.modify=0 ; 'xcom q'
activatefile plfileid
endif
if insrtflg = 1 then insert_toggle endif /* restore initial conditions */
if mkt = '' then unmark endif
.cursorx = plsvcx; .cursory = plsvcy; .col = plsvcol;
if plsvline>.last then .line=.last else .line = plsvline endif
compile if REFLOW_LIKE_PE /* position on next paragraph (like PE) */
call pfind_blank_line()
if plsvline = .line then .line=.last else .line = .line + 1 endif
call pfind_nonblank_line()
compile else
getmark firstline,lastline
.line=firstline
.cursory=plsvcy;.cursorx=plsvcx; .line=plsvline;.col=plsvcol;
compile endif