diff --git a/aggressive-indent.el b/aggressive-indent.el index da21bfe..27994cb 100644 --- a/aggressive-indent.el +++ b/aggressive-indent.el @@ -164,11 +164,9 @@ change." ;;; Preventing indentation (defconst aggressive-indent--internal-dont-indent-if - '((memq last-command aggressive-indent-protected-commands) - (memq this-command aggressive-indent-protected-current-commands) + '((memq this-command aggressive-indent-protected-current-commands) (region-active-p) buffer-read-only - undo-in-progress (null (buffer-modified-p)) (and (boundp 'smerge-mode) smerge-mode) (equal (buffer-name) "*ediff-merge*") @@ -423,6 +421,15 @@ typing, try tweaking this number." (while-no-input (aggressive-indent--proccess-changed-list-and-indent)))))) +(defun aggressive-indent--post-command () + "Hook run after every command while in `aggressive-indent-mode'. + +Clears `aggressive-indent--changed-list' iff the current +command (the one that's now finished) lives in +`aggressive-indent-protected-current-commands'." + (when (memq this-command aggressive-indent-protected-commands) + (setq aggressive-indent--changed-list nil))) + (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 @@ -459,14 +466,15 @@ typing, try tweaking this number." (aggressive-indent--local-electric nil) (aggressive-indent--local-electric t)) (add-hook 'after-change-functions #'aggressive-indent--keep-track-of-changes nil 'local) - (add-hook 'before-save-hook #'aggressive-indent--proccess-changed-list-and-indent nil 'local)) + (add-hook 'before-save-hook #'aggressive-indent--proccess-changed-list-and-indent nil 'local) + (add-hook 'post-command-hook #'aggressive-indent--post-command nil 'local)) ;; Clean the hooks (when (timerp aggressive-indent--idle-timer) (cancel-timer aggressive-indent--idle-timer) (setq aggressive-indent--idle-timer nil)) (remove-hook 'after-change-functions #'aggressive-indent--keep-track-of-changes 'local) (remove-hook 'before-save-hook #'aggressive-indent--proccess-changed-list-and-indent 'local) - (remove-hook 'post-command-hook #'aggressive-indent--softly-indent-defun 'local))) + (remove-hook 'post-command-hook #'aggressive-indent--post-command 'local))) (defun aggressive-indent--local-electric (on) "Turn variable `electric-indent-mode' on or off locally, as per boolean ON."