Loading ...
Sorry, an error occurred while loading the content.
 

optwin.vim - setlocal on global options ? ...

Expand Messages
  • Marc Weber
    First of all: Why is setlocal aw allowed because its a global option only. I d like to tidy up optwin.vim and change its output maybe adding core funtions
    Message 1 of 12 , Jan 29, 2011
      First of all: Why is setlocal aw allowed because its a global option
      only.

      I'd like to tidy up optwin.vim and change its output maybe adding core
      funtions which can be used to query wether a buf local var has been set
      at all.

      I'd like the output to look like this:

      === START ==
      (g); global option
      (b): options belonging to a buffer
      (w): options belonging to a window

      You don't assign values to binary options. You set or unset them like this:
      set option
      set nooption


      # shiftwidth (b) number of spaces used for each step of (auto)indent (local to buffer)
      setlocal sw=2

      # autowrite (g) automatically write a file when leaving a modified buffer
      set aw

      # ⇧shelltemp (g,b) use a temp file for shell commands instead of using a pipe
      setlocal stmp=value1
      set stmp="value2" (*)
      == END ==



      So what's different?

      - it shows clearly whether an option is a buffer local, a window local
      or a global option. The current behaviour is inconsistent. Some
      options have a second line saying (local to buffer), but not all
      (example "sts")

      - it shows both: global and buffer local vars if they are set.
      (How to query this?)


      Do you know about any reason why not to change the format?


      It looks like several lines in the file could be improved:

      " If there already is an option window, jump to that one.
      if bufwinnr("option-window") > 0
      let s:thiswin = winnr()
      while 1
      if @% == "option-window"
      finish
      endif
      exe "norm! \<C-W>w"
      if s:thiswin == winnr()
      break
      endif
      endwhile
      endif

      What the heck does it do? Let's rewrite it:

      " If there already is an option window, jump to that one.
      if bufwinnr("option-window") > 0
      " if buffer is shown finish even if the buffer whose options should
      " be shouwn has different local vars. focus it
      exec bufwinnr("option-window").' wincmd w'
      finish
      endif

      Now that you know what this code does you'll notice some issues:

      - if you hide buffer (quit with set hidden) and run options again
      you'll have the options twice

      - if you don't hide and jump to a different buffer which has buffer
      local values set differently those local buffers won't update !

      This makes me think the :options command is close to useless and should
      be fixed.

      While the optwin.vim code pays much attention about whether an option is
      a local or a global one the output does not reflect this.

      global autowrite output vs local shiftwidth output:

      autowrite automatically write a file when leaving a modified buffer
      set aw noaw
      shiftwidth number of spaces used for each step of (auto)indent
      (local to buffer)
      set sw=10


      Let's have look at the code BinOptionL:


      " These functions are called often below. Keep them fast!

      " Init a local binary option
      fun! <SID>BinOptionL(name)
      exe "norm! \<C-W>p"
      exe "let val = &" . a:name
      exe "norm! \<C-W>p"
      call append("$", substitute(substitute(" \tset " . val . a:name . "\t" .
      \!val . a:name, "0", "no", ""), "1", "", ""))
      endfun

      Why is it important to keep it fast - is :options used that often?
      why is exe used if there is wincmd p (or even getbufvar ?)
      ... some more questions appear but its not worth writing them down.


      Yours
      Marc Weber

      --
      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
    • ZyX
      Reply to message «optwin.vim - setlocal on global options ? ...», sent 10:13:02 30 January 2011, Sunday ... By the way, is substitute really faster then
      Message 2 of 12 , Jan 30, 2011
        Reply to message «optwin.vim - setlocal on global options ? ...»,
        sent 10:13:02 30 January 2011, Sunday
        by Marc Weber:

        > fun! <SID>BinOptionL(name)
        > exe "norm! \<C-W>p"
        > exe "let val = &" . a:name
        > exe "norm! \<C-W>p"
        > call append("$", substitute(substitute(" \tset " . val . a:name . "\t"
        > . \!val . a:name, "0", "no", ""), "1", "", ""))
        > endfun
        >
        > Why is it important to keep it fast - is :options used that often?
        > why is exe used if there is wincmd p (or even getbufvar ?)
        > ... some more questions appear but its not worth writing them down.
        By the way, is substitute really faster then ((val)?(""):("no"))? I guess it is
        not.

        Other possible improvements:
        --- /usr/share/vim/vim73/optwin.vim 2011-01-24 05:44:22.000000000 +0300
        +++ optwin.vim 2011-01-30 12:43:32.000000000 +0300
        @@ -26,15 +26,11 @@
        fun! <SID>CR()

        " If on a continued comment line, go back to the first comment line
        - let lnum = line(".")
        + let lnum = search("^[^\t]", 'bWcn')
        let line = getline(lnum)
        - while line[0] == "\t"
        - let lnum = lnum - 1
        - let line = getline(lnum)
        - endwhile

        " <CR> on a "set" line executes the option line
        - if match(line, "^ \tset ") >= 0
        + if line[:5] ==# " \tset "

        " For a local option: go to the previous window
        " If this is a help window, go to the window below it
        @@ -63,7 +59,7 @@
        let line = getline(lnum)

        " <Space> on a "set" line refreshes the option line
        - if match(line, "^ \tset ") >= 0
        + if line[:5] ==# " \tset "

        " For a local option: go to the previous window
        " If this is a help window, go to the window below it
        @@ -79,21 +75,21 @@
        " find the window in which the option applies
        " returns 0 for global option, 1 for local option, -1 for error
        fun! <SID>Find(lnum)
        - if getline(a:lnum - 1) =~ "(local to"
        + if stridx(getline(a:lnum-1), "(local to")!=-1
        let local = 1
        let thiswin = winnr()
        - exe "norm! \<C-W>p"
        - if exists("b:current_syntax") && b:current_syntax == "help"
        - exe "norm! \<C-W>j"
        + wincmd p
        + if getbufvar(winbufnr(0), '&buftype') ==# "help"
        + wincmd j
        if winnr() == thiswin
        - exe "norm! \<C-W>j"
        + wincmd j
        endif
        endif
        else
        let local = 0
        endif
        - if local && (winnr() == thiswin || (exists("b:current_syntax")
        - \ && b:current_syntax == "help"))
        + if local && (winnr() == thiswin
        + \ || getbufvar(winbufnr(0), '&buftype') ==# "help")
        echo "Don't know in which window"
        let local = -1
        endif
        @@ -138,16 +134,13 @@
        " If the current window is a help window, try finding a non-help window.
        " Relies on syntax highlighting to be switched on.
        let s:thiswin = winnr()
        -while exists("b:current_syntax") && b:current_syntax == "help"
        +while s:thiswin != winnr() && getbufvar(winbufnr(0), '&buftype') ==# 'help'
        exe "norm! \<C-W>w"
        - if s:thiswin == winnr()
        - break
        - endif
        endwhile

        " Open the window
        new option-window
        -setlocal ts=15 tw=0 noro
        +setlocal ts=15 tw=0 noro buftype=nofile

        " Insert help and a "set" command for each option.
        call append(0, '" Each "set" line shows the current value of an option (on the
        left).')
        @@ -162,31 +155,30 @@

        " Init a local binary option
        fun! <SID>BinOptionL(name)
        - exe "norm! \<C-W>p"
        - exe "let val = &" . a:name
        - exe "norm! \<C-W>p"
        - call append("$", substitute(substitute(" \tset " . val . a:name . "\t" .
        - \!val . a:name, "0", "no", ""), "1", "", ""))
        + wincmd p
        + let val = eval("&".a:name)
        + wincmd p
        + call append('$', " \tset " . (val?"":"no") . a:name . "\t" .
        + \ (val?"no":"") . a:name)
        endfun

        " Init a global binary option
        fun! <SID>BinOptionG(name, val)
        - call append("$", substitute(substitute(" \tset " . a:val . a:name . "\t" .
        - \!a:val . a:name, "0", "no", ""), "1", "", ""))
        + call append('$', " \tset " . (a:val?"":"no") . a:name . "\t" .
        + \ (a:val?"no":"") . a:name)
        endfun

        " Init a local string option
        fun! <SID>OptionL(name)
        - exe "norm! \<C-W>p"
        - exe "let val = substitute(&" . a:name . ', "[ \\t\\\\\"|]", "\\\\\\0", "g")'
        - exe "norm! \<C-W>p"
        + wincmd p
        + let val = escape(eval("&".a:name), " \t\\\"|")
        + wincmd p
        call append("$", " \tset " . a:name . "=" . val)
        endfun

        " Init a global string option
        fun! <SID>OptionG(name, val)
        - call append("$", " \tset " . a:name . "=" . substitute(a:val, '[ \t\\"|]',
        - \ '\\\0', "g"))
        + call append("$", " \tset " . a:name . "=" . escape(a:val, " \t\\\"|"))
        endfun

        let s:idx = 1

        Original message:
        > First of all: Why is setlocal aw allowed because its a global option
        > only.
        >
        > I'd like to tidy up optwin.vim and change its output maybe adding core
        > funtions which can be used to query wether a buf local var has been set
        > at all.
        >
        > I'd like the output to look like this:
        >
        > === START ==
        > (g); global option
        > (b): options belonging to a buffer
        > (w): options belonging to a window
        >
        > You don't assign values to binary options. You set or unset them like
        > this: set option
        > set nooption
        >
        >
        > # shiftwidth (b) number of spaces used for each step of (auto)indent
        > (local to buffer) setlocal sw=2
        >
        > # autowrite (g) automatically write a file when leaving a modified
        buffer
        > set aw
        >
        > # ⇧shelltemp (g,b) use a temp file for shell commands instead of using
        > a pipe setlocal stmp=value1
        > set stmp="value2" (*)
        > == END ==
        >
        >
        >
        > So what's different?
        >
        > - it shows clearly whether an option is a buffer local, a window local
        > or a global option. The current behaviour is inconsistent. Some
        > options have a second line saying (local to buffer), but not all
        > (example "sts")
        >
        > - it shows both: global and buffer local vars if they are set.
        > (How to query this?)
        >
        >
        > Do you know about any reason why not to change the format?
        >
        >
        > It looks like several lines in the file could be improved:
        >
        > " If there already is an option window, jump to that one.
        > if bufwinnr("option-window") > 0
        > let s:thiswin = winnr()
        > while 1
        > if @% == "option-window"
        > finish
        > endif
        > exe "norm! \<C-W>w"
        > if s:thiswin == winnr()
        > break
        > endif
        > endwhile
        > endif
        >
        > What the heck does it do? Let's rewrite it:
        >
        > " If there already is an option window, jump to that one.
        > if bufwinnr("option-window") > 0
        > " if buffer is shown finish even if the buffer whose options should
        > " be shouwn has different local vars. focus it
        > exec bufwinnr("option-window").' wincmd w'
        > finish
        > endif
        >
        > Now that you know what this code does you'll notice some issues:
        >
        > - if you hide buffer (quit with set hidden) and run options again
        > you'll have the options twice
        >
        > - if you don't hide and jump to a different buffer which has buffer
        > local values set differently those local buffers won't update !
        >
        > This makes me think the :options command is close to useless and should
        > be fixed.
        >
        > While the optwin.vim code pays much attention about whether an option is
        > a local or a global one the output does not reflect this.
        >
        > global autowrite output vs local shiftwidth output:
        >
        > autowrite automatically write a file when leaving a modified buffer
        > set aw noaw
        > shiftwidth number of spaces used for each step of (auto)indent
        > (local to buffer)
        > set sw=10
        >
        >
        > Let's have look at the code BinOptionL:
        >
        >
        > " These functions are called often below. Keep them fast!
        >
        > " Init a local binary option
        > fun! <SID>BinOptionL(name)
        > exe "norm! \<C-W>p"
        > exe "let val = &" . a:name
        > exe "norm! \<C-W>p"
        > call append("$", substitute(substitute(" \tset " . val . a:name . "\t"
        > . \!val . a:name, "0", "no", ""), "1", "", ""))
        > endfun
        >
        > Why is it important to keep it fast - is :options used that often?
        > why is exe used if there is wincmd p (or even getbufvar ?)
        > ... some more questions appear but its not worth writing them down.
        >
        >
        > Yours
        > Marc Weber
      • Christian Brabandt
        Hi Marc! ... setlocal will set the global option, if the option does not have a local value. ... because the functions are called a lot for all the options
        Message 3 of 12 , Jan 30, 2011
          Hi Marc!

          On So, 30 Jan 2011, Marc Weber wrote:

          > First of all: Why is setlocal aw allowed because its a global option
          > only.

          setlocal will set the global option, if the option does not have a local
          value.

          > I'd like to tidy up optwin.vim and change its output maybe adding core
          > funtions which can be used to query wether a buf local var has been set
          > at all.
          >
          > I'd like the output to look like this:
          >
          > === START ==
          > (g); global option
          > (b): options belonging to a buffer
          > (w): options belonging to a window
          >
          > You don't assign values to binary options. You set or unset them like this:
          > set option
          > set nooption
          >
          >
          > # shiftwidth (b) number of spaces used for each step of (auto)indent (local to buffer)
          > setlocal sw=2
          >
          > # autowrite (g) automatically write a file when leaving a modified buffer
          > set aw
          >
          > # ⇧shelltemp (g,b) use a temp file for shell commands instead of using a pipe
          > setlocal stmp=value1
          > set stmp="value2" (*)
          > == END ==
          >
          >
          >
          > So what's different?
          >
          > - it shows clearly whether an option is a buffer local, a window local
          > or a global option. The current behaviour is inconsistent. Some
          > options have a second line saying (local to buffer), but not all
          > (example "sts")
          >
          > - it shows both: global and buffer local vars if they are set.
          > (How to query this?)
          >
          >
          > Do you know about any reason why not to change the format?
          >
          >
          > It looks like several lines in the file could be improved:
          >
          > " If there already is an option window, jump to that one.
          > if bufwinnr("option-window") > 0
          > let s:thiswin = winnr()
          > while 1
          > if @% == "option-window"
          > finish
          > endif
          > exe "norm! \<C-W>w"
          > if s:thiswin == winnr()
          > break
          > endif
          > endwhile
          > endif
          >
          > What the heck does it do? Let's rewrite it:
          >
          > " If there already is an option window, jump to that one.
          > if bufwinnr("option-window") > 0
          > " if buffer is shown finish even if the buffer whose options should
          > " be shouwn has different local vars. focus it
          > exec bufwinnr("option-window").' wincmd w'
          > finish
          > endif
          >
          > Now that you know what this code does you'll notice some issues:
          >
          > - if you hide buffer (quit with set hidden) and run options again
          > you'll have the options twice
          >
          > - if you don't hide and jump to a different buffer which has buffer
          > local values set differently those local buffers won't update !
          >
          > This makes me think the :options command is close to useless and should
          > be fixed.
          >
          > While the optwin.vim code pays much attention about whether an option is
          > a local or a global one the output does not reflect this.
          >
          > global autowrite output vs local shiftwidth output:
          >
          > autowrite automatically write a file when leaving a modified buffer
          > set aw noaw
          > shiftwidth number of spaces used for each step of (auto)indent
          > (local to buffer)
          > set sw=10
          >
          >
          > Let's have look at the code BinOptionL:
          >
          >
          > " These functions are called often below. Keep them fast!
          >
          > " Init a local binary option
          > fun! <SID>BinOptionL(name)
          > exe "norm! \<C-W>p"
          > exe "let val = &" . a:name
          > exe "norm! \<C-W>p"
          > call append("$", substitute(substitute(" \tset " . val . a:name . "\t" .
          > \!val . a:name, "0", "no", ""), "1", "", ""))
          > endfun
          >
          > Why is it important to keep it fast - is :options used that often?

          because the functions are called a lot for all the options available.

          > why is exe used if there is wincmd p (or even getbufvar ?)

          I guess getbufvar() was not available when optwin.vim was written
          originally and getbufvar() is probably also faster than to start jumping
          around between windows, since that would trigger autocommands.

          > ... some more questions appear but its not worth writing them down.

          It sounds like a good idea, to improve the optwin code.

          regards,
          Christian
          --

          --
          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
        • ZyX
          Reply to message «Re: optwin.vim - setlocal on global options ? ...», sent 15:41:09 30 January 2011, Sunday ... There is one problem with it: options may be
          Message 4 of 12 , Jan 30, 2011
            Reply to message «Re: optwin.vim - setlocal on global options ? ...»,
            sent 15:41:09 30 January 2011, Sunday
            by Christian Brabandt:

            > I guess getbufvar() was not available when optwin.vim was written
            > originally and getbufvar() is probably also faster than to start jumping
            > around between windows, since that would trigger autocommands.

            There is one problem with it: options may be local either to buffer or
            to window, so getbufvar() is not an option. I reread help for gettabwinvar()
            (which is referenced in :h getwinvar()) and it looks like
            «getwinvar(winnr('#'), '&'.a:name)» is what should be used. Attached
            new version with getwinvar and diff between it and old version.
            Here is a benchmark:

            (zyx:~/tmp/vim) % time ( for (( I=0 ; I<100 ; I++ )) ; do vim -u NONE -S optwin.vim -c
            'qa!' ; done )
            (; for ((I=0 ; I<100 ; I++ )) do; vim -u NONE -S optwin.vim -c 'qa!'; done; ) 3,01s user
            0,58s system 85% cpu 4,187 total
            (zyx:~/tmp/vim) % time ( for (( I=0 ; I<100 ; I++ )) ; do vim -u NONE -S
            /usr/share/vim/vim73/optwin.vim -c 'qa!' ; done )
            (; for ((I=0 ; I<100 ; I++ )) do; vim -u NONE -S -c 'qa!'; done; ) 3,55s user 0,57s
            system 84% cpu 4,885 total
            (zyx:~/tmp/vim) % time ( for (( I=0 ; I<100 ; I++ )) ; do vim -u
            /usr/share/vim/vim73/vimrc_example.vim -S optwin.vim -c 'qa!' ; done )
            (; for ((I=0 ; I<100 ; I++ )) do; vim -u -S optwin.vim -c 'qa!'; done; ) 27,06s user
            1,81s system 97% cpu 29,484 total
            (zyx:~/tmp/vim) % time ( for (( I=0 ; I<100 ; I++ )) ; do vim -u
            /usr/share/vim/vim73/vimrc_example.vim -S /usr/share/vim/vim73/optwin.vim -c 'qa!' ; done
            )
            (; for ((I=0 ; I<100 ; I++ )) do; vim -u -S /usr/share/vim/vim73/optwin.vim ) 30,76s
            user 1,79s system 98% cpu 32,889 total
            (zyx:~/tmp/vim) % time ( for (( I=0 ; I<10 ; I++ )) ; do vim -S optwin.vim -c 'qa!' ; done
            )
            (; for ((I=0 ; I<10 ; I++ )) do; vim -S optwin.vim -c 'qa!'; done; ) 8,84s user 0,40s
            system 99% cpu 9,286 total
            (zyx:~/tmp/vim) % time ( for (( I=0 ; I<10 ; I++ )) ; do vim -S
            /usr/share/vim/vim73/optwin.vim -c 'qa!' ; done )
            (; for ((I=0 ; I<10 ; I++ )) do; vim -S /usr/share/vim/vim73/optwin.vim -c ; ) 10,22s
            user 0,45s system 98% cpu 10,786 total

            Result: old version is 12-17% slower.

            (zyx:~/tmp/vim) % vim -S /usr/share/vim/vim73/optwin.vim -c 'w! optwin.txt' -c 'qa!'
            (zyx:~/tmp/vim) % vim -S optwin.vim -c 'w! optwin2.txt' -c 'qa!'
            (zyx:~/tmp/vim) % diff optwin*.txt
            (zyx:~/tmp/vim) %

            Original message:
            > Hi Marc!
            >
            > On So, 30 Jan 2011, Marc Weber wrote:
            > > First of all: Why is setlocal aw allowed because its a global option
            > > only.
            >
            > setlocal will set the global option, if the option does not have a local
            > value.
            >
            > > I'd like to tidy up optwin.vim and change its output maybe adding core
            > > funtions which can be used to query wether a buf local var has been set
            > > at all.
            > >
            > > I'd like the output to look like this:
            > > === START ==
            > > (g); global option
            > > (b): options belonging to a buffer
            > > (w): options belonging to a window
            > >
            > > You don't assign values to binary options. You set or unset them like
            > > this: set option
            > > set nooption
            > >
            > >
            > > # shiftwidth (b) number of spaces used for each step of (auto)indent
            > > (local to buffer) setlocal sw=2
            > >
            > > # autowrite (g) automatically write a file when leaving a modified
            > > buffer set aw
            > >
            > > # ⇧shelltemp (g,b) use a temp file for shell commands instead of
            > > using a pipe setlocal stmp=value1
            > > set stmp="value2" (*)
            > > == END ==
            > >
            > > So what's different?
            > >
            > > - it shows clearly whether an option is a buffer local, a window local
            > >
            > > or a global option. The current behaviour is inconsistent. Some
            > > options have a second line saying (local to buffer), but not all
            > > (example "sts")
            > >
            > > - it shows both: global and buffer local vars if they are set.
            > >
            > > (How to query this?)
            > >
            > > Do you know about any reason why not to change the format?
            > >
            > > It looks like several lines in the file could be improved:
            > > " If there already is an option window, jump to that one.
            > > if bufwinnr("option-window") > 0
            > >
            > > let s:thiswin = winnr()
            > > while 1
            > >
            > > if @% == "option-window"
            > >
            > > finish
            > >
            > > endif
            > > exe "norm! \<C-W>w"
            > > if s:thiswin == winnr()
            > >
            > > break
            > >
            > > endif
            > >
            > > endwhile
            > >
            > > endif
            > >
            > > What the heck does it do? Let's rewrite it:
            > > " If there already is an option window, jump to that one.
            > > if bufwinnr("option-window") > 0
            > >
            > > " if buffer is shown finish even if the buffer whose options should
            > > " be shouwn has different local vars. focus it
            > > exec bufwinnr("option-window").' wincmd w'
            > > finish
            > >
            > > endif
            > >
            > > Now that you know what this code does you'll notice some issues:
            > >
            > > - if you hide buffer (quit with set hidden) and run options again
            > >
            > > you'll have the options twice
            > >
            > > - if you don't hide and jump to a different buffer which has buffer
            > >
            > > local values set differently those local buffers won't update !
            > >
            > > This makes me think the :options command is close to useless and should
            > > be fixed.
            > >
            > > While the optwin.vim code pays much attention about whether an option is
            > > a local or a global one the output does not reflect this.
            > >
            > > global autowrite output vs local shiftwidth output:
            > > autowrite automatically write a file when leaving a modified buffer
            > >
            > > set aw noaw
            > >
            > > shiftwidth number of spaces used for each step of (auto)indent
            > >
            > > (local to buffer)
            > >
            > > set sw=10
            > >
            > > Let's have look at the code BinOptionL:
            > > " These functions are called often below. Keep them fast!
            > >
            > > " Init a local binary option
            > > fun! <SID>BinOptionL(name)
            > >
            > > exe "norm! \<C-W>p"
            > > exe "let val = &" . a:name
            > > exe "norm! \<C-W>p"
            > > call append("$", substitute(substitute(" \tset " . val . a:name .
            > > "\t" .
            > >
            > > \!val . a:name, "0", "no", ""), "1", "", ""))
            > >
            > > endfun
            > >
            > > Why is it important to keep it fast - is :options used that often?
            >
            > because the functions are called a lot for all the options available.
            >
            > > why is exe used if there is wincmd p (or even getbufvar ?)
            >
            > I guess getbufvar() was not available when optwin.vim was written
            > originally and getbufvar() is probably also faster than to start jumping
            > around between windows, since that would trigger autocommands.
            >
            > > ... some more questions appear but its not worth writing them down.
            >
            > It sounds like a good idea, to improve the optwin code.
            >
            > regards,
            > Christian
          • Marc Weber
            ... I ve counted them. They are called 35 times. Should be fast enough. A noticeable delay occurs if you have 2.000 invokations. ... My last thought was : Do
            Message 5 of 12 , Jan 30, 2011
              Excerpts from Christian Brabandt's message of Sun Jan 30 13:41:09 +0100 2011:
              > because the functions are called a lot for all the options available.
              I've counted them. They are called 35 times. Should be fast enough. A
              noticeable delay occurs if you have > 2.000 invokations.

              > It sounds like a good idea, to improve the optwin code.
              My last thought was : Do it in C - because C already knows about all
              options and their attributes..

              I'll think about it again.

              Marc Weber

              --
              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
            • Bram Moolenaar
              ... We can have a long discussion about using :setlocal for a global option should fail or not. ... The user would get here to change option values, keep the
              Message 6 of 12 , Jan 30, 2011
                Marc Weber wrote:

                > First of all: Why is setlocal aw allowed because its a global option
                > only.

                We can have a long discussion about using :setlocal for a global option
                should fail or not.

                > I'd like to tidy up optwin.vim and change its output maybe adding core
                > funtions which can be used to query wether a buf local var has been set
                > at all.
                >
                > I'd like the output to look like this:
                >
                > === START ==
                > (g); global option
                > (b): options belonging to a buffer
                > (w): options belonging to a window
                >
                > You don't assign values to binary options. You set or unset them like this:
                > set option
                > set nooption

                The user would get here to change option values, keep the header as
                short as possible.

                I don't think this window should repeat what's in the help files. A
                line pointing beginners to the help for options would be better.

                > # shiftwidth (b) number of spaces used for each step of (auto)indent (local to buffer)
                > setlocal sw=2
                >
                > # autowrite (g) automatically write a file when leaving a modified buffer
                > set aw
                >
                > # ⇧shelltemp (g,b) use a temp file for shell commands instead of using a pipe
                > setlocal stmp=value1
                > set stmp="value2" (*)
                > == END ==

                When using :set and :setlocal in this way, only for :setlocal we would
                need to mention whether it's window-local or buffer-local. Otherwise
                it's global.

                > So what's different?
                >
                > - it shows clearly whether an option is a buffer local, a window local
                > or a global option. The current behaviour is inconsistent. Some
                > options have a second line saying (local to buffer), but not all
                > (example "sts")
                >
                > - it shows both: global and buffer local vars if they are set.
                > (How to query this?)
                >
                > Do you know about any reason why not to change the format?

                It's a compromise between being complete and keeping it short.

                > It looks like several lines in the file could be improved:
                >
                > " If there already is an option window, jump to that one.
                > if bufwinnr("option-window") > 0
                > let s:thiswin = winnr()
                > while 1
                > if @% == "option-window"
                > finish
                > endif
                > exe "norm! \<C-W>w"
                > if s:thiswin == winnr()
                > break
                > endif
                > endwhile
                > endif
                >
                > What the heck does it do? Let's rewrite it:
                >
                > " If there already is an option window, jump to that one.
                > if bufwinnr("option-window") > 0
                > " if buffer is shown finish even if the buffer whose options should
                > " be shouwn has different local vars. focus it
                > exec bufwinnr("option-window").' wincmd w'
                > finish
                > endif

                That might find the option window for another window. We need to find
                the option window that belongs to the current window.

                > Now that you know what this code does you'll notice some issues:
                >
                > - if you hide buffer (quit with set hidden) and run options again
                > you'll have the options twice

                The option window should never be hidden. That needs to be fixed.

                > - if you don't hide and jump to a different buffer which has buffer
                > local values set differently those local buffers won't update !
                >
                > This makes me think the :options command is close to useless and should
                > be fixed.
                >
                > While the optwin.vim code pays much attention about whether an option is
                > a local or a global one the output does not reflect this.
                >
                > global autowrite output vs local shiftwidth output:
                >
                > autowrite automatically write a file when leaving a modified buffer
                > set aw noaw
                > shiftwidth number of spaces used for each step of (auto)indent
                > (local to buffer)
                > set sw=10
                >
                >
                > Let's have look at the code BinOptionL:
                >
                >
                > " These functions are called often below. Keep them fast!
                >
                > " Init a local binary option
                > fun! <SID>BinOptionL(name)
                > exe "norm! \<C-W>p"
                > exe "let val = &" . a:name
                > exe "norm! \<C-W>p"
                > call append("$", substitute(substitute(" \tset " . val . a:name . "\t" .
                > \!val . a:name, "0", "no", ""), "1", "", ""))
                > endfun
                >
                > Why is it important to keep it fast - is :options used that often?
                > why is exe used if there is wincmd p (or even getbufvar ?)
                > ... some more questions appear but its not worth writing them down.

                On slow machines opening the option window can be really slow.
                It can probably be made faster by avoiding too many window-switch
                commands. I haven't spent time on that.

                --
                "Hit any key to continue" is very confusing when you have two keyboards.

                /// Bram Moolenaar -- Bram@... -- 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
              • ZyX
                Reply to message «Re: optwin.vim - setlocal on global options ? ...», sent 00:07:54 31 January 2011, Monday ... I don t understand you. ... will bring me to
                Message 7 of 12 , Jan 30, 2011
                  Reply to message «Re: optwin.vim - setlocal on global options ? ...»,
                  sent 00:07:54 31 January 2011, Monday
                  by Bram Moolenaar:

                  > That might find the option window for another window. We need to find
                  > the option window that belongs to the current window.
                  I don't understand you.
                  :wincmd v
                  :options
                  :wincmd h
                  :options
                  will bring me to the first option window. If you meant option window on other
                  tab, then Marc's code is just fine: bufwinnr() is not able to find window on
                  other tab.

                  > On slow machines opening the option window can be really slow.
                  > It can probably be made faster by avoiding too many window-switch
                  > commands. I haven't spent time on that.
                  Then may be you include my patch? It has not changed that find-option-window
                  code (just because I forgot about it while writing this patch).

                  > The option window should never be hidden. That needs to be fixed.
                  augroup OptionWindowDelete
                  execute "autocmd! * <buffer=".bufnr('%').">"
                  execute "autocmd BufHidden <buffer=".bufnr('%')."> bwipeout! ".bufnr('%')
                  augroup END
                  just after «new option-window»?

                  Original message:
                  > Marc Weber wrote:
                  > > First of all: Why is setlocal aw allowed because its a global option
                  > > only.
                  >
                  > We can have a long discussion about using :setlocal for a global option
                  > should fail or not.
                  >
                  > > I'd like to tidy up optwin.vim and change its output maybe adding core
                  > > funtions which can be used to query wether a buf local var has been set
                  > > at all.
                  > >
                  > > I'd like the output to look like this:
                  > > === START ==
                  > > (g); global option
                  > > (b): options belonging to a buffer
                  > > (w): options belonging to a window
                  > >
                  > > You don't assign values to binary options. You set or unset them like
                  > > this: set option
                  > > set nooption
                  >
                  > The user would get here to change option values, keep the header as
                  > short as possible.
                  >
                  > I don't think this window should repeat what's in the help files. A
                  > line pointing beginners to the help for options would be better.
                  >
                  > > # shiftwidth (b) number of spaces used for each step of (auto)indent
                  > > (local to buffer) setlocal sw=2
                  > >
                  > > # autowrite (g) automatically write a file when leaving a modified
                  > > buffer set aw
                  > >
                  > > # ⇧shelltemp (g,b) use a temp file for shell commands instead of
                  > > using a pipe setlocal stmp=value1
                  > > set stmp="value2" (*)
                  > > == END ==
                  >
                  > When using :set and :setlocal in this way, only for :setlocal we would
                  > need to mention whether it's window-local or buffer-local. Otherwise
                  > it's global.
                  >
                  > > So what's different?
                  > >
                  > > - it shows clearly whether an option is a buffer local, a window local
                  > >
                  > > or a global option. The current behaviour is inconsistent. Some
                  > > options have a second line saying (local to buffer), but not all
                  > > (example "sts")
                  > >
                  > > - it shows both: global and buffer local vars if they are set.
                  > >
                  > > (How to query this?)
                  > >
                  > > Do you know about any reason why not to change the format?
                  >
                  > It's a compromise between being complete and keeping it short.
                  >
                  > > It looks like several lines in the file could be improved:
                  > > " If there already is an option window, jump to that one.
                  > > if bufwinnr("option-window") > 0
                  > >
                  > > let s:thiswin = winnr()
                  > > while 1
                  > >
                  > > if @% == "option-window"
                  > >
                  > > finish
                  > >
                  > > endif
                  > > exe "norm! \<C-W>w"
                  > > if s:thiswin == winnr()
                  > >
                  > > break
                  > >
                  > > endif
                  > >
                  > > endwhile
                  > >
                  > > endif
                  > >
                  > > What the heck does it do? Let's rewrite it:
                  > > " If there already is an option window, jump to that one.
                  > > if bufwinnr("option-window") > 0
                  > >
                  > > " if buffer is shown finish even if the buffer whose options should
                  > > " be shouwn has different local vars. focus it
                  > > exec bufwinnr("option-window").' wincmd w'
                  > > finish
                  > >
                  > > endif
                  >
                  > That might find the option window for another window. We need to find
                  > the option window that belongs to the current window.
                  >
                  > > Now that you know what this code does you'll notice some issues:
                  > >
                  > > - if you hide buffer (quit with set hidden) and run options again
                  > >
                  > > you'll have the options twice
                  >
                  > The option window should never be hidden. That needs to be fixed.
                  >
                  > > - if you don't hide and jump to a different buffer which has buffer
                  > >
                  > > local values set differently those local buffers won't update !
                  > >
                  > > This makes me think the :options command is close to useless and should
                  > > be fixed.
                  > >
                  > > While the optwin.vim code pays much attention about whether an option is
                  > > a local or a global one the output does not reflect this.
                  > >
                  > > global autowrite output vs local shiftwidth output:
                  > > autowrite automatically write a file when leaving a modified buffer
                  > >
                  > > set aw noaw
                  > >
                  > > shiftwidth number of spaces used for each step of (auto)indent
                  > >
                  > > (local to buffer)
                  > >
                  > > set sw=10
                  > >
                  > > Let's have look at the code BinOptionL:
                  > > " These functions are called often below. Keep them fast!
                  > >
                  > > " Init a local binary option
                  > > fun! <SID>BinOptionL(name)
                  > >
                  > > exe "norm! \<C-W>p"
                  > > exe "let val = &" . a:name
                  > > exe "norm! \<C-W>p"
                  > > call append("$", substitute(substitute(" \tset " . val . a:name .
                  > > "\t" .
                  > >
                  > > \!val . a:name, "0", "no", ""), "1", "", ""))
                  > >
                  > > endfun
                  > >
                  > > Why is it important to keep it fast - is :options used that often?
                  > > why is exe used if there is wincmd p (or even getbufvar ?)
                  > > ... some more questions appear but its not worth writing them down.
                  >
                  > On slow machines opening the option window can be really slow.
                  > It can probably be made faster by avoiding too many window-switch
                  > commands. I haven't spent time on that.
                • ZyX
                  Reply to message «Re: optwin.vim - setlocal on global options ? ...», sent 00:28:57 31 January 2011, Monday ... One addition: if option window is opened on
                  Message 8 of 12 , Jan 30, 2011
                    Reply to message «Re: optwin.vim - setlocal on global options ? ...»,
                    sent 00:28:57 31 January 2011, Monday
                    by ZyX:

                    > I don't understand you.
                    >
                    > :wincmd v
                    > :options
                    > :wincmd h
                    > :options
                    >
                    > will bring me to the first option window. If you meant option window on
                    > other tab, then Marc's code is just fine: bufwinnr() is not able to find
                    > window on other tab.
                    One addition: if option window is opened on some tab, «new option-window» in
                    other tab will create new window associated with existing buffer, so it should
                    probably be fixed.

                    Original message:
                    > Reply to message «Re: optwin.vim - setlocal on global options ? ...»,
                    > sent 00:07:54 31 January 2011, Monday
                    >
                    > by Bram Moolenaar:
                    > > That might find the option window for another window. We need to find
                    > > the option window that belongs to the current window.
                    >
                    > I don't understand you.
                    >
                    > :wincmd v
                    > :options
                    > :wincmd h
                    > :options
                    >
                    > will bring me to the first option window. If you meant option window on
                    > other tab, then Marc's code is just fine: bufwinnr() is not able to find
                    > window on other tab.
                    >
                    > > On slow machines opening the option window can be really slow.
                    > > It can probably be made faster by avoiding too many window-switch
                    > > commands. I haven't spent time on that.
                    >
                    > Then may be you include my patch? It has not changed that
                    > find-option-window code (just because I forgot about it while writing this
                    > patch).
                    >
                    > > The option window should never be hidden. That needs to be fixed.
                    >
                    > augroup OptionWindowDelete
                    > execute "autocmd! * <buffer=".bufnr('%').">"
                    > execute "autocmd BufHidden <buffer=".bufnr('%')."> bwipeout!
                    > ".bufnr('%') augroup END
                    > just after «new option-window»?
                    >
                    > Original message:
                    > > Marc Weber wrote:
                    > > > First of all: Why is setlocal aw allowed because its a global option
                    > > > only.
                    > >
                    > > We can have a long discussion about using :setlocal for a global option
                    > > should fail or not.
                    > >
                    > > > I'd like to tidy up optwin.vim and change its output maybe adding core
                    > > > funtions which can be used to query wether a buf local var has been set
                    > > > at all.
                    > > >
                    > > > I'd like the output to look like this:
                    > > > === START ==
                    > > > (g); global option
                    > > > (b): options belonging to a buffer
                    > > > (w): options belonging to a window
                    > > >
                    > > > You don't assign values to binary options. You set or unset them like
                    > > > this: set option
                    > > > set nooption
                    > >
                    > > The user would get here to change option values, keep the header as
                    > > short as possible.
                    > >
                    > > I don't think this window should repeat what's in the help files. A
                    > > line pointing beginners to the help for options would be better.
                    > >
                    > > > # shiftwidth (b) number of spaces used for each step of
                    (auto)indent
                    > > > (local to buffer) setlocal sw=2
                    > > >
                    > > > # autowrite (g) automatically write a file when leaving a modified
                    > > > buffer set aw
                    > > >
                    > > > # ⇧shelltemp (g,b) use a temp file for shell commands instead of
                    > > > using a pipe setlocal stmp=value1
                    > > > set stmp="value2" (*)
                    > > > == END ==
                    > >
                    > > When using :set and :setlocal in this way, only for :setlocal we would
                    > > need to mention whether it's window-local or buffer-local. Otherwise
                    > > it's global.
                    > >
                    > > > So what's different?
                    > > >
                    > > > - it shows clearly whether an option is a buffer local, a window
                    > > > local
                    > > >
                    > > > or a global option. The current behaviour is inconsistent. Some
                    > > > options have a second line saying (local to buffer), but not all
                    > > > (example "sts")
                    > > >
                    > > > - it shows both: global and buffer local vars if they are set.
                    > > >
                    > > > (How to query this?)
                    > > >
                    > > > Do you know about any reason why not to change the format?
                    > >
                    > > It's a compromise between being complete and keeping it short.
                    > >
                    > > > It looks like several lines in the file could be improved:
                    > > > " If there already is an option window, jump to that one.
                    > > > if bufwinnr("option-window") > 0
                    > > >
                    > > > let s:thiswin = winnr()
                    > > > while 1
                    > > >
                    > > > if @% == "option-window"
                    > > >
                    > > > finish
                    > > >
                    > > > endif
                    > > > exe "norm! \<C-W>w"
                    > > > if s:thiswin == winnr()
                    > > >
                    > > > break
                    > > >
                    > > > endif
                    > > >
                    > > > endwhile
                    > > >
                    > > > endif
                    > > >
                    > > > What the heck does it do? Let's rewrite it:
                    > > > " If there already is an option window, jump to that one.
                    > > > if bufwinnr("option-window") > 0
                    > > >
                    > > > " if buffer is shown finish even if the buffer whose options should
                    > > > " be shouwn has different local vars. focus it
                    > > > exec bufwinnr("option-window").' wincmd w'
                    > > > finish
                    > > >
                    > > > endif
                    > >
                    > > That might find the option window for another window. We need to find
                    > > the option window that belongs to the current window.
                    > >
                    > > > Now that you know what this code does you'll notice some issues:
                    > > >
                    > > > - if you hide buffer (quit with set hidden) and run options again
                    > > >
                    > > > you'll have the options twice
                    > >
                    > > The option window should never be hidden. That needs to be fixed.
                    > >
                    > > > - if you don't hide and jump to a different buffer which has buffer
                    > > >
                    > > > local values set differently those local buffers won't update !
                    > > >
                    > > > This makes me think the :options command is close to useless and should
                    > > > be fixed.
                    > > >
                    > > > While the optwin.vim code pays much attention about whether an option
                    > > > is a local or a global one the output does not reflect this.
                    > > >
                    > > > global autowrite output vs local shiftwidth output:
                    > > > autowrite automatically write a file when leaving a modified
                    > > > buffer
                    > > >
                    > > > set aw noaw
                    > > >
                    > > > shiftwidth number of spaces used for each step of (auto)indent
                    > > >
                    > > > (local to buffer)
                    > > >
                    > > > set sw=10
                    > > >
                    > > > Let's have look at the code BinOptionL:
                    > > > " These functions are called often below. Keep them fast!
                    > > >
                    > > > " Init a local binary option
                    > > > fun! <SID>BinOptionL(name)
                    > > >
                    > > > exe "norm! \<C-W>p"
                    > > > exe "let val = &" . a:name
                    > > > exe "norm! \<C-W>p"
                    > > > call append("$", substitute(substitute(" \tset " . val . a:name .
                    > > > "\t" .
                    > > >
                    > > > \!val . a:name, "0", "no", ""), "1", "", ""))
                    > > >
                    > > > endfun
                    > > >
                    > > > Why is it important to keep it fast - is :options used that often?
                    > > > why is exe used if there is wincmd p (or even getbufvar ?)
                    > > > ... some more questions appear but its not worth writing them down.
                    > >
                    > > On slow machines opening the option window can be really slow.
                    > > It can probably be made faster by avoiding too many window-switch
                    > > commands. I haven't spent time on that.
                  • Marc Weber
                    ... I think it should because it strengthens the user awareness about cope of options. Anyway: Is there a way to view/set both: local and global settings for
                    Message 9 of 12 , Jan 30, 2011
                      Excerpts from Bram Moolenaar's message of Sun Jan 30 22:07:54 +0100 2011:
                      > We can have a long discussion about using :setlocal for a global option
                      > should fail or not.

                      I think it should because it strengthens the user awareness about cope of
                      options.

                      Anyway: Is there a way to view/set both: local and global settings for those
                      options which are both?

                      > The user would get here to change option values, keep the header as
                      > short as possible.
                      I totally missed that you can change options that way. I never missed it
                      either. By reading the code I assumed its a view only.

                      > I don't think this window should repeat what's in the help files. A
                      > line pointing beginners to the help for options would be better.
                      Agreed.

                      > On slow machines opening the option window can be really slow.
                      I'd assume people using Vim on very slow machines know the options they
                      use very often anyway - probably they have also mapped them.

                      Do you have a rough estimate about how long it takes on such slow
                      machines? Maybe I can can benchmark alternative solutions to find out
                      how much slower they would be.

                      Eg pressing <cr> on binary options could be enough to toggle them - no
                      need to edit them - no need to show the "alternative" value.

                      The logic is pretty simple.

                      Thanks for making me understand what that page is about.

                      Marc Weber

                      --
                      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
                    • ZyX
                      Reply to message «Re: optwin.vim - setlocal on global options ? ...», sent 00:36:46 31 January 2011, Monday ... My solution without most of window changes is
                      Message 10 of 12 , Jan 30, 2011
                        Reply to message «Re: optwin.vim - setlocal on global options ? ...»,
                        sent 00:36:46 31 January 2011, Monday
                        by Marc Weber:

                        > Do you have a rough estimate about how long it takes on such slow
                        > machines? Maybe I can can benchmark alternative solutions to find out
                        > how much slower they would be.
                        My solution without most of window changes is at least 10% faster then
                        old solution. But it will be good if you improve my benchmark
                        (taking into account the fact that I measured (vim_startup+optwin+vim_shutdown),
                        not only (optwin)).
                        Second attempt:

                        (zyx:~/tmp/vim) % for (( I=0 ; I<100 ; I++ )) ; do vim -u NONE -c 'let rt=reltime()' -c
                        'so /usr/share/vim/vim73/optwin.vim' -c "call writefile([reltimestr(reltime(rt))],
                        'ow$I')" -c 'qa!' ; done
                        (zyx:~/tmp/vim) % cat ow* | sort | head -n 1
                        0.014335
                        (zyx:~/tmp/vim) % for (( I=0 ; I<100 ; I++ )) ; do vim -u NONE -c 'let rt=reltime()' -c
                        'so optwin.vim' -c "call writefile([reltimestr(reltime(rt))], 'owm$I')" -c 'qa!' ; done
                        (zyx:~/tmp/vim) % cat owm* | sort | head -n 1
                        0.010008

                        Now 30% improvement (which is expected). With your code that finds existing
                        option window it is just 0.8% faster (though 0.010008-0.009929=7.9e-5 is probably
                        below the precision). It should make more difference with more windows opened
                        or more autocommands set then with «-u NONE».

                        Original message:
                        > Excerpts from Bram Moolenaar's message of Sun Jan 30 22:07:54 +0100 2011:
                        > > We can have a long discussion about using :setlocal for a global option
                        > > should fail or not.
                        >
                        > I think it should because it strengthens the user awareness about cope of
                        > options.
                        >
                        > Anyway: Is there a way to view/set both: local and global settings for
                        > those options which are both?
                        >
                        > > The user would get here to change option values, keep the header as
                        > > short as possible.
                        >
                        > I totally missed that you can change options that way. I never missed it
                        > either. By reading the code I assumed its a view only.
                        >
                        > > I don't think this window should repeat what's in the help files. A
                        > > line pointing beginners to the help for options would be better.
                        >
                        > Agreed.
                        >
                        > > On slow machines opening the option window can be really slow.
                        >
                        > I'd assume people using Vim on very slow machines know the options they
                        > use very often anyway - probably they have also mapped them.
                        >
                        > Do you have a rough estimate about how long it takes on such slow
                        > machines? Maybe I can can benchmark alternative solutions to find out
                        > how much slower they would be.
                        >
                        > Eg pressing <cr> on binary options could be enough to toggle them - no
                        > need to edit them - no need to show the "alternative" value.
                        >
                        > The logic is pretty simple.
                        >
                        > Thanks for making me understand what that page is about.
                        >
                        > Marc Weber
                      • Ben Schmidt
                        ... need to use :setlocal and :setglobal. Ben. -- You received this message from the vim_dev maillist. Do not top-post! Type your reply below the text you
                        Message 11 of 12 , Jan 30, 2011
                          > Anyway: Is there a way to view/set both: local and global settings for those
                          > options which are both?

                          :set sets both, but displays the value in effect. To display both, you
                          need to use :setlocal and :setglobal.

                          Ben.



                          --
                          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
                        • ZyX
                          Reply to message «Re: optwin.vim - setlocal on global options ? ...», sent 02:56:03 31 January 2011, Monday by Ben Schmidt: It is also possible to use
                          Message 12 of 12 , Jan 30, 2011
                            Reply to message «Re: optwin.vim - setlocal on global options ? ...»,
                            sent 02:56:03 31 January 2011, Monday
                            by Ben Schmidt:

                            It is also possible to use &l:option and &g:option. They are better then parsing
                            :set* output.

                            Original message:
                            > > Anyway: Is there a way to view/set both: local and global settings for
                            > > those options which are both?
                            > :
                            > :set sets both, but displays the value in effect. To display both, you
                            >
                            > need to use :setlocal and :setglobal.
                            >
                            > Ben.
                          Your message has been successfully submitted and would be delivered to recipients shortly.