[vim/vim] C comment leader wrongly inserted when 'indentexpr' is set and 'formatoptions' contains "o" flag (Issue #9426)

8 views
Skip to first unread message

lacygoill

unread,
Dec 29, 2021, 9:22:38 AM12/29/21
to vim/vim, Subscribed

Steps to reproduce

Run this shell command:

vim -Nu NONE -S <(tee <<'EOF'
    vim9script
    &formatoptions = 'o'
    &indentexpr = 'g:IndentExpr()'
    def g:IndentExpr(): number
        return 0
    enddef
    ['aaa', 'bbb//']->setline(1)
    normal! GO
EOF
)

The buffer contains these lines:

aaa
//
bbb//

Expected behavior

The buffer contains these lines:

 aaa

 bbb//

Version of Vim

8.2 Included patches: 1-3932

Environment

Operating system: Ubuntu 20.04.3 LTS
Terminal: xterm
Value of $TERM: xterm-256color
Shell: zsh 5.8

Additional Context

Regression introduced in 8.2.3787.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9426@github.com>

Bram Moolenaar

unread,
Dec 29, 2021, 10:16:34 AM12/29/21
to vim/vim, Subscribed

Closed #9426 via 5ea5f37.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/9426/issue_event/5825144499@github.com>

lacygoill

unread,
Dec 29, 2021, 10:26:56 AM12/29/21
to vim/vim, Subscribed

The issue persists for the o command:

vim -Nu NORC --cmd 'filetype indent on' -S <(tee <<'EOF'
    vim9script
    edit /tmp/sh.sh
    &formatoptions = 'o'
    var lines =<< trim END
        #!/bin/bash
        git clone 'https://github.com/vim/vim/'
    END
    lines->setline(1)
    normal! Go
EOF
)

The buffer contains these lines:

#!/bin/bash
git clone https://github.com/vim/vim/
//

There is no reason for the C comment leader (//) to be inserted below the git(1) command:

  • this is bash script; not a C file
  • the double slash is part of a url; it does not start a comment


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9426/1002648165@github.com>

Bram Moolenaar

unread,
Dec 29, 2021, 11:11:23 AM12/29/21
to vim/vim, Subscribed

The cause for this appears to be that the 'comments' option for shell script does contain "://".
If you have a line starting with "//" and use "o" then the comment leader is also copied.
I could add a condition for 'cindent' being set, but this is really a text formatting feature, not indenting.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9426/1002668061@github.com>

Bram Moolenaar

unread,
Dec 29, 2021, 11:15:45 AM12/29/21
to vim/vim, Subscribed


> The issue persists for the `o` command:
>
> vim -Nu NORC --cmd 'filetype indent on' -S <(tee <<'EOF'
> vim9script
> edit /tmp/sh.sh
> &formatoptions = 'o'
> var lines =<< trim END
> #!/bin/bash
> git clone 'https://github.com/vim/vim/'
> END
> lines->setline(1)
> normal! Go
> EOF
> )
>
> The buffer contains these lines:
>
> #!/bin/bash
> git clone https://github.com/vim/vim/
> //
>
> There is no reason for the C comment leader (`//`) to be inserted below the `git(1)` command:
>
> - this is bash script; not a C file
> - the double slash is part of a url; it does not start a comment

I mentioned on github:

The cause for this appears to be that the 'comments' option for shell
script does contain "://". If you have a line starting with "//" and
use "o" then the comment leader is also copied.

It would be good to set the 'comments' option in the shell filetype
plugin. The maintainer for that is Dan Sharp (cc'ed).

--
hundred-and-one symptoms of being an internet addict:
139. You down your lunch in five minutes, at your desk, so you can
spend the rest of the hour surfing the Net.

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9426/1002669977@github.com>

Christian Brabandt

unread,
Dec 29, 2021, 11:34:18 AM12/29/21
to vim/vim, Subscribed

can you (@brammool or Dan) please notify me once there are changes, so I can adjust the comments setting for zsh accordingly?


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9426/1002678020@github.com>

lacygoill

unread,
Dec 29, 2021, 11:39:30 AM12/29/21
to vim/vim, Subscribed

The cause for this appears to be that the 'comments' option for shell script does contain "://".
If you have a line starting with "//" and use "o" then the comment leader is also copied.

I could add a condition for 'cindent' being set, but this is really a text formatting feature, not indenting.

Google tells me that this code in golang should run the previously mentioned git(1) command:

package main

import (
    "log"
    "os/exec"
)

func main() {

    cmd := exec.Command("git clone 'https://github.com/vim/vim/'")

    err := cmd.Run()

    if err != nil {
        log.Fatal(err)
    }
}

If we press o on the cmd assignment, // is inserted at the start of the newly created line. Again, there is no reason to do that. // is inside a quoted url. And this time, it can't be fixed by removing // from 'comments', because // is a valid comment leader in golang.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9426/1002680232@github.com>

Bram Moolenaar

unread,
Dec 29, 2021, 11:45:23 AM12/29/21
to vim...@googlegroups.com, Dan Sharp, Christian Brabandt

> can you (@brammool or Dan) please notify me once there are changes, so I can adjust the comments setting for [zsh](https://github.com/chrisbra/vim-zsh/blob/master/ftplugin/zsh.vim) accordingly?

It appears that the "zsh" filetype plugin already sets 'comments', so this
can be an example for the "sh" filetype.

--
I wish there was a knob on the TV to turn up the intelligence.
There's a knob called "brightness", but it doesn't seem to work.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\

Bram Moolenaar

unread,
Dec 29, 2021, 12:46:49 PM12/29/21
to vim/vim, Subscribed

For finding "//" inside a string there is a todo item. Let's see if I can fix that...


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9426/1002707486@github.com>

Reply all
Reply to author
Forward
0 new messages