Fix by Eric Raymond: make the code that looks for various bits of
tab-setting magic much smarter, more correct, and more easily extensible.
This commit is contained in:
parent
a1f0a8f4a4
commit
ab5ca15f94
|
@ -564,24 +564,39 @@ PyTokenizer_Get(tok, p_start, p_end)
|
||||||
/* Set start of current token */
|
/* Set start of current token */
|
||||||
tok->start = tok->cur - 1;
|
tok->start = tok->cur - 1;
|
||||||
|
|
||||||
/* Skip comment */
|
/* Skip comment, while looking for tab-setting magic */
|
||||||
if (c == '#') {
|
if (c == '#') {
|
||||||
/* Hack to allow overriding the tabsize in the file.
|
static char *tabforms[] = {
|
||||||
This is also recognized by vi, when it occurs near the
|
"tab-width:", /* Emacs */
|
||||||
beginning or end of the file. (Will vi never die...?)
|
":tabstop=", /* vim, full form */
|
||||||
For Python it must be at the beginning of the file! */
|
":ts=", /* vim, abbreviated form */
|
||||||
/* XXX The real vi syntax is actually different :-( */
|
"set tabsize=", /* will vi never die? */
|
||||||
/* XXX Should recognize Emacs syntax, too */
|
/* more templates can be added here to support other editors */
|
||||||
int x;
|
};
|
||||||
if (sscanf(tok->cur,
|
char cbuf[80];
|
||||||
" vi:set tabsize=%d:", &x) == 1 &&
|
char *tp, **cp;
|
||||||
x >= 1 && x <= 40) {
|
tp = cbuf;
|
||||||
/* PySys_WriteStderr("# vi:set tabsize=%d:\n", x); */
|
|
||||||
tok->tabsize = x;
|
|
||||||
}
|
|
||||||
do {
|
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;
|
||||||
|
PySys_WriteStderr(
|
||||||
|
"Tab size set to %d\n",
|
||||||
|
newsize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (c != EOF && c != '\n')
|
||||||
c = tok_nextc(tok);
|
c = tok_nextc(tok);
|
||||||
} while (c != EOF && c != '\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for EOF and errors now */
|
/* Check for EOF and errors now */
|
||||||
|
|
Loading…
Reference in New Issue