Hello, The untabification of C files didn't produce any noticeable problem on the buildbots. I've updated PEP 7 with the mention that all C files should be 4-space indented, and removed the obsolete wording about some files being indented with tabs. Regards Antoine.
On 9 May, 2010, at 20:33, Antoine Pitrou wrote:
Hello,
The untabification of C files didn't produce any noticeable problem on the buildbots. I've updated PEP 7 with the mention that all C files should be 4-space indented, and removed the obsolete wording about some files being indented with tabs.
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? Ronald
On Mon, May 10, 2010 at 04:09:06PM +0200, Ronald Oussoren 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?
BufReadPre /usr/local/src/Python/*/*.c set sts=4 sw=4 Oleg. -- Oleg Broytman http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
On Mon, 10 May 2010 20:40:00 +0400, Oleg Broytman <phd@phd.pp.ru> wrote:
On Mon, May 10, 2010 at 04:09:06PM +0200, Ronald Oussoren 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?
BufReadPre /usr/local/src/Python/*/*.c set sts=4 sw=4
Alternatively you could sniff the file for leading tabs and set the "filetype" or the tab setting based on that. I think Brett has a vimrc somewhere that does something like that. --David
On Mon, May 10, 2010 at 11:10, R. David Murray <rdmurray@bitdance.com>wrote:
On Mon, 10 May 2010 20:40:00 +0400, Oleg Broytman <phd@phd.pp.ru> wrote:
On Mon, May 10, 2010 at 04:09:06PM +0200, Ronald Oussoren 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?
BufReadPre /usr/local/src/Python/*/*.c set sts=4 sw=4
Alternatively you could sniff the file for leading tabs and set the "filetype" or the tab setting based on that. I think Brett has a vimrc somewhere that does something like that.
Misc/Vim/python.vim does what you need to do.
On Mon, May 10, 2010 at 07:09, Ronald Oussoren <ronaldoussoren@mac.com>wrote:
On 9 May, 2010, at 20:33, Antoine Pitrou wrote:
Hello,
The untabification of C files didn't produce any noticeable problem on the buildbots. I've updated PEP 7 with the mention that all C files should be 4-space indented, and removed the obsolete wording about some files being indented with tabs.
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?
:help autocmd-patterns has this example, which should be easy to adapt: :autocmd BufRead /vim/src/*.c set cindent Set the 'cindent' option for C files in the /vim/src directory.
Ronald
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/ddborowitz%40gmail.com
-- It is better to be quotable than to be honest. -Tom Stoppard Borowitz
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:detectindent_preferred_expandtab = 1 let g:detectindent_preferred_tabsize = 8 let g:detectindent_preferred_indent = 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 <ciaranm at gentoo.org> " 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:detectindent_preferred_expandtab = 1 " " " to set a preferred indent level when detection is " " impossible: " :let g:detectindent_preferred_indent = 4 " " Requirements: Untested on Vim versions below 6.2 fun! <SID>IsCommentStart(line) " &comments isn't reliable if &ft == "c" || &ft == "cpp" return -1 != match(a:line, '/\*') else return 0 endif endfun fun! <SID>IsCommentEnd(line) if &ft == "c" || &ft == "cpp" return -1 != match(a:line, '\*/') else return 0 endif endfun fun! <SID>DetectIndent() let l:has_leading_tabs = 0 let l:has_leading_spaces = 0 let l:shortest_leading_spaces_run = 0 let l:longest_leading_spaces_run = 0 let l:idx_end = line("$") let l:idx = 1 while l:idx <= l:idx_end 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 <SID>IsCommentStart(l:line) while l:idx <= l:idx_end && ! <SID>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:leading_char = strpart(l:line, 0, 1) if l:leading_char == "\t" let l:has_leading_tabs = 1 elseif l:leading_char == " " " only interested if we don't have a run of spaces followed by a " tab. if -1 == match(l:line, '^ \+\t') let l:has_leading_spaces = 1 let l:spaces = strlen(matchstr(l:line, '^ \+')) if l:shortest_leading_spaces_run == 0 || \ l:spaces < l:shortest_leading_spaces_run let l:shortest_leading_spaces_run = l:spaces endif if l:spaces > l:longest_leading_spaces_run let l:longest_leading_spaces_run = l:spaces endif endif endif let l:idx = l:idx + 1 endwhile if l:has_leading_tabs && ! l:has_leading_spaces " tabs only, no spaces set noexpandtab if exists("g:detectindent_preferred_tabsize") let &shiftwidth = g:detectindent_preferred_indent let &tabstop = g:detectindent_preferred_indent endif elseif l:has_leading_spaces && ! l:has_leading_tabs " spaces only, no tabs set expandtab let &shiftwidth = l:shortest_leading_spaces_run elseif l:has_leading_spaces && l:has_leading_tabs " spaces and tabs set noexpandtab let &shiftwidth = l:shortest_leading_spaces_run " mmmm, time to guess how big tabs are if l:longest_leading_spaces_run < 2 let &tabstop = 2 elseif l:longest_leading_spaces_run < 4 let &tabstop = 4 else let &tabstop = 8 endif else " no spaces, no tabs if exists("g:detectindent_preferred_tabsize") let &shiftwidth = g:detectindent_preferred_indent let &tabstop = g:detectindent_preferred_indent endif if exists("g:detectindent_preferred_expandtab") set expandtab endif endif endfun command! -nargs=0 DetectIndent call <SID>DetectIndent()
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@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:detectindent_preferred_expandtab = 1 let g:detectindent_preferred_tabsize = 8 let g:detectindent_preferred_indent = 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 <ciaranm at gentoo.org> " 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:detectindent_preferred_expandtab = 1 " " " to set a preferred indent level when detection is " " impossible: " :let g:detectindent_preferred_indent = 4 " " Requirements: Untested on Vim versions below 6.2
fun! <SID>IsCommentStart(line) " &comments isn't reliable if &ft == "c" || &ft == "cpp" return -1 != match(a:line, '/\*') else return 0 endif endfun
fun! <SID>IsCommentEnd(line) if &ft == "c" || &ft == "cpp" return -1 != match(a:line, '\*/') else return 0 endif endfun
fun! <SID>DetectIndent() let l:has_leading_tabs = 0 let l:has_leading_spaces = 0 let l:shortest_leading_spaces_run = 0 let l:longest_leading_spaces_run = 0
let l:idx_end = line("$") let l:idx = 1 while l:idx <= l:idx_end 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 <SID>IsCommentStart(l:line) while l:idx <= l:idx_end && ! <SID>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:leading_char = strpart(l:line, 0, 1)
if l:leading_char == "\t" let l:has_leading_tabs = 1
elseif l:leading_char == " " " only interested if we don't have a run of spaces followed by a " tab. if -1 == match(l:line, '^ \+\t') let l:has_leading_spaces = 1 let l:spaces = strlen(matchstr(l:line, '^ \+')) if l:shortest_leading_spaces_run == 0 || \ l:spaces < l:shortest_leading_spaces_run let l:shortest_leading_spaces_run = l:spaces endif if l:spaces > l:longest_leading_spaces_run let l:longest_leading_spaces_run = l:spaces endif endif
endif
let l:idx = l:idx + 1 endwhile
if l:has_leading_tabs && ! l:has_leading_spaces " tabs only, no spaces set noexpandtab if exists("g:detectindent_preferred_tabsize") let &shiftwidth = g:detectindent_preferred_indent let &tabstop = g:detectindent_preferred_indent endif
elseif l:has_leading_spaces && ! l:has_leading_tabs " spaces only, no tabs set expandtab let &shiftwidth = l:shortest_leading_spaces_run
elseif l:has_leading_spaces && l:has_leading_tabs " spaces and tabs set noexpandtab let &shiftwidth = l:shortest_leading_spaces_run
" mmmm, time to guess how big tabs are if l:longest_leading_spaces_run < 2 let &tabstop = 2 elseif l:longest_leading_spaces_run < 4 let &tabstop = 4 else let &tabstop = 8 endif
else " no spaces, no tabs if exists("g:detectindent_preferred_tabsize") let &shiftwidth = g:detectindent_preferred_indent let &tabstop = g:detectindent_preferred_indent endif if exists("g:detectindent_preferred_expandtab") set expandtab endif
endif endfun
command! -nargs=0 DetectIndent call <SID>DetectIndent()
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/brett%40python.org
Nor did it break any of our ActivePython 2.7 (Python trunk) builds ... though I had to hand-edit the patches to use 4 spaces now. Will this untabification change be made to the `release2.6-maint` branch too? -srid On 2010-05-09, at 11:33 AM, Antoine Pitrou wrote:
Hello,
The untabification of C files didn't produce any noticeable problem on the buildbots. I've updated PEP 7 with the mention that all C files should be 4-space indented, and removed the obsolete wording about some files being indented with tabs.
Regards
Antoine.
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/sridharr%40activestate.com
Le mardi 11 mai 2010 à 16:44 -0700, Sridhar Ratnakumar a écrit :
Nor did it break any of our ActivePython 2.7 (Python trunk) builds ... though I had to hand-edit the patches to use 4 spaces now. Will this untabification change be made to the `release2.6-maint` branch too?
It has already been made to the 2.6 branch. By the way, you don't have to untabify patches by hand, you can just use "untabify.py -p". Regards Antoine.
participants (8)
-
Antoine Pitrou
-
Brett Cannon
-
David Borowitz
-
Oleg Broytman
-
R. David Murray
-
Ronald Oussoren
-
Sridhar Ratnakumar
-
Trent Nelson