From ad744dc1478e767c1d568d6eba8b765da8b0610b Mon Sep 17 00:00:00 2001
From: Alcor <alcor@tilde.club>
Date: Mon, 4 May 2026 16:04:30 +0200
Subject: [PATCH 04/19] fix off-by-one error in macroExpand()

---
 input.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/input.c b/input.c
index 7e1f9c1..748dca2 100644
--- a/input.c
+++ b/input.c
@@ -271,8 +271,10 @@ void inputCompletion(void) {
 
 static int macroExpand(struct Edit *e) {
 	size_t macro = e->pos;
+	if (!macro) return 0;
+	--macro;
 	while (macro && e->buf[macro] != L'\\') macro--;
-	if (macro == e->pos) return 0;
+	if (e->buf[macro] != L'\\') return 0;
 	for (size_t i = 0; i < ARRAY_LEN(Macros); ++i) {
 		if (wcslen(Macros[i].name) != e->pos - macro) continue;
 		if (wcsncmp(Macros[i].name, &e->buf[macro], e->pos - macro)) continue;
-- 
2.47.3

