commit 175c566ceadcdd9c233194625bfc388c46677db9
parent 9eb8e9bc2c26bcd46b6062a4f75c7337fea4f42a
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 10 Dec 2017 02:48:43 -0500
Improve indentation handling
Diffstat:
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/scdoc.1.scd b/scdoc.1.scd
@@ -55,7 +55,8 @@ the output. Indented lines may not contain headers.
You may use multiple lines and most _formatting_.
-Deindent to return to normal.
+Deindent to return to normal, or indent again to increase your indentation
+depth.
## LISTS
diff --git a/src/main.c b/src/main.c
@@ -157,13 +157,19 @@ static int parse_indent(struct parser *p, int *indent, bool write) {
++i;
}
parser_pushch(p, ch);
+ if (ch == '\n' && *indent != 0) {
+ // Don't change indent when we encounter empty lines
+ return *indent;
+ }
if (write) {
- if (i == *indent - 1) {
- roff_macro(p, "RE", NULL);
+ if (i < *indent) {
+ for (int j = *indent; i < j; --j) {
+ roff_macro(p, "RE", NULL);
+ }
} else if (i == *indent + 1) {
roff_macro(p, "RS", "4", NULL);
} else if (i != *indent && ch == '\t') {
- parser_fatal(p, "(De)indented by an amount greater than 1");
+ parser_fatal(p, "Indented by an amount greater than 1");
}
}
*indent = i;