diff --git a/modules/lang/lua/autoload.el b/modules/lang/lua/autoload.el deleted file mode 100644 index d31acd426..000000000 --- a/modules/lang/lua/autoload.el +++ /dev/null @@ -1,27 +0,0 @@ -;;; lang/lua/autoload.el -*- lexical-binding: t; -*- - -;;;###autoload -(defun +lua/open-repl () - "Open Lua REPL." - (interactive) - (lua-start-process "lua" "lua") - (pop-to-buffer lua-process-buffer)) - -;;;###autoload -(defun +lua/run-love-game () - "Run the current project with Love2D." - (interactive) - (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/autoload/lua.el b/modules/lang/lua/autoload/lua.el new file mode 100644 index 000000000..53f23b758 --- /dev/null +++ b/modules/lang/lua/autoload/lua.el @@ -0,0 +1,38 @@ +;;; lang/lua/autoload/lua.el -*- lexical-binding: t; -*- + +(defun +lua-love-build-command () + (when-let (root (+lua-love-project-root)) + (format "%s %s" + (if (executable-find "love") + "love" + (if IS-MAC "open -a love.app")) + (shell-quote-argument root)))) + +;;;###autoload +(defun +lua/open-repl () + "Open Lua REPL." + (interactive) + (lua-start-process "lua" "lua") + (pop-to-buffer lua-process-buffer)) + +;;;###autoload +(defun +lua/run-love-game () + "Run the current project with Love2D." + (interactive) + (if-let (cmd (+lua-love-build-command)) + (async-shell-command cmd) + (user-error "Couldn't find love project"))) + +;;;###autoload +(defun +lua-love-project-root () + "Returns the directory where a main.lua exists. + +Returns nil if 'love' executable can't be found." + (when (executable-find "love") + (or (and (projectile-locate-dominating-file default-directory "main.lua") + (when-let (root (projectile-locate-dominating-file default-directory "src/main.lua")) + (expand-file-name "src" root))) + (and (featurep! +moonscript) + (projectile-locate-dominating-file default-directory "main.moon") + (when-let (root (projectile-locate-dominating-file default-directory "src/main.moon")) + (expand-file-name "src" root)))))) diff --git a/modules/lang/lua/autoload/moonscript.el b/modules/lang/lua/autoload/moonscript.el new file mode 100644 index 000000000..77f9ae07a --- /dev/null +++ b/modules/lang/lua/autoload/moonscript.el @@ -0,0 +1,16 @@ +;;; lang/lua/autoload/moonscript.el -*- lexical-binding: t; -*- +;;;###if (featurep! +moonscript) + +;;;###autoload +(defun +lua|moonscript-fix-single-quotes () + "Single-quoted strings aren't treated as strings." + ;; (modify-syntax-entry ?\" "\"" moonscript-mode-syntax-table) + (modify-syntax-entry ?\' "\"" moonscript-mode-syntax-table)) + +;;;###autoload +(defun +lua|moonscript-fontify-interpolation () + "Highlight interpolated expressions in moonscript strings." + (font-lock-add-keywords + nil '(("#{\\([^}]+\\)}" + (0 font-lock-preprocessor-face t) + (1 nil t))))) diff --git a/modules/lang/lua/config.el b/modules/lang/lua/config.el index d6d5efd6c..e2c849787 100644 --- a/modules/lang/lua/config.el +++ b/modules/lang/lua/config.el @@ -19,21 +19,28 @@ (set-company-backend! 'lua-mode '(company-lua company-yasnippet))) -;;;###package moonscript -(setq-hook! 'moonscript-mode-hook moonscript-indent-offset tab-width) +(def-package! moonscript + :when (featurep! +moonscript) + :defer t + :config + (setq-hook! 'moonscript-mode-hook + moonscript-indent-offset tab-width) + (add-hook! 'moonscript-mode-hook + #'(+lua|moonscript-fix-single-quotes + +lua|moonscript-fontify-interpolation))) ;; ;;; Frameworks (def-project-mode! +lua-love-mode - :modes (lua-mode markdown-mode json-mode) - :files (and "main.lua" "conf.lua") + :modes (moonscript-mode lua-mode markdown-mode json-mode) + :when #'+lua-love-project-root :on-load (progn (set-project-type! 'love2d :predicate #'+lua-love-project-root - :run #'+lua/run-love-game) + :run #'+lua-love-build-command) (map! :localleader :map +lua-love-mode-map "b" #'+lua/run-love-game)))