86
86
(eq major-mode 'lua-mode ))))
87
87
88
88
(defun blox--echo (message-string command-name )
89
- " Display MESSAGE-STRING formatted with COMMAND-NAME in the echo area."
90
- (message " [%s ]: %s " command-name message-string))
91
-
92
- (defun blox--echo-filter (command )
93
- " Return a filter that displays output from COMMAND in the echo area.
94
- Also write the output to the process buffer."
89
+ " Display MESSAGE-STRING prefixed with COMMAND-NAME in the echo area.
90
+ Removes any trailing newlines from MESSAGE-STRING."
91
+ (message " [%s ]: %s "
92
+ command-name
93
+ (replace-regexp-in-string " \n \\ '" " " message-string)))
94
+
95
+ (defun blox--echo-filter (command-name )
96
+ " Process filter to display process output in the echo area.
97
+ The filter prefixes any output with COMMAND-NAME and writes the
98
+ result to the process buffer, in addition to displaying it in the
99
+ echo area."
95
100
(lambda (proc string )
96
101
(with-current-buffer (process-buffer proc)
97
102
(let ((moving (= (point ) (process-mark proc))))
@@ -102,11 +107,11 @@ Also write the output to the process buffer."
102
107
(set-marker (process-mark proc) (point )))
103
108
(if moving (goto-char (process-mark proc)))
104
109
(setq buffer-read-only t ))
105
- (blox--echo string command))))
110
+ (blox--echo string command-name ))))
106
111
107
112
(defun blox--run-in-roblox-sentinel (buffer )
108
- " Return a process sentinel to call `display-buffer' on BUFFER.
109
- Also turn on `help-mode' in BUFFER and display a message in the
113
+ " Process sentinel to call `display-buffer' on BUFFER.
114
+ Also enable `help-mode' in BUFFER and display a message in the
110
115
echo area."
111
116
(lambda (_process _event )
112
117
(with-current-buffer buffer
@@ -116,17 +121,18 @@ echo area."
116
121
" blox-run-in-roblox" ))))
117
122
118
123
(defun blox--run-after-build-sentinel (script-path project-path )
119
- " Return a process sentinel to run SCRIPT-PATH in PROJECT-PATH."
124
+ " Process sentinel to run SCRIPT-PATH in PROJECT-PATH once finished ."
120
125
(lambda (_process event )
121
126
(if (equal event " finished\n " )
122
127
(blox-run-in-roblox
123
128
script-path
124
- (blox--project- build-filename project-path)))))
129
+ (blox--build-path project-path)))))
125
130
126
131
(defun blox--kill-if-running-p (process-name )
127
132
" Prompt to kill the process if PROCESS-NAME is running.
128
- Return t if the answer is \" y\" or if the process is not running.
129
- Return nil if the process is running and the answer is \" n\" ."
133
+ Return t if the answer is \" yes\" or if the process is not
134
+ running. Return nil if the process is running and the answer is
135
+ \" no\" ."
130
136
(or (not (and (get-process process-name)
131
137
(eq (process-status process-name) 'run )))
132
138
(kill-buffer (process-buffer (get-process process-name)))))
@@ -139,49 +145,56 @@ Return nil if the process is running and the answer is \"n\"."
139
145
" .rbxlx"
140
146
" .rbxmx" )))
141
147
142
- (defun blox--project- build-filename (project-path )
148
+ (defun blox--build-path (project-path )
143
149
" Return the path of the build corresponding to PROJECT-PATH."
144
- (concat (file-name-sans-extension (file-name-nondirectory
145
- project-path))
150
+ (concat (file-name-sans-extension (file-name-base project-path))
146
151
(blox--roblox-file-extension project-path)))
147
152
153
+ (defun blox-rojo-serve (project-path )
154
+ " Serve the Rojo project at PROJECT-PATH."
155
+ (blox--save-some-lua-mode-buffers)
156
+ (if (blox--kill-if-running-p " *rojo-serve*" )
157
+ (with-current-buffer (get-buffer-create " *rojo-serve*" )
158
+ (cd (or (vc-root-dir ) default-directory))
159
+ (help-mode )
160
+ (make-process
161
+ :name " *rojo-serve*"
162
+ :buffer (get-buffer " *rojo-serve*" )
163
+ :filter (blox--echo-filter " blox-prompt-serve" )
164
+ :command
165
+ (list blox-rojo-executable " serve" project-path)))))
166
+
148
167
(defun blox-rojo-build (project-path &optional sentinel )
149
- " Build the project at PROJECT-PATH and return the build's filename .
150
- If the function SENTINEL is provided, attach it to the rojo
168
+ " Build the Rojo project at PROJECT-PATH.
169
+ If the function SENTINEL is provided, attach it to the Rojo
151
170
process."
152
171
(blox--save-some-lua-mode-buffers)
153
- (let* ((previous-directory default-directory)
154
- (output (blox--project-build-filename project-path)))
172
+ (with-current-buffer (get-buffer-create " *rojo-build*" )
155
173
(cd (file-name-directory project-path))
156
- (with-current-buffer (get-buffer-create " *rojo-build*" )
157
- (help-mode )
158
- (make-process
159
- :name " *rojo-build*"
160
- :buffer (get-buffer " *rojo-build*" )
161
- :filter (blox--echo-filter " blox-rojo-build" )
162
- :sentinel sentinel
163
- :command
164
- (list blox-rojo-executable " build"
165
- (file-name-nondirectory project-path)
166
- " --output" output)))
167
- (cd previous-directory)))
168
-
169
- (defun blox-run-in-roblox (script-path place-filename )
170
- " Run the Lua script at SCRIPT-PATH in PLACE-FILENAME with run-in-roblox.
171
- Both SCRIPT-PATH and PLACE-FILENAME must be under the same
174
+ (help-mode )
175
+ (make-process
176
+ :name " *rojo-build*"
177
+ :buffer (get-buffer " *rojo-build*" )
178
+ :filter (blox--echo-filter " blox-rojo-build" )
179
+ :sentinel sentinel
180
+ :command
181
+ (list
182
+ blox-rojo-executable " build" (file-name-nondirectory
183
+ project-path)
184
+ " --output" (blox--build-path project-path)))))
185
+
186
+ (defun blox-run-in-roblox (script-path build-path )
187
+ " Run the Lua script at SCRIPT-PATH in BUILD-PATH with run-in-roblox.
188
+ Both SCRIPT-PATH and BUILD-PATH must have the same penultimate
172
189
directory. If this is not the case, abort and display a message
173
190
in the echo area."
174
191
(if (blox--kill-if-running-p " *run-in-roblox*" )
175
- ; ; We're fussing with the current directory and the locations of
176
- ; ; --place and --script here because some weirdness is happening
177
- ; ; when run-in-roblox is given absolute pathnames. This
178
- ; ; probably only happens when it's called from WSL?
179
- (if (not (locate-file place-filename
192
+ (if (not (locate-file build-path
180
193
(list (file-name-directory script-path))))
181
194
(blox--echo
182
195
" Script and place files must be under the same directory"
183
196
" blox-run-in-roblox" )
184
- (let ((previous-directory default-directory) )
197
+ (with-current-buffer ( get-buffer-create " *run-in-roblox* " )
185
198
(cd (file-name-directory script-path))
186
199
(blox--echo " Waiting for output from Roblox Studio..."
187
200
" blox-run-in-roblox" )
@@ -192,25 +205,17 @@ in the echo area."
192
205
(get-buffer " *run-in-roblox*" ))
193
206
:command
194
207
(list blox-run-in-roblox-executable
195
- " --place" place-filename
196
- " --script" (file-name-nondirectory script-path)))
197
- (cd previous-directory)))))
208
+ " --place" (file-name-nondirectory build-path)
209
+ " --script" (file-name-nondirectory script-path)))))))
198
210
199
211
(defun blox-prompt-serve ()
200
- " Prompt for a project file for Rojo to start serving ."
212
+ " Prompt to serve a Rojo project ."
201
213
(interactive )
202
214
(blox--save-some-lua-mode-buffers)
203
215
(if (blox--kill-if-running-p " *rojo-serve*" )
204
- (let ((directory (or (vc-root-dir ) default-directory)))
205
- (with-current-buffer (get-buffer-create " *rojo-serve*" )
206
- (help-mode )
207
- (make-process
208
- :name " *rojo-serve*"
209
- :buffer (get-buffer " *rojo-serve*" )
210
- :filter (blox--echo-filter " blox-prompt-serve" )
211
- :command
212
- (list blox-rojo-executable " serve"
213
- (read-file-name " Choose project: " directory " " )))))))
216
+ (blox-rojo-serve (read-file-name " Choose project: "
217
+ (or (vc-root-dir )
218
+ default-directory)))))
214
219
215
220
(defun blox-prompt-build ()
216
221
" Prompt to build a Rojo project."
@@ -234,14 +239,14 @@ in the echo area."
234
239
(blox-rojo-build (concat project " default.project.json" )))))
235
240
236
241
(defun blox-prompt-build-and-run ()
237
- " Prompt to build a Rojo project and a script to run in it.
242
+ " Prompt to build a Rojo project, then for a script to run in it.
238
243
The script and project files are expected to be under the same
239
244
directory. If this is not the case, abort and display a message
240
245
in the echo area."
241
246
(interactive )
242
247
(let* ((directory (or (vc-root-dir ) default-directory))
243
- (project (read-file-name " Choose project: " directory " " ))
244
- (script (read-file-name " Choose script " directory " " )))
248
+ (project (read-file-name " Choose project: " directory))
249
+ (script (read-file-name " Choose script " directory)))
245
250
(blox-rojo-build project
246
251
(blox--run-after-build-sentinel script
247
252
project))))
0 commit comments