Remove doom-modeline-add-hook!.

This commit is contained in:
Vincent Zhang 2018-06-19 18:06:01 +08:00
parent 0234007b08
commit 747f060cdf

View file

@ -96,54 +96,6 @@ then it detaches itself."
((symbolp ,hook)
(add-hook ,hook #',fn ,append))))))
(defmacro doom-modeline-add-hook! (&rest args)
"A convenience macro for `add-hook'. Takes, in order:
1. Optional properties :local and/or :append, which will make the hook
buffer-local or append to the list of hooks (respectively),
2. The hooks: either an unquoted major mode, an unquoted list of major-modes,
a quoted hook variable or a quoted list of hook variables. If unquoted, the
hooks will be resolved by appending -hook to each symbol.
3. A function, list of functions, or body forms to be wrapped in a lambda.
Examples:
(doom-modeline-add-hook! 'some-mode-hook 'enable-something) (same as `add-hook')
(doom-modeline-add-hook! some-mode '(enable-something and-another))
(doom-modeline-add-hook! '(one-mode-hook second-mode-hook) 'enable-something)
(doom-modeline-add-hook! (one-mode second-mode) 'enable-something)
(doom-modeline-add-hook! :append (one-mode second-mode) 'enable-something)
(doom-modeline-add-hook! :local (one-mode second-mode) 'enable-something)
(doom-modeline-add-hook! (one-mode second-mode) (setq v 5) (setq a 2))
(doom-modeline-add-hook! :append :local (one-mode second-mode) (setq v 5) (setq a 2))
Body forms can access the hook's arguments through the let-bound variable
`args'."
(declare (indent defun) (debug t))
(let ((hook-fn 'add-hook)
append-p local-p)
(while (keywordp (car args))
(pcase (pop args)
(:append (setq append-p t))
(:local (setq local-p t))
(:remove (setq hook-fn 'remove-hook))))
(let ((hooks (doom-modeline--resolve-hook-forms (pop args)))
(funcs
(let ((val (car args)))
(if (memq (car-safe val) '(quote function))
(if (cdr-safe (cadr val))
(cadr val)
(list (cadr val)))
(list args))))
forms)
(dolist (fn funcs)
(setq fn (if (symbolp fn)
`(function ,fn)
`(lambda (&rest _) ,@args)))
(dolist (hook hooks)
(push (if (eq hook-fn 'remove-hook)
`(remove-hook ',hook ,fn ,local-p)
`(add-hook ',hook ,fn ,append-p ,local-p))
forms)))
`(progn ,@(if append-p (nreverse forms) forms)))))
;;
;; Modeline library
;;
@ -1016,7 +968,8 @@ enabled."
;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc.
(defvar-local doom-modeline-env-version nil)
(defvar-local doom-modeline-env-command nil)
(doom-modeline-add-hook! '(focus-in-hook find-file-hook) #'doom-modeline-update-env)
(add-hook 'focus-in-hook #'doom-modeline-update-env)
(add-hook 'find-file-hook #'doom-modeline-update-env)
(defun doom-modeline-update-env ()
(when doom-modeline-env-command
(let* ((default-directory (doom-modeline-project-root))
@ -1028,8 +981,11 @@ enabled."
;; Only support python and ruby for now
;; TODO torgeir
(doom-modeline-add-hook! 'python-mode-hook (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2"))
(doom-modeline-add-hook! 'ruby-mode-hook (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2"))
(add-hook 'python-mode-hook
(lambda ()
(setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2")))
(add-hook 'ruby-mode-hook
(lambda () (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2")))
;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise)
(defvar doom-modeline-remap-face-cookie nil)