From: fairfield@umahe1.slac.stanford.edu
Subject: KHF$FORMAT.2-OF-3, V2.2  (EVE Justify/Unjustify)
Organization: Stanford Linear Accelerator Center
Date: Mon, 25 Jan 1993 23:09:57 GMT

-+-+-+-+-+-+-+-+ START OF PART 2 -+-+-+-+-+-+-+-+
Xend\1D08;
X
Xif`20get_info`20(\4807_buffer,`20"system")
Xthen
X\4B04eve$message`20(EVE$_CANTSYSTEMBUF);
X\2608learn_abort;\1505return`20(FALSE);
Xendif;
X
X!`20Can't`20fill`20an`20empty`20\8406`20-`20avoid`20additional`20checks`20lat
V\2003on\C405beginning_of\C810)`20=`20end\1A14\D81CNOFILL\D134if`20not`20eve$de
Vclare_intention`20(eve$k_action_format)\880A\541Bdo_justify\D103tpu$k_unspecif
Vied`09`09`09`09`09!`20KHF
Xthen\0F05\130A\5B04\400B:=`20FALSE;`09\240B\6B06\390F\7907fill_edit`20\7B38
V\420A:=`20\8B0A\8223position`20(TEXT);
Xsaved_mark`20:=`20\0805(NONE);
X
X!`20Find`20beginning`20of`20paragraph.`20`20P\0C08`20breaks`20are`20blank`20li
Vnes,`20DOCUMENT`20tags,
X!`20runoff`20commands,`20FF`20(hard`20FF),`20or`20FF+NL`20(soft`20FF)\6703If
V`20on`20a`20\7B09\6F06
X!`20other`20than\1F03\6C0C\4904\6B0E\9205,`20then`20do`20preceding`20\D10A
X
Xposition`20(LINE_BEGIN);
Xif`20search_quietly`20(ANCHOR`20+`20\290A`20+
X`09`09`20`20`20(("."`20`7C`20"<")\2103any`20(eve$x_\9206_characters)),
X\3405FORWARD)`20<>`200
Xthen
X`20\1703!`20on`20\D825go`20to`20next\1105\3E05\CE0FEND);
X\1904move_horizontal`20(1\1907start_paragraph`20:=`20mark`20(NONE);
Xelse\2905loop
X`09!`20stop`20at`20\0704of`20buffer
X`09exitif`20\3C0B`20=`20beginning_of`20(current_buffer);
X`09move_vertic\9404-1\1504\C40FBEGIN);`20`20!`20incase`20set(column_m\410C,on)
V\A20Ca`20break`20and`20move`20to\EF06\B804next`20line
X`09if`20eve$paragraph_break
X`09then
X`09\FC04\930FEND);
X`09\1A04move_horizont\C404\C305\1A04exitif;
X`09endif;
X\1405ndloop\0D06start_p\7608`20:=`20mark`20(NONE);
X\790Esaved_mark);
X\5307
X!`20find`20end\D304\4B09
X
Xloop\410FLINE_BEGIN)\8D07xitif\740C`20=\4B04_of`20(current_buffer)\320Deve$
V\6C09_break\2006move_vertical`20(1\AA06\F206
Xif`20\F210\F10D
Xthen
X\6705ve$message`20(EVE$_NOFILL\8607\D30Asaved_mark\A108ve$learn_abort;\1505ret
Vurn`20(FALSE);
Xelse
X\AF09horizont\B104-1\4807stop\A80B:=\A90C;
X
X\2404!`20Now`20fill`20the`20p\2E08
X
X\1F05the_right_margin`20:=`20get_info`20(current_buffer,`20"r\2B0B")\6307if
V\D205$x_word_wrap_indent`20`7B\420E`7D`20<>`20tpu$k_unspecified\8908n
X`09the_left\8E0B\5B28;
X\4704else\4715\D51B\2A0B");
X\4705ndif\DF11paragraph_\DF3B\3B07\DA0A\5621
X`09`09`20\4404`20-\4704\D90C\F410\5C0A\EF28`20-\5E09\5C16ndif;
X\0C05fill_range\6204create\1007(start\CB0A,`20stop\100CNONE);\4906if`20do_
V\4F05edit`09`09`09`09\0303!`20KHF
X\8A07n`09\160D`09khf$f\3108`20(\8B0A);\270C!`20`20Replace\4504`20previous`20li
Vne`20by:\2B0E\DF03\4E0F,`20COMPRESS,`20TRIM,`20OFF)\6304\360Ato`20suppress`20e
Vxtra`20space`20following`20sentences...\D80Celse\D80F\8112TRIM_LEADING\7F07
V\3D06ndif\ED06\3F09\1905fill\430Eeve$x_fill_separators,
X`09`20`20the_left_margin,`20the_righ\120Eindent);
X\6105if`20do_justify`09\800C\1E04then`09\D50Ekhf$\2F07\990C);\3B0F\D319positio
Vn`20(stop_paragraph);
X\3805ve$show_first_line;
X\4D06
Xreturn`20(TRUE);
X
Xendprocedure;\6403eve$fill_\5509
X
X`0C
X!`20EVE$FORMAT.TPU\9307Page`2012
X
Xp\4308\400Arange\B604Fill`20a`20range\9F05(range_arg\AF06`20do_justify,\3105la
Vg`20whether`20to`20right-j\2206`20the\4C07\8204!`20\5003DEFAULT`20=`20FALSE)
V\5609fill_edit)`09\5813callKhf$Fill_Edit`20befor\590Afill\5E0C\A80A)
X
Xlocal`09the\EA06,
X`09start_mark,\4105Start`20of`20\B309\7604fill
X`09the_right_margin,\1306left\120Eindent\5E06tus,
X`09old_\3B0Fend_mark;`09\7804Marker`20for`20end\8104range
X
Xon_error
X`20\DD03`5BTPU$_CONTROLC`5D:
X`09eve$$release_scratch_buffer;
X`09if`20\7A10`20<>`200
X\A704n
X`09`20\5403set`20(RIGHT_MARGIN,`20eve$$x_\4F0E,`20\4B10);\C605if\0804ve$learn_
Vabort;
X`09\0807\B705OTHERWISE`5D\B38Aendon_error;
X
Xif`20not`20eve$declare_intention`20(eve$k_action_format)
Xthen
X\8F04return`20(FALSE);
Xendif;
X\5404do_justify`20=`20TPU$K_UNSPECIFIED`09`09`09`09`09!`20KHF
Xthen\0F05\130A\5B04\400B:=`20FALSE;`09\240B\6B06\390F\7907fill_edit`20\7B38
V\420A:=`20\8B0A\8223the_range\3A04range_arg;
Xif`20\1B0A<>`200
Xthen\7005if`20get_info`20(\2509,`20"type")`20=`20ARRAY
X\2C04then
X\6C03box`20selection
X`09if`20not`20eve$$reserve_scratch_buffer
X`09t\3B05\4504eve$message`20(EVE$_ILLSCRATCHRES);
X\2705return`20(FALSE);
X`09\F206
X`09erase`20(eve$$x_\680E\2804position\CE0B`20`7B1`7D\1B04!`20cut`20\BE04to`20s
V\3A06`20b\A207eve$$box_cut`20\3C0A,`20\6A15,
X`09`09\A704`20`20TRUE,`09!`20delete`20the\6204\1F09\C007\2103no`20m\F806s
X\0F03set`20up\3005\8B0E\9D04be`20filled`20\0D04ox's`20width
X`09old_right_margin`20:=`20get_info`20(\AC16`20"\320C");
X`09if`20length\EB0B`20`7B1`7D)`20=`201
X`09then`09!`20avoid`20left=right=1
X`09\D504\BC04(RIGHT_MARGIN,`20e\7A162);
X`09else\3930\9E16\4E05ndif\0804ve$trim\3307\FD17\3204position\231Bif\8905fill
V\6F07(creat\7D08(BUFFER_BE\B505\0E07END),`09!`20KHF
X`09`09\E204do_justify,`20do_fill_edit)`09`09`09\2807then
X\2C04`20!`20Now`20overstrike`20the`20filled`20s\A306`20b\DD06over`20original
V`20box.\4308This`20can't`20add`20more`20lines`20since`20no`20text`20that`20exc
Veeds\6904\4008box`20right`20side`20is`20ever`20wrapped`20down\6C07position`20(
Vbeginning_of`20(the_range`20`7B1`7D));
X\2E05eve$$box_o\E00A(eve$$x_\DD07_buffer\320Cclear_message;\1806status`20:=
V`20TRUE;
X`09else\1B10FALS\1C05ndif\0804ve$$release\700F;
X`09set`20(RIGHT_MARGIN,\B006\9B10,`20old_right_margin\AD04return`20(\7E06);
X\BE05\7906\0C05!`20standard`20selection
X\1A05if`20beginning_of`20(the_range)`20<=\4504\160F\3605then
X`09start_mark`20:=`20\4718\FC04nd_\2708\5212\AF07lse
X\2A0D\511B\7A0E\5319ndif\0B06\1B09\30040;\FC06position`20(\500A);
X\1C05!`20Move`20s\690Aif`20on`20an`20DOCUMENT`20tag`20or`20runoff`20command
V`20line\4406if`20search_quietly`20(eve$pattern_skip_paragraph_break,
X`09`09\3B04\0303FORWARD)`20<>`200
X\C507n
X`09!`20skip`20past`20\8B0C,`20\8913,`20ff's
X`09\EB0ALINE_END);
X`09move_horizontal`20(1\1604\F40B:=`20m\0804(NONE);
X\8604endif;\E206loop`09`09\9303Find`20the`20pa\D007`20bounds`20for`20all`20
V\1909s
X`09loop
X`09\4104\9816\6705xitif`20\7F0B`20=\7C04_of`20(current_buffer)\3307\CF16\4D17>
V`20end_mark\240Eeve$\AC09_break;
X`09endloop;
X`09\6511-1);
X
X`09\5F19
X`09then\EF10\1E08\A204endif\4404the_right_margin`20:=`20get_info`20\F50F,`20"r
V\2B0B")\8507eve$$x_word_wrap_indent`20`7B\3F0E`7D`20<>`20tpu$k_unspecified
V\AC0Cthe_left\8C0B\5C28\D404lse
X\4818\D41B\2A0B");
X`09endif\DB0Eparagraph_\DB3C\3C07\D60A\5721
X`09`09`09`20`20-`20\D10F\ED11\5A0A\E828`20-\5C06\5A13\FF08the_range`20:=`20cre
Vate\1007(start_mark,`20mark`20(NONE),`20NONE)\3D04if`20do_fill_edit`09\6D03
V\0303!`20KHF
X\5A04n`09\130E\CA04khf$\3209`20(\8009);\2A10!`20`20Replace\C104`20previous`20l
Vine`20by:\2F12`20`20\550F,`20COMPRESS,`20TRIM,`20OFF)\6A04\390Eto`20suppress
V`20extra`20space`20following`20sentences...\3E09else\E313\8511TRIM_LEADING
V\8307
X`09endif\F506\3F09
X`09fill\3C0Deve$x_fill_separators,`20the_left_margin,\7A06\CA03he_right\1908
V\1205indent);
X
X`09if`20do_justify`09\BC0Dthen`09\CF12khf$\3007\9A0B);\280C\CD16loop\1006Skip
V\8A04`20inter-paragraph`20break;\6906position`20(LINE_END);
X\1A05move_horizontal`20(1\1A08exitif`20not`20eve$\5909_b\5907endloop;
X`09start_mark`20:=`20\0805(NONE)\2604\4706\230B>=`20end_mark;
X\6A05\4908\AB0E\2508);
X!!!!!!!!\0808\1010\2020\0A0A\4B1B`20screen`20manager`20issue`20\4B1B\AF04updat
Ve`20(current_window\B368\4B31
Xelse
X\B904eve$message`20(EVE$_SELFIRST);
X\2108learn_abort;\1505return`20(FALSE);
Xendif;
Xeve$clear_m\5306;
X\2A08TRUE);
X
Xendprocedure;`09!\5F05fill_range
X
X`0C
X
X!--------\0808\0C0CNew`20EVE/KHF`20P\4908s-\321B
X
X
XP\2908`20Eve_Justify`09`09!`20Fill`20and`20j\1406`20a`20range`20or`20paragraph
V
X!`09`20`20\510DLocal`09the_selection,
X`09the_status;
X
XOn_Error
X`20`20`20`20`5BOTHERWISE`5D:
XEndo\1D07;
X
XIf`20Get_Info`20(CURRENT_BUFFER,`20"system")
XThen
X\4B04Eve$Message`20(EVE$_CANTSYSTEMBUF);\2609Learn_Abort;\1505Return`20(FALSE)
V;
XEndif;
X
X\C80D`20:=`20Eve$Se\1108\3006,,,`20eve$x_\2B06_remove_flag,,`20TRUE);
XIf`20(t\4F0D<>`200\BF0BSet`20(TIM\DE04ON,`20"Justifying..."\BF07the_status`20
V\8F07Fill_Ran\F604\610D\7B09\5E11FF);
XElse
X\7941Paragraph`20(T\6E1Dndif;
XReturn\A907tatus);
X
XEndprocedure;`09`09!`20Eve_J\8606
X
X
X
XPr\1D07\190C\7B0A
X!`09`20`20------\0606\0909
XLocal`09t\6E09;
X
X\EF22\EB29\E712\E032\C70B\E918Range
X\E515\E106`20t\E10COn_Error
X`20`20`20`20`5BOTHERWISE`5D:
XEndon\1D06;
X
XIf`20Get_Info`20(CURRENT_BUFFER,`20"system")
XThen\4B05Eve$Message`20(EVE$_CANTSYSTEMBUF);
X\2608Learn_Abort;\1505Return`20(FALSE);
XEndif;
X
XSet`20(TIM\7204ON,`20"\F307ing...");
X\DA0A`20:=`20Eve$Fill_Ran\8605ve$Selectio\5F08,,,
X`09`09`09`09`09`20\7A04eve$x_select_remove_flag,,TRUE),\2B0BTRUE);
X\940DFF);
X\BE08\8C0A);
X
XEndprocedure;`09`09!`20Eve_J\C006\A006
X
X`0C
XPr\2307\1F05Unjustify\3004Fill_edit`20and`20fill`20a`20r\D905or`20paragraph
X!\9F03-------------
X
XLocal`09the_s\FE08;
X
XOn_Error
X`20\CE03`5BOTHERWISE`5D:
XEndon\1D06;
X
XIf`20Get_Info`20(CURRENT_BUFFER,`20"system")
XThen\4B05Eve$Message`20(EVE$_CANTSYSTEMBUF);\2609Learn_Abort;\1505Return`20(FA
VLSE);
XEndif;
X
X\BB0D`20:=`20Eve$Se\1108\3006,,,`20eve$x_\2B06_remove_flag,,`20TRUE);
XIf`20(t\4F0D<>`200\BF0B\8408Eve$Fill_Ran\CA04\350D,`20\7306\5606);
XElse
X\3F15Paragraph`20\A707\340A\DE07Endprocedure;`09`09!`20Eve_Unjustify
X
X
X
XPr\1F07\1B0E\5C0A
X!`09`20`20------\0606\0B0B
X
X\982F\911F\760B\9A1ARange
X\9617
X
XOn_Error\9B05`5BOTHERWISE`5D:
XEndon\1D06;
X
XIf`20Get_Info`20(CURRENT_BUFFER,`20"system")
XThen
X\4B04Eve$Message`20(EVE$_CANTSYSTEMBUF);
X\2608Learn_Abort;\1505Return`20(FALSE);
XEndif;
X
X\1808Eve$Fill\DB06\1006Selectio\3708,,,`20eve$x_select_remove_flag,,
X`09`09`09`09`20\6C04`20`20TRUE),`20FALSE,\0E06);
X
XEndprocedure;`09`09!`20Eve_Unjustify\7B06
X
X`0C
X!+
X!\4604his`20\3109`20loops`20through`20all`20lines`20in`20the`20ra\B904provided
V`20and
X\4504right-\6306ies`20each`20so`20that\3805last`20word`20in`20\1E05line`20is
V`20flush`20with\4A05\6505ight`20margin.
X!\1804Notes:
X!
X!`09The`20EVE`20internal\BD0BEve$End_of_Word,`20foun\7305EVE$FORMAT.TPU,
X!`09Version`20V02-100b,`20is`20used`20here`20to`20fill`20khf$x_word_array
V\AA05`20MARKs
X!`09corresponding`20to`20\BF04beginning`20of\EC06\F905(but\2005first)\9604a
V`20line.
X!`09Changes\4306at\D40Bmust`20be`20track\9E07.
X!
X!`09Khf$Justify`20expects`20the`20range_arg`20parameter`20to`20be`20a`20typica
Vl`20para-
X!`09graph`20range`20as`20defined`20in,`20e.g.,`20Eve_Fill_Paragraph,`20with
V\6A05end
X!`09of`20\7709`20a\E406LINE_END`20o\1D06last`20line\F704\1104paragraph\FE04Th
V\220Ds`20NOT`20justified.\EE05Four\BF04es\5404space-fillin\E804tterns`20are
V`20used:`20from`20\6904center`20of
X!`09\8A05\6304toward`20either`20end,`20\3105both`20ends`20\2207\420A\2206
V\4507right`20t\240Abeginn\8C04\F108ine,`20and`20\8A09left\4004\360Aend\300C.
V`20`20The`20type\1704fill\DB0Aused`20may`20be
X!`09restricted`20by`20limiting`20\9C05ange\5708variable\4D05_type,`20e.g.,
X!`09at\2305point`20it`20is`20incremented`20followi\5607Endcase`20statement.
X!`09\AE04order`20\AF1C`20alter\AA06simply`20changing
X!`09\5D04\5A05labels.
X!
X!`20`20Acknowledgements:
X!
X!`09Wri\E705\DD05is`20procedure`20was`20motiva\BB04by`20previous`20justify
V\6D06routines`20written`20by`20Hunter`20Goatley`20<goathunter@wkuvx1.bitnet>
V`20and
X!`09by`20Ken`20Selvia`20<ucs_kas@shsu\2A08.`20`20In`20particular,`20I`20made
V`20use`20of
X!`09\7506's`20idea`20of`20alterna\DF05the`20fill`20pattern`20from`20left`20to
V`20right
X!`09on`20successive`20li\D704(and`20added`20center-out\B804`20outside-in),`20
V\C906Ken\8108to`20\9B04an`20array\9104\8504words`20on`20each\6305,`20retrieved
V`20by
X!`09Eve$Current_Word`20(although`20here\F903have`20used`20Eve$End_of_Word).
V`20`20Both\CC04\7006earlier`20procedures`20implemented`20appending`20a`20secon
Vd`20space
X!`09follow\1B08ntence`20terminator,`20but`20\8C07mo\BE04that\F804the
X!`09call\3E04\7A09.
X!
X!`20`20Author/Date:`09`09K.H.`20Fairfield,`09`0922-DEC-1992
X\2E03\0404Revisions:\1208\3710`2025-JAN-1993:`20Intialization`20of`20"the_fill
V"`20was\4105`09`09`09`20`20`20`20`20incorrect`20if`20"nbig\2405`20zero`20and
X\2D0Csmall_fill\2405greater`20than`201`20space.
X!\310BThis`20gave`20one`20too`20many\2A06s`20per
X\2E03\2A05\0707\0E0E\0808gap`20and`20the`20last`20word`20of`20\1104sen-\4726te
Vnce`20extended`20past`20\4204right`20margin.
X!--
X
XProcedure`20Khf$Justify
X!`09`20`20-----------
X`09`20`20(range_arg)`09`09!`20Range\9A04lines`20to`20j\3C07
XLocal`09saved_position,`20!`20Save\8705current`20\1D08
X`09\2D06mode,`09\2913mode\6C04\1404buffer
X`09the_end\3004Mark`20at`20end_o\2606range\2506rmarg\2704Ri\FE0A`20value\2104i
Vs_mark\2104Just`20a\2204k...
X`09last_column,\1F03Column`20number`20\FB04ast`20character`20in`20a`20line
X`09fill_typ\CF05Fill`20pattern,`20one\3C04four`20types
X`09nspaces\2C04Nu\5D08fill`20spaces`20required
X`09sm_size\2B1Afor`20small`20gaps
X`09nbig,`09\2F0D"big"`20\1F07small\2110small\2308the_fill\7404String\740F
V\9604all\251E\9911indx\7805Index`20into`20word_array
X\20051,indx2,\2606ic\4707center-out`20and`20outside-in`20filling
X`09ngaps\D70Fgaps,`20equals`20words`20in`20\740A`20less`20one
X`09temp;\3E04Just`20a`20temporary`20variable...
X
XOn_Error
X`20`20`20`20`5BOTHERWISE`5D:
XEndon\1D06;
X
X
Xsaved_position`20:=`20Mark`20(NONE);\1F07mode\1B04Get_Info`20(CURRENT_BUFFER,
V`20"mode");
Xthe_rmarg`20\311Fright_margin\3908end`20\B003:=`20End_Of`20(range_arg);
Xfill_type`20\22041;
X
X!+
X!`20`20Create`20khf$x_word_array`20on`20first`20use.`20`20Should`20be`20big
V`20enough`20for`20most`20lines;\4F04will\2604extended\4804the`20fly`20otherwis
Ve.
X!-
XIf`20(\7611=`20TPU$K_UNSPECIFIED)
XThen
X`20`20\2D11:=`20\BE06_A\1005(40);
XEndif\DF09Do`20a`20TRIM_TRAILING`20edit`20on`20range_arg`20since`20there`20co
V\E807some\4204leftovers`20from\CD05Fill`20following`20Khf$Fill_Edit.
X!-
XEdit`20(\6109,`20\820D,`20OFF);
XSet`20(INSERT,`20CURRENT_BUFFER);
XPosition`20(Beginning_Of`20\560A))\E609Start`20loop`20over`20lines`20withi
V\E80B.
X!-
XLoop
X`20`20`20`20P\6009LINE_END);
X\1904this_mark`20:=`20Mark`20(NONE)\1E06Exitif`20(\260A>=`20the_end)\2306last_
Vcolumn`20:=`20Get_Info\340B,`20"offse\2708")`20-`201\3E06If`20(\420C<`20the_rm
Varg)\2105Then
X`09\BF0FBEGIN);
X`09nspaces`20:=`20\3809\5D03\520B;
X`09indx`09:=`200;
X!+
X!`20`20Loop`20over`20words`20in`20the`20current`20line,`20fill`20khf$x_word_ar
Vray`20with`20marks
X\4903corresponding`20to`20\4704beginn\1104each\6305`20except`20\1F04first.`20
V`20Note`20that\4904Eve$End_of_W\3004po\F006s`20\5507_start_`20of\0F06next_`20w
Vord.
X!-
X`09Loop
+-+-+-+-+-+-+-+-  END  OF PART 2 +-+-+-+-+-+-+-+-
-- 
 Dr. Kenneth H. Fairfield    |  Internet: Fairfield@Slac.Stanford.Edu
 SLAC, P.O.Box 4349, MS 98   |  DECnet:   45537::FAIRFIELD (45537=SLACVX)
 Stanford, CA   94309        |  BITNET    Fairfield@Slacvx
 ----------------------------------------------------------------------------
 These opinions are mine, not SLAC's, Stanford's, nor the DOE's...