34 Commits

Author SHA1 Message Date
Nathan Lovato
36c92dff15 Add shortcuts to the README 2020-05-28 10:42:02 -06:00
Nathan Lovato
87ba0803e0 Update keyboard shortcuts to use mnemonic keys
Closes #58
2020-05-28 10:39:31 -06:00
Nathan Lovato
3e46706855 Make symbols pseudo-private, update README and CHANGELOG 2020-05-28 10:06:11 -06:00
Nathan Lovato
ef3f0c529f Merge pull request #57 from VlachJosef/debug-collisions
Add options to debug collisions with gdscript-godot-run-project-debug
2020-05-28 09:59:31 -06:00
Josef Vlach
194552fcb8 Option to debug collisions with gdscript-godot-run-project-debug 2020-05-27 21:12:00 +01:00
Nathan Lovato
a52e91c3a6 Make docs functions pseudo-private, update docstrings 2020-05-27 13:48:04 -06:00
Nathan Lovato
e4981f7656 Rename gdscript-documentation to gdscript-docs, update README 2020-05-27 11:06:33 -06:00
Nathan Lovato
fea2afb96d Merge pull request #56 from VlachJosef/master
Godot API browsing using eww
2020-05-27 10:58:34 -06:00
Josef Vlach
b45fa69944 eww-after-render-hook is now used directly 2020-05-27 17:49:42 +01:00
Josef Vlach
db2f50f9bf Display only main section when browsing Godot API documentation 2020-05-27 17:41:53 +01:00
Josef Vlach
59753af564 Godot API browsing using eww 2020-05-25 09:39:20 +01:00
Nathan Lovato
46c17d352f Merge pull request #55 from VlachJosef/master
Fix deindentation for elif and else keywords
2020-05-24 08:55:14 -06:00
Josef Vlach
f89d087f3a elif / else deindentation fix
This is changing `(gdscript-rx block-start)` so that elif / else
deindentation is working properly.

This is not handling `match` patterns as a blocks, so no deindentation
will work in case of nested match patterns on match branches.

To support that much bigger rewrite would be needed.
2020-05-24 14:13:13 +01:00
Nathan Lovato
b6e1f9a512 Merge pull request #54 from hristoast/gdformat-error-handling
Only replace the formatted buffer if the gdformat exits with a 0
2020-05-19 14:25:24 -06:00
Hristos N. Triantafillou
a0027df0a1 Only replace the formatted buffer if the gdformat exits with a 0 2020-05-19 13:24:37 -05:00
Nathan Lovato
6a1a894a14 Merge pull request #53 from hristoast/preserve-window-pos
format-buffer: preserve point instead of jumping to the top of the file
2020-05-16 16:01:12 -06:00
Hristos N. Triantafillou
4ddfc8edce Preserve the window pos rather than jumping to the top of the file
This inspired by how blacken.el does it:

3bdb26788e/blacken.el (L140)
2020-05-16 16:41:38 -05:00
Nathan Lovato
0718ca9b09 Merge pull request #50 from tavurth/master
Add missing built-in functions for Godot3.2
2020-04-27 09:14:26 -06:00
Will Whitty
c74e2cd77b Added missing built-in functions 2020-04-27 19:59:22 +05:45
Nathan Lovato
584d61b6aa Merge pull request #49 from tavurth/master
Add missing keywords (puppet, remotesync)
2020-04-27 06:10:41 -06:00
Will Whitty
028df8c749 Add missing keywords (remotesync puppet) 2020-04-27 12:39:29 +05:45
Nathan Lovato
9a74dd3b6c Merge pull request #46 from francogarcia/function_highlighting
Add syntax highlighting for function calls
2020-04-03 19:12:26 -06:00
Franco Eusébio Garcia
6a3e4070bb Add syntax highlighting for function calls
Closes #30.

Pattern: identifier optional_spaces open_parenthesis

The implementation uses `"("` instead `(syntax open-parenthesis)` as
`open-parenthesis` is defined from `(open-paren (or "{" "[" "("))`. As a result,
the regular expression would also highlight array and dictionary variables.

The regular expression does highlight signal definitions with parameters,
though, as they follow the same pattern of function calls. This could be avoided
by ignoring expressions started with "signal" (or by adding a custom rule to
highlight signal definitions).
2020-04-03 15:22:52 -03:00
Nathan Lovato
753f4e6be6 Update CHANGELOG 2020-04-02 18:53:07 -06:00
Nathan Lovato
94645632c5 Merge pull request #45 from francogarcia/format-region
Format buffer and region.
2020-04-02 18:49:30 -06:00
Franco Eusébio Garcia
b4d2bec304 Format buffer and region.
Closes #38.

The implementation was simplified. Moreover, it is now possible to customize the
path to the `gdformat` executable.
2020-04-02 20:12:54 -03:00
Nathan Lovato
7b45e32e8d Update the CHANGELOG 2020-03-31 21:37:20 -06:00
Nathan Lovato
2752ab4ad3 Require projectile without throwing errors to fix linter warnings 2020-03-31 21:35:29 -06:00
Nathan Lovato
9f64525155 Merge pull request #44 from francogarcia/insert_file_path_at_point
Added a command to insert a file path at point using Projectile
2020-03-31 21:34:13 -06:00
Franco Eusébio Garcia
dc2100f9f4 Fallback to built-in read-file-name when Projectile is not available 2020-03-31 13:32:24 -03:00
Franco Eusébio Garcia
68c425b57f Added a command to insert a file path at point using Projectile.
Closes #36.
2020-03-30 21:36:48 -03:00
Nathan Lovato
2e0468b4b9 Rename gdscript-run-command to make it private 2020-03-30 10:52:57 -06:00
Nathan Lovato
bdf31f54d5 Merge pull request #43 from francogarcia/run_in_godot_fixes
Address omissions from fa26dd5 refactor
2020-03-30 10:51:26 -06:00
Franco Eusébio Garcia
e30e890d62 Address omissions from fa26dd5 refactor. 2020-03-30 13:36:30 -03:00
12 changed files with 348 additions and 108 deletions

View File

@@ -2,6 +2,39 @@
This document lists new features, improvements, changes, and bug fixes in each release of the package.
## GDScript mode 1.2.0
### Features
- Added commands to open the API reference in `eww`.
- Added debug options when running `gdscript-godot-run-project-debug`.
- Added a command to insert a path to a project file, either using `project-find-file` if `projectile` is available, otherwise with `find-file`.
- Added a command to format a selected region with `gdformat`.
- Added syntax highlighting for function calls.
- Added missing built in functions.
- Added missing `puppet` and `remotesync` keywords.
### Changes
- Changed keyboard shortcuts:
- <kbd>C-c i</kbd> `gdscript-completion-insert-file-path-at-point`
- <kbd>C-c C-f r</kbd> `gdscript-format-region`
- <kbd>C-c C-f b</kbd> `gdscript-format-buffer`
- <kbd>C-c C-r p</kbd> `gdscript-godot-open-project-in-editor`
- <kbd>C-c C-r r</kbd> `gdscript-godot-run-project`
- <kbd>C-c C-r d</kbd> `gdscript-godot-run-project-debug`
- <kbd>C-c C-r s</kbd> `gdscript-godot-run-current-scene`
- <kbd>C-c C-r q</kbd> `gdscript-godot-run-current-scene-debug`
- <kbd>C-c C-r e</kbd> `gdscript-godot-edit-current-scene`
- <kbd>C-c C-r x</kbd> `gdscript-godot-run-current-script`
- <kbd>C-c C-b a</kbd> `gdscript-docs-browse-api`
- <kbd>C-c C-b o</kbd> `gdscript-docs-browse-symbol-at-point`
### Bug fixes
- Fixed loading the `gdscript-godot` module at initialization.
- Fixed function calls in the mode map.
## GDScript mode 1.1.0
Emacs GDScript mode is now available on the [MELPA](https://melpa.org/) package archive!

View File

@@ -22,6 +22,7 @@ This mode already features all the essentials:
[gdformat](https://github.com/scony/godot-gdscript-toolkit/).
- Auto-completion for all the keywords in the `gdscript-keywords.el` file.
- Run or open the project and files with Godot.
- Browsing the API reference in Emacs.
## Contributing
@@ -135,6 +136,19 @@ If you don't have `godot` available there, you can set a custom executable name
You can also use `customize` to change this path: `M-x customize` and search for "godot".
### Running Godot with visual debug options
When running `gdscript-godot-run-project-debug`, you can use the universal argument <kbd>C-u</kbd> to invoke a mini-buffer with extra options to pass to godot.
Here are the available options:
1. `<no options>` _(default)_
2. `--debug-collisions`
3. `--debug-navigation`
4. `--debug-collisions --debug-navigation`
The last selected option is saved for the next time you call `gdscript-godot-run-project-debug`. To remove debug options, you need to call the command with the universal argument again.
### Formatting code with gdformat
You can call the `gdscript-format` function to format the current buffer with
@@ -148,6 +162,33 @@ command in your shell to install it:
pip3 install gdtoolkit
```
### Browsing the Godot API with eww
With the point on a built-in class you can press `C-c C-r C-o` to open the code reference for that class in the text browser [eww](https://www.gnu.org/software/emacs/manual/html_node/emacs/EWW.html).
To open the main API reference page and browse it, press `C-c C-r C-a`.
## Keyboard shortcuts
The following shortcuts are available by default:
- Inserting:
- <kbd>C-c i</kbd> `gdscript-completion-insert-file-path-at-point`
- Formatting:
- <kbd>C-c C-f r</kbd> `gdscript-format-region`
- <kbd>C-c C-f b</kbd> `gdscript-format-buffer`
- Running the project and scenes in Godot:
- <kbd>C-c C-r p</kbd> `gdscript-godot-open-project-in-editor`
- <kbd>C-c C-r r</kbd> `gdscript-godot-run-project`
- <kbd>C-c C-r d</kbd> `gdscript-godot-run-project-debug`
- <kbd>C-c C-r s</kbd> `gdscript-godot-run-current-scene`
- <kbd>C-c C-r q</kbd> `gdscript-godot-run-current-scene-debug`
- <kbd>C-c C-r e</kbd> `gdscript-godot-edit-current-scene`
- <kbd>C-c C-r x</kbd> `gdscript-godot-run-current-script`
- Browsing the code reference:
- <kbd>C-c C-b a</kbd> `gdscript-docs-browse-api`
- <kbd>C-c C-b o</kbd> `gdscript-docs-browse-symbol-at-point`
## Customization
To find all GDScript-mode settings, press `M-x customize` and search for "gdscript".

View File

@@ -33,6 +33,8 @@
;;; Code:
(require 'gdscript-syntax)
(require 'gdscript-utils)
(require 'projectile nil t)
(defvar-local gdscript-completion--all-keywords
(eval-when-compile (append gdscript-keywords gdscript-built-in-classes
@@ -48,6 +50,38 @@
(list start end gdscript-completion--all-keywords
. nil)))
(defun gdscript-completion-insert-file-path-at-point (&optional arg)
"Insert a file path at point using Godot's relative path (\"res:\").
If Projectile is available, list only the files in the current
project. Otherwise, fallback to the built-in function
`read-file-name'.
If using Projectile, with a prefix ARG invalidates the cache
first."
(interactive "P")
(let ((has-projectile (featurep 'projectile)))
(when has-projectile
(projectile-maybe-invalidate-cache arg))
(let* ((project-root
(if has-projectile
(projectile-ensure-project (projectile-project-root))
(gdscript-util--find-project-configuration-file)))
(file
(if has-projectile
(projectile-completing-read
"Find file: "
(projectile-project-files project-root))
(read-file-name
"Find file: "
project-root))))
(when file
(insert
(concat "\"res://"
(gdscript-util--get-godot-project-file-path-relative file)
"." (file-name-extension file) "\""))))))
(provide 'gdscript-completion)
;;; gdscript-completion.el ends here

View File

@@ -110,5 +110,12 @@ PATH."
"The path to the Godot executable.
By default, it assumes that the executable is in the system's
PATH."
:type 'string
:group 'gdscript)
(defcustom gdscript-gdformat-executable "gdformat"
"The path to the gdformat executable.
By default, it assumes that the executable is in the system's
PATH."
:type 'string
:group 'gdscript)

109
gdscript-docs.el Normal file
View File

@@ -0,0 +1,109 @@
;;; gdscript-docs.el --- Open documentation in Godot -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020 GDQuest and contributors
;;
;; Author: Josef Vlach <vlach.josef@gmail.com>
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
;; Version: 1.0.0
;; Package-Requires: ((emacs "26.3"))
;; Maintainer: nathan@gdquest.com
;; Created: May 2020
;; Keywords: languages
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;
;; Browse the Godot API reference in the text-based browser eww.
;;
;;; Code:
(require 'eww)
;;;###autoload
(defun gdscript-docs-browse-api ()
"Open the main page of Godot API in eww browser."
(interactive)
(eww-browse-url "https://docs.godotengine.org/en/stable/classes/index.html?#godot-api"))
(defun gdscript-docs-browse-symbol-at-point ()
"Open the API reference for the symbol at point in the browser eww.
If a page is already open, switch to its buffer."
(interactive)
(let* ((symbol (downcase (thing-at-point 'symbol t)))
(buffer
(seq-find
(lambda (current-buffer)
(with-current-buffer current-buffer
(when (derived-mode-p 'eww-mode)
(string-suffix-p symbol (plist-get eww-data :url) t)
))) (buffer-list))))
(if buffer (pop-to-buffer-same-window buffer)
(eww-browse-url (format "https://docs.godotengine.org/en/stable/classes/class_%s.html#%s" symbol symbol) t))))
(defun gdscript-docs--rename-eww-buffer ()
"Rename the eww buffer visiting the Godot documentation.
Rename the buffer from a generic name to a name based on the web page's title."
(when (derived-mode-p 'eww-mode)
(let ((title (plist-get eww-data :title)))
(when (string-match "Godot Engine" title)
(rename-buffer (format "*eww - %s*" title) t)))))
(defun gdscript-docs--filter-content-to-main-div ()
"Filters a page in the Godot docs down to its main <div>.
This is a re-implementation of `eww-readable'."
(let* ((old-data eww-data)
(dom (with-temp-buffer
(insert (plist-get old-data :source))
(condition-case nil
(decode-coding-region (point-min) (point-max) 'utf-8)
(coding-system-error nil))
(libxml-parse-html-region (point-min) (point-max))))
(base (plist-get eww-data :url))
;; Filters the page down to the main div: <div role="main"> ... </div>
(main (dom-elements dom 'role "main")))
(eww-display-html nil nil
(list 'base (list (cons 'href base))
main)
nil (current-buffer))
(dolist (elem '(:source :url :title :next :previous :up))
(plist-put eww-data elem
(plist-get old-data elem)))
(eww-update-header-line-format)))
(defun gdscript-docs--eww-follow-link (orig-fun &rest args)
"Remember url when following local link on a page.
ORIG-FUN is function we wrap around. ARGS are argument to ORIG-FUN function."
(let ((url (plist-get eww-data :url))
(res (apply orig-fun args)))
(plist-put eww-data :url url)
res))
(defun gdscript-docs--eww-setup ()
"Convenience setup for pages with Godot documentation."
(setq multi-isearch-next-buffer-function nil)
(gdscript-docs--rename-eww-buffer)
(gdscript-docs--filter-content-to-main-div))
(add-hook 'eww-after-render-hook #'gdscript-docs--eww-setup)
(advice-add 'eww-follow-link :around #'gdscript-docs--eww-follow-link)
(provide 'gdscript-docs)
;;; gdscript-docs.el ends here

View File

@@ -31,65 +31,33 @@
;;; Code:
(defun gdscript-format--run-gdformat (buffer-input buffer-output buffer-error)
"Call gdformat process.
Argument BUFFER-INPUT reference to the input buffer to format.
Argument BUFFER-OUTPUT the buffer to write the output of the gdformat call.
Argument BUFFER-ERROR the buffer to write errors to."
(with-current-buffer buffer-input
(let ((process (make-process :name "gdformat"
:command (list "gdformat" "-"):buffer
buffer-output
:stderr buffer-error
:noquery t
:sentinel (lambda (_process _event)))))
(set-process-query-on-exit-flag (get-buffer-process buffer-error)
nil)
(set-process-sentinel (get-buffer-process buffer-error)
(lambda (_process _event)))
(save-restriction (widen)
(process-send-region process
(point-min)
(point-max)))
(process-send-eof process)
(accept-process-output process nil nil t)
(while (process-live-p process)
(accept-process-output process nil nil t))
(process-exit-status process))))
(defun gdscript-format--format-region (start end)
"Format the region between START and END using `gdformat'."
(let
((cmd (concat "echo " (shell-quote-argument (buffer-substring start end)) "|" gdscript-gdformat-executable " -"))
(error-buffer "*gdformat-errors*"))
(if (eq (with-temp-buffer (call-process-shell-command cmd)) 0)
(save-excursion
(shell-command-on-region start end cmd (buffer-name) t error-buffer t))
(progn
(with-current-buffer error-buffer (erase-buffer))
(shell-command-on-region start end cmd nil nil error-buffer t)))))
(defun gdscript-format-buffer ()
"Formats current buffer using 'gdformat'."
(defun gdscript-format-region()
"Format the selected region using `gdformat'"
(interactive)
(let* ((buffer-start (current-buffer))
(point-start (point))
(window-pos-start (window-start))
(buffer-temp (get-buffer-create "*gdformat*"))
(buffer-error (get-buffer-create "*gdformat-error*")))
(dolist (buf (list buffer-temp buffer-error))
(with-current-buffer buf
(erase-buffer)))
(condition-case err
(if (/= 0 (gdscript-format--run-gdformat buffer-start buffer-temp
buffer-error))
(error "GDSCript formatter: failed, see buffer %s for details"
(buffer-name buffer-error))
(if (/= 0 (compare-buffer-substrings buffer-temp nil
nil buffer-start nil nil))
(progn
(with-current-buffer buffer-temp
(copy-to-buffer buffer-start
(point-min)
(point-max)))
(goto-char point-start)
(set-window-start (selected-window)
window-pos-start)
(message "gdscript formatter: success"))
(message "gdscript formatter: nothing to do"))
(mapc 'kill-buffer
(list buffer-temp buffer-error)))
(error (message "%s"
(error-message-string err))
(pop-to-buffer buffer-error)))))
(gdscript-format--format-region
(region-beginning) (region-end)))
(defun gdscript-format-buffer()
"Format the entire current buffer using `gdformat'"
(interactive)
(let ((original-point (point))
(original-window-pos (window-start)))
(gdscript-format--format-region
(point-min) (point-max))
(goto-char original-point)
(set-window-start (selected-window) original-window-pos)))
(provide 'gdscript-format)

View File

@@ -36,21 +36,20 @@
(require 'gdscript-utils)
;;;###autoload
(defun gdscript-run-command (cmd &optional show)
"Run a Godot process.
Input and output via buffer named after `*godot*'. If there is a process
already running in that buffer, just switch to it.
(defvar gdscript-godot--debug-selected-option 1)
With argument, allows you to define CMD so you can edit the
command used to call the interpreter.
When numeric prefix arg is other than 0 or 4 do not SHOW."
(interactive
(if current-prefix-arg
(list
(read-string "Run Godot: " (gdscript-godot--build-shell-command))
(y-or-n-p "Make dedicated process? ")
(= (prefix-numeric-value current-prefix-arg) 4))
(list (gdscript-godot--build-shell-command) nil t)))
(defvar gdscript-godot--debug-options-alist
'((1 . "")
(2 . "--debug-collisions")
(3 . "--debug-navigation")
(4 . "--debug-collisions --debug-navigation")))
(defun gdscript-godot--run-command (cmd &optional show)
"Run a Godot process.
CMD is the command to be invoked by the shell. If SHOW, the
output of the process will be provided in a buffer named
`*godot*'."
(start-process-shell-command "Godot Process" (if show
"*godot*" nil) cmd))
@@ -65,41 +64,47 @@ file's directory as starting point."
(defun gdscript-godot-open-project-in-editor ()
"Run Godot Engine Editor."
(interactive)
(gdscript-run-command
(gdscript-godot--run-command
(concat (gdscript-godot--build-shell-command) " -e")))
(defun gdscript-godot-run-project ()
"Run the current project in Godot Engine."
(interactive)
(let* ()
(gdscript-run-command
(gdscript-godot--build-shell-command))))
(gdscript-godot--run-command
(gdscript-godot--build-shell-command)))
(defun gdscript-godot-run-project-debug ()
"Run the current project in Godot Engine."
"Run the current project in Godot Engine.
When run with prefix argument, it offers extra debug options to choose from."
(interactive)
(let* ()
(gdscript-run-command
(concat (gdscript-godot--build-shell-command) " -d"))))
(let* ((debug-option-index
(if current-prefix-arg
(gdscript-godot--change-debug-options)
gdscript-godot--debug-selected-option))
(debug-options (cdr (assoc debug-option-index gdscript-godot--debug-options-alist))))
(gdscript-godot--run-command
(concat (gdscript-godot--build-shell-command) " -d " debug-options) t)))
(defun gdscript-godot-run-current-scene ()
"Run the current script file in Godot Engine."
(interactive)
(gdscript-run-command
(gdscript-godot--run-command
(concat (gdscript-godot--build-shell-command) " "
(gdscript-util--get-godot-project-file-path-relative buffer-file-name) ".tscn")))
(defun gdscript-godot-run-current-scene-debug ()
"Run the current script file in Godot Engine."
(interactive)
(gdscript-run-command
(gdscript-godot--run-command
(concat (gdscript-godot--build-shell-command) " -d "
(gdscript-util--get-godot-project-file-path-relative buffer-file-name) ".tscn")))
(gdscript-util--get-godot-project-file-path-relative buffer-file-name) ".tscn")
t))
(defun gdscript-godot-edit-current-scene ()
"Run the current script file in Godot Engine."
(interactive)
(gdscript-run-command
(gdscript-godot--run-command
(concat (gdscript-godot--build-shell-command) " -e "
(gdscript-util--get-godot-project-file-path-relative buffer-file-name) ".tscn")))
@@ -109,8 +114,35 @@ file's directory as starting point."
For this to work, the script must inherit either from
\"SceneTree\" or \"MainLoop\"."
(interactive)
(gdscript-run-command
(concat (gdscript-godot--build-shell-command) " -s " (file-relative-name buffer-file-name))))
(gdscript-godot--run-command
(concat (gdscript-godot--build-shell-command) " -s " (file-relative-name buffer-file-name))
t))
(defun gdscript-godot--debug-options-collection ()
"Output a list of debug options to choose from by *-read function."
(list
(format "1) [%s] <no options>" (if (eq gdscript-godot--debug-selected-option 1) "X" " "))
(format "2) [%s] %s" (if (eq gdscript-godot--debug-selected-option 2) "X" " ") (cdr (assoc 2 gdscript-godot--debug-options-alist)))
(format "3) [%s] %s" (if (eq gdscript-godot--debug-selected-option 3) "X" " ") (cdr (assoc 3 gdscript-godot--debug-options-alist)))
(format "4) [%s] %s" (if (eq gdscript-godot--debug-selected-option 4) "X" " ") (cdr (assoc 4 gdscript-godot--debug-options-alist)))))
(defun gdscript-godot--read-debug-options ()
"Read debug options preference by user from mini-buffer."
(cond ((fboundp 'ivy-read)
(ivy-read "Options: " (gdscript-godot--debug-options-collection)))
((fboundp 'ido-completing-read)
(ido-completing-read "Options: " (gdscript-godot--debug-options-collection)))
(t
(completing-read "Options (hit TAB to auto-complete): " (gdscript-godot--debug-options-collection) nil t))))
(defun gdscript-godot--change-debug-options ()
"Read debug option and parse it as a number.
Once read it is saved in `gdscript-godot--debug-selected-option'
variable for later use."
(let* ((option (gdscript-godot--read-debug-options))
(index (string-to-number option)))
(setq gdscript-godot--debug-selected-option index)))
(provide 'gdscript-godot)
;;; gdscript-godot.el ends here

View File

@@ -33,19 +33,22 @@
(defconst gdscript-keywords '("and" "as" "assert" "break" "breakpoint" "case" "class" "class_name"
"const" "continue" "do" "elif" "else" "enum" "export" "extends" "false" "for" "func" "if" "in" "is"
"master" "match" "not" "onready" "or" "pass" "preload" "remote" "return" "self" "setget" "signal"
"master" "match" "not" "onready" "or" "pass" "preload" "puppet" "remote" "remotesync" "return" "self" "setget" "signal"
"slave" "static" "switch" "sync" "tool" "true" "var" "while" "yield"))
(defconst gdscript-built-in-constants '("INF" "NAN" "PI" "TAU"))
;; Only contains types that are not classes and that the Godot editor highlights
;; like built-in keywords
(defconst gdscript-built-in-types '("bool" "float" "int" "null" "void"))
(defconst gdscript-built-in-functions '("Color8" "abs" "acos" "asin" "assert" "atan" "atan2"
"bytes2var" "ceil" "char" "clamp" "convert" "cos" "cosh" "db2linear" "decimals" "dectime" "deg2rad"
"dict2inst" "ease" "exp" "floor" "fmod" "fposmod" "funcref" "hash" "inst2dict" "instance_from_id"
"is_inf" "is_nan" "lerp" "linear2db" "load" "log" "max" "min" "name" "nearest_po2" "pow" "preload"
"print" "print_stack" "printerr" "printraw" "prints" "printt" "rad2deg" "rand_range" "rand_seed"
"randf" "randi" "randomize" "range" "round" "seed" "sign" "sin" "sinh" "sqrt" "stepify" "str"
"str2var" "tan" "tanh" "type_exists" "typeof" "var2bytes" "var2str" "weakref" "yield"))
(defconst gdscript-built-in-functions '("Color8" "ColorN" "abs" "acos" "asin" "assert" "atan" "atan2"
"bytes2var" "cartesian2polar" "ceil" "char" "clamp" "convert" "cos" "cosh" "db2linear" "decimals"
"dectime" "deg2rad" "dict2inst" "ease" "exp" "floor" "fmod" "fposmod" "funcref" "get_stack" "hash"
"inst2dict" "instance_from_id" "inverse_lerp" "is_equal_approx" "is_inf" "is_instance_valid" "is_nan"
"is_zero_approx" "len" "lerp" "lerp_angle" "linear2db" "load" "log" "max" "min" "move_toward" "nearest_po2"
"ord" "parse_json" "polar2cartesian" "posmod" "pow" "preload" "print" "print_debug" "print_stack" "printerr"
"printraw" "prints" "printt" "push_error" "push_warning" "rad2deg" "rand_range" "rand_seed" "randf" "randi"
"randomize" "range" "range_lerp" "round" "seed" "sign" "sin" "sinh" "smoothstep" "sqrt" "step_decimals" "stepify"
"str" "str2var" "tan" "tanh" "to_json" "type_exists" "typeof" "validate_json" "var2bytes" "var2str" "weakref"
"wrapf" "wrapi" "yield"))
;; Contains all engine classes and node types, including vectors, transforms, etc.
(defconst gdscript-built-in-classes '("AABB" "ARVRAnchor" "ARVRCamera" "ARVRController"
"ARVRInterface" "ARVROrigin" "ARVRPositionalTracker" "ARVRServer" "AStar" "AStar2D" "AcceptDialog"

View File

@@ -31,6 +31,7 @@
;;; Code:
(require 'gdscript-customization)
(require 'gdscript-docs)
(require 'gdscript-syntax)
(require 'gdscript-indent-and-nav)
(require 'gdscript-imenu)
@@ -38,6 +39,7 @@
(require 'gdscript-completion)
(require 'gdscript-format)
(require 'gdscript-rx)
(require 'gdscript-godot)
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.gd\\'" . gdscript-mode))
@@ -52,19 +54,27 @@
(define-key map [remap forward-sentence] 'gdscript-nav-forward-block)
(define-key map [remap backward-up-list] 'gdscript-nav-backward-up-list)
(define-key map [remap mark-defun] 'gdscript-mark-defun)
(define-key map "\C-c\C-j" 'imenu)
(define-key map (kbd "C-c C-j") 'imenu)
;; Indent specific
(define-key map "\177" 'gdscript-indent-dedent-line-backspace)
(define-key map (kbd "<backtab>") 'gdscript-indent-dedent-line)
(define-key map (kbd "\t") 'company-complete)
;; Insertion.
(define-key map (kbd "C-c i") 'gdscript-completion-insert-file-path-at-point)
;; Formatting.
(define-key map (kbd "C-c C-f r") 'gdscript-format-region)
(define-key map (kbd "C-c C-f b") 'gdscript-format-buffer)
;; Run in Godot.
(define-key map "\C-c\C-g" 'gdscript--run-godot-editor)
(define-key map "\C-c\C-p" 'gdscript--run-project-in-godot)
(define-key map "\C-c\C-s" 'gdscript--run-current-scene-in-godot)
(define-key map "\C-c\C-e" 'gdscript-godot-edit-current-scene)
(define-key map "\C-c\C-r" 'gdscript--run-current-script-in-godot)
(define-key map "\C-c\C-dp" 'gdscript--run-project-in-godot-debug-mode)
(define-key map "\C-c\C-ds" 'gdscript--run-current-scene-in-godot-debug-mode)
(define-key map (kbd "C-c C-r p") 'gdscript-godot-open-project-in-editor)
(define-key map (kbd "C-c C-r r") 'gdscript-godot-run-project)
(define-key map (kbd "C-c C-r d") 'gdscript-godot-run-project-debug)
(define-key map (kbd "C-c C-r s") 'gdscript-godot-run-current-scene)
(define-key map (kbd "C-c C-r q") 'gdscript-godot-run-current-scene-debug)
(define-key map (kbd "C-c C-r e") 'gdscript-godot-edit-current-scene)
(define-key map (kbd "C-c C-r x") 'gdscript-godot-run-current-script)
;; Docs.
(define-key map (kbd "C-c C-b a") 'gdscript-docs-browse-api)
(define-key map (kbd "C-c C-b o") 'gdscript-docs-browse-symbol-at-point)
map)
"Keymap for `gdscript-mode'.")

View File

@@ -1445,10 +1445,9 @@ following constructs:
(defmacro gdscript-rx (&rest regexps)
"Gdscript mode specialized rx macro.
This variant of `rx' supports common Gdscript named REGEXPS."
`(gdscript-rx-let ((block-start (seq (zero-or-more nonl)
":"
(or (seq (zero-or-more " ") eol)
(seq (zero-or-more " ") "#" (zero-or-more nonl) eol))))
`(gdscript-rx-let ((block-start (seq symbol-start
(or "func" "class" "if" "elif" "else" "for" "while" "match")
symbol-end))
(dedenter (seq symbol-start
(or "elif" "else")
symbol-end))

View File

@@ -75,7 +75,12 @@
(or "var" "const")
(1+ space)
(group (1+ (or word ?_))))
(1 font-lock-variable-name-face))))
(1 font-lock-variable-name-face))
;; Function call
(,(rx (group (1+ (or word ?_)))
(0+ space)
"(")
(1 font-lock-function-name-face))))
(defvar gdscript-syntax-table (make-syntax-table))

View File

@@ -115,8 +115,7 @@ WARNING: the Godot project must exist for this function to work."
(defun gdscript-util--get-godot-project-file-path-relative (file-path)
"Return the relative path of `FILE-PATH' to Godot's configuration file."
(concat (gdscript-godot--build-shell-command) " -d "
(file-name-sans-extension
(concat (file-name-sans-extension
(file-relative-name file-path
(gdscript-util--find-project-configuration-file)))))