Refactor def-project-mode! with cl-defmacro
This commit is contained in:
parent
02d532a09a
commit
5501b949ef
|
@ -140,7 +140,15 @@ state are passed in.")
|
||||||
unless (symbol-value mode)
|
unless (symbol-value mode)
|
||||||
do (funcall mode)))))
|
do (funcall mode)))))
|
||||||
|
|
||||||
(defmacro def-project-mode! (name &rest plist)
|
(cl-defmacro def-project-mode! (name &key
|
||||||
|
modes
|
||||||
|
files
|
||||||
|
when
|
||||||
|
match
|
||||||
|
add-hooks
|
||||||
|
on-load
|
||||||
|
on-enter
|
||||||
|
on-exit)
|
||||||
"Define a project minor-mode named NAME (a symbol) and declare where and how
|
"Define a project minor-mode named NAME (a symbol) and declare where and how
|
||||||
it is activated. Project modes allow you to configure 'sub-modes' for
|
it is activated. Project modes allow you to configure 'sub-modes' for
|
||||||
major-modes that are specific to a specific folder, certain project structure,
|
major-modes that are specific to a specific folder, certain project structure,
|
||||||
|
@ -175,37 +183,25 @@ should be activated. If they are *all* true, NAME is activated.
|
||||||
:on-exit FORM -- FORM is run each time the mode is disabled.
|
:on-exit FORM -- FORM is run each time the mode is disabled.
|
||||||
|
|
||||||
Relevant: `doom-project-hook'."
|
Relevant: `doom-project-hook'."
|
||||||
(declare (indent 1) (doc-string 2))
|
(declare (indent 1))
|
||||||
(let ((doc-string (if (stringp (car plist))
|
(let ((init-var (intern (format "%s-init" name))))
|
||||||
(prog1 (car plist)
|
|
||||||
(setq plist (cdr plist)))
|
|
||||||
"A project minor mode."))
|
|
||||||
(modes (plist-get plist :modes))
|
|
||||||
(files (plist-get plist :files))
|
|
||||||
(when (plist-get plist :when))
|
|
||||||
(match (plist-get plist :match))
|
|
||||||
(hooks (plist-get plist :add-hooks))
|
|
||||||
(load-form (plist-get plist :on-load))
|
|
||||||
(enter-form (plist-get plist :on-enter))
|
|
||||||
(exit-form (plist-get plist :on-exit))
|
|
||||||
(init-var (intern (format "%s-init" name))))
|
|
||||||
`(progn
|
`(progn
|
||||||
,(if load-form `(defvar ,init-var nil))
|
,(if on-load `(defvar ,init-var nil))
|
||||||
(define-minor-mode ,name
|
(define-minor-mode ,name
|
||||||
,doc-string
|
"A project minor mode generated by `def-project-mode!'."
|
||||||
:init-value nil
|
:init-value nil
|
||||||
:lighter ""
|
:lighter ""
|
||||||
:keymap (make-sparse-keymap)
|
:keymap (make-sparse-keymap)
|
||||||
(if (not ,name)
|
(if (not ,name)
|
||||||
,exit-form
|
,on-exit
|
||||||
(run-hook-with-args 'doom-project-hook ',name ,name)
|
(run-hook-with-args 'doom-project-hook ',name ,name)
|
||||||
,(when load-form
|
,(when on-load
|
||||||
`(unless ,init-var
|
`(unless ,init-var
|
||||||
,load-form
|
,on-load
|
||||||
(setq ,init-var t)))
|
(setq ,init-var t)))
|
||||||
,enter-form))
|
,on-enter))
|
||||||
,(when hooks
|
,(when add-hooks
|
||||||
`(setq ,(intern (format "%s-hook" name)) ',hooks))
|
`(setq ,(intern (format "%s-hook" name)) ',add-hooks))
|
||||||
,(when (or modes match files when)
|
,(when (or modes match files when)
|
||||||
`(associate! ,name
|
`(associate! ,name
|
||||||
:modes ,modes
|
:modes ,modes
|
||||||
|
|
Loading…
Reference in New Issue
Block a user