From e8bf88919c177024abec159c22cb4e88fbe5a4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Mon, 19 Nov 2018 15:01:07 +0000 Subject: [PATCH] Really protect against unwanted indentation after undo When I am undoing changes to a region I really want the changes to be undone verbatim, that is, I want the buffer's contents to be like they were before the change that I want to undo occured. This is the very definition of undo. It is probably the rationale for have undo-in-progress in aggressive-indent--internal-dont-indent-if in the first place. It means that the undo command won't immediately cause for reindentation. But it doesn't fix the whole problem, because changes performed by undo itself are still recorded into aggressive-indent--changed-list and the very next command, be it a move or an edit somewhere else, will still indent those regions. Among other things, it's impossible in practice to use `undo' to undo an aggressive indent of a region. The proposed fix checks undo-in-progress before registering a change. It's possible that other elements (but maybe not all) in aggressive-indent--internal-dont-indent-if merit this treatment, too. * aggressive-indent.el (aggressive-indent--keep-track-of-changes): Check undo-in-progress. --- aggressive-indent.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aggressive-indent.el b/aggressive-indent.el index da21bfe..ce64240 100644 --- a/aggressive-indent.el +++ b/aggressive-indent.el @@ -426,7 +426,8 @@ typing, try tweaking this number." (defun aggressive-indent--keep-track-of-changes (l r &rest _) "Store the limits (L and R) of each change in the buffer." (when aggressive-indent-mode - (push (list l r) aggressive-indent--changed-list) + (unless undo-in-progress + (push (list l r) aggressive-indent--changed-list)) (unless (timerp aggressive-indent--idle-timer) (setq aggressive-indent--idle-timer (run-with-idle-timer aggressive-indent-sit-for-time t #'aggressive-indent--indent-if-changed)))))