- (let ((inhibit-modification-hooks t))
- (when -changed-list-left
- (-softly-indent-region-and-on
- (apply #'min -changed-list-left)
- (apply #'max -changed-list-right))
- (setq -changed-list-left nil
- -changed-list-right nil))))
-
-(defun -keep-track-of-changes (l r &rest _)
- "Store the limits of each change that happens in the buffer."
- (push l -changed-list-left)
- (push r -changed-list-right))
-
-(defun -in-comment-p ()
- "Return non-nil if point is inside a comment.
-Assumes that the syntax table is sufficient to find comments."
- (nth 4 (syntax-ppss)))
-
-\f
-;;; Keymap
-(defun delete-backward ()
- "Either `delete-indentation' or call [backspace]."
- (interactive)
- (if (looking-back "^[[:blank:]]+")
- (call-interactively 'delete-indentation)
- (let ((mode nil))
- (execute-kbd-macro [backspace]))))
+ (when (and aggressive-indent--changed-list aggressive-indent--balanced-parens)
+ (save-excursion
+ (save-selected-window
+ (unless (or (run-hook-wrapped 'aggressive-indent--internal-dont-indent-if #'eval)
+ (aggressive-indent--run-user-hooks))
+ (while-no-input
+ (redisplay)
+ (let ((inhibit-modification-hooks t)
+ (inhibit-point-motion-hooks t)
+ (indent-function
+ (if (cl-member-if #'derived-mode-p aggressive-indent-modes-to-prefer-defun)
+ #'aggressive-indent--softly-indent-defun #'aggressive-indent--softly-indent-region-and-on)))
+ (while aggressive-indent--changed-list
+ (apply indent-function (car aggressive-indent--changed-list))
+ (setq aggressive-indent--changed-list
+ (cdr aggressive-indent--changed-list))))))))))
+
+(defun aggressive-indent--check-parens ()
+ "Check if parens are balanced in the current buffer.
+Store result in `aggressive-indent--balanced-parens'."
+ (setq aggressive-indent--balanced-parens
+ (save-excursion
+ (ignore-errors
+ (save-restriction
+ (check-parens)
+ t)))))
+
+(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)
+ (aggressive-indent--check-parens)))