Add :when to associate! and def-project-type! macros

This commit is contained in:
Henrik Lissner 2016-05-18 02:13:46 -04:00
parent 10ca8bc7df
commit 1d4e23ee11

View file

@ -74,9 +74,10 @@ Examples:
(let ((minor (plist-get rest :minor)) (let ((minor (plist-get rest :minor))
(in (plist-get rest :in)) (in (plist-get rest :in))
(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)))
`(progn `(progn
(,@(cond ((or files in) (,@(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 "narf--init-mode-%s" mode)))) (let ((hook-name (intern (format "narf--init-mode-%s" mode))))
@ -86,7 +87,9 @@ Examples:
(or ,(not files) (or ,(not files)
(and (boundp ',mode) (and (boundp ',mode)
(not ,mode) (not ,mode)
(narf/project-has-files ,@(-list files))))) (narf/project-has-files ,@(-list files))))
(or (not ,pred)
(funcall ,pred buffer-file-name)))
(,mode 1))) (,mode 1)))
,@(if (and in (listp in)) ,@(if (and in (listp in))
(mapcar (lambda (h) `(add-hook ',h ',hook-name)) (mapcar (lambda (h) `(add-hook ',h ',hook-name))
@ -107,6 +110,7 @@ Examples:
(mode-hook-sym (intern (format "%s-hook" mode-name))) (mode-hook-sym (intern (format "%s-hook" mode-name)))
(mode-init-sym (intern (format "narf--init-project-%s" mode-name)))) (mode-init-sym (intern (format "narf--init-project-%s" mode-name))))
(let ((modes (plist-get body :modes)) (let ((modes (plist-get body :modes))
(pred (plist-get body :when))
(match (plist-get body :match)) (match (plist-get body :match))
(files (plist-get body :files)) (files (plist-get body :files))
(build (plist-get body :build)) (build (plist-get body :build))
@ -128,7 +132,8 @@ Examples:
:minor t :minor t
:in ,modes :in ,modes
:match ,match :match ,match
:files ,files) :files ,files
:when ,pred)
(defun ,mode-init-sym () (defun ,mode-init-sym ()
(after! yasnippet (after! yasnippet