From 680c37314b7a21fdad7cc2b9959f283b59712fa4 Mon Sep 17 00:00:00 2001 From: conao3 Date: Sat, 16 Nov 2019 23:49:35 +0900 Subject: [PATCH] define aggressive-indent--hook-alist and use it --- aggressive-indent.el | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/aggressive-indent.el b/aggressive-indent.el index c467db8..dfcd916 100644 --- a/aggressive-indent.el +++ b/aggressive-indent.el @@ -481,6 +481,12 @@ If BODY finishes, `while-no-input' returns whatever value BODY produced." (run-with-idle-timer aggressive-indent-sit-for-time t #'aggressive-indent--indent-if-changed)))) ;;; Minor modes +(defvar aggressive-indent--hook-alist + '((after-change-functions . aggressive-indent--keep-track-of-changes) + (after-revert-hook . aggressive-indent--clear-change-list) + (before-save-hook . aggressive-indent--proccess-changed-list-and-indent)) + "Hooks for `aggressive-indent-mode'.") + ;;;###autoload (define-minor-mode aggressive-indent-mode nil nil " =>" @@ -507,16 +513,15 @@ If BODY finishes, `while-no-input' returns whatever value BODY produced." (cl-member-if #'derived-mode-p aggressive-indent-dont-electric-modes)) (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 'after-revert-hook #'aggressive-indent--clear-change-list nil 'local) - (add-hook 'before-save-hook #'aggressive-indent--proccess-changed-list-and-indent nil 'local)) - ;; Clean the hooks + (mapc (lambda (hook) + (add-hook (car hook) (cdr hook) nil 'local)) + aggressive-indent--hook-alist) + ;; Clean the hooks (when (timerp aggressive-indent--idle-timer) (cancel-timer aggressive-indent--idle-timer)) - (remove-hook 'after-change-functions #'aggressive-indent--keep-track-of-changes 'local) - (remove-hook 'after-revert-hook #'aggressive-indent--clear-change-list '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))) + (mapc (lambda (hook) + (remove-hook (car hook) (cdr hook) nil 'local)) + aggressive-indent--hook-alist))) (defun aggressive-indent--local-electric (on) "Turn variable `electric-indent-mode' on or off locally, as per boolean ON."