mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-08-10 01:51:15 +10:00
Moving to Doom Emacs!
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
;;; 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-love-project-root ()
|
||||
"Returns the directory where a main.lua or main.moon exists.
|
||||
|
||||
Returns nil if 'love' executable can't be found."
|
||||
(when (executable-find "love")
|
||||
(if (doom-project-p)
|
||||
(file-name-directory
|
||||
(or (project-file-exists-p! (or "main.lua" "src/main.lua"))
|
||||
(and (featurep! +moonscript)
|
||||
(project-file-exists-p! (or "main.moon" "src/main.moon")))
|
||||
""))
|
||||
;; Since Love2D games are likely to be prototypes, they may not be in a
|
||||
;; well-formed project as far as projecitle is concerned, so we search for
|
||||
;; main.lua/main.moon up the file tree as a backup.
|
||||
(or (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)
|
||||
(or (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))))))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Commands
|
||||
|
||||
;;;###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")))
|
||||
@@ -0,0 +1,16 @@
|
||||
;;; lang/lua/autoload/moonscript.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +moonscript)
|
||||
|
||||
;;;###autoload
|
||||
(defun +lua-moonscript-fix-single-quotes-h ()
|
||||
"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-h ()
|
||||
"Highlight interpolated expressions in moonscript strings."
|
||||
(font-lock-add-keywords
|
||||
nil '(("#{\\([^}]+\\)}"
|
||||
(0 font-lock-preprocessor-face t)
|
||||
(1 nil t)))))
|
||||
@@ -0,0 +1,48 @@
|
||||
;;; lang/lua/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
;; sp's default rules are obnoxious, so disable them
|
||||
(provide 'smartparens-lua)
|
||||
|
||||
|
||||
;;
|
||||
;; Major modes
|
||||
|
||||
(use-package! lua-mode
|
||||
:defer t
|
||||
:init
|
||||
;; lua-indent-level defaults to 3 otherwise. Madness.
|
||||
(setq lua-indent-level 2)
|
||||
:config
|
||||
(set-lookup-handlers! 'lua-mode :documentation 'lua-search-documentation)
|
||||
(set-electric! 'lua-mode :words '("else" "end"))
|
||||
(set-repl-handler! 'lua-mode #'+lua/open-repl)
|
||||
(set-company-backend! 'lua-mode '(company-lua company-yasnippet)))
|
||||
|
||||
|
||||
(use-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-h
|
||||
#'+lua-moonscript-fontify-interpolation-h)
|
||||
(when (featurep! :tools flycheck)
|
||||
(require 'flycheck-moonscript nil t)))
|
||||
|
||||
|
||||
;;
|
||||
;;; Frameworks
|
||||
|
||||
(def-project-mode! +lua-love-mode
|
||||
: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-love-build-command)
|
||||
(map! :localleader
|
||||
:map +lua-love-mode-map
|
||||
"b" #'+lua/run-love-game)))
|
||||
@@ -0,0 +1,14 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/lua/packages.el
|
||||
|
||||
(package! lua-mode)
|
||||
|
||||
(when (featurep! +moonscript)
|
||||
(package! moonscript)
|
||||
(when (featurep! :tools flycheck)
|
||||
(package! flycheck-moonscript
|
||||
:recipe (:host github :repo "hlissner/emacs-flycheck-moonscript"))))
|
||||
|
||||
(when (featurep! :completion company)
|
||||
(package! company-lua))
|
||||
|
||||
Reference in New Issue
Block a user