core-lib: refactor associate!
This commit is contained in:
parent
c71b8ac438
commit
fb53c8fda7
1 changed files with 24 additions and 24 deletions
|
@ -63,13 +63,12 @@ Examples:
|
|||
(match (plist-get rest :match))
|
||||
(files (plist-get rest :files))
|
||||
(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))))
|
||||
(user-error "associate! :files expects a string or list of strings"))
|
||||
(let ((hook-name (intern (format "doom--init-mode-%s" mode))))
|
||||
`(progn
|
||||
(defun ,hook-name ()
|
||||
(macroexp-progn
|
||||
(list `(defun ,hook-name ()
|
||||
(when (and ,(if match `(if buffer-file-name (string-match-p ,match buffer-file-name)) t)
|
||||
(or ,(not files)
|
||||
(and (boundp ',mode)
|
||||
|
@ -78,15 +77,16 @@ Examples:
|
|||
(or (not ,pred)
|
||||
(funcall ,pred buffer-file-name)))
|
||||
(,mode 1)))
|
||||
,@(if (and in (listp in))
|
||||
(if (and in (listp in))
|
||||
(macroexp-progn
|
||||
(mapcar (lambda (h) `(add-hook ',h ',hook-name))
|
||||
(mapcar (lambda (m) (intern (format "%s-hook" m))) in))
|
||||
`((add-hook 'find-file-hook ',hook-name))))))
|
||||
(mapcar (lambda (m) (intern (format "%s-hook" m))) in)))
|
||||
`(add-hook 'find-file-hook ',hook-name))))))
|
||||
(match
|
||||
`(add-to-list ',(if minor 'doom-auto-minor-mode-alist 'auto-mode-alist)
|
||||
(cons ,match ',mode)))
|
||||
(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!')
|
||||
(put ':prefix 'lisp-indent-function 'defun)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue