FAQ
Dear list,

the vim indent plugin (misc/vim/indent/go.vim) does not indent correctly
after some lines that end with a one-line C-style comment (/*...*/).

Example:

     for i := range something { /* comment */

does not indent the next line. The following does:

     for i := range something { // comment

I propose the fix in the diff at the end of this email.

I can not claim that I am a vim-script expert, nor a regex expert, so
please let me know if there's a better way to handle this. I have a
feeling, there may be a more efficient way.
The regexp removes all one-line C-style comments, using the shortest
match algorithm. That is the only way I could think of to support both
the following two (albeit stupid) cases:

     for i := range sth /*com1*/ { /*com2*/
     for i := range sth { /*com1*/ /*com2*/

The evaluation of my added substitution has to occur first to correctly
handle the following case:

     for i := range sth { /* com // etc */

Let me know if you'd like me to commit this for review, and who to CC.

Thanks,
Eike M Wuelfers


--- go.vim.orig 2013-08-21 13:59:05.000000000 +0200
+++ go.vim 2013-08-21 14:04:31.000000000 +0200
@@ -32,8 +32,10 @@
    endif

    " grab the previous and current line, stripping comments.
- let prevl = substitute(getline(prevlnum), '//.*$', '', '')
- let thisl = substitute(getline(a:lnum), '//.*$', '', '')
+ let prevl = substitute(getline(prevlnum), '/\*.\{-}\*/', '', 'g')
+ let prevl = substitute(prevl, '//.*$', '', '')
+ let thisl = substitute(getline(a:lnum), '/\*.\{-}\*/', '', 'g')
+ let thisl = substitute(thisl, '//.*$', '', '')
    let previ = indent(prevlnum)

    let ind = previ

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • David Symonds at Aug 22, 2013 at 1:53 am
    I'm not sure we want to go down this track. /* ... */ comments on a
    line like this aren't common for Go, and there's endless complexities
    trying to support even the usual style. It's regrettable that the vim
    indent script botches this case, but it is a long way from perfect in
    many other cases too, and will never match gofmt exactly.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedAug 21, '13 at 2:28p
activeAug 22, '13 at 1:53a
posts2
users2
websitegolang.org

2 users in discussion

Eike M. Wülfers: 1 post David Symonds: 1 post

People

Translate

site design / logo © 2022 Grokbase