Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define aggressive-indent--hook-alist and use it #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions aggressive-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 " =>"
Expand All @@ -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."
Expand Down