Smarter associate! macro
This commit is contained in:
parent
aac4d4ee48
commit
9bda8c3112
3 changed files with 29 additions and 20 deletions
|
@ -92,22 +92,27 @@ Examples:
|
|||
(declare (indent 1))
|
||||
(let* ((minor-p (assoc mode minor-mode-alist)))
|
||||
`(progn
|
||||
(,@(when match
|
||||
`(add-to-list ',(if minor-p 'narf-auto-minor-mode-alist 'auto-mode-alist)
|
||||
(cons ,match ',mode))))
|
||||
(,@(when files
|
||||
(unless (or (listp files) (stringp files))
|
||||
(user-error "associate! :files expects a string or list of strings"))
|
||||
(let ((hook-name (intern (format "narf--init-mode-%s" mode))))
|
||||
`(progn
|
||||
(defun ,hook-name ()
|
||||
(when (and (not ,mode)
|
||||
(narf/project-has-files ,@(-list files)))
|
||||
(,mode 1)))
|
||||
,@(if (and in (listp in))
|
||||
(mapcar (lambda (h) `(add-hook ',h ',hook-name))
|
||||
(mapcar (lambda (m) (intern (format "%s-hook" m))) in))
|
||||
`((add-hook 'find-file-hook ',hook-name))))))))))
|
||||
(,@(cond ((or files in)
|
||||
(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 "narf--init-mode-%s" mode))))
|
||||
`(progn
|
||||
(defun ,hook-name ()
|
||||
(when (and (if ,match (string-match-p ,match (buffer-file-name)) t)
|
||||
(or ,(not files)
|
||||
(and (not ,mode)
|
||||
(narf/project-has-files ,@(-list files)))))
|
||||
(,mode 1)))
|
||||
,@(if (and in (listp in))
|
||||
(mapcar (lambda (h) `(add-hook ',h ',hook-name))
|
||||
(mapcar (lambda (m) (intern (format "%s-hook" m))) in))
|
||||
`((add-hook 'find-file-hook ',hook-name))))))
|
||||
(match
|
||||
`(add-to-list ',(if minor-p 'narf-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)))))))
|
||||
|
||||
(after! evil
|
||||
;; Register keywords for proper indentation (see `map!')
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
:commands nose-mode
|
||||
:preface (defvar nose-mode-map (make-sparse-keymap))
|
||||
:init
|
||||
(associate! nose-mode :pattern "/test_.+\\.py\\'")
|
||||
(associate! nose-mode :match "/test_.+\\.py\\'")
|
||||
:config
|
||||
(map! :map nose-mode-map
|
||||
(:localleader
|
||||
|
|
|
@ -107,9 +107,12 @@
|
|||
:keymap (make-sparse-keymap)
|
||||
(add-yas-minor-mode! 'jekyll-mode))
|
||||
(associate! jekyll-mode
|
||||
:match "/\\(css\\|_\\(layouts\\|posts\\|sass\\)\\)/.+$"
|
||||
:match "/\\(\\(css\\|_\\(layouts\\|posts\\|sass\\)\\)/.+\\|.+.html\\)$"
|
||||
:files ("config.yml" "_layouts")
|
||||
:in (web-mode scss-mode html-mode markdown-mode))
|
||||
(add-hook! jekyll-mode
|
||||
(when (eq major-mode 'web-mode)
|
||||
(web-mode-set-engine "django")))
|
||||
;; (after! company-dict (add-to-list 'company-dict-minor-mode-alist 'jekyll-mode))
|
||||
|
||||
(define-minor-mode wordpress-mode
|
||||
|
@ -118,8 +121,9 @@
|
|||
:lighter " wp"
|
||||
:keymap (make-sparse-keymap)
|
||||
(add-yas-minor-mode! 'wordpress-mode))
|
||||
(associate! wordpress-mode :match "/wp-\\(content\\|admin\\|includes\\)/.+$")
|
||||
(associate! wordpress-mode :match "/wp-.+\\.php$")
|
||||
(associate! wordpress-mode
|
||||
:match "/wp-\\(\\(content\\|admin\\|includes\\)/\\)?.+$"
|
||||
:files ("wp-config.php" "wp-content"))
|
||||
;; (after! company-dict (add-to-list 'company-dict-minor-mode-alist 'wordpress-mode))
|
||||
|
||||
(provide 'module-web)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue