[Python-Dev] PEP 7 updated (original) (raw)

Brett Cannon brett at python.org
Thu May 13 20:39:23 CEST 2010


Feel free to look at Misc/Vim/python.vim and see if this works better than what is already there.

On Wed, May 12, 2010 at 20:47, Trent Nelson <trent at snakebite.org> wrote:

Does anyone know of a way to teach vim that C sources in a python checkout should have 4-space indents without changing the defaults for other C files? I use this in my vimrc: "----------------------------------------------------------------------------" " indentation: use detectindent plugin if possible "----------------------------------------------------------------------------" set autoindent set smartindent try  let g:detectindentpreferredexpandtab = 1  let g:detectindentpreferredtabsize = 8  let g:detectindentpreferredindent = 4  source $VIMRUNTIME/plugin/detectindent.vim  au BufNewFile,BufRead * .* DetectIndent catch  set smarttab  set expandtab  set tabstop=8  set shiftwidth=4  set softtabstop=4  set textwidth=80 endtry *** And this is plugin/detectindent.vim: " Name:          detectindent (global plugin) " Version:       1.0 " Author:        Ciaran McCreesh " Updates:       http://dev.gentoo.org/~ciaranm/vim/ " Purpose:       Detect file indent settings " " License:       You may redistribute this plugin under the same terms as Vim "                itself. " " Usage:         :DetectIndent " "                " to prefer expandtab to noexpandtab when detection is "                " impossible: "                :let g:detectindentpreferredexpandtab = 1 " "                " to set a preferred indent level when detection is "                " impossible: "                :let g:detectindentpreferredindent = 4 " " Requirements:  Untested on Vim versions below 6.2 fun! IsCommentStart(line)  " &comments isn't reliable  if &ft == "c" || &ft == "cpp"  return -1 != match(a:line, '/*')  else  return 0  endif endfun fun! IsCommentEnd(line)  if &ft == "c" || &ft == "cpp"  return -1 != match(a:line, '*/')  else  return 0  endif endfun fun! DetectIndent()  let l:hasleadingtabs            = 0  let l:hasleadingspaces          = 0  let l:shortestleadingspacesrun = 0  let l:longestleadingspacesrun  = 0  let l:idxend = line("$")  let l:idx = 1  while l:idx <= l:idxend_  _let l:line = getline(l:idx)_  _" try to skip over comment blocks, they can give really screwy indent_  _" settings in c/c++ files especially_  _if IsCommentStart(l:line)  while l:idx <= l:idxend && ! IsCommentEnd(l:line)  let l:line = getline(l:idx)  let l:idx = l:idx + 1  endwhile  let l:idx = l:idx + 1  continue  endif  let l:leadingchar = strpart(l:line, 0, 1)  if l:leadingchar == "\t"  let l:hasleadingtabs = 1  elseif l:leadingchar == " "  " only interested if we don't have a run of spaces followed by a  " tab.  if -1 == match(l:line, '^ +\t')  let l:hasleadingspaces = 1  let l:spaces = strlen(matchstr(l:line, '^ +'))  if l:shortestleadingspacesrun == 0 ||  \ l:spaces < l:shortestleadingspacesrun_  _let l:shortestleadingspacesrun = l:spaces_  _endif_  _if l:spaces > l:longestleadingspacesrun  let l:longestleadingspacesrun = l:spaces  endif  endif  endif  let l:idx = l:idx + 1  endwhile  if l:hasleadingtabs && ! l:hasleadingspaces  " tabs only, no spaces  set noexpandtab  if exists("g:detectindentpreferredtabsize")  let &shiftwidth  = g:detectindentpreferredindent  let &tabstop     = g:detectindentpreferredindent  endif  elseif l:hasleadingspaces && ! l:hasleadingtabs  " spaces only, no tabs  set expandtab  let &shiftwidth  = l:shortestleadingspacesrun  elseif l:hasleadingspaces && l:hasleadingtabs  " spaces and tabs  set noexpandtab  let &shiftwidth = l:shortestleadingspacesrun  " mmmm, time to guess how big tabs are  if l:longestleadingspacesrun < 2_  _let &tabstop = 2_  _elseif l:longestleadingspacesrun < 4_  _let &tabstop = 4_  _else_  _let &tabstop = 8_  _endif_  _else_  _" no spaces, no tabs_  _if exists("g:detectindentpreferredtabsize")_  _let &shiftwidth  = g:detectindentpreferredindent_  _let &tabstop     = g:detectindentpreferredindent_  _endif_  _if exists("g:detectindentpreferredexpandtab")_  _set expandtab_  _endif_  _endif_ _endfun_ _command! -nargs=0 DetectIndent call DetectIndent()


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/brett%40python.org



More information about the Python-Dev mailing list