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

Re: vim60h - new 'indent' feature

Expand Messages
  • Bram Moolenaar
    ... OK, I ll add the indentkeys option. Hopefully it s not too confusing to have two options with the same format and meaning, but apply in another
    Message 1 of 6 , Sep 22, 2000
    • 0 Attachment
      Zdenek Sekera wrote:

      > Well, cinkeys applies when ft=c, for others 'indentkeys' applies if
      > indentexpr exists.
      > I understand and sympathise with your argument, but I still don't like it.
      > That's when your last sentence kicks in :-)

      OK, I'll add the 'indentkeys' option. Hopefully it's not too confusing to
      have two options with the same format and meaning, but apply in another
      situation.

      > OK, so why this doesn't work for me? (60h):
      >
      > indent/sh.vim:
      >
      > " Sh indent file ---------------------------------------------
      > setlocal indentexpr=GetShIndent()
      > "setlocal cinkeys-=e cinkeys+==else,=do,=esac,=fi,=elif,=then
      > setlocal cinkeys=''

      If you make 'cinkeys' completely empty, there will also be no formatting when
      you start a new line. You should at least include "o" and "O". Read the docs
      for 'cinkeys' about this.

      --
      Just remember...if the world didn't suck, we'd all fall off.

      /// Bram Moolenaar Bram@... http://www.moolenaar.net \\\
      \\\ Vim: http://www.vim.org ICCF Holland: http://iccf-holland.org ///
    • Zdenek Sekera
      ... I think it s a good idea. ... come into play ... cindent if it is on, and indentkeys come into play. indentkeys may later even have an expanded meaning
      Message 2 of 6 , Sep 29, 2000
      • 0 Attachment
        Bram Moolenaar wrote:
        >
        > Zdenek Sekera wrote:
        >
        > > Well, cinkeys applies when ft=c, for others 'indentkeys' applies if
        > > indentexpr exists.
        > > I understand and sympathise with your argument, but I still don't like it.
        > > That's when your last sentence kicks in :-)
        >
        > OK, I'll add the 'indentkeys' option. Hopefully it's not too confusing to
        > have two options with the same format and meaning, but apply in another
        > situation.
        >

        I think it's a good idea.
        It seems logical to me to have two scenario:
        :set cindent - enables c-indenting, in this case 'cinkeys', cinoptions'
        come into play
        :set indentexpr=... - enables "user specified" indenting, overrides
        "cindent" if it is on, and indentkeys come into play.
        indentkeys may later even have an expanded meaning (if somebody has
        an idea why/what) and it never breaks c-indenting, no problems with
        backward compatibility..
        Seems clear & clean to me.

        > > OK, so why this doesn't work for me? (60h):
        > >
        > > indent/sh.vim:
        > >
        > > " Sh indent file ---------------------------------------------
        > > setlocal indentexpr=GetShIndent()
        > > "setlocal cinkeys-=e cinkeys+==else,=do,=esac,=fi,=elif,=then
        > > setlocal cinkeys=''
        >
        > If you make 'cinkeys' completely empty, there will also be no formatting when
        > you start a new line. You should at least include "o" and "O". Read the docs
        > for 'cinkeys' about this.

        Yes, got it (now :-)!) Thanks!

        ---Zdenek
      • Aric Blumer
        I ve been trying to put together an indent function for VHDL. Here is what I have so far (this file is named vhdl.vim in the indent ... setlocal
        Message 3 of 6 , Sep 29, 2000
        • 0 Attachment
          I've been trying to put together an indent function for VHDL. Here is
          what I have so far (this file is named vhdl.vim in the indent
          directory):

          --------------------------- >8 -----------------------------------
          setlocal indentexpr=GetVimIndent()
          setlocal cinkeys==end,=els,!^F,O

          " Only define the function once.
          if exists("*GetVimIndent")
          finish
          endif

          function GetVimIndent()
          if v:lnum == 1
          return 0
          endif
          let ind = indent(v:lnum - 1)
          if getline(v:lnum - 1) =~ '^\s*\(if\>\|while\>\|begin\>\|elsif\>\|when\>\|for\>\|loop\>\|architecture\>\|component\>\|port\>\)'
          let ind = ind + &sw
          endif
          if getline(v:lnum) =~ '^\s*\(end\>\|elsif\)'
          let ind = ind - &sw
          endif
          return ind
          endfunction
          --------------------------- >8 -----------------------------------

          The problem I'm having with this is the following: Edit a file like
          junk.vhd, and enter the following two lines without any leading space:

          if(a = 5) then
          a <= 6;
          end if;

          That indents just fine. Now try this:

          if(a = 5) then
          a <= 6;

          end if;

          The "end if" does not outdent like I expect. I see that the function
          indent(v:lnum - 1) returns the indent of the line right above the
          cursor. I take this behavior to mean that the line above "end if" has
          in indent of zero and that a return of a negative number from
          GetVimIndent does nothing to the indent.

          Is there a way to get the indent of the previous non-empty line?
        • Bram Moolenaar
          ... Yes, see this code in the vim.vim indent file: function GetVimIndent() Find a non-empty line above the current line. let lnum = v:lnum - 1 while lnum 0
          Message 4 of 6 , Sep 30, 2000
          • 0 Attachment
            Aric Blumer wrote:

            > The "end if" does not outdent like I expect. I see that the function
            > indent(v:lnum - 1) returns the indent of the line right above the
            > cursor. I take this behavior to mean that the line above "end if" has
            > in indent of zero and that a return of a negative number from
            > GetVimIndent does nothing to the indent.
            >
            > Is there a way to get the indent of the previous non-empty line?

            Yes, see this code in the vim.vim indent file:

            function GetVimIndent()
            " Find a non-empty line above the current line.
            let lnum = v:lnum - 1
            while lnum > 0
            if getline(lnum) !~ '^\s*$'
            break
            endif
            let lnum = lnum - 1
            endwhile

            " Hit the start of the file, use zero indent.
            if lnum == 0
            return 0
            endif

            Perhaps, if this is a very common thing to do for indenting, I could make a
            special function for it. Should make the indenting a bit faster.

            --
            hundred-and-one symptoms of being an internet addict:
            62. If your doorbell rings, you think hat new mail has arrived. And then
            you're disappointed that it's only someone at the door.

            /// Bram Moolenaar Bram@... http://www.moolenaar.net \\\
            \\\ Vim: http://www.vim.org ICCF Holland: http://iccf-holland.org ///
          • Zdenek Sekera
            ... [...] ... [...] ... That s a good idea!
            Message 5 of 6 , Oct 2, 2000
            • 0 Attachment
              Bram Moolenaar wrote:
              >
              > Aric Blumer wrote:
              [...]
              > >
              > > Is there a way to get the indent of the previous non-empty line?
              >
              > Yes, see this code in the vim.vim indent file:
              [...]
              >
              > Perhaps, if this is a very common thing to do for indenting, I could make a
              > special function for it. Should make the indenting a bit faster.

              That's a good idea!

              ---Zdenek
            Your message has been successfully submitted and would be delivered to recipients shortly.