mirror of
https://github.com/godotengine/emacs-gdscript-mode.git
synced 2026-01-04 18:09:55 +03:00
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.
This commit is contained in:
@@ -30,16 +30,26 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defun gdscript--get-package-file-content-as-string (file-path)
|
||||
(defun gdscript--get-package-file-content-as-string (file-path-relative)
|
||||
"Returns the content of a file in this package as a list of
|
||||
strings. Used to retrieve lists of keywords for syntax
|
||||
highlighting."
|
||||
(with-temp-buffer
|
||||
(insert-file-contents (concat (file-name-directory (or load-file-name buffer-file-name)) file-path))
|
||||
(split-string (buffer-string) "\n" t)))
|
||||
highlighting.
|
||||
|
||||
(defconst gdscript-keywords (gdscript--get-package-file-content-as-string "data/keywords.txt"))
|
||||
(defconst gdscript-built-in-constants (gdscript--get-package-file-content-as-string "data/built-in-constants.txt"))
|
||||
If the file isn't available, the function tries to access the
|
||||
file without the directory path. This is for compatibility with
|
||||
the Doom Emacs distribution, which flattens the package's
|
||||
structure."
|
||||
(with-temp-buffer
|
||||
(setq this-directory (file-name-directory (or load-file-name buffer-file-name)))
|
||||
(setq requested-path (concat this-directory file-path-relative))
|
||||
(setq file-path (if (file-readable-p requested-path)
|
||||
requested-path
|
||||
(concat this-directory
|
||||
(file-name-nondirectory file-path-relative))))
|
||||
(insert-file-contents file-path)
|
||||
(split-string (buffer-string)
|
||||
"\n"
|
||||
t)))
|
||||
;; Only contains types that are not classes and that the Godot editor highlights
|
||||
;; like built-in keywords
|
||||
(defconst gdscript-built-in-types (gdscript--get-package-file-content-as-string "data/built-in-types.txt"))
|
||||
|
||||
Reference in New Issue
Block a user