From 175c566ceadcdd9c233194625bfc388c46677db9 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 10 Dec 2017 02:48:43 -0500 Subject: [PATCH] Improve indentation handling --- scdoc.1.scd | 3 ++- src/main.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scdoc.1.scd b/scdoc.1.scd index b9dd71a..4a7dfcc 100644 --- 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 index da63b50..a70283b 100644 --- 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;