Skip to content

Commit

Permalink
Simplify + rename blox--prompt-kill-p, add blox--project-build-path
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethloeffler committed Feb 14, 2021
1 parent a395074 commit 0ff8a6f
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions blox.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Copyright (C) 2021 Kenneth Loeffler

;; Author: Kenneth Loeffler <[email protected]>
;; Version: 0.1.2
;; Version: 0.1.3
;; Keywords: roblox, rojo, tools
;; URL: https://github.com/kennethloeffler/blox
;; Package-Requires: ((emacs "25.1"))
Expand Down Expand Up @@ -115,32 +115,33 @@ echo area."
(blox--echo "Waiting for output from Roblox Studio...done"
"blox-run-in-roblox"))))

(defun blox--prompt-kill-p (process-name)
"Prompt to kill PROCESS-NAME and return nil if the user answers no.
Return t if the process is not running or if the user answers yes."
(if (and (get-process process-name)
(eq (process-status process-name) 'run))
(if (not (y-or-n-p (format
"The process %s is still running. Kill it? "
process-name)))
nil
(kill-process process-name)
t)
t))

(defun blox--get-project-type (project-path)
(defun blox--kill-if-running-p (process-name)
"Prompt to kill the process if PROCESS-NAME is running.
Return t if the answer is \"y\" or if the process is not running.
Return nil if the process is running and the answer is \"n\"."
(or (not (and (get-process process-name)
(eq (process-status process-name) 'run)))
(kill-buffer (process-buffer (get-process process-name)))))

(defun blox--roblox-file-extension (project-path)
"Return the appropriate Roblox file extension for PROJECT-PATH."
(with-temp-buffer
(insert-file-contents project-path)
(if (search-forward "DataModel" nil t)
".rbxlx"
".rbxmx")))

(defun blox--project-build-path (project-path)
"Return the path of the build corresponding to PROJECT-PATH."
(concat (file-name-sans-extension (file-name-nondirectory
project-path))
(blox--roblox-file-extension project-path)))

(defun blox-rojo-serve ()
"Prompt for a project file for Rojo to start serving."
(interactive)
(blox--save-some-lua-mode-buffers)
(if (blox--prompt-kill-p "*rojo-serve*")
(if (blox--kill-if-running-p "*rojo-serve*")
(let ((directory (or (vc-root-dir) default-directory)))
(with-current-buffer (get-buffer-create "*rojo-serve*")
(help-mode)
Expand All @@ -163,10 +164,7 @@ prompting."
(project-path (or force-project-path
(read-file-name "Choose project: "
vc-or-default "")))
(output (concat
(file-name-sans-extension (file-name-nondirectory
project-path))
(blox--get-project-type project-path))))
(output (blox--project-build-path project-path)))
(cd (file-name-directory project-path))
(with-current-buffer (get-buffer-create "*rojo-build*")
(help-mode)
Expand Down Expand Up @@ -202,7 +200,7 @@ in the echo area."
Both SCRIPT-PATH and PLACE-FILENAME must be under the same
directory. If this is not the case, abort and display a message
in the echo area."
(if (blox--prompt-kill-p "*run-in-roblox*")
(if (blox--kill-if-running-p "*run-in-roblox*")
(if (not (locate-file place-filename
(list (file-name-directory script-path))))
(blox--echo
Expand Down

0 comments on commit 0ff8a6f

Please sign in to comment.