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

Re: 0# in cinkeys

Expand Messages
  • David Bustos
    ... This doesn t make a difference, since the function doesn t handle comment lines and returns -1, resulting in no indent change for that line. ... Ah ha,
    Message 1 of 3 , Oct 1, 2000
    • 0 Attachment
      On Mon, Oct 02, 2000 at 02:57:48AM +0200, Johannes Zellner wrote:
      > I'm using the python.vim indenter from David Bustos <bustos@...>.
      > I'd like to have comments '#.*' indented this way:
      >
      > def fred():
      > pass
      > # bla
      >
      > unfortunately '#' triggers immediate reindenting which results in
      >
      > def fred():
      > pass
      > # ...
      >
      > so I did `setlocal cinkeys-=#0' but w/o any effect.

      This doesn't make a difference, since the function doesn't handle
      comment lines and returns -1, resulting in no indent change for that
      line.

      > finally I figured out that I had
      >
      > setlocal nocindent smartindent

      Ah ha, smartindent is the problem.

      > shouldn't indentexpr turn off any builtin indention ?

      Yes, good call. Here is the new version.


      " Python indent file
      " Language: Python
      " Maintainer: David Bustos <bustos@...>
      " Last Change: October 1, 2000

      " Some preliminary settings
      setlocal cinkeys+=<:> " Reindent when : is inserted
      setlocal nolisp " Make sure lisp indenting doesn't supersede us
      setlocal nosmartindent " Smart indent will move remove all comment indentation

      setlocal indentexpr=GetPythonIndent(v:lnum)

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

      function GetPythonIndent(lnum)
      " Give up if this line is explicitly joined.
      if getline(a:lnum - 1) =~ '\\$'
      return -1
      endif

      " Search backwards for the frist non-empty line.
      let plnum = a:lnum - 1
      while plnum > 0 && getline(plnum) =~ '^\s*$'
      let plnum = plnum - 1
      endwhile

      if plnum == 0
      " This is the first non-empty line, use zero indent.
      return 0
      endif

      " If the previous line ended with a colon, indent this line
      if getline(plnum) =~ '^[^#]*:\s*\(#.*\)\=$'
      return indent(plnum) + &sw

      " If the previous line was a stop-execution statement...
      elseif getline(plnum) =~ '^\s*\(break\|continue\|raise\|return\)\>'
      " See if the user has already dedented
      if indent(a:lnum) > indent(plnum) - &sw
      " If not, recommend one dedent
      return indent(plnum) - &sw
      else
      " Otherwise, trust the user
      return -1
      endif

      " If the current line begins with a header keyword, dedent
      elseif getline(a:lnum) =~ '^\s*\(elif\|else\|except\|finaly\)\>'

      " Unless the previous line was a one-liner
      if getline(plnum) =~ '^\s*\(for\|if\|try\)\>'
      return indent(plnum)
      endif

      return indent(plnum) - &sw

      else
      return -1

      endif
      endfunction

      " vim:sw=2
    • Flemming Madsen
      I use a BufEnter autocommand that maps # as appropriate: autocmd BufEnter * call BufEnterGlobalOpts() function! BufEnterGlobalOpts() Avoid #-in-1.-column
      Message 2 of 3 , Oct 2, 2000
      • 0 Attachment
        I use a BufEnter autocommand that maps '#' as appropriate:

        autocmd BufEnter * call BufEnterGlobalOpts()
        function! BufEnterGlobalOpts()
        " Avoid '#-in-1.-column' problem with cindent & smartindent
        if &filetype == 'c' || &filetype == 'cpp'
        inoremap # #
        else
        inoremap # X<BS>#
        endif
        endfun

        Regards
        /Flemming


        Johannes Zellner wrote:
        >
        > Hello,
        >
        > I'm using the python.vim indenter from David Bustos <bustos@...>.
        > I'd like to have comments '#.*' indented this way:
        >
        > def fred():
        > pass
        > # bla
        >
        > unfortunately '#' triggers immediate reindenting which results in
        >
        > def fred():
        > pass
        > # ...
        >
        > so I did `setlocal cinkeys-=#0' but w/o any effect.
        > finally I figured out that I had
        >
        > setlocal nocindent smartindent
        >
        > shouldn't indentexpr turn off any builtin indention ?
        >
        > --
        > Johannes
      Your message has been successfully submitted and would be delivered to recipients shortly.