New feature? Here-documents

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

New feature? Here-documents

A.J.Mechelynck
Hi Bram,

I haven't looked in todo.txt but what would you think of allowing the use of
here-documents for commands like

    :yank x
    :[range]put
    :write foobar.txt
    :hardcopy
    :!
    :[range]r !
    :!program
    :[range]r !program

maybe even ":loadkeymap", which already takes a kind of here-document, but
with no termination pattern other than the end of the file

etc.? Just a wild idea that went through my head, I don't know if it's worth
anything. (We already have them for "other" interpreted languages after
all.)


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: New feature? Here-documents

Bram Moolenaar

Tony Mechelynck wrote:

> I haven't looked in todo.txt but what would you think of allowing the use of
> here-documents for commands like
>
>     :yank x
>     :[range]put
>     :write foobar.txt
>     :hardcopy
>     :!
>     :[range]r !
>     :!program
>     :[range]r !program
>
> maybe even ":loadkeymap", which already takes a kind of here-document, but
> with no termination pattern other than the end of the file
>
> etc.? Just a wild idea that went through my head, I don't know if it's worth
> anything. (We already have them for "other" interpreted languages after
> all.)

Could be useful for scripts.  But it might not be easy to find a syntax
that works for all commands.

--
If someone questions your market projections, simply point out that your
target market is "People who are nuts" and "People who will buy any damn
thing".  Nobody is going to tell you there aren't enough of those people
to go around.
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: New feature? Here-documents

A.J.Mechelynck
----- Original Message -----
From: "Bram Moolenaar" <[hidden email]>
To: "Tony Mechelynck" <[hidden email]>
Cc: <[hidden email]>
Sent: Thursday, August 04, 2005 3:55 PM
Subject: Re: New feature? Here-documents


>
> Tony Mechelynck wrote:
>
>> I haven't looked in todo.txt but what would you think of allowing the use
>> of
>> here-documents for commands like
>>
>>     :yank x
>>     :[range]put
>>     :write foobar.txt
>>     :hardcopy
>>     :!
>>     :[range]r !
>>     :!program
>>     :[range]r !program
>>
>> maybe even ":loadkeymap", which already takes a kind of here-document,
>> but
>> with no termination pattern other than the end of the file
>>
>> etc.? Just a wild idea that went through my head, I don't know if it's
>> worth
>> anything. (We already have them for "other" interpreted languages after
>> all.)
>
> Could be useful for scripts.  But it might not be easy to find a syntax
> that works for all commands.
>
> --
> If someone questions your market projections, simply point out that your
> target market is "People who are nuts" and "People who will buy any damn
> thing".  Nobody is going to tell you there aren't enough of those people
> to go around.
> (Scott Adams - The Dilbert principle)
>
> /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
> ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ 
> \\\
> \\\              Project leader for A-A-P -- http://www.A-A-P.org 
> ///
> \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///

What about the following?

    :blah-blah <<terminator
...
...
...
...
terminator

where ":blah-blah" is the existing command (with arguments if needed) and
"terminator" (default: full stop) appears (with no preceding whitespace) in
column 1 after the here-document (as for perl <<terminator, python
<<terminator, etc.) Of course it would only "make sense" for commands like
those listed above, which can have as input a number of text lines.

    - I don't suggest it for Normal-mode commands, only Ex commands, and
only those for which it makes sense.

    - The here-document itself (which is in a script being sourced, not in a
buffer being edited) is not modified by the command.

    - For instance,

    yank x <<EOF
...
...
...
EOF

would copy the lines (up to but not including EOF) to register x (use X
instead to append);

    0put <<EOF
line1
line2
line3
EOF

would add three lines at the top of the current buffer (useful for
templates, which can then be included in a plugin without the need for a
separate file);

    $r ! <<EOF
<shell scriptlet comes here>
EOF

would add to the end of the current buffer the STDOUT output of running the
shell scriptlet; etc.

Like other (perl, python, etc.) here-documents, to include any here-document
in a conditional clause one would include it in a function (the following
assumes a config option):

    if has("vim_here_documents")
        function! funcname()
            :commandname <<EOF
            ...
EOF
        endfunction
        call funcname()
    else
        ...
    endif

I imagine that these "generalised" here-documents could be included with not
too much overhead (I believe most of the mechanics is already there) but I
don't know much of Vim's "inner workings" -- my imagination can go wrong.


Best regards,
Tony.