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
|
@ -451,51 +451,6 @@ DOCSTRING and BODY are as in `defun'."
|
|||
(advice-remove target #',symbol)
|
||||
(advice-add target ,where #',symbol)))))
|
||||
|
||||
(cl-defmacro associate! (mode &key modes match files when)
|
||||
"Enables a minor mode if certain conditions are met.
|
||||
|
||||
The available conditions are:
|
||||
|
||||
:modes SYMBOL_LIST
|
||||
A list of major/minor modes in which this minor mode may apply.
|
||||
:match REGEXP
|
||||
A regexp to be tested against the current file path.
|
||||
:files SPEC
|
||||
Accepts what `project-file-exists-p!' accepts. Checks if certain files or
|
||||
directories exist relative to the project root.
|
||||
:when FORM
|
||||
Whenever FORM returns non-nil."
|
||||
(declare (indent 1))
|
||||
(unless noninteractive
|
||||
(cond ((or files modes when)
|
||||
(when (and files
|
||||
(not (or (listp files)
|
||||
(stringp files))))
|
||||
(user-error "associate! :files expects a string or list of strings"))
|
||||
(let ((hook-name (intern (format "doom--enable-mode-%s-h" mode))))
|
||||
`(progn
|
||||
(fset ',hook-name
|
||||
(lambda ()
|
||||
(and (fboundp ',mode)
|
||||
(not (bound-and-true-p ,mode))
|
||||
(and buffer-file-name (not (file-remote-p buffer-file-name)))
|
||||
,(or (not match)
|
||||
`(if buffer-file-name (string-match-p ,match buffer-file-name)))
|
||||
,(or (not files)
|
||||
(doom--resolve-path-forms
|
||||
(if (stringp (car files)) (cons 'and files) files)
|
||||
'(doom-project-root)))
|
||||
,(or when t)
|
||||
(,mode 1))))
|
||||
,@(if (and modes (listp modes))
|
||||
(cl-loop for hook in (doom--resolve-hook-forms modes)
|
||||
collect `(add-hook ',hook #',hook-name))
|
||||
`((add-hook 'after-change-major-mode-hook #',hook-name))))))
|
||||
(match
|
||||
`(add-to-list 'doom-auto-minor-mode-alist '(,match . ,mode)))
|
||||
((user-error "Invalid `associate!' rules for mode [%s] (:modes %s :match %s :files %s :when %s)"
|
||||
mode modes match files when)))))
|
||||
|
||||
(defmacro file-exists-p! (spec &optional directory)
|
||||
"Returns non-nil if the files in SPEC all exist.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue