Kaydet (Commit) 6caa07b2 authored tarafından Thomas Wouters's avatar Thomas Wouters

Make 'python -tt' the default, meaning Python won't allow mixing tabs and

spaces for indentation. Adds a '-ttt' option to turn the errors back into
warnings; I'm not yet sure whether that's desireable for Py3K.

Also remove the magic for setting the size of tabs based on emacs/vim-style
comments. Python now always considers tabstops to be every-8-spaces.
üst 0c4eb625
...@@ -47,11 +47,8 @@ PyParser_ParseStringFlagsFilename(const char *s, const char *filename, ...@@ -47,11 +47,8 @@ PyParser_ParseStringFlagsFilename(const char *s, const char *filename,
} }
tok->filename = filename ? filename : "<string>"; tok->filename = filename ? filename : "<string>";
if (Py_TabcheckFlag || Py_VerboseFlag) { if (Py_TabcheckFlag >= 3)
tok->altwarning = (tok->filename != NULL); tok->alterror = 0;
if (Py_TabcheckFlag >= 2)
tok->alterror++;
}
return parsetok(tok, g, start, err_ret, flags); return parsetok(tok, g, start, err_ret, flags);
} }
...@@ -79,12 +76,8 @@ PyParser_ParseFileFlags(FILE *fp, const char *filename, grammar *g, int start, ...@@ -79,12 +76,8 @@ PyParser_ParseFileFlags(FILE *fp, const char *filename, grammar *g, int start,
return NULL; return NULL;
} }
tok->filename = filename; tok->filename = filename;
if (Py_TabcheckFlag || Py_VerboseFlag) { if (Py_TabcheckFlag >= 3)
tok->altwarning = (filename != NULL); tok->alterror = 0;
if (Py_TabcheckFlag >= 2)
tok->alterror++;
}
return parsetok(tok, g, start, err_ret, flags); return parsetok(tok, g, start, err_ret, flags);
} }
......
...@@ -120,8 +120,8 @@ tok_new(void) ...@@ -120,8 +120,8 @@ tok_new(void)
tok->lineno = 0; tok->lineno = 0;
tok->level = 0; tok->level = 0;
tok->filename = NULL; tok->filename = NULL;
tok->altwarning = 0; tok->altwarning = 1;
tok->alterror = 0; tok->alterror = 1;
tok->alttabsize = 1; tok->alttabsize = 1;
tok->altindstack[0] = 0; tok->altindstack[0] = 0;
tok->decoding_state = 0; tok->decoding_state = 0;
...@@ -1207,41 +1207,10 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end) ...@@ -1207,41 +1207,10 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
/* Set start of current token */ /* Set start of current token */
tok->start = tok->cur - 1; tok->start = tok->cur - 1;
/* Skip comment, while looking for tab-setting magic */ /* Skip comment */
if (c == '#') { if (c == '#')
static char *tabforms[] = {
"tab-width:", /* Emacs */
":tabstop=", /* vim, full form */
":ts=", /* vim, abbreviated form */
"set tabsize=", /* will vi never die? */
/* more templates can be added here to support other editors */
};
char cbuf[80];
char *tp, **cp;
tp = cbuf;
do {
*tp++ = c = tok_nextc(tok);
} while (c != EOF && c != '\n' &&
tp - cbuf + 1 < sizeof(cbuf));
*tp = '\0';
for (cp = tabforms;
cp < tabforms + sizeof(tabforms)/sizeof(tabforms[0]);
cp++) {
if ((tp = strstr(cbuf, *cp))) {
int newsize = atoi(tp + strlen(*cp));
if (newsize >= 1 && newsize <= 40) {
tok->tabsize = newsize;
if (Py_VerboseFlag)
PySys_WriteStderr(
"Tab size set to %d\n",
newsize);
}
}
}
while (c != EOF && c != '\n') while (c != EOF && c != '\n')
c = tok_nextc(tok); c = tok_nextc(tok);
}
/* Check for EOF and errors now */ /* Check for EOF and errors now */
if (c == EOF) { if (c == EOF) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment