Ken Takata wrote:
> 2016/7/22 Fri 3:54:18 UTC+9 Bram Moolenaar wrote:
> > Ozaki Kiichi wrote:
> >
> > > > > I propose new conversion specifier '%v' (and '%V') of printf();
> > > > > inspired by golang.
> > > > >
> > > > > This spec takes a value of any type and converts into string by
> > > > > echo_string().
> > > > >
> > > > > example:
> > > > >
> > > > > " list
> > > > > :echo printf('%v', [0, 1, 2, 3])
> > > > > [0, 1, 2, 3]
> > > > >
> > > > > " dict
> > > > > :echo printf('%v', {'str' : 'abcdef', 'num' : 123, 'pt' :
> > > > > function('printf', ['%%'])})
> > > > > {'str': 'abcdef', 'num': 123, 'pt': function('printf', ['%%'])}
> > > > >
> > > > > " funcref
> > > > > :echo printf('%v', function('str2nr'))
> > > > > str2nr
> > > > >
> > > > >
> > > > > '%V' is simular with '%S'.
> > > > >
> > > > > patch:
> > > > >
> > > > > https://gist.github.com/ichizok/c1ad7759d7a0a0734fb02f5a4d37445c
> > > >
> > > >
> > > > So, the same would be done with using "%s" and string() on the value?
> > > >
> > > > :echo printf('%s', string([0, 1, 2, 3]))
> > > > [0, 1, 2, 3]
> > > >
> > > > I suppose golang doesn't have a string() function.
> > > >
> > > > An even simpler way is to do what Swift does:
> > > >
> > > > "lead \(expression) tail"
> > > >
> > > > With the example above:
> > > > "\([0, 1, 2, 3])"
> > > >
> > > > I'm using this in Zimbu, works quite well.
> > >
> > > When converting multiple values of any types (e.g. in debugging),
> > > it is rather bothersome to use string() to each values:
> > >
> > > :echo printf('foo: %s, bar: %s, baz: %s, qux: %s', string(foo),
> > > string(bar), string(baz), string(qux))
> > >
> > > and, when a argument is string, string() is redundant.
> > >
> > > Thus, simply:
> > >
> > > :echo printf('foo: %v, bar: %v, baz: %v, qux: %v', foo, bar, baz, qux)
> > >
> > > It is easy to reuse format string.
> > >
> > > let fmt = '[%v] [%v] [%v]'
> > > ...
> > > echo printf(fmt, x1, x2, x3)
> > > ...
> > > echo printf(fmt, y1, y2, y3)
> >
> > Well, since currently this produces an error, we could just convert to a
> > string when using "%s".
>
> Then how about this patch?
> https://bitbucket.org/k_takata/vim-ktakata-mq/src/9963788ec24a00f70f232af8bf944b85cfda8c15/enhance-printf-s.patch?at=default
Thanks. I guess that works for everybody.
--
FATAL ERROR! SYSTEM HALTED! - Press any key to continue doing nothing.
/// Bram Moolenaar -- [email protected] -- 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 ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.