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 +++++++++--- diff --git a/scdoc.1.scd b/scdoc.1.scd index b9dd71ad7fe0b8ebb963fb800ddf76a07cd6ea73..4a7dfcc2f03ab74c61e8627257b9772b7b3d0a51 100644 --- a/scdoc.1.scd +++ b/scdoc.1.scd @@ -55,7 +55,8 @@ The result looks something like this. 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 da63b5077c9f6619aea565191aeb9b879ba8fd99..a70283b93bcfd711643556d74061f0373e4f4da7 100644 --- a/src/main.c +++ b/src/main.c @@ -157,13 +157,19 @@ while ((ch = parser_getch(p)) == '\t') { ++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; -- 2.48.1