Convert activation function into global minor mode

This commit is contained in:
Jessie Hildebrandt 2019-05-10 19:59:04 -04:00
parent 4786beec95
commit c55958bb9e

View File

@ -21,7 +21,7 @@
;; * Lightweight with no dependencies ;; * Lightweight with no dependencies
;; ;;
;; To enable mood-line: ;; To enable mood-line:
;; (mood-line-activate) ;; (mood-line-mode)
;;; License: ;;; License:
;; ;;
@ -257,16 +257,23 @@
;; Activation function ;; Activation function
;; ;;
;;;###autoload ;; Store the default mode-line format
(defun mood-line-activate () (defvar mood-line--default-mode-line mode-line-format)
"Replace the current mode-line with mood-line."
(interactive)
;; Setup flycheck hooks (if available) ;;;###autoload
(define-minor-mode mood-line-mode
"Toggle mood-line on or off."
:group 'mood-line
:global t
:lighter nil
(if mood-line-mode
(progn
;; Setup flycheck hooks
(add-hook 'flycheck-status-changed-functions #'mood-line--update-flycheck-segment) (add-hook 'flycheck-status-changed-functions #'mood-line--update-flycheck-segment)
(add-hook 'flycheck-mode-hook #'mood-line--update-flycheck-segment) (add-hook 'flycheck-mode-hook #'mood-line--update-flycheck-segment)
;; Setup VC hooks (if available) ;; Setup VC hooks
(add-hook 'find-file-hook #'mood-line--update-vc-segment) (add-hook 'find-file-hook #'mood-line--update-vc-segment)
(add-hook 'after-save-hook #'mood-line--update-vc-segment) (add-hook 'after-save-hook #'mood-line--update-vc-segment)
(advice-add #'vc-refresh-state :after #'mood-line--update-vc-segment) (advice-add #'vc-refresh-state :after #'mood-line--update-vc-segment)
@ -295,6 +302,25 @@
(:eval (mood-line-segment-major-mode)) (:eval (mood-line-segment-major-mode))
(:eval (mood-line-segment-flycheck)) (:eval (mood-line-segment-flycheck))
" "))))))) " ")))))))
(progn
;; Remove flycheck hooks
(remove-hook 'flycheck-status-changed-functions #'mood-line--update-flycheck-segment)
(remove-hook 'flycheck-mode-hook #'mood-line--update-flycheck-segment)
;; Remove VC hooks
(remove-hook 'file-find-hook #'mood-line--update-vc-segment)
(remove-hook 'after-save-hook #'mood-line--update-vc-segment)
(advice-remove #'vc-refresh-state #'mood-line--update-vc-segment)
;; Remove window update hooks
(remove-hook 'window-configuration-change-hook #'mood-line--update-selected-window)
(remove-hook 'focus-in-hook #'mood-line--update-selected-window)
(advice-remove #'handle-switch-frame #'mood-line--update-selected-window)
(advice-remove #'select-window #'mood-line--update-selected-window)
;; Restore the original mode-line format
(setq-default mode-line-format mood-line--default-mode-line))))
;; ;;
;; Provide mood-line ;; Provide mood-line