Skip to content

Commit faadd1f

Browse files
committed
Update function to load syntax keywords for doom emacs
Doom Emacs seems to flatten the package's file structure when installing from GitHub. The new gdscript--get-package-file-content-as-string function will try to load the file without the relative directory component if it can't find it in, e.g., a data/ subdirectory.
1 parent 339c008 commit faadd1f

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Diff for: gdscript-syntax.el

+17-7
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,26 @@
3030

3131
;;; Code:
3232

33-
(defun gdscript--get-package-file-content-as-string (file-path)
33+
(defun gdscript--get-package-file-content-as-string (file-path-relative)
3434
"Returns the content of a file in this package as a list of
3535
strings. Used to retrieve lists of keywords for syntax
36-
highlighting."
37-
(with-temp-buffer
38-
(insert-file-contents (concat (file-name-directory (or load-file-name buffer-file-name)) file-path))
39-
(split-string (buffer-string) "\n" t)))
36+
highlighting.
4037
41-
(defconst gdscript-keywords (gdscript--get-package-file-content-as-string "data/keywords.txt"))
42-
(defconst gdscript-built-in-constants (gdscript--get-package-file-content-as-string "data/built-in-constants.txt"))
38+
If the file isn't available, the function tries to access the
39+
file without the directory path. This is for compatibility with
40+
the Doom Emacs distribution, which flattens the package's
41+
structure."
42+
(with-temp-buffer
43+
(setq this-directory (file-name-directory (or load-file-name buffer-file-name)))
44+
(setq requested-path (concat this-directory file-path-relative))
45+
(setq file-path (if (file-readable-p requested-path)
46+
requested-path
47+
(concat this-directory
48+
(file-name-nondirectory file-path-relative))))
49+
(insert-file-contents file-path)
50+
(split-string (buffer-string)
51+
"\n"
52+
t)))
4353
;; Only contains types that are not classes and that the Godot editor highlights
4454
;; like built-in keywords
4555
(defconst gdscript-built-in-types (gdscript--get-package-file-content-as-string "data/built-in-types.txt"))

0 commit comments

Comments
 (0)