diff --git a/core/autoload/projects.el b/core/autoload/projects.el index a5d66a67d..5ff4ef6fb 100644 --- a/core/autoload/projects.el +++ b/core/autoload/projects.el @@ -5,9 +5,23 @@ ;;;###autoload (autoload 'projectile-relevant-known-projects "projectile") +;;;###autodef +(cl-defun set-project-type! (name &key predicate compile run test configure dir) + "Add a project type to `projectile-project-type'." + (declare (indent 1)) + (after! projectile + (add-to-list 'projectile-project-types + (list name + 'marker-files when + 'compilation-dir dir + 'configure-command configure + 'compile-command compile + 'test-command test + 'run-command run)))) + ;; -;; Macros +;;; Macros ;;;###autoload (defmacro without-project-cache! (&rest body) @@ -29,7 +43,7 @@ they are absolute." ;; -;; Commands +;;; Commands ;;;###autoload (defun doom/find-file-in-other-project (project-root) @@ -55,7 +69,7 @@ they are absolute." ;; -;; Library +;;; Library ;;;###autoload (defun doom-project-p (&optional dir) diff --git a/modules/lang/lua/autoload.el b/modules/lang/lua/autoload.el index 8b303e3c6..d31acd426 100644 --- a/modules/lang/lua/autoload.el +++ b/modules/lang/lua/autoload.el @@ -11,10 +11,17 @@ (defun +lua/run-love-game () "Run the current project with Love2D." (interactive) - (when-let (root (locate-dominating-file buffer-file-name "main.lua")) + (when-let (root (+lua-love-project-root)) (async-shell-command (format "%s %s" (or (executable-find "love") (if IS-MAC "open -a love.app")) (shell-quote-argument (file-name-directory root)))))) +;;;###autoload +(defun +lua-love-project-root () + "Returns the directory where a main.lua exists. + +Returns nil if 'love' executable can't be found." + (and (executable-find "love") + (locate-dominating-file buffer-file-name "main.lua"))) diff --git a/modules/lang/lua/config.el b/modules/lang/lua/config.el index 99e148747..346f2c9af 100644 --- a/modules/lang/lua/config.el +++ b/modules/lang/lua/config.el @@ -30,6 +30,9 @@ :modes (lua-mode markdown-mode json-mode) :files (and "main.lua" "conf.lua") :on-load + (set-project-type! 'love2d + :predicate #'+lua-love-project-root + :run #'+lua/run-love-game) (map! :localleader :map +lua-love-mode-map "b" #'+lua/run-love-game))