core-lib: refactor associate!
This commit is contained in:
parent
c71b8ac438
commit
fb53c8fda7
1 changed files with 24 additions and 24 deletions
|
@ -63,30 +63,30 @@ Examples:
|
||||||
(match (plist-get rest :match))
|
(match (plist-get rest :match))
|
||||||
(files (plist-get rest :files))
|
(files (plist-get rest :files))
|
||||||
(pred (plist-get rest :when)))
|
(pred (plist-get rest :when)))
|
||||||
`(progn
|
(cond ((or files in pred)
|
||||||
(,@(cond ((or files in pred)
|
(when (and files (not (or (listp files) (stringp files))))
|
||||||
(when (and files (not (or (listp files) (stringp files))))
|
(user-error "associate! :files expects a string or list of strings"))
|
||||||
(user-error "associate! :files expects a string or list of strings"))
|
(let ((hook-name (intern (format "doom--init-mode-%s" mode))))
|
||||||
(let ((hook-name (intern (format "doom--init-mode-%s" mode))))
|
(macroexp-progn
|
||||||
`(progn
|
(list `(defun ,hook-name ()
|
||||||
(defun ,hook-name ()
|
(when (and ,(if match `(if buffer-file-name (string-match-p ,match buffer-file-name)) t)
|
||||||
(when (and ,(if match `(if buffer-file-name (string-match-p ,match buffer-file-name)) t)
|
(or ,(not files)
|
||||||
(or ,(not files)
|
(and (boundp ',mode)
|
||||||
(and (boundp ',mode)
|
(not ,mode)
|
||||||
(not ,mode)
|
(doom-project-has-files ,@(-list files))))
|
||||||
(doom-project-has-files ,@(-list files))))
|
(or (not ,pred)
|
||||||
(or (not ,pred)
|
(funcall ,pred buffer-file-name)))
|
||||||
(funcall ,pred buffer-file-name)))
|
(,mode 1)))
|
||||||
(,mode 1)))
|
(if (and in (listp in))
|
||||||
,@(if (and in (listp in))
|
(macroexp-progn
|
||||||
(mapcar (lambda (h) `(add-hook ',h ',hook-name))
|
(mapcar (lambda (h) `(add-hook ',h ',hook-name))
|
||||||
(mapcar (lambda (m) (intern (format "%s-hook" m))) in))
|
(mapcar (lambda (m) (intern (format "%s-hook" m))) in)))
|
||||||
`((add-hook 'find-file-hook ',hook-name))))))
|
`(add-hook 'find-file-hook ',hook-name))))))
|
||||||
(match
|
(match
|
||||||
`(add-to-list ',(if minor 'doom-auto-minor-mode-alist 'auto-mode-alist)
|
`(add-to-list ',(if minor 'doom-auto-minor-mode-alist 'auto-mode-alist)
|
||||||
(cons ,match ',mode)))
|
(cons ,match ',mode)))
|
||||||
(t (user-error "associate! invalid rules for mode [%s] (in %s) (match %s) (files %s)"
|
(t (user-error "associate! invalid rules for mode [%s] (in %s) (match %s) (files %s)"
|
||||||
mode in match files)))))))
|
mode in match files)))))
|
||||||
|
|
||||||
;; Register keywords for proper indentation (see `map!')
|
;; Register keywords for proper indentation (see `map!')
|
||||||
(put ':prefix 'lisp-indent-function 'defun)
|
(put ':prefix 'lisp-indent-function 'defun)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue