Looking for a TPU section that does automatic word wrap - VMS

This is a discussion on Looking for a TPU section that does automatic word wrap - VMS ; Hi ! Does anyone know of a TPU section file that would do automatic word wrapping ? Does it exist as a freeware or else, or can it be done at all, you think ? Currently the wrapping is really ...

+ Reply to Thread
Results 1 to 16 of 16

Thread: Looking for a TPU section that does automatic word wrap

  1. Looking for a TPU section that does automatic word wrap

    Hi !

    Does anyone know of a TPU section file that would do automatic word wrapping
    ?
    Does it exist as a freeware or else, or can it be done at all, you think ?

    Currently the wrapping is really simplistic as the cursor must be at the end
    of the line for the wrap to occur.

    If that does not exist, is there a way to force a FILL on the entire buffer
    upon exit ?

    Thanks
    OVMS 8.3

    --
    Syltrem
    http://pages.infinit.net/syltrem (OpenVMS information and help, en franšais)



  2. Re: Looking for a TPU section that does automatic word wrap

    Syltrem wrote:
    > Hi !
    >
    > Does anyone know of a TPU section file that would do automatic word wrapping
    > ?
    > Does it exist as a freeware or else, or can it be done at all, you think ?
    >
    > Currently the wrapping is really simplistic as the cursor must be at the end
    > of the line for the wrap to occur.
    >
    > If that does not exist, is there a way to force a FILL on the entire buffer
    > upon exit ?
    >


    What editor are you using? TPU by itself isn't an editor but an
    environment used to write editors.

    If you are using EVE, you can find all the sources for EVE in
    SYS$EXAMPLES:EVE*.*

    There is a whole section in the TPU manual about writing TPU code
    compatible with EVE and extending existing section files. I think you
    can do what you want. FILL at exit is probably the easiest if that is
    all you need.

    --
    John Reagan
    OpenVMS Pascal/Macro-32/COBOL Project Leader
    Hewlett-Packard Company

  3. Re: Looking for a TPU section that does automatic word wrap

    John Reagan wrote:
    > Syltrem wrote:
    >> Hi !
    >>
    >> Does anyone know of a TPU section file that would do automatic word
    >> wrapping ?
    >> Does it exist as a freeware or else, or can it be done at all, you
    >> think ?
    >>
    >> Currently the wrapping is really simplistic as the cursor must be at
    >> the end of the line for the wrap to occur.
    >>
    >> If that does not exist, is there a way to force a FILL on the entire
    >> buffer upon exit ?
    >>

    >
    > What editor are you using? TPU by itself isn't an editor but an
    > environment used to write editors.
    >
    > If you are using EVE, you can find all the sources for EVE in
    > SYS$EXAMPLES:EVE*.*
    >
    > There is a whole section in the TPU manual about writing TPU code
    > compatible with EVE and extending existing section files. I think you
    > can do what you want. FILL at exit is probably the easiest if that is
    > all you need.
    >



    Syltrem,

    Here is a TPU command file (TPU$COMMAND.TPU) in my SYS$LOGIN directory.
    Among the procedures described are 3 that re-wrap paragraphs within
    different right & left margins. The 3 key assignments to trigger these
    paragraph-wrapping procedures are PF1-P, PF1-O, and PF1-I . The margins
    are 4,70; 8,66; 12,62; respectively.

    To use a TPU command file, you need to specify it somehow. Read the
    DCL help available online. HELP EDIT/TPU/COMMAND

    After having correctly specified the TPU command file, to get these
    procedures to work, once inside EVE, put your cursor inside the paragraph
    in question. Key in one of the key sequences. Voila, the paragraph is
    reformatted with the selected margins.

    After re-formatting each paragraph, your default margins are left
    at 1 and 79. This may not suit your needs, so you can change that.

    Another approach would be to alter the code to grab pre-existing
    left and right margin settings, and restore those after each paragraph
    is done.



    .. fred bach ... music at triumf dot c a

    !/\/\/\/\/\/ This is the code for SYS$LOGIN:TPU$COMMAND.TPU /\/\/\/\/\/\/\/\/\
    ! This is the file sys$login:tpu$command.tpu The procedures in this file
    ! are made available to your EVE editing session. (Unless you've defined
    ! the logical tpu$command to point to something else.) To execute these
    ! procedures enter the command TPU XXXX (where XXXX is the procedure-name)
    ! at the EVE "Command:" prompt.
    !
    !

    PROCEDURE user_mark_text
    !
    ! This procedure will stick a ">" in front of every line in the current buffer.
    ! It leaves the cursor in its original position.

    !Local variables...
    LOCAL
    starting_location,
    numlines,
    i;

    !Make note of the current cursor position.
    starting_location:=MARK (NONE);

    !How many lines are in the buffer?
    numlines:=GET_INFO (CURRENT_BUFFER,"record_count");

    !For every line in the buffer, go to the beginning of that line and
    !insert a ">".
    i:=0;
    LOOP
    EXITIF i>=numlines;
    i:=i+1;
    POSITION (i);
    POSITION (LINE_BEGIN);
    COPY_TEXT (">");
    ENDLOOP;

    !Put the cursor back where we found it.
    POSITION (starting_location);

    ENDPROCEDURE;

    PROCEDURE user_append_signature
    ! This procedure appends the contents of sys$login:mail.signature to
    ! the end of the current buffer.

    !Go to the end of the buffer.
    POSITION (BUFFER_END);

    !And include the file.
    READ_FILE ("sys$login:mail.signature");

    ENDPROCEDURE;

    procedure user_tidy_mail_paragraph
    set (LEFT_MARGIN, current_buffer, 4);
    set (RIGHT_MARGIN, current_buffer, 70);
    eve_fill_paragraph;
    set (LEFT_MARGIN, current_buffer, 1);
    set (RIGHT_MARGIN, current_buffer, 79);
    endprocedure;

    procedure user_tidy_mail_paragraph_8_66
    set (LEFT_MARGIN, current_buffer, 8);
    set (RIGHT_MARGIN, current_buffer, 66);
    eve_fill_paragraph;
    set (LEFT_MARGIN, current_buffer, 1);
    set (RIGHT_MARGIN, current_buffer, 79);
    endprocedure;

    procedure user_tidy_mail_paragraph_12_62
    set (LEFT_MARGIN, current_buffer, 12);
    set (RIGHT_MARGIN, current_buffer, 62);
    eve_fill_paragraph;
    set (LEFT_MARGIN, current_buffer, 1);
    set (RIGHT_MARGIN, current_buffer, 79);
    endprocedure;

    PROCEDURE user_enable_mouse_copy
    ! This procedure sets the mouse to select and insert text from other windows
    ! 10Feb96 FWB adapted from [.news]vms_tpu_tricks.txt

    if get_info (screen,"vt300")
    then
    SET(MOUSE,OFF);
    MESSAGE ("Mouse copying ENabled; Mouse cursor-positioning DISabled.");
    endif;

    endprocedure;

    PROCEDURE user_disable_mouse_copy
    ! This procedure sets the mouse to position the editor cursor
    ! 10Feb96 FWB adapted from [.news]vms_tpu_tricks.txt

    if get_info (screen,"vt300")
    then
    SET(MOUSE,ON);
    MESSAGE ("Mouse copying DISabled; Mouse cursor-positioning ENabled.");
    endif;

    endprocedure;

    eve$define_key ("user_tidy_mail_paragraph", KEY_NAME ("p", SHIFT_KEY),
    "tidy mail paragraph", EVE$X_USER_KEYS);

    eve$define_key ("user_tidy_mail_paragraph_8_66", KEY_NAME ("o", SHIFT_KEY),
    "tidy mail paragraph", EVE$X_USER_KEYS);

    eve$define_key ("user_tidy_mail_paragraph_12_62", KEY_NAME ("i", SHIFT_KEY),
    "tidy mail paragraph", EVE$X_USER_KEYS);

    eve$define_key ("user_enable_mouse_copy", KEY_NAME ("m", SHIFT_KEY),
    "enable mouse copy", EVE$X_USER_KEYS);

    eve$define_key ("user_disable_mouse_copy", KEY_NAME ("n", SHIFT_KEY),
    "disable mouse copy", EVE$X_USER_KEYS);

    !/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

  4. Re: Looking for a TPU section that does automatic word wrap

    Syltrem wrote:

    > Does anyone know of a TPU section file that would do automatic word wrapping



    The standard EVE section has a command:

    SET KEYPAD WPS (yes folks, WPSPLUS in TPU :-) :-)

    Your can set the margins with GOLD - R (GOLD PF1 on numeric keypad).
    L for left margin, R for right margin. When margins are set, press return.

    Then, as you type, the text automatically flows inside those margins.

    The one caveat is that if you modify an existing paragraph, the text
    does not reflow automatically, you need to use the FILL command or
    GOLD 5

    Pressing the HELP key displays the WPS keypad descriptions. (5 =
    Paragraph).

  5. Re: Looking for a TPU section that does automatic word wrap

    On Mon, 19 Nov 2007, JF Mezei wrote:

    > Syltrem wrote:
    >
    >> Does anyone know of a TPU section file that would do automatic word
    >> wrapping

    >
    >
    > The standard EVE section has a command:
    >
    > SET KEYPAD WPS (yes folks, WPSPLUS in TPU :-) :-)
    >
    > Your can set the margins with GOLD - R (GOLD PF1 on numeric keypad).
    > L for left margin, R for right margin. When margins are set, press
    > return.
    >
    > Then, as you type, the text automatically flows inside those
    > margins.
    >
    > The one caveat is that if you modify an existing paragraph, the text
    > does not reflow automatically, you need to use the FILL command or
    > GOLD 5


    Similar things happen (perhaps less conveniently) with SET KEYPAD EDT.

    Use the SET LEFT MARGIN and SET RIGHT MARGIN commands and SET WRAP for
    automatically wrapping text as you type. SELECT and Gold-8 to fill
    text to the current margins.


    --

    Rob Brown b r o w n a t g m c l d o t c o m
    G. Michaels Consulting Ltd. (780)438-9343 (voice)
    Edmonton (780)437-3367 (FAX)
    http://gmcl.com/


  6. Re: Looking for a TPU section that does automatic word wrap

    Syltrem wrote:
    > Hi !
    >
    > Does anyone know of a TPU section file that would do automatic word wrapping


    After hours of tireless non-stop research I have found an even simpler
    solution:

    to get you to command mode, and then type SET WRAP followed by
    carriage return.

    SET NOWRAP to disable it.

    YOu can define some key to do a FILL and whenever you make changes that
    don't autowrap the paragraph, you can press the key.



    HELP SET WRAP will give you a good overview of the word
    wrap functionlity in TPU.

  7. Re: Looking for a TPU section that does automatic word wrap

    In article <13k4282oo2tms2c@corp.supernews.com>, "Syltrem" writes:
    > Hi !
    >
    > Does anyone know of a TPU section file that would do automatic word wrapping
    > ?
    > Does it exist as a freeware or else, or can it be done at all, you think ?
    >
    > Currently the wrapping is really simplistic as the cursor must be at the end
    > of the line for the wrap to occur.
    >
    > If that does not exist, is there a way to force a FILL on the entire buffer
    > upon exit ?
    >


    You can write your own exit routine to replace eve$exit_dispatch and
    make it call all the exit handlers you want.


  8. Re: Looking for a TPU section that does automatic word wrap

    BTW, to reflow a whole document:

    goto TOP,
    SELECT
    goto BOTTOM
    issue the FILL command
    All paragraphs will be refilled.

    Note that if you have any tabular data, ascii graphs etc, those get
    refilled too ;-)

  9. Re: Looking for a TPU section that does automatic word wrap

    Thanks for the code sample; that will get me started.

    Still unsure that FILL is the answer though.
    Not even sure I want to go the EVE/TPU route with this. I'm still in the
    thinking process.

    What I need if for people to enter thex and not have lines over 60
    characters in length.
    But they may indent stuff or not leave a blank line between paragraphs, and
    I don't want to break their "nice" alignment if they do.

    Syltrem



  10. Re: Looking for a TPU section that does automatic word wrap

    Syltrem wrote:
    > Still unsure that FILL is the answer though.
    > Not even sure I want to go the EVE/TPU route with this. I'm still in the
    > thinking process.


    DECwrite could be an answer. But it needs decwindows. It will do dynamic
    text flowing and won't allow text to exceed the margins you have set.
    Not sure how scriptable/callable decwrite is though.

    WPSPLUS will reflow the rest of the paragraph as you add/remove from it.
    But it will not reflow the text when you change the ruler until you
    scroll past it. (doing so wastes a LOT of time on a character cell
    terminals, especially for very long documents).


    > What I need if for people to enter thex and not have lines over 60
    > characters in length.


    > But they may indent stuff or not leave a blank line between paragraphs, and
    > I don't want to break their "nice" alignment if they do.


    If you go with X/Motif, you have a text widget that does a hard margin
    at whatever you want it. But when you select an automatic text flow,
    what the application gets back is a single buffer with a line end at the
    end of paragraphs, so you have to use your program to add line breaks at
    strategic locations within the buffer. (this is what Microsoft failed to
    do it is email software which resulted in people getting one line emails
    with the line being extremely long).

    With X, you can really come close to what was on screen since the logic
    to flow words is pretty standard and you can essentially recreate how
    the text looked by inserting real line ends where the X widgets inserted
    phantom ones.


    You can probably do some real TPU coding to achieve what you want though.

  11. Re: Looking for a TPU section that does automatic word wrap

    Syltrem wrote:
    > Thanks for the code sample; that will get me started.
    >
    > Still unsure that FILL is the answer though.
    > Not even sure I want to go the EVE/TPU route with this. I'm still in the
    > thinking process.
    >
    > What I need if for people to enter thex and not have lines over 60
    > characters in length.
    > But they may indent stuff or not leave a blank line between paragraphs, and
    > I don't want to break their "nice" alignment if they do.


    The source of EVE is on every VMS system in SYS$HELP:EVE$*.TPU.
    The stuff that handles word wrap is in EVE$FORMAT.TPU. You can
    look at the stuff that's in there for ideas, or modify it for your
    own use.

    I spent a few minutes reviewing it myself and I think, for your
    needs, it's both too much and too little.

    If I read your requirements correctly, what you really want is not
    to fill paragraphs, but to split lines that are too long. Is that
    right? If so, I would write a procedure that simply started at
    the top of the buffer, moved to the end of line, and checked the
    offset_column. If beyond column 60, find the beginning of the
    current word (and check its offset column) then split the line, else
    goto to the next line.

    I'm not at my VMS system at the moment, so I hesitate to provide
    sample code, but I'll note that the Length(CURRENT_LINE) does not
    give the character position of the last character if there are tabs
    or non-zero line indent present, etc., so you need to be a little
    careful with that. There are EVE routines for find beginning and end
    of word, and others that may be helpful. I could probably knock
    out something in about ten minutes if I were at my VMS system...

    ----
    However, if in addition to wrapping at column 60, you *also* want to
    fill short lines, that is, do what FILL PARAGRAPH does, but you also
    want to maintain the user's ad hoc alignment, that's going to be hard.
    You've already commented that paragraphs may not have blank lines
    between them, do how does your program identify the beginning and end
    of a paragraph (you've broken EVE's rules)? If you can solve that
    problem, you might be able to keep the user's indention, say for a
    list of bullet points, or the initial paragraph indention. But it
    will take examining the leading whitespace on each line and using
    some rule to decide whether to keep it or not, and when you split a
    line, determine whether the next line needs to be joined to it or
    not.

    I find this sort of thing much easier for the user to do than a
    program (EVE procedure). EVE is perfectly capable, for example,
    of setting the left margin to 10, and the paragraph indention to
    -4, producing a paragraph with "hanging indention" suitable for a
    list of bullet points. The user knows when to fill a series of
    these bullet points as edits take place, but I'd be very worried
    about an EVE exit routine knowing what the user wanted...

    -Ken
    --
    Ken & Ann Fairfield
    What: Ken dot And dot Ann
    Where: Gmail dot Com

  12. Re: Looking for a TPU section that does automatic word wrap


    "Ken Fairfield" wrote in message
    news:5qm3mrF102j81U1@mid.individual.net...
    > Syltrem wrote:
    >> Thanks for the code sample; that will get me started.
    >>
    >> Still unsure that FILL is the answer though.
    >> Not even sure I want to go the EVE/TPU route with this. I'm still in the
    >> thinking process.
    >>
    >> What I need if for people to enter thex and not have lines over 60
    >> characters in length.
    >> But they may indent stuff or not leave a blank line between paragraphs,
    >> and I don't want to break their "nice" alignment if they do.

    >
    > The source of EVE is on every VMS system in SYS$HELP:EVE$*.TPU.
    > The stuff that handles word wrap is in EVE$FORMAT.TPU. You can
    > look at the stuff that's in there for ideas, or modify it for your
    > own use.
    >
    > I spent a few minutes reviewing it myself and I think, for your
    > needs, it's both too much and too little.
    >
    > If I read your requirements correctly, what you really want is not
    > to fill paragraphs, but to split lines that are too long. Is that
    > right? If so, I would write a procedure that simply started at
    > the top of the buffer, moved to the end of line, and checked the
    > offset_column. If beyond column 60, find the beginning of the
    > current word (and check its offset column) then split the line, else
    > goto to the next line.
    >
    > I'm not at my VMS system at the moment, so I hesitate to provide
    > sample code, but I'll note that the Length(CURRENT_LINE) does not
    > give the character position of the last character if there are tabs
    > or non-zero line indent present, etc., so you need to be a little
    > careful with that. There are EVE routines for find beginning and end
    > of word, and others that may be helpful. I could probably knock
    > out something in about ten minutes if I were at my VMS system...
    >
    > ----



    Yes, that's what I need. I just want to split long lines. It doesn't need to
    be too fancy and know about paragraphs.
    I just want to make sure I do not loose text, and also don't mess too much
    with the user's formatting.
    Thanks for the pointer to EVE$FORMAT.TPU.


    > However, if in addition to wrapping at column 60, you *also* want to
    > fill short lines, that is, do what FILL PARAGRAPH does, but you also
    > want to maintain the user's ad hoc alignment, that's going to be hard.
    > You've already commented that paragraphs may not have blank lines
    > between them, do how does your program identify the beginning and end
    > of a paragraph (you've broken EVE's rules)? If you can solve that
    > problem, you might be able to keep the user's indention, say for a
    > list of bullet points, or the initial paragraph indention. But it
    > will take examining the leading whitespace on each line and using
    > some rule to decide whether to keep it or not, and when you split a
    > line, determine whether the next line needs to be joined to it or
    > not.
    >


    I may do this too - if a long line starts with blank characters, break the
    line and insert those same blank characters at the beginning of the new
    line.

    > I find this sort of thing much easier for the user to do than a
    > program (EVE procedure). EVE is perfectly capable, for example,
    > of setting the left margin to 10, and the paragraph indention to
    > -4, producing a paragraph with "hanging indention" suitable for a
    > list of bullet points. The user knows when to fill a series of
    > these bullet points as edits take place, but I'd be very worried
    > about an EVE exit routine knowing what the user wanted...
    >
    > -Ken
    > --
    > Ken & Ann Fairfield
    > What: Ken dot And dot Ann
    > Where: Gmail dot Com



    So If I have some text like this that's too long:
    1) I could split the lines so that I don't loose characters at the end
    of a line
    2) It may not look pretty, but not that bad either.

    It would come out like this

    ---- below is above text processed by the new exit procedure ----
    (approximately - I did not count characters here!)

    So If I have some text like this
    that's too long:
    1) I could split the lines so that
    I don't loose characters at the end
    of a line
    2) It may not look pretty, but not
    that bad either.
    It would come out like this

    ------------
    Something that would do this is sufficient at this point.
    I will look into EVE$FORMAT.TPU (it's not short! 2069 lines)

    Thanks
    Syltrem



  13. Re: Looking for a TPU section that does automatic word wrap

    On Nov 19, 5:06 pm, "Syltrem" wrote:
    > Hi !
    >
    > Does anyone know of a TPU section file that would do automatic word wrapping


    I would probably use a perl one-liner to do a job like that.


    $ typ tmp.tmp ! Notice 4 space leading second line, 2 spaces leading
    3rd.
    So If I have some text like this that's too long:
    1) I could split the lines so that I don't loose characters at the
    end of a line
    2) It may not look pretty, but not that bad either. It would come
    out like this

    perl, maintaining leading spaces

    $ perl -ne "while (length > 35) { m/(\s*)(.{0,35})\s+(.*)/;{ print
    qq($1$2\n); $_=$1.$3}} print qq($_\n)" tmp.tmp
    So If I have some text like this
    that's too long:
    1) I could split the lines so that
    I don't loose characters at the end
    of a line
    2) It may not look pretty, but not
    that bad either. It would come out
    like this

    More basic perl, not perserving line indent

    $ perl -ne "while (length > 35) { m/(.{0,35})(\s.*)/;{ print qq($1\n);
    $_=$2}} print qq($_\n)" tmp.tmp



    the crucial part is the MATCH regular expression: m/(.{0,35})(\s.*)/

    $_ is the 'default' line buffer variable.
    The m// is the match function. Could also use m%% or whatever.
    The parens identify a remember zone, identified as $1, $2, $3,...
    So we are looking for, and remember in $1 anything '.' for up to 35
    times '{0,35} followed by a second string which we remember by $1
    which must start with whitespace, followed by anything, any number of
    time '.*' up to the end'.
    Print the first part, and save the second part in the default line
    veriable for the next iteration untill the line is shorter than
    target.

    If we move the whitepace match '\s' out of the second paren, then we
    'eat' that:

    $ perl -ne "while (length > 35) { m/(.{0,35})\s(.*)/;{ print qq($1\n);
    $_=$2}} print qq($_\n)" tmp.tmp
    So If I have some text like this
    that's too long:
    1) I could split the lines so
    that I don't loose characters at
    the end of a line
    2) It may not look pretty, but
    not that bad either. It would come
    out like this


    hth,
    Hein.







  14. Re: Looking for a TPU section that does automatic word wrap

    If you don't need "live" reformatting, you could simply redefinethe save
    command to also call one of your subroutines.

    That souroutine would scan the buffer for any line exceeding 60
    characters, and if so, select the first character, move to end of line,
    then issue the equivalent of the FILL command.

    This would then reflow only that one line.

  15. Re: Looking for a TPU section that does automatic word wrap


    "Hein RMS van den Heuvel" wrote in message
    news:db2f5c06-b1d8-4cb4-93ce-38954b8efde4@j44g2000hsj.googlegroups.com...
    > On Nov 19, 5:06 pm, "Syltrem" wrote:
    >> Hi !
    >>
    >> Does anyone know of a TPU section file that would do automatic word
    >> wrapping

    >
    > I would probably use a perl one-liner to do a job like that.
    >
    >
    > $ typ tmp.tmp ! Notice 4 space leading second line, 2 spaces leading
    > 3rd.
    > So If I have some text like this that's too long:
    > 1) I could split the lines so that I don't loose characters at the
    > end of a line
    > 2) It may not look pretty, but not that bad either. It would come
    > out like this
    >
    > perl, maintaining leading spaces
    >
    > $ perl -ne "while (length > 35) { m/(\s*)(.{0,35})\s+(.*)/;{ print
    > qq($1$2\n); $_=$1.$3}} print qq($_\n)" tmp.tmp
    > So If I have some text like this
    > that's too long:
    > 1) I could split the lines so that
    > I don't loose characters at the end
    > of a line
    > 2) It may not look pretty, but not
    > that bad either. It would come out
    > like this
    >
    > More basic perl, not perserving line indent
    >
    > $ perl -ne "while (length > 35) { m/(.{0,35})(\s.*)/;{ print qq($1\n);
    > $_=$2}} print qq($_\n)" tmp.tmp
    >
    >
    >
    > the crucial part is the MATCH regular expression: m/(.{0,35})(\s.*)/
    >
    > $_ is the 'default' line buffer variable.
    > The m// is the match function. Could also use m%% or whatever.
    > The parens identify a remember zone, identified as $1, $2, $3,...
    > So we are looking for, and remember in $1 anything '.' for up to 35
    > times '{0,35} followed by a second string which we remember by $1
    > which must start with whitespace, followed by anything, any number of
    > time '.*' up to the end'.
    > Print the first part, and save the second part in the default line
    > veriable for the next iteration untill the line is shorter than
    > target.
    >
    > If we move the whitepace match '\s' out of the second paren, then we
    > 'eat' that:
    >
    > $ perl -ne "while (length > 35) { m/(.{0,35})\s(.*)/;{ print qq($1\n);
    > $_=$2}} print qq($_\n)" tmp.tmp
    > So If I have some text like this
    > that's too long:
    > 1) I could split the lines so
    > that I don't loose characters at
    > the end of a line
    > 2) It may not look pretty, but
    > not that bad either. It would come
    > out like this
    >
    >
    > hth,
    > Hein.
    >
    >
    >


    Wow that's cool !
    I will study this (somewhat cryptic for me). I can certainly use PERL to do
    this, after the user has entered the data.
    Very good for what I have to do; I don't need "live" reformatting.
    I just tried it; works nice !

    Thanks !
    Syltrem



    >
    >
    >




  16. Re: Looking for a TPU section that does automatic word wrap

    On Nov 26, 4:51 pm, "Syltrem" wrote:
    > "Hein RMS van den Heuvel" wrote in


    > > I would probably use a perl one-liner to do a job like that.

    :
    > > More basic perl, not perserving line indent


    > > $ perl -ne "while (length > 35) { m/(.{0,35})(\s.*)/;{ print qq($1\n);
    > > $_=$2}} print qq($_\n)" tmp.tmp


    > Wow that's cool !


    Thanks.

    It can actually be shortened a little more to:

    $ perl -ple "while (length > 35) { m/(.{0,35})\s/;print $1; $_=$'}"
    tmp.tmp

    The first example worked with the help of an implied loop through the
    "-n" = "do Not print", the alternative used above is -p = "Print $_
    variable at bottom of loop"
    This is used in the shortened example, as well as -l for "new Line,
    after print"
    And I replaced the explicit any-match-to-EOL after the space '(.*)'
    with the build in 'post match' variable $'.



    > I will study this (somewhat cryptic for me). I can certainly use PERL to do
    > this, after the user has entered the data.


    A few remarks
    Perl commandline parsing takes care of the Unix style re-directs.
    So you do not need pipe to do something like:

    $perl -n prog.pl < input.dat > output.dat

    By default the last command line variable is the input file name.
    The -e gives the program as a one line text.
    It would be clearer to stick it into a file say prog.pl and indent.
    (actually, I noticed a redundant 'block' {} while writing this
    explanation:
    For example:

    ----- prog.pl --------
    while (length > 35) { # check length of variable $_
    m/(.{0,35})(\s.*)/; # match up to 35 chars before whitespace,
    and the rest.
    print qq($1\n); # print first match
    $_=$2 # make line variable be the rest.
    }
    print qq($_\n); # print last chunk
    -------------------------------------------


    Exposing the loop and the $_ variable you could also use

    $perl prog.pl < old > new
    ---- prog.pl ----
    while ($_ = ) {
    while while (length > 35) { # check length of variable $_
    $_ =~ m/(.{0,35})(\s.*)/; # match up to 35 chars before
    whitespace, and the rest.
    print STDOUT qq($1\n); # print first match
    $_=$2 # make line variable be the
    rest.
    }
    print STDOUT qq($_\n); # print last chunk
    }

    btw, that first loop is more often written as: while (<>) { ...

    TIMTOWTDI ! "Tim Toady" = "There is more than one way to do it"

    hth,
    Hein.

+ Reply to Thread