core-lib: add auto-minor-mode, revise def-project-mode!
- Adds the auto-minor-mode package to replace our in-house implementation. - Merges associate! into the def-project-mode! macro because associate! on its own is less useful than auto-minor-mode-alist, auto-minor-mode-magic-alist or hooks. - Changes the semantics of :modes and :add-hooks properties of def-project-mode!. Its arguments are evaluated as is; lists will need to be quoted. squash! core-lib: remove associate! macro
This commit is contained in:
parent
3404899ec3
commit
0a84d2f0a9
15 changed files with 88 additions and 137 deletions
|
@ -200,30 +200,47 @@ should be activated. If they are *all* true, NAME is activated.
|
|||
Relevant: `doom-project-hook'."
|
||||
(declare (indent 1))
|
||||
(let ((init-var (intern (format "%s-init" name))))
|
||||
`(progn
|
||||
,(if on-load `(defvar ,init-var nil))
|
||||
(define-minor-mode ,name
|
||||
"A project minor mode generated by `def-project-mode!'."
|
||||
:init-value nil
|
||||
:lighter ""
|
||||
:keymap (make-sparse-keymap)
|
||||
(if (not ,name)
|
||||
,on-exit
|
||||
(run-hook-with-args 'doom-project-hook ',name ,name)
|
||||
,(when on-load
|
||||
`(unless ,init-var
|
||||
,on-load
|
||||
(setq ,init-var t)))
|
||||
,on-enter))
|
||||
,@(cl-loop for hook in add-hooks
|
||||
collect `(add-hook ',(intern (format "%s-hook" name))
|
||||
#',hook))
|
||||
,(when (or modes match files when)
|
||||
`(associate! ,name
|
||||
:modes ,modes
|
||||
:match ,match
|
||||
:files ,files
|
||||
:when ,when)))))
|
||||
(macroexp-progn
|
||||
(append
|
||||
(when on-load
|
||||
`((defvar ,init-var nil)))
|
||||
`((define-minor-mode ,name
|
||||
"A project minor mode generated by `def-project-mode!'."
|
||||
:init-value nil
|
||||
:lighter ""
|
||||
:keymap (make-sparse-keymap)
|
||||
(if (not ,name)
|
||||
,on-exit
|
||||
(run-hook-with-args 'doom-project-hook ',name ,name)
|
||||
,(when on-load
|
||||
`(unless ,init-var
|
||||
,on-load
|
||||
(setq ,init-var t)))
|
||||
,on-enter))
|
||||
(dolist (hook ,add-hooks)
|
||||
(add-hook ',(intern (format "%s-hook" name)) hook)))
|
||||
(cond ((or files modes when)
|
||||
(cl-check-type files (or null list string))
|
||||
(let ((fn `(lambda ()
|
||||
(and (not (bound-and-true-p ,name))
|
||||
(and buffer-file-name (not (file-remote-p buffer-file-name nil t)))
|
||||
,(or (null match)
|
||||
`(if buffer-file-name (string-match-p ,match buffer-file-name)))
|
||||
,(or (null files)
|
||||
(doom--resolve-path-forms
|
||||
(if (stringp (car files)) (cons 'and files) files)
|
||||
'(doom-project-root)))
|
||||
,(or when t)
|
||||
(,name 1)))))
|
||||
`((dolist (mode ,modes)
|
||||
(let ((hook-name (intern (format "doom--enable-%s%s-h" ',name
|
||||
(if (eq mode t) "" (format "-in-" mode))))))
|
||||
(fset hook-name #',fn)
|
||||
(if (eq mode t)
|
||||
(add-to-list 'auto-minor-mode-magic-alist (cons hook-name #',name))
|
||||
(add-hook (intern (format "%s-hook" mode)) hook-name)))))))
|
||||
(match
|
||||
`((add-to-list 'auto-minor-mode-alist (cons ,match #',name)))))))))
|
||||
|
||||
(provide 'core-projects)
|
||||
;;; core-projects.el ends here
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue