Skip to content

Commit 05c9d21

Browse files
committed
Clean up source
1 parent 34b68bc commit 05c9d21

File tree

1 file changed

+36
-43
lines changed

1 file changed

+36
-43
lines changed

unity.el

+36-43
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
:group 'unity)
1515

1616
(defcustom unity-code-shim-source-directory
17-
(file-name-directory (or (locate-library "unity") load-file-name))
17+
(file-name-directory (or (locate-library "unity")
18+
load-file-name
19+
buffer-file-name))
1820
"Directory containing the code shim source."
1921
:type 'directory
2022
:group 'unity)
@@ -43,7 +45,8 @@ See https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line."
4345

4446
(defun unity--project-path-p (path)
4547
"Return t if PATH is in a Unity project."
46-
(string-match-p "/[Aa]ssets/" path))
48+
(let ((case-fold-search t))
49+
(if (string-match-p "/assets/" path) t)))
4750

4851
(defun unity--rename-file-advice (file newname &optional ok-if-already-exists)
4952
"Advice function for `rename-file' for renaming Unity files.
@@ -61,14 +64,14 @@ FILE, NEWNAME, and OK-IF-ALREADY-EXISTS are documented by `rename-file'."
6164
"code.exe"
6265
"code")))
6366

64-
(defun unity--code-source-file ()
65-
"Return the file name of the code shim source."
66-
(concat unity-code-shim-source-directory
67-
(if (eq system-type 'windows-nt)
68-
"code-windows.c"
69-
"code-unix.c")))
67+
(defun unity--build-code-shim-unix (subprocess-buffer)
68+
"Build the code shim on Unix and output to SUBPROCESS-BUFFER."
69+
(call-process unity-cc nil subprocess-buffer nil
70+
"-O2" (expand-file-name "code-unix.c"
71+
unity-code-shim-source-directory)
72+
"-o" (unity--code-binary-file)))
7073

71-
(defun unity--build-code-shim-call-process-windows (subprocess-buffer)
74+
(defun unity--build-code-shim-windows (subprocess-buffer)
7275
"Build the code shim on Windows and output to SUBPROCESS-BUFFER."
7376
(let ((temp-script (make-temp-file "emacs-unity" nil ".bat"))
7477
(temp-object (make-temp-file "emacs-unity" nil ".obj")))
@@ -88,7 +91,8 @@ cl /nologo /O2 \"%s\" /Fo\"%s\" /Fe\"%s\" user32.lib shlwapi.lib || exit /b 1"
8891
unity-vcvarsall-arch
8992
;; cl.
9093
(convert-standard-filename
91-
(expand-file-name (unity--code-source-file)))
94+
(expand-file-name "code-windows.c"
95+
unity-code-shim-source-directory))
9296
(convert-standard-filename
9397
(expand-file-name temp-object))
9498
(convert-standard-filename
@@ -99,40 +103,29 @@ cl /nologo /O2 \"%s\" /Fo\"%s\" /Fe\"%s\" user32.lib shlwapi.lib || exit /b 1"
99103
(delete-file temp-script)
100104
(delete-file temp-object)))))
101105

102-
(defun unity--build-code-shim-call-process-unix (subprocess-buffer)
103-
"Build the code shim on Unix and output to SUBPROCESS-BUFFER."
104-
(call-process unity-cc nil subprocess-buffer nil
105-
"-O2" (unity--code-source-file) "-o" (unity--code-binary-file)))
106-
107-
(defun unity--build-code-shim ()
108-
"Build the code shim."
109-
(make-directory unity-var-directory t)
110-
(when (get-buffer "*unity-subprocess*")
111-
(kill-buffer "*unity-subprocess*"))
112-
(let ((subprocess-buffer (get-buffer-create "*unity-subprocess*")))
113-
(if (eq (if (eq system-type 'windows-nt)
114-
(unity--build-code-shim-call-process-windows subprocess-buffer)
115-
(unity--build-code-shim-call-process-unix subprocess-buffer))
116-
0)
106+
(defun unity-build-code-shim (&optional force-rebuild)
107+
"Build the code shim.
108+
109+
This function is a no-op if the code shim is already built unless
110+
FORCE-REBUILD is t. This argument is always t when invoked
111+
interactively."
112+
(interactive '(t))
113+
(when (or (not (file-exists-p (unity--code-binary-file)))
114+
force-rebuild)
115+
(make-directory unity-var-directory t)
116+
(when (get-buffer "*unity-subprocess*")
117+
(kill-buffer "*unity-subprocess*"))
118+
(let ((subprocess-buffer (get-buffer-create "*unity-subprocess*")))
119+
(if (eq (if (eq system-type 'windows-nt)
120+
(unity--build-code-shim-windows subprocess-buffer)
121+
(unity--build-code-shim-unix subprocess-buffer))
122+
0)
123+
(progn
124+
(kill-buffer subprocess-buffer)
125+
(message "Unity code shim built successfully."))
117126
(progn
118-
(kill-buffer subprocess-buffer)
119-
(message "Unity code shim built successfully."))
120-
(progn
121-
(switch-to-buffer-other-window subprocess-buffer)
122-
(special-mode)))))
123-
124-
(defun unity-build-code-shim ()
125-
"Build the code shim if it's not already built."
126-
(interactive)
127-
(unless (file-exists-p (unity--code-binary-file))
128-
(unity--build-code-shim)))
129-
130-
(defun unity-rebuild-code-shim ()
131-
"Force rebuild the code shim."
132-
(interactive)
133-
(when (file-exists-p (unity--code-binary-file))
134-
(delete-file (unity--code-binary-file)))
135-
(unity--build-code-shim))
127+
(switch-to-buffer-other-window subprocess-buffer)
128+
(special-mode))))))
136129

137130
(defun unity-setup ()
138131
"Activate Unity.el integration."

0 commit comments

Comments
 (0)