Vim9: line continuation and comments

27 views
Skip to first unread message

Bram Moolenaar

unread,
Apr 13, 2020, 3:38:12 PM4/13/20
to vim...@googlegroups.com

In case you haven't been keeping track of progress of the Vim9 script
features, here are two items I would like to highlight.

So far line continuation was indicated by a backslash in the next line.
This was done so that no old Vi command would break. It leads to ugly
code in some places, such as defining a list constant:

let mylist = [
\ 'one',
\ 'two',
\ 'three',
\]

Since in Vim9 script we do not need to be 100% backwards compatible, I
made line continuation work where it could be recognized. That is, if
we run into the end of a line but the command isn't finished yet, we
assume it continues in the next line. This works for a list constant
where we haven't seen the ] yet:

let mylist = [
'one',
'two',
'three',
]

This also works for expressions, so long as it ends in an operator, so
that Vim knows another expression must be following:

let text = header ..
GetMiddle() ..
tail

Inside an expression a comment starting with a double quote is hard to
distinguish from a string constant. Thus in the above example there
cannot be a comment after the ".." operator.

To make it possible to add a comment here we need a different prefix.
Many languages use "#" and that works here as well:

let text = header .. # header comes first
GetMiddle() .. # body
tail # finish

The # character was not used in legacy Vim script, because ":#" is a
valid command. But we don't really need it, ":number" does the same.

One restriction: #{ starts a dictionary, thus that can't be used to
start a comment. We can live with that.

Together this works nicely to comment function arguments:

def MySplitter(
text: string, # what to split
pat: string, # separator pattern
max = -1, # maximum nr of splits
): list<string>

Enjoy!

This is not completely implemented yet, work in progress...

--
BODY: I'm not dead!
CART DRIVER: 'Ere. He says he's not dead.
LARGE MAN: Yes he is.
BODY: I'm not!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Apr 14, 2020, 4:02:56 AM4/14/20
to vim...@googlegroups.com

On Mo, 13 Apr 2020, Bram Moolenaar wrote:

> This is not completely implemented yet, work in progress...

Thanks, for the feedback. Looks very promising!

Best,
Christian
--
Das Chaos will anerkannt, will gelebt sein, ehe es sich in eine neue
Ordnung bringen läßt.
-- Hermann Hesse
Reply all
Reply to author
Forward
0 new messages