diff options
author | Peter Stephenson <pws@zsh.org> | 2015-06-05 11:21:22 +0100 |
---|---|---|
committer | Peter Stephenson <pws@zsh.org> | 2015-06-05 11:21:22 +0100 |
commit | 2abba7243a736a2fc626f3cc917d8a67014d4d20 (patch) | |
tree | c91850e5786a9a8e0c9ebbedc65abbc3a3131cd0 /Src/text.c | |
parent | 4804a7c5ff144fc7cc974484d16f2f88cc131264 (diff) | |
download | zsh-2abba7243a736a2fc626f3cc917d8a67014d4d20.tar.gz zsh-2abba7243a736a2fc626f3cc917d8a67014d4d20.tar.xz zsh-2abba7243a736a2fc626f3cc917d8a67014d4d20.zip |
35386: expand tabs where useful in builtins outputing function.
Also add to zed -f. Option is -x <numm>.
Diffstat (limited to 'Src/text.c')
-rw-r--r-- | Src/text.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/Src/text.c b/Src/text.c index 958303c68..850879699 100644 --- a/Src/text.c +++ b/Src/text.c @@ -30,6 +30,16 @@ #include "zsh.mdh" #include "text.pro" +/* + * If non-zero, expand syntactically significant leading tabs in text + * to this number of spaces. + * + * If negative, don't output leading whitespace at all. + */ + +/**/ +int text_expand_tabs; + static char *tptr, *tbuf, *tlim, *tpending; static int tsiz, tindent, tnewlins, tjob; @@ -156,8 +166,16 @@ taddnl(int no_semicolon) if (tnewlins) { tdopending(); taddchr('\n'); - for (t0 = 0; t0 != tindent; t0++) - taddchr('\t'); + for (t0 = 0; t0 != tindent; t0++) { + if (text_expand_tabs >= 0) { + if (text_expand_tabs) { + int t1; + for (t1 = 0; t1 < text_expand_tabs; t1++) + taddchr(' '); + } else + taddchr('\t'); + } + } } else if (no_semicolon) { taddstr(" "); } else { @@ -165,6 +183,30 @@ taddnl(int no_semicolon) } } +/* + * Output a tab that may be expanded as part of a leading set. + * Note this is not part of the text framework; it's for + * code that needs to output its own tabs that are to be + * consistent with those from getpermtext(). + * + * Note these tabs are only expected to be useful at the + * start of the line, so we make no attempt to count columns. + */ + +/**/ +void +zoutputtab(FILE *outf) +{ + if (text_expand_tabs < 0) + return; + if (text_expand_tabs) { + int i; + for (i = 0; i < text_expand_tabs; i++) + fputc(' ', outf); + } else + fputc('\t', outf); +} + /* get a permanent textual representation of n */ /**/ |