This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Auto-detect indentation in C source in vimrc
Type: enhancement Stage: resolved
Components: Demos and Tools Versions: Python 2.7
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: KirkMcDonald, brett.cannon, georg.brandl, johshoff
Priority: low Keywords: patch

Created on 2009-03-30 18:10 by KirkMcDonald, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
vimrc.diff KirkMcDonald, 2009-03-30 18:10
Messages (4)
msg84602 - (view) Author: Kirk McDonald (KirkMcDonald) Date: 2009-03-30 18:10
According to PEP 7, older C source files are indented with tabs, and
newer ones are indented with spaces. The vimrc file in the repository
assumes that existing C source files should be indented with tabs, and it
should indent with spaces when you create a new C source file. This has
an obvious drawback: It will configure vim to use tabs when you edit a
file that in fact uses spaces.

The attached patch will search for the regex '^\t'; if it is found, vim
will be configured to use tabs and an 8-column shiftwidth; and if it is
not found, it will be configured to use spaces and a 4-column shiftwidth.
msg85488 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-04-05 13:19
You should restrict the search to the first 100 lines or so, if
possible.  Many of our C files have inconsistent indentation, and using
this script with such a file, automatically relying on it to do the
right thing, will result in even more inconsistencies.  Restricting the
search to the beginning of a file greatly reduces the probability of it
finding a stray tab indentation.
msg88882 - (view) Author: Johannes Hoff (johshoff) Date: 2009-06-04 11:39
I came across this bug while searching for autodetecting tabs/spaces. 
Thanks for the help.

To address Georg's question, the patch should be modified to say
    if search('^\t', 'n', 100)
instead of
    if search('^\t')

The former will not move the cursor, and will only search the first 100 
lines.
msg95046 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-11-08 21:42
in r76154 for trunk and r76155 for py3k. Thanks for the help, guys!
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 49861
2009-11-08 21:42:05brett.cannonsetstatus: open -> closed
resolution: accepted
messages: + msg95046

stage: patch review -> resolved
2009-06-04 11:39:28johshoffsetnosy: + johshoff
messages: + msg88882
2009-04-05 13:19:09georg.brandlsetnosy: + georg.brandl
messages: + msg85488
2009-03-30 19:21:11brett.cannonsetnosy: + brett.cannon
priority: low
assignee: brett.cannon
type: enhancement
stage: patch review
2009-03-30 18:10:45KirkMcDonaldcreate