def-project-type now defers init until first run
This commit is contained in:
parent
5c1557d911
commit
63b8204b91
1 changed files with 25 additions and 26 deletions
|
@ -113,15 +113,13 @@ Examples:
|
||||||
mode in match files))))))
|
mode in match files))))))
|
||||||
|
|
||||||
(defmacro def-project-type! (name lighter &rest body)
|
(defmacro def-project-type! (name lighter &rest body)
|
||||||
"Define a minor mode for a specific framework, library or project type. e.g.
|
"Define a minor mode for a specific framework, library or project type."
|
||||||
|
|
||||||
(def-project-type! angularjs \"angjs\"
|
|
||||||
:modes (js2-mode)
|
|
||||||
:files (\"package.json\"))"
|
|
||||||
(declare (indent 2))
|
(declare (indent 2))
|
||||||
(let* ((mode-name (format "%s-project-mode" name))
|
(let* ((mode-name (format "%s-project-mode" name))
|
||||||
(mode (intern mode-name))
|
(mode (intern mode-name))
|
||||||
(mode-map (intern (format "%s-map" mode-name))))
|
(mode-map (intern (format "%s-map" mode-name)))
|
||||||
|
(mode-hook-sym (intern (format "%s-hook" 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))
|
||||||
(match (plist-get body :match))
|
(match (plist-get body :match))
|
||||||
(files (plist-get body :files))
|
(files (plist-get body :files))
|
||||||
|
@ -136,26 +134,9 @@ Examples:
|
||||||
"Auto-generated by `def-project-type!'"
|
"Auto-generated by `def-project-type!'"
|
||||||
:init-value nil
|
:init-value nil
|
||||||
:lighter ,(concat " " lighter)
|
:lighter ,(concat " " lighter)
|
||||||
:keymap (make-sparse-keymap)
|
:keymap (make-sparse-keymap))
|
||||||
(after! yasnippet
|
|
||||||
(when (boundp 'yas--extra-modes)
|
|
||||||
(add-hook ',(intern (concat mode-name "-hook"))
|
|
||||||
(lambda ()
|
|
||||||
(if (symbol-value ',mode)
|
|
||||||
(yas-activate-extra-mode ',mode)
|
|
||||||
(yas-deactivate-extra-mode ',mode)))))))
|
|
||||||
|
|
||||||
(after! company-dict
|
,(when bind `(map! :map ,mode-map ,bind))
|
||||||
(push ',mode company-dict-minor-mode-list))
|
|
||||||
|
|
||||||
,(when build
|
|
||||||
(when (listp build)
|
|
||||||
(setq build (car-safe (cdr-safe build))))
|
|
||||||
(let ((cmd (or (car-safe build) build))
|
|
||||||
(file (car-safe (cdr-safe build))))
|
|
||||||
`(def-builder! ,mode ,cmd ,file)))
|
|
||||||
,(when bind
|
|
||||||
`(map! :map ,mode-map ,bind))
|
|
||||||
|
|
||||||
(associate! ,mode
|
(associate! ,mode
|
||||||
:minor t
|
:minor t
|
||||||
|
@ -163,7 +144,25 @@ Examples:
|
||||||
:match ,match
|
:match ,match
|
||||||
:files ,files)
|
:files ,files)
|
||||||
|
|
||||||
|
(defun ,mode-init-sym ()
|
||||||
|
(after! yasnippet
|
||||||
|
(when (boundp 'yas--extra-modes)
|
||||||
|
(add-hook ',(intern (concat mode-name "-hook"))
|
||||||
|
(lambda ()
|
||||||
|
(if (symbol-value ',mode)
|
||||||
|
(yas-activate-extra-mode ',mode)
|
||||||
|
(yas-deactivate-extra-mode ',mode))))))
|
||||||
|
(after! company-dict
|
||||||
|
(push ',mode company-dict-minor-mode-list))
|
||||||
|
,(when build
|
||||||
|
(when (listp build)
|
||||||
|
(setq build (car-safe (cdr-safe build))))
|
||||||
|
(let ((cmd (or (car-safe build) build))
|
||||||
|
(file (car-safe (cdr-safe build))))
|
||||||
|
`(def-builder! ,mode ,cmd ,file)))
|
||||||
,@body
|
,@body
|
||||||
|
(remove-hook ',mode-hook-sym ',mode-init-sym))
|
||||||
|
(add-hook ',mode-hook-sym ',mode-init-sym)
|
||||||
',mode))))
|
',mode))))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue