mirror of
https://github.com/godotengine/emacs-gdscript-mode.git
synced 2025-12-31 21:48:34 +03:00
Compare commits
216 Commits
v1.0.0
...
jcs090218-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a89ae451d9 | ||
|
|
32086df833 | ||
|
|
4ae8760e19 | ||
|
|
ab6aae89aa | ||
|
|
2737f1c68c | ||
|
|
cd92e12084 | ||
|
|
becce1a4ba | ||
|
|
718267511f | ||
|
|
d25f778f02 | ||
|
|
b8a840448a | ||
|
|
e0a8dc9f0b | ||
|
|
8a28276daa | ||
|
|
a6efb8713d | ||
|
|
9b26d25aa3 | ||
|
|
bcb50cfe2c | ||
|
|
0938403561 | ||
|
|
3e2ae19f03 | ||
|
|
812da6aa3c | ||
|
|
4946aff35a | ||
|
|
0692056e95 | ||
|
|
b7188197a5 | ||
|
|
44fc361bd7 | ||
|
|
268abf778b | ||
|
|
13a3e00e6c | ||
|
|
45e05fd58b | ||
|
|
cee6d61591 | ||
|
|
3995a7b2ae | ||
|
|
70a243278a | ||
|
|
a5a25f07ac | ||
|
|
a48ad04502 | ||
|
|
73dac51758 | ||
|
|
68f18932a4 | ||
|
|
586d957650 | ||
|
|
72ddbec953 | ||
|
|
c8c22a6884 | ||
|
|
30c4d48f81 | ||
|
|
f071667776 | ||
|
|
d392e8aa7e | ||
|
|
d9e1f7f766 | ||
|
|
4badcf6a0c | ||
|
|
b7bfa6a3b2 | ||
|
|
9043e1a6b6 | ||
|
|
16c631cd6f | ||
|
|
4a1175f467 | ||
|
|
bdce2da794 | ||
|
|
fe59b77c3f | ||
|
|
e54edf94b8 | ||
|
|
d751ce6249 | ||
|
|
fa9ec1fead | ||
|
|
287acb7c76 | ||
|
|
b53d56e467 | ||
|
|
4e5bb877e3 | ||
|
|
4edc27ee7c | ||
|
|
9b1e313e2c | ||
|
|
f6c7bb5bb4 | ||
|
|
20fc7e4381 | ||
|
|
75fe658ab8 | ||
|
|
0aa2e8f52f | ||
|
|
95fdf3aa23 | ||
|
|
163a1340e5 | ||
|
|
1d6d707144 | ||
|
|
f87cc3e1c2 | ||
|
|
ef7a7f2789 | ||
|
|
55a6637424 | ||
|
|
58ef86f8d3 | ||
|
|
7375291bca | ||
|
|
a26c1d3bda | ||
|
|
c5d34c22d5 | ||
|
|
a9263e30ae | ||
|
|
d9b7c26c89 | ||
|
|
c5da04810d | ||
|
|
341495023a | ||
|
|
5c17d7b4b9 | ||
|
|
e457b05d2a | ||
|
|
406bc58d77 | ||
|
|
6621b71a1a | ||
|
|
152e1b8cea | ||
|
|
ea94ba5360 | ||
|
|
34a88c5cb2 | ||
|
|
80b08e0afd | ||
|
|
dde7ffa735 | ||
|
|
1031e6f87e | ||
|
|
099ca4471f | ||
|
|
828ff63da1 | ||
|
|
110d36da96 | ||
|
|
1a31e42273 | ||
|
|
13812f4a17 | ||
|
|
08654b4e38 | ||
|
|
01a0c56bb4 | ||
|
|
4db7ed6369 | ||
|
|
a1ff8e2801 | ||
|
|
949ac8c47a | ||
|
|
2e9f6fbe2a | ||
|
|
3f33cb6611 | ||
|
|
4ff18e6755 | ||
|
|
4a95d69034 | ||
|
|
16a4bc6c46 | ||
|
|
7adaf201c1 | ||
|
|
6744e3b74d | ||
|
|
7aea87bd7b | ||
|
|
123c0df70d | ||
|
|
4bf308023b | ||
|
|
e8f56823eb | ||
|
|
86dcaa2430 | ||
|
|
e31da43351 | ||
|
|
fd6754d36b | ||
|
|
c57e2a88f3 | ||
|
|
3fc2e92ce7 | ||
|
|
04732e7e46 | ||
|
|
ce95576aa8 | ||
|
|
fe17656b4e | ||
|
|
506480939f | ||
|
|
7eb2a3156d | ||
|
|
dbe43ebb0d | ||
|
|
c772b6e3af | ||
|
|
651622c860 | ||
|
|
cfeba7e72b | ||
|
|
35fe376cc3 | ||
|
|
4fcfc61c0e | ||
|
|
18c86dbb6c | ||
|
|
b768f80498 | ||
|
|
d55471dd02 | ||
|
|
8e61cf6faf | ||
|
|
3ad2680edf | ||
|
|
8d8b710ca9 | ||
|
|
f94b8d209c | ||
|
|
36c92dff15 | ||
|
|
87ba0803e0 | ||
|
|
3e46706855 | ||
|
|
ef3f0c529f | ||
|
|
194552fcb8 | ||
|
|
a52e91c3a6 | ||
|
|
e4981f7656 | ||
|
|
fea2afb96d | ||
|
|
b45fa69944 | ||
|
|
db2f50f9bf | ||
|
|
59753af564 | ||
|
|
46c17d352f | ||
|
|
f89d087f3a | ||
|
|
b6e1f9a512 | ||
|
|
a0027df0a1 | ||
|
|
6a1a894a14 | ||
|
|
4ddfc8edce | ||
|
|
0718ca9b09 | ||
|
|
c74e2cd77b | ||
|
|
584d61b6aa | ||
|
|
028df8c749 | ||
|
|
9a74dd3b6c | ||
|
|
6a3e4070bb | ||
|
|
753f4e6be6 | ||
|
|
94645632c5 | ||
|
|
b4d2bec304 | ||
|
|
7b45e32e8d | ||
|
|
2752ab4ad3 | ||
|
|
9f64525155 | ||
|
|
dc2100f9f4 | ||
|
|
68c425b57f | ||
|
|
2e0468b4b9 | ||
|
|
bdf31f54d5 | ||
|
|
e30e890d62 | ||
|
|
86577f81dc | ||
|
|
7e6eef308e | ||
|
|
fa26dd5676 | ||
|
|
beac587761 | ||
|
|
56a864ecff | ||
|
|
2e6e1aad90 | ||
|
|
427b6761eb | ||
|
|
994fb62206 | ||
|
|
13a84a0193 | ||
|
|
246cad5890 | ||
|
|
a36a3e775b | ||
|
|
35cbac7fb9 | ||
|
|
c296065c15 | ||
|
|
475cc6b8d2 | ||
|
|
7d2ed510c1 | ||
|
|
d924845be5 | ||
|
|
155abe1f8b | ||
|
|
922ff92f07 | ||
|
|
f9bd2f6ccb | ||
|
|
dd8c5bc5bf | ||
|
|
57cbde873c | ||
|
|
7ce4c220dd | ||
|
|
e900e05bde | ||
|
|
beb278d10f | ||
|
|
6997f4ddd3 | ||
|
|
40d08c3b02 | ||
|
|
f72ce3b7d3 | ||
|
|
dfb7cd9a11 | ||
|
|
81294f8972 | ||
|
|
3cd94546f3 | ||
|
|
f8c0444c82 | ||
|
|
94d8642f0d | ||
|
|
c866a7fb12 | ||
|
|
48765f3209 | ||
|
|
60ee1a62bc | ||
|
|
b028badcd9 | ||
|
|
53a955c492 | ||
|
|
9118d91a3c | ||
|
|
bba752032a | ||
|
|
236f3a2e31 | ||
|
|
e4a39b02da | ||
|
|
102b63e24d | ||
|
|
e922a1fc83 | ||
|
|
f77656f685 | ||
|
|
fb215bb83b | ||
|
|
f80758d517 | ||
|
|
1717837d34 | ||
|
|
00c629cd94 | ||
|
|
81d9d5b9e1 | ||
|
|
361439f28b | ||
|
|
3c5e31bfe3 | ||
|
|
dfe2cd922e | ||
|
|
f17c6a7418 | ||
|
|
68be13a965 | ||
|
|
c633a6f4d1 | ||
|
|
92a1087a30 |
56
.github/workflows/test.yml
vendored
Normal file
56
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
continue-on-error: ${{ matrix.experimental }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
emacs-version:
|
||||
- 26.3
|
||||
- 27.2
|
||||
- 28.2
|
||||
- 29.4
|
||||
experimental: [false]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
emacs-version: snapshot
|
||||
experimental: true
|
||||
- os: macos-latest
|
||||
emacs-version: snapshot
|
||||
experimental: true
|
||||
- os: windows-latest
|
||||
emacs-version: snapshot
|
||||
experimental: true
|
||||
exclude:
|
||||
- os: macos-latest
|
||||
emacs-version: 26.3
|
||||
- os: macos-latest
|
||||
emacs-version: 27.2
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: jcs090218/setup-emacs@master
|
||||
with:
|
||||
version: ${{ matrix.emacs-version }}
|
||||
|
||||
- uses: emacs-eask/setup-eask@master
|
||||
with:
|
||||
version: 'snapshot'
|
||||
|
||||
- name: Run tests
|
||||
run:
|
||||
make ci
|
||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -2,10 +2,14 @@
|
||||
*.elc
|
||||
|
||||
# Packaging
|
||||
.cask
|
||||
.eask
|
||||
dist/
|
||||
|
||||
# Backup files
|
||||
*~
|
||||
|
||||
# Undo-tree save-files
|
||||
*.~undo-tree
|
||||
|
||||
#emacs projectile
|
||||
.projectile
|
||||
150
CHANGELOG.md
150
CHANGELOG.md
@@ -1,8 +1,154 @@
|
||||
# Changelog #
|
||||
# Changelog
|
||||
|
||||
This document lists new features, improvements, changes, and bug fixes in each release of the package.
|
||||
|
||||
## GDScript mode 1.0.0 ##
|
||||
## GDScript mode 1.5.0
|
||||
|
||||
- Added the ability to toggle breakpoint on the current line instead of either adding or removing them.
|
||||
- Added keybindings matching Godot to run the project (<kbd>f5</kbd>), current scene (<kbd>f6</kbd>), continue execution (<kbd>f7</kbd>), and toggle breakpoints <kbd>F9</kbd>.
|
||||
|
||||
## GDScript mode 1.4.1
|
||||
|
||||
Thanks to @clangdo for the contribution!
|
||||
|
||||
- Fixed indent functions preventing double hanging indent in parentheses or after a `\`.
|
||||
|
||||
## GDScript mode 1.4.0
|
||||
|
||||
Big thanks to @VlachJosef and @rileyrg for their work on this release.
|
||||
|
||||
### New features
|
||||
|
||||
- Debugger support with breakpoints, code stepping, stack frames, remote scene tree, and more. See the [README](https://github.com/godotengine/emacs-gdscript-mode/blob/master/README.md) for more information.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fix scene and script selection not aborting when pressing <kbd>C-g</kbd>.
|
||||
|
||||
## GDScript mode 1.3.0
|
||||
|
||||
This release brings many quality-of-life improvements to work more productively with Godot and Emacs.
|
||||
|
||||
Big thanks to @VlachJosef and @rileyrg for contributing to this release.
|
||||
|
||||
### Features
|
||||
|
||||
- Support for running the project and scenes with [hydra](https://github.com/abo-abo/hydra) with `gdscript-hydra-show`.
|
||||
- Command interpreter (`comint` support) for Godot processes: get and navigate errors within Emacs, and jump to files and GDScript code causing errors.
|
||||
- The command buffer pops up automatically when you run a scene or the project in the editor.
|
||||
- Added command `gdscript-format-all` to format all gdscript buffers.
|
||||
- Added commands `gdscript-format-all` and `gdscript-format-buffer` to gdscript-mode's hydra window (`gdscript-hydra-show`).
|
||||
- Added command interpreter support for `gdscript-format-*` commands
|
||||
- Add the ability to open a local copy of the Godot docs with `gdscript-docs-*` commands.
|
||||
- Multiple projects support. Every project's `godot` process runs in its own buffer.
|
||||
- Godot's standard output and standard error are fed to a `comint` buffer. This allows you to navigate errors and jump to the corresponding source files, using `compilation-*` commands.
|
||||
- Hydra provides a history of commands for quick re-execution of godot commands. It also provides a quick way to rerun the last command.
|
||||
- The `gdscript-godot-run-current-scene` command now offers to run any scene file if the current buffer is not a scene file.
|
||||
- The `gdscript-godot-run-current-script` command now offers to run any script file if the current buffer is not a script file.
|
||||
- Syntax highlighting for the `$` operator.
|
||||
|
||||
### Improvements
|
||||
|
||||
- Added unit tests (see `gdscript-tests.el`).
|
||||
- Added check for missing `godot` executable and a corresponding error message.
|
||||
- You can force selecting a scene when calling `gdscript-godot-run-current-scene` by using the universal argument (<kbd>C-u</kbd>).
|
||||
- `gdscript-godot-run-current-scene` will use `projectile` by default if available, otherwise `ivy` or `ido`.
|
||||
- You can now customize the URL for the Godot API reference: `gdscript-docs-online-search-api-url`.
|
||||
- Also, use the universal argument (<kbd>C-u</kbd>) before calling `gdscript-docs-browse-api` to force it to use the online docs, even if a local build of the docs is available.
|
||||
|
||||
### Changes
|
||||
|
||||
- Removed guessing indentation size, which could guess indent sizes wrong.
|
||||
- Removed the customizable variables `gdscript-indent-guess-indent-offset` and `gdscript-indent-guess-indent-offset-verbose`.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fixed auto-indentation not working with match blocks.
|
||||
- Fixed auto-indentation of new blocks sometimes over-indenting.
|
||||
- Fixed `eww-after-render-hook` always calling gdscript docs formatter, even outside of `gdscript-mode` buffers.
|
||||
- Removed call to nonexisting function `f-executable-p`.
|
||||
|
||||
## 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!
|
||||
|
||||
### Features
|
||||
|
||||
- Added commands to run files or open the project in Godot. Type `M-x gdscript-godot` to find and try them.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fixed incorrect match block indentation.
|
||||
- Fixed error with code folding.
|
||||
- Added syntax highlighting for more built-in keywords .
|
||||
- Fixed error at startup on Emacs 26.3
|
||||
|
||||
### Documentation
|
||||
|
||||
- Added instructions to install with use-package.
|
||||
- Updated install instructions for MELPA.
|
||||
- Added documentation on using `gdscript-godot-*` commands.
|
||||
|
||||
## GDScript mode 1.0.2
|
||||
|
||||
### Changes
|
||||
|
||||
- Addressed linting and checkdoc errors for a release on the [MELPA](https://melpa.org/) package archive.
|
||||
- Split some more of the code to make the code easier to read and to maintain.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fixed `function-definition-void` errors in some cases due to a missing file import.
|
||||
- Fixed package loading error in some configurations.
|
||||
- Added syntax highlighting and completion for the following keywords: `in`, `and`, `or`, `not`, `true`, `false`.
|
||||
- Fixed incorrect auto-indentation in `match` blocks.
|
||||
|
||||
## GDScript mode 1.0.1
|
||||
|
||||
This minor release fixes a bug with the GDScript keywords.
|
||||
|
||||
### Improvements
|
||||
|
||||
- Compile keywords for faster auto-completion and syntax highlighting.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
- Fixed missing language keywords and constants lists.
|
||||
|
||||
## GDScript mode 1.0.0
|
||||
|
||||
This is the initial release of gdscript-mode, which adds support for the [Godot engine](https://godotengine.org/)'s GDScript programming language in Emacs.
|
||||
|
||||
|
||||
17
Eask
Normal file
17
Eask
Normal file
@@ -0,0 +1,17 @@
|
||||
(package "gdscript-mode"
|
||||
"0.1.0"
|
||||
"Major mode for Godot's GDScript language")
|
||||
|
||||
(website-url "https://github.com/godotengine/emacs-gdscript-mode/")
|
||||
(keywords "languages")
|
||||
|
||||
(package-file "gdscript-mode.el")
|
||||
(files "*.el")
|
||||
|
||||
(script "test" "echo \"Error: no test specified\" && exit 1")
|
||||
|
||||
(source "gnu")
|
||||
|
||||
(depends-on "emacs" "26.3")
|
||||
|
||||
(setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) 2020 GDQuest and contributors
|
||||
|
||||
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/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
Emacs GDScript Mode Copyright (C) 2020 GDQuest and contributors
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
36
Makefile
Normal file
36
Makefile
Normal file
@@ -0,0 +1,36 @@
|
||||
SHELL := /usr/bin/env bash
|
||||
|
||||
EMACS ?= emacs
|
||||
EASK ?= eask
|
||||
|
||||
.PHONY: clean checkdoc lint package install compile test
|
||||
|
||||
# TODO: add `lint` if we can?
|
||||
ci: clean package install compile checkdoc
|
||||
|
||||
package:
|
||||
@echo "Packaging..."
|
||||
$(EASK) package
|
||||
|
||||
install:
|
||||
@echo "Installing..."
|
||||
$(EASK) install
|
||||
|
||||
compile:
|
||||
@echo "Compiling..."
|
||||
$(EASK) compile
|
||||
|
||||
test:
|
||||
@echo "Testing..."
|
||||
$(EASK) ert ./test/*.el
|
||||
|
||||
checkdoc:
|
||||
@echo "Run checkdoc..."
|
||||
$(EASK) lint checkdoc
|
||||
|
||||
lint:
|
||||
@echo "Run package-lint..."
|
||||
$(EASK) lint package
|
||||
|
||||
clean:
|
||||
$(EASK) clean all
|
||||
463
README.md
463
README.md
@@ -1,85 +1,472 @@
|
||||
# GDScript mode for Emacs #
|
||||
# GDScript mode for Emacs
|
||||
|
||||
This package adds support for the GDScript programming language from the Godot game engine in Emacs. It gives syntax highlighting and indentations.
|
||||

|
||||
|
||||
This is currently a work in progress, and my first time creating an Emacs package. Feedback, tips, and contributions are more than welcome!
|
||||
This package adds support for the GDScript programming language from the Godot
|
||||
game engine in Emacs. It gives syntax highlighting and indentations.
|
||||
[Contributors](#contributing) are welcome!
|
||||
|
||||
## Features ##
|
||||

|
||||
|
||||
This mode already features all the essentials:
|
||||
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
|
||||
**Table of Contents**
|
||||
|
||||
- [Features](#features)
|
||||
- [Contributing](#contributing)
|
||||
- [How to install](#how-to-install)
|
||||
- [Installing in Spacemacs](#installing-in-spacemacs)
|
||||
- [Installing in Doom Emacs](#installing-in-doom-emacs)
|
||||
- [Installing with `use-package` + `straight.el`](#installing-with-use-package--straightel)
|
||||
- [Installing manually](#installing-manually)
|
||||
- [Auto-completion with the Language Server Protocol (LSP)](#auto-completion-with-the-language-server-protocol-lsp)
|
||||
- [Known issues](#known-issues)
|
||||
- [Major mode with Treesit](#major-mode-with-treesit)
|
||||
- [Install treesit](#install-treesit)
|
||||
- [Install grammar](#install-grammar)
|
||||
- [How to use](#how-to-use)
|
||||
- [Opening the project in the editor](#opening-the-project-in-the-editor)
|
||||
- [Running Godot with visual debug options](#running-godot-with-visual-debug-options)
|
||||
- [Using Hydra](#using-hydra)
|
||||
- [Formatting code with gdformat](#formatting-code-with-gdformat)
|
||||
- [Browsing the Godot API with eww](#browsing-the-godot-api-with-eww)
|
||||
- [Using a local copy of the Godot docs](#using-a-local-copy-of-the-godot-docs)
|
||||
- [Keyboard shortcuts](#keyboard-shortcuts)
|
||||
- [Customization](#customization)
|
||||
- [Using the debugger](#using-the-debugger)
|
||||
- [Adding and removing breakpoints](#adding-and-removing-breakpoints)
|
||||
- [Running the project with the debugger active](#running-the-project-with-the-debugger-active)
|
||||
- [Multi-line display](#multi-line-display)
|
||||
- [Fetching an object's details](#fetching-an-objects-details)
|
||||
- [Debug Hydra](#debug-hydra)
|
||||
- [The `* Stack frame vars *` buffer](#the--stack-frame-vars--buffer)
|
||||
- [`* Inspector *` buffer](#-inspector--buffer)
|
||||
- [`* Stack dump *` buffer](#-stack-dump--buffer)
|
||||
- [`* Breakpoints *` buffer](#-breakpoints--buffer)
|
||||
- [`* Scene tree *` buffer](#-scene-tree--buffer)
|
||||
|
||||
<!-- markdown-toc end -->
|
||||
|
||||
## Features
|
||||
|
||||
This mode features all the essentials:
|
||||
|
||||
- Syntax highlighting.
|
||||
- Code folding.
|
||||
- Debugger support.
|
||||
- [Imenu](https://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html).
|
||||
- Support for scenes (`.tscn`) and script (`.gd`) files.
|
||||
- Comment wrapping when using `fill-paragraph`.
|
||||
- Indentation and auto-indentation: tab-based (default) and space-based.
|
||||
- Automatic pairing of parentheses, brackets, etc.
|
||||
- Code formatting using [gdformat](https://github.com/scony/godot-gdscript-toolkit/).
|
||||
- Auto-completion for all the keywords in the `data/` directory.
|
||||
- Code formatting using
|
||||
[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.
|
||||
- Add treesit major mode support `gdscript-ts-mode` .
|
||||
|
||||
## How to install ##
|
||||

|
||||
|
||||
As it is in development, the package is not available yet on Emacs package managers.
|
||||
_Code folding in action._
|
||||
|
||||
To install it:
|
||||
## Contributing
|
||||
|
||||
1. Clone the repository to your computer.
|
||||
1. In your init.el file, add a call to load and require the package.
|
||||
Contributors are welcome! Check the [issues tab](issues) for tasks to work on and open a PR anytime.
|
||||
|
||||
```lisp
|
||||
(add-to-list 'load-path "/path/to/gdscript-mode.el")
|
||||
If you find a bug or would like to suggest an improvement, [open a new
|
||||
issue](issues/new).
|
||||
|
||||
For code style, we follow the [Emacs lisp style
|
||||
guide](https://github.com/bbatsov/emacs-lisp-style-guide) by Bozhidar Batsov,
|
||||
and the [tips and
|
||||
conventions](https://www.gnu.org/software/emacs/manual/html_node/elisp/Tips.html)
|
||||
from the Emacs manual.
|
||||
|
||||
You should also check for errors and linter warnings in your code. You can do so in Emacs with flymake or flycheck, but we recommend running the tool `Eask` provided with the repository:
|
||||
|
||||
This assumes you have [Eask](https://github.com/emacs-eask/cli) installed.
|
||||
|
||||
```sh
|
||||
eask compile
|
||||
```
|
||||
|
||||
This program will tell you if there is any problem with your code. If there's no output, everything is fine. You can run all tests like so, but note it might give you spelling errors that aren't relevant in this project:
|
||||
|
||||
```sh
|
||||
eask lint checkdoc && eask lint package
|
||||
```
|
||||
|
||||
## How to install
|
||||
|
||||
The package is available in the [MELPA](https://melpa.org/#/) package archive. Once you [set up MELPA](https://melpa.org/#/getting-started) you can install the package from Emacs:
|
||||
|
||||
```elisp
|
||||
M-x package-install gdscript-mode
|
||||
```
|
||||
|
||||
Then, in your init.el file, you can require the package:
|
||||
|
||||
```elisp
|
||||
(require 'gdscript-mode)
|
||||
```
|
||||
|
||||
### Installing in Spacemacs ###
|
||||
### Installing in Spacemacs
|
||||
|
||||
1. Clone the repository to the `private/local` subdirectory of your `.emacs.d` directory, where you installed spacemacs.
|
||||
2. Add the package to the `dotspacemacs-additional-packages` and mark it as local. That's Spacemacs' feature to make it easy to load locally installed packages.
|
||||
1. Add the package to the `dotspacemacs-additional-packages`. You can find it under the dotspacemacs/layers function:
|
||||
|
||||
```lisp
|
||||
dotspacemacs-additional-packages '((gdscript-mode :location local))
|
||||
```elisp
|
||||
(defun dotspacemacs/layers ()
|
||||
"Configuration Layers declaration..."
|
||||
(setq-default
|
||||
;; ...
|
||||
dotspacemacs-additional-packages '(gdscript-mode)
|
||||
;; ...
|
||||
))
|
||||
```
|
||||
|
||||
3. In your `dotspacemacs/user-config` function, require the package.
|
||||
2. In your `dotspacemacs/user-config` function, require the package.
|
||||
|
||||
```lisp
|
||||
```elisp
|
||||
(defun dotspacemacs/user-config ()
|
||||
(require 'gdscript-mode))
|
||||
```
|
||||
|
||||
### Installing in Doom Emacs ###
|
||||
### Installing in Doom Emacs
|
||||
|
||||
Add the following package definition to your `.doom.d/packages.el` file:
|
||||
Doom Emacs comes with a Godot GDScript module.
|
||||
|
||||
```lisp
|
||||
(package! gdscript-mode
|
||||
:recipe (:host github
|
||||
:repo "GDQuest/emacs-gdscript-mode"
|
||||
:files ("*.el" "data/*.txt")))
|
||||
You just need to add the "lang: gdscript" keyword to your `.doom.d/init.el` file.
|
||||
|
||||
```elisp
|
||||
:lang
|
||||
(gdscript +lsp) ; the language you waited for
|
||||
```
|
||||
|
||||
Require the package in your `.doom.d/config.el` file:
|
||||
The `+lsp` flag adds language server support for game development with Godot.
|
||||
|
||||
```lisp
|
||||
To see the module's documentation in Emacs, place your cursor over the word `gdscript` and press <kbd>k</kbd>.
|
||||
|
||||
### Installing with `use-package` + `straight.el`
|
||||
|
||||
Add the call to use-package to your Emacs configuration:
|
||||
|
||||
```elisp
|
||||
(use-package gdscript-mode
|
||||
:straight (gdscript-mode
|
||||
:type git
|
||||
:host github
|
||||
:repo "godotengine/emacs-gdscript-mode"))
|
||||
```
|
||||
|
||||
### Installing manually
|
||||
|
||||
1. Clone the repository or download a [stable release](https://github.com/godotengine/emacs-gdscript-mode/releases) to your computer.
|
||||
1. In your init.el file, add a call to load and require the package.
|
||||
|
||||
```elisp
|
||||
(add-to-list 'load-path "/path/to/gdscript-mode")
|
||||
(require 'gdscript-mode)
|
||||
```
|
||||
|
||||
## Formatting with gdformat ##
|
||||
## Auto-completion with the Language Server Protocol (LSP)
|
||||
|
||||
You can call the `gdscript-format` function to format the current buffer with `gdformat`. This feature requires the python package `gdtoolkit` to be installed and available on the system's PATH variable.
|
||||
For auto-completion, we rely on either the [eglot](https://github.com/joaotavora/eglot) or [lsp-mode](https://emacs-lsp.github.io/lsp-mode/) packages, and the GDScript language server which is built into Godot.
|
||||
|
||||
You can install gdtoolkit using the pip package manager from Python 3. Run this command in your shell to install it:
|
||||
To use the LSP with `eglot`, you need to install `eglot` on top of `gdscript-mode`, if using an Emacs version earlier than 29.
|
||||
After installation, `eglot` can be connected on startup by adding `eglot-ensure` as a hook on `gdscript-mode-hook`.
|
||||
|
||||
Note that, due to language server changes made in Godot 4, usage with Godot 3 requires `gdscript-eglot-version` to be customized to 3.
|
||||
|
||||
An example configuration for Godot 3 usage with `use-package`:
|
||||
|
||||
```elisp
|
||||
(use-package gdscript-mode
|
||||
:hook (gdscript-mode . eglot-ensure)
|
||||
:custom (gdscript-eglot-version 3))
|
||||
```
|
||||
|
||||
To use the LSP with `lsp-mode`, you need to install `lsp-mode` on top of `gdscript-mode` and configure it. To install and configure `lsp-mode`, see the [lsp-mode documentation](https://emacs-lsp.github.io/lsp-mode/page/installation/).
|
||||
|
||||
### Known issues
|
||||
|
||||
There are some known issues with the GDScript language server in Godot 3.2 due to the server being a bit young and not following the specification strictly. This mainly causes some `unknown notification` errors in lsp-mode at the moment. You can suppress them by adding the following code to your Emacs configuration (thanks to Franco Garcia for sharing this workaround):
|
||||
|
||||
```elisp
|
||||
(defun lsp--gdscript-ignore-errors (original-function &rest args)
|
||||
"Ignore the error message resulting from Godot not replying to the `JSONRPC' request."
|
||||
(if (string-equal major-mode "gdscript-mode")
|
||||
(let ((json-data (nth 0 args)))
|
||||
(if (and (string= (gethash "jsonrpc" json-data "") "2.0")
|
||||
(not (gethash "id" json-data nil))
|
||||
(not (gethash "method" json-data nil)))
|
||||
nil ; (message "Method not found")
|
||||
(apply original-function args)))
|
||||
(apply original-function args)))
|
||||
;; Runs the function `lsp--gdscript-ignore-errors` around `lsp--get-message-type` to suppress unknown notification errors.
|
||||
(advice-add #'lsp--get-message-type :around #'lsp--gdscript-ignore-errors)
|
||||
```
|
||||
|
||||
## Major mode with Treesit
|
||||
|
||||
[Treesit](https://github.com/tree-sitter/tree-sitter) is an incremental parsing system for programming tools.
|
||||
|
||||
This package has a major mode (gdscript-ts-mode). That supports the use tree-sitter for font-lock, imenu, indentation, and navigation of `gdscript` files.
|
||||
|
||||
Emacs version 29 or higher is required to use this mode.
|
||||
|
||||
### Install treesit
|
||||
|
||||
We need to install tree-sitter library, When under Arch Linux :
|
||||
|
||||
```sh
|
||||
sudo pacman -S tree-sitter
|
||||
```
|
||||
|
||||
### Install grammar
|
||||
|
||||
To support Gdscript, we must install [gdscript-grammar](https://github.com/PrestonKnopp/tree-sitter-gdscript.git):
|
||||
|
||||
```sh
|
||||
git clone https://github.com/PrestonKnopp/tree-sitter-gdscript.git
|
||||
cd tree-sitter-gdscript/src
|
||||
cc -std=c99 -c parser.c
|
||||
cc -c scanner.cc
|
||||
cc -shared parser.o scanner.o -o libtree-sitter-gdscript.so
|
||||
```
|
||||
|
||||
Additional directories to look for tree-sitter language definitions. ( DIR is your working path )
|
||||
|
||||
```emacs-lisp
|
||||
(setq treesit-extra-load-path '("DIR/tree-sitter-gdscript/src/"))
|
||||
```
|
||||
enjoy.
|
||||
|
||||
## How to use
|
||||
|
||||
### Opening the project in the editor
|
||||
|
||||
You can open the Godot editor with `M-x gdscript-godot-open-project-in-editor`, or open files and more in Godot with the `M-x gdscript-godot-*` commands.
|
||||
|
||||
By default, these commands try to use an executable named `godot` on the system [PATH environment variable](<https://en.wikipedia.org/wiki/PATH_(variable)>).
|
||||
|
||||
If you don't have `godot` available there, you can set a custom executable name or path to use instead:
|
||||
|
||||
```elisp
|
||||
(setq gdscript-godot-executable "/path/to/godot")
|
||||
```
|
||||
|
||||
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 turn off debug options, you need to call the command with the universal argument again.
|
||||
|
||||
### Using Hydra
|
||||
|
||||
Running `gdscript-hydra-show` (<kbd>C-c r</kbd>) opens a [hydra](https://github.com/abo-abo/hydra) popup with options to open the editor or run the project, a scene, or a script, including with visual debug options.
|
||||
|
||||

|
||||
|
||||
_Hydra interactive menu to run the project and set debug options on the fly._
|
||||
|
||||
### Formatting code with gdformat
|
||||
|
||||
You can call the `gdscript-format` function to format the current buffer with
|
||||
`gdformat`. Alternatively, `gdscript-format-all` will reformat all GDScript files in
|
||||
the project. This feature requires the python package `gdtoolkit` to be installed
|
||||
and available on the system's PATH variable.
|
||||
|
||||
You can install gdtoolkit using the pip package manager from Python 3. Run this
|
||||
command in your shell to install it:
|
||||
|
||||
```
|
||||
pip3 install gdtoolkit
|
||||
```
|
||||
|
||||
## Customization ##
|
||||
### Browsing the Godot API with eww
|
||||
|
||||
Set the following variables to customize gdscript-mode:
|
||||
With the point on a built-in class, you can press `C-c C-b 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).
|
||||
|
||||
```lisp
|
||||
(setq gdscript-tabs-mode t) ;; If true, use tabs for indents. Default: t
|
||||
(setq gdscript-tab-width 4) ;; Controls the width of tab-based indents
|
||||
To open the main API reference page and browse it, press `C-c C-b a`.
|
||||
|
||||
#### Using a local copy of the Godot docs
|
||||
|
||||
You can browse the API reference offline with `eww`. To do so:
|
||||
|
||||
1. Get a build of the official documentation. You can build it from the [godot docs repository](https://github.com/godotengine/godot-docs/) or [download a build](https://hugo.pro/projects/godot-builds/) from Hugo Lourcio's website.
|
||||
2. Set `gdscript-docs-local-path` to the docs' directory, that contains the docs' `index.html` file.
|
||||
|
||||
For example:
|
||||
|
||||
```elisp
|
||||
(setq gdscript-docs-local-path "/home/gdquest/Documents/docs/godot")
|
||||
```
|
||||
|
||||
## 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`
|
||||
- Open hydra:
|
||||
- <kbd>C-c r</kbd> `gdscript-hydra-show` (require hydra package to be installed)
|
||||
- <kbd>C-c n</kbd> `gdscript-debug-hydra` (require hydra package to be installed)
|
||||
|
||||
## Customization
|
||||
|
||||
To find all GDScript-mode settings, press `M-x customize` and search for "gdscript".
|
||||
|
||||
Code example:
|
||||
|
||||
```elisp
|
||||
(setq gdscript-use-tab-indents t) ;; If true, use tabs for indents. Default: t
|
||||
(setq gdscript-indent-offset 4) ;; Controls the width of tab-based indents
|
||||
(setq gdscript-godot-executable "/path/to/godot") ;; Use this executable instead of 'godot' to open the Godot editor.
|
||||
(setq gdscript-gdformat-save-and-format t) ;; Save all buffers and format them with gdformat anytime Godot executable is run.
|
||||
```
|
||||
|
||||
## Using the debugger
|
||||
|
||||
Emacs GDScript mode includes support for the GDScript debugger.
|
||||
|
||||
*The debugger in this package is only for Godot 3. Godot 4 supports the Debugger Adapter Procol (DAP), which you can use with the [dap-mode](https://github.com/emacs-lsp/dap-mode) package.*
|
||||
|
||||
You can use the debugger tools to manage breakpoints, step through code, and more.
|
||||
|
||||
To get started with this feature, you need to add a least one breakpoint.
|
||||
|
||||
### Adding and removing breakpoints
|
||||
|
||||
Like in Godot's editor, you can toggle a breakpoint on the current line with `gdscript-debug-toggle-breakpoint` (<kbd>F9</kbd>).
|
||||
|
||||
After adding at least one breakpoint to the project, a buffer named `* Breakpoints *` is created. This buffer displays all existing breakpoints in a project. In that buffer, pressing <kbd>D</kbd> on a breakpoint line deletes the breakpoint. Pressing <kbd>RET</kbd> opens the corresponding GDScript file in another buffer.
|
||||
|
||||
### Running the project with the debugger active
|
||||
|
||||
When any breakpoint exists, running the project with `gdscript-godot-run-project` will automatically start the debugger's server if one isn't already running and connect to it.
|
||||
|
||||
The debugger's server runs on `localhost` through port `6010` by default. You can customize the port with the `gdscript-debug-port` variable.
|
||||
|
||||
Once Godot hits a breakpoint, Emacs displays two new buffers:
|
||||
|
||||
- `* Stack frame vars *` displays the locals, members, and globals variables for the current stack point. It shows the variable name, its type, and its value.
|
||||
- `* Inspector *` displays detailed information about the selected object. By default, it shows the properties of `self`.
|
||||
|
||||
You can inspect any object in those two buffers by pressing <kbd>RET</kbd> on the corresponding line.
|
||||
|
||||
#### Multi-line display
|
||||
|
||||
You can toggle between one-line and multi-line display for values of type `Dictionary`, `PoolRealArray`, `PoolStringArray`, `PoolVector2Array`, `PoolVector3Array` and `PoolColorArray`. To do so, press `TAB` on the corresponding line.
|
||||
|
||||
### Fetching an object's details
|
||||
|
||||
Pressing <kbd>d</kbd> in `* Stack frame vars *` or `* Inspector *` buffers (or in the debug hydra) will fetch on the background data for all objects present in those two buffers and redisplay once done. Doing that adds two extra bits of information about the objects:
|
||||
|
||||
- Their real type, for example, `KinematicBody2D` instead of `ObjectId`.
|
||||
- Their node path.
|
||||
|
||||
### Debug Hydra
|
||||
|
||||
If `hydra` is available, the debug hydra displays below `* Stack frame vars *` and `* Inspector *` buffers upon hitting a breakpoint.
|
||||
|
||||
You can also call it by pressing <kbd>C-c n</kbd>.
|
||||
|
||||
```
|
||||
n next c continue m step b breakpoints s stack v vars i inspector t scene-tree d details
|
||||
o pin u unpin q quit
|
||||
```
|
||||
|
||||
- <kbd>n</kbd> - Steps to the next line of code.
|
||||
- <kbd>c</kbd> - Continue program execution until the next breakpoint.
|
||||
- <kbd>m</kbd> - Steps into the code.
|
||||
- <kbd>s</kbd> - Shows the `* Stack dump *` buffer.
|
||||
- <kbd>v</kbd> - Shows the `* Stack frame vars *` buffer.
|
||||
- <kbd>i</kbd> - Shows the `* Inspector *` buffer.
|
||||
- <kbd>t</kbd> - Shows the `* Scene tree *` buffer.
|
||||
- <kbd>d</kbd> - Fetches details for all object present in the `* Stack frame vars *` and `* Inspector *` buffers and redisplay the buffers.
|
||||
- <kbd>o</kbd> - Pins `self` in the `* Inspector *` buffer. It stays displayed until Godot frees the instance or you unpin it.
|
||||
- <kbd>u</kbd> - Unpins the currently pinned object.
|
||||
- <kbd>q</kbd> - Closes the debug hydra.
|
||||
|
||||
### The `* Stack frame vars *` buffer
|
||||
|
||||
The stack frame buffer displays the locals, members, and global variables for the current stack point. Here are available keyboard shortcuts:
|
||||
|
||||
- <kbd>TAB</kbd> toggles multi-line display for selected types.
|
||||
- <kbd>RET</kbd> on an object line to display its details in the `* Inspector *`buffer.
|
||||
- <kbd>l</kbd> displays the `* Stack dump *` buffer.
|
||||
- <kbd>d</kbd> displays additional details for `ObjectId` variables.
|
||||
- <kbd>p</kbd> goes to the previous line.
|
||||
- <kbd>n</kbd> goes to the next line.
|
||||
- <kbd>o</kbd> pins the current object in the `* Inspector *` buffer.
|
||||
- <kbd>u</kbd> unpins the currently pinned object.
|
||||
- <kbd>q</kbd> closes the buffer.
|
||||
|
||||
### `* Inspector *` buffer
|
||||
|
||||
Contains information about inspected object. By default `self` variable from `* Stack frame vars *` is displayed. The inspected object is kept in focus until you inspect another object or until the active object ceases to exists, in which case the current `self` is displayed instead.
|
||||
|
||||
- Press <kbd>TAB</kbd> to toggle multi-line display for selected typess.
|
||||
- Press <kbd>RET</kbd> on object line to display its detailss.
|
||||
- Press <kbd>RET</kbd> on `Node/path` line (second line from the top) to show given object in `* Scene Tree *` buffers.
|
||||
- Press <kbd>l</kbd> deep in nested object to navigate one level up in the structure (ie. back). Pressing `l` while on top-level object displays `* Stack frame vars *` buffers.
|
||||
- Press <kbd>d</kbd> to display additional details for object variabless.
|
||||
- Press <kbd>p</kbd> to go to the previous lines.
|
||||
- Press <kbd>n</kbd> to go to the next lines.
|
||||
- Press <kbd>o</kbd> to pin current object in `* Inspector *` buffers.
|
||||
- Press <kbd>u</kbd> to unpin currently pinned objects.
|
||||
- Press <kbd>q</kbd> to close the buffers.
|
||||
|
||||
### `* Stack dump *` buffer
|
||||
|
||||
Contains stack dump information.
|
||||
|
||||
- Press <kbd>SPC</kbd> to jump to gdscript file where stack frame points to.
|
||||
- Press <kbd>RET</kbd> to jump to the gdscript file and show `* Stack frame vars *`, `* Inspector *` buffers, and a debug hydra.
|
||||
- Press <kbd>l</kbd> to display the `* Stack frame vars *` buffer.
|
||||
- Press <kbd>p</kbd> to go to the previous line.
|
||||
- Press <kbd>n</kbd> to go to the next line.
|
||||
- Press <kbd>q</kbd> to close the buffer.
|
||||
|
||||
### `* Breakpoints *` buffer
|
||||
|
||||
Lists all existing breakpoints in the project.
|
||||
|
||||
- Press <kbd>SPC</kbd> to enable or disable all breakpoints.
|
||||
- Press <kbd>RET</kbd> to jump to the file and line corresponding to the breakpoint..
|
||||
- Press <kbd>TAB</kbd> to display the `* Stack dump *` buffer.
|
||||
- Press <kbd>D</kbd> to delete the breakpoint.
|
||||
- Press <kbd>q</kbd> to close the buffer.
|
||||
|
||||
### `* Scene tree *` buffer
|
||||
|
||||
Contains a tree visualisation of all objects in the running program.
|
||||
|
||||
- Press <kbd>RET</kbd> to open the corresponding object in the `* Inspector *` buffer.
|
||||
- Press <kbd>p</kbd> to go to the previous line.
|
||||
- Press <kbd>n</kbd> to go to the next line.
|
||||
- Press <kbd>q</kbd> to close the buffer.
|
||||
|
||||
BIN
assets/banner.png
Normal file
BIN
assets/banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
1
assets/banner.svg
Normal file
1
assets/banner.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 209 KiB |
BIN
assets/emacs-gdscript-code-folding.png
Normal file
BIN
assets/emacs-gdscript-code-folding.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
BIN
assets/emacs-gdscript-hydra.png
Normal file
BIN
assets/emacs-gdscript-hydra.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
BIN
assets/emacs-gdscript-imenu.png
Normal file
BIN
assets/emacs-gdscript-imenu.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 87 KiB |
@@ -1,557 +0,0 @@
|
||||
AABB
|
||||
AcceptDialog
|
||||
AnimatedSprite3D
|
||||
AnimatedSprite
|
||||
AnimatedTexture
|
||||
AnimationNodeAdd2
|
||||
AnimationNodeAdd3
|
||||
AnimationNodeAnimation
|
||||
AnimationNodeBlend2
|
||||
AnimationNodeBlend3
|
||||
AnimationNodeBlendSpace1D
|
||||
AnimationNodeBlendSpace2D
|
||||
AnimationNodeBlendTree
|
||||
AnimationNodeOneShot
|
||||
AnimationNodeOutput
|
||||
AnimationNodeStateMachinePlayback
|
||||
AnimationNodeStateMachineTransition
|
||||
AnimationNodeStateMachine
|
||||
AnimationNodeTimeScale
|
||||
AnimationNodeTimeSeek
|
||||
AnimationNodeTransition
|
||||
AnimationNode
|
||||
AnimationPlayer
|
||||
AnimationRootNode
|
||||
AnimationTrackEditPlugin
|
||||
AnimationTreePlayer
|
||||
AnimationTree
|
||||
Animation
|
||||
Area2D
|
||||
Area
|
||||
ArrayMesh
|
||||
Array
|
||||
ARVRAnchor
|
||||
ARVRCamera
|
||||
ARVRController
|
||||
ARVRInterface
|
||||
ARVROrigin
|
||||
ARVRPositionalTracker
|
||||
ARVRServer
|
||||
AStar2D
|
||||
AStar
|
||||
AtlasTexture
|
||||
AudioBusLayout
|
||||
AudioEffectAmplify
|
||||
AudioEffectBandLimitFilter
|
||||
AudioEffectBandPassFilter
|
||||
AudioEffectChorus
|
||||
AudioEffectCompressor
|
||||
AudioEffectDelay
|
||||
AudioEffectDistortion
|
||||
AudioEffectEQ10
|
||||
AudioEffectEQ21
|
||||
AudioEffectEQ6
|
||||
AudioEffectEQ
|
||||
AudioEffectFilter
|
||||
AudioEffectHighPassFilter
|
||||
AudioEffectHighShelfFilter
|
||||
AudioEffectInstance
|
||||
AudioEffectLimiter
|
||||
AudioEffectLowPassFilter
|
||||
AudioEffectLowShelfFilter
|
||||
AudioEffectNotchFilter
|
||||
AudioEffectPanner
|
||||
AudioEffectPhaser
|
||||
AudioEffectPitchShift
|
||||
AudioEffectRecord
|
||||
AudioEffectReverb
|
||||
AudioEffectSpectrumAnalyzerInstance
|
||||
AudioEffectSpectrumAnalyzer
|
||||
AudioEffectStereoEnhance
|
||||
AudioEffect
|
||||
AudioServer
|
||||
AudioStreamGeneratorPlayback
|
||||
AudioStreamGenerator
|
||||
AudioStreamMicrophone
|
||||
AudioStreamPlaybackResampled
|
||||
AudioStreamPlayback
|
||||
AudioStreamPlayer2D
|
||||
AudioStreamPlayer3D
|
||||
AudioStreamPlayer
|
||||
AudioStreamRandomPitch
|
||||
AudioStreamSample
|
||||
AudioStream
|
||||
BackBufferCopy
|
||||
BakedLightmapData
|
||||
BakedLightmap
|
||||
BaseButton
|
||||
Basis
|
||||
BitmapFont
|
||||
BitMap
|
||||
Bone2D
|
||||
BoneAttachment
|
||||
bool
|
||||
BoxContainer
|
||||
BoxShape
|
||||
ButtonGroup
|
||||
Button
|
||||
Camera2D
|
||||
CameraFeed
|
||||
CameraServer
|
||||
CameraTexture
|
||||
Camera
|
||||
CanvasItemMaterial
|
||||
CanvasItem
|
||||
CanvasLayer
|
||||
CanvasModulate
|
||||
CapsuleMesh
|
||||
CapsuleShape2D
|
||||
CapsuleShape
|
||||
CenterContainer
|
||||
CharFXTransform
|
||||
CheckBox
|
||||
CheckButton
|
||||
CircleShape2D
|
||||
ClassDB
|
||||
ClippedCamera
|
||||
CollisionObject2D
|
||||
CollisionObject
|
||||
CollisionPolygon2D
|
||||
CollisionPolygon
|
||||
CollisionShape2D
|
||||
CollisionShape
|
||||
ColorPickerButton
|
||||
ColorPicker
|
||||
ColorRect
|
||||
Color
|
||||
ConcavePolygonShape2D
|
||||
ConcavePolygonShape
|
||||
ConeTwistJoint
|
||||
ConfigFile
|
||||
ConfirmationDialog
|
||||
Container
|
||||
Control
|
||||
ConvexPolygonShape2D
|
||||
ConvexPolygonShape
|
||||
CPUParticles2D
|
||||
CPUParticles
|
||||
CryptoKey
|
||||
Crypto
|
||||
CubeMap
|
||||
CubeMesh
|
||||
Curve2D
|
||||
Curve3D
|
||||
CurveTexture
|
||||
Curve
|
||||
CylinderMesh
|
||||
CylinderShape
|
||||
DampedSpringJoint2D
|
||||
Dictionary
|
||||
DirectionalLight
|
||||
Directory
|
||||
DynamicFontData
|
||||
DynamicFont
|
||||
EditorExportPlugin
|
||||
EditorFeatureProfile
|
||||
EditorFileDialog
|
||||
EditorFileSystemDirectory
|
||||
EditorFileSystem
|
||||
EditorImportPlugin
|
||||
EditorInspectorPlugin
|
||||
EditorInspector
|
||||
EditorInterface
|
||||
EditorNavigationMeshGenerator
|
||||
EditorPlugin
|
||||
EditorProperty
|
||||
EditorResourceConversionPlugin
|
||||
EditorResourcePreviewGenerator
|
||||
EditorResourcePreview
|
||||
EditorSceneImporterAssimp
|
||||
EditorSceneImporter
|
||||
EditorScenePostImport
|
||||
EditorScript
|
||||
EditorSelection
|
||||
EditorSettings
|
||||
EditorSpatialGizmoPlugin
|
||||
EditorSpatialGizmo
|
||||
EditorSpinSlider
|
||||
EditorVCSInterface
|
||||
EncodedObjectAsID
|
||||
Engine
|
||||
Environment
|
||||
Expression
|
||||
FileDialog
|
||||
File
|
||||
float
|
||||
Font
|
||||
FuncRef
|
||||
Generic6DOFJoint
|
||||
GeometryInstance
|
||||
Geometry
|
||||
GIProbeData
|
||||
GIProbe
|
||||
@GlobalScope
|
||||
GradientTexture
|
||||
Gradient
|
||||
GraphEdit
|
||||
GraphNode
|
||||
GridContainer
|
||||
GrooveJoint2D
|
||||
HashingContext
|
||||
HBoxContainer
|
||||
HeightMapShape
|
||||
HingeJoint
|
||||
HScrollBar
|
||||
HSeparator
|
||||
HSlider
|
||||
HSplitContainer
|
||||
HTTPClient
|
||||
HTTPRequest
|
||||
ImageTexture
|
||||
Image
|
||||
ImmediateGeometry
|
||||
InputDefault
|
||||
InputEventAction
|
||||
InputEventGesture
|
||||
InputEventJoypadButton
|
||||
InputEventJoypadMotion
|
||||
InputEventKey
|
||||
InputEventMagnifyGesture
|
||||
InputEventMIDI
|
||||
InputEventMouseButton
|
||||
InputEventMouseMotion
|
||||
InputEventMouse
|
||||
InputEventPanGesture
|
||||
InputEventScreenDrag
|
||||
InputEventScreenTouch
|
||||
InputEventWithModifiers
|
||||
InputEvent
|
||||
InputMap
|
||||
Input
|
||||
InstancePlaceholder
|
||||
InterpolatedCamera
|
||||
int
|
||||
IP_Unix
|
||||
IP
|
||||
ItemList
|
||||
JavaScript
|
||||
Joint2D
|
||||
Joint
|
||||
JSONParseResult
|
||||
JSONRPC
|
||||
JSON
|
||||
KinematicBody2D
|
||||
KinematicBody
|
||||
KinematicCollision2D
|
||||
KinematicCollision
|
||||
Label
|
||||
LargeTexture
|
||||
Light2D
|
||||
LightOccluder2D
|
||||
Light
|
||||
Line2D
|
||||
LineEdit
|
||||
LineShape2D
|
||||
LinkButton
|
||||
Listener
|
||||
MainLoop
|
||||
MarginContainer
|
||||
Marshalls
|
||||
Material
|
||||
MenuButton
|
||||
MeshDataTool
|
||||
MeshInstance2D
|
||||
MeshInstance
|
||||
MeshLibrary
|
||||
MeshTexture
|
||||
Mesh
|
||||
MultiMeshInstance2D
|
||||
MultiMeshInstance
|
||||
MultiMesh
|
||||
MultiplayerAPI
|
||||
Mutex
|
||||
Navigation2D
|
||||
NavigationMeshInstance
|
||||
NavigationMesh
|
||||
NavigationPolygonInstance
|
||||
NavigationPolygon
|
||||
Navigation
|
||||
NetworkedMultiplayerPeer
|
||||
Nil
|
||||
NinePatchRect
|
||||
Node2D
|
||||
NodePath
|
||||
Node
|
||||
Object
|
||||
OccluderPolygon2D
|
||||
OmniLight
|
||||
OptionButton
|
||||
OS
|
||||
PackedDataContainerRef
|
||||
PackedDataContainer
|
||||
PackedScene
|
||||
PacketPeerStream
|
||||
PacketPeerUDP
|
||||
PacketPeer
|
||||
PanelContainer
|
||||
Panel
|
||||
PanoramaSky
|
||||
ParallaxBackground
|
||||
ParallaxLayer
|
||||
Particles2D
|
||||
ParticlesMaterial
|
||||
Particles
|
||||
Path2D
|
||||
PathFollow2D
|
||||
PathFollow
|
||||
Path
|
||||
PCKPacker
|
||||
Performance
|
||||
PHashTranslation
|
||||
PhysicalBone
|
||||
Physics2DDirectBodyStateSW
|
||||
Physics2DDirectBodyState
|
||||
Physics2DDirectSpaceState
|
||||
Physics2DServerSW
|
||||
Physics2DServer
|
||||
Physics2DShapeQueryParameters
|
||||
Physics2DShapeQueryResult
|
||||
Physics2DTestMotionResult
|
||||
PhysicsBody2D
|
||||
PhysicsBody
|
||||
PhysicsDirectBodyState
|
||||
PhysicsDirectSpaceState
|
||||
PhysicsMaterial
|
||||
PhysicsServer
|
||||
PhysicsShapeQueryParameters
|
||||
PhysicsShapeQueryResult
|
||||
PinJoint2D
|
||||
PinJoint
|
||||
PlaneMesh
|
||||
PlaneShape
|
||||
Plane
|
||||
PointMesh
|
||||
Polygon2D
|
||||
PolygonPathFinder
|
||||
PoolByteArray
|
||||
PoolColorArray
|
||||
PoolIntArray
|
||||
PoolRealArray
|
||||
PoolStringArray
|
||||
PoolVector2Array
|
||||
PoolVector3Array
|
||||
PopupDialog
|
||||
PopupMenu
|
||||
PopupPanel
|
||||
Popup
|
||||
Position2D
|
||||
Position3D
|
||||
PrimitiveMesh
|
||||
PrismMesh
|
||||
ProceduralSky
|
||||
ProgressBar
|
||||
ProjectSettings
|
||||
ProximityGroup
|
||||
ProxyTexture
|
||||
QuadMesh
|
||||
Quat
|
||||
RandomNumberGenerator
|
||||
Range
|
||||
RayCast2D
|
||||
RayCast
|
||||
RayShape2D
|
||||
RayShape
|
||||
Rect2
|
||||
RectangleShape2D
|
||||
ReferenceRect
|
||||
Reference
|
||||
ReflectionProbe
|
||||
RemoteTransform2D
|
||||
RemoteTransform
|
||||
ResourceFormatLoaderCrypto
|
||||
ResourceFormatLoader
|
||||
ResourceFormatSaverCrypto
|
||||
ResourceFormatSaver
|
||||
ResourceImporter
|
||||
ResourceInteractiveLoader
|
||||
ResourceLoader
|
||||
ResourcePreloader
|
||||
ResourceSaver
|
||||
Resource
|
||||
RichTextEffect
|
||||
RichTextLabel
|
||||
RID
|
||||
RigidBody2D
|
||||
RigidBody
|
||||
RootMotionView
|
||||
SceneState
|
||||
SceneTreeTimer
|
||||
SceneTree
|
||||
ScriptCreateDialog
|
||||
ScriptEditor
|
||||
Script
|
||||
ScrollBar
|
||||
ScrollContainer
|
||||
SegmentShape2D
|
||||
|
||||
Semaphore
|
||||
Separator
|
||||
ShaderMaterial
|
||||
Shader
|
||||
Shape2D
|
||||
Shape
|
||||
ShortCut
|
||||
Skeleton2D
|
||||
SkeletonIK
|
||||
Skeleton
|
||||
SkinReference
|
||||
Skin
|
||||
Sky
|
||||
SliderJoint
|
||||
Slider
|
||||
SoftBody
|
||||
SpatialGizmo
|
||||
SpatialMaterial
|
||||
SpatialVelocityTracker
|
||||
Spatial
|
||||
SphereMesh
|
||||
SphereShape
|
||||
SpinBox
|
||||
SplitContainer
|
||||
SpotLight
|
||||
SpringArm
|
||||
Sprite3D
|
||||
SpriteBase3D
|
||||
SpriteFrames
|
||||
Sprite
|
||||
StaticBody2D
|
||||
StaticBody
|
||||
StreamPeerBuffer
|
||||
StreamPeerSSL
|
||||
StreamPeerTCP
|
||||
StreamPeer
|
||||
StreamTexture
|
||||
String
|
||||
StyleBoxEmpty
|
||||
StyleBoxFlat
|
||||
StyleBoxLine
|
||||
StyleBoxTexture
|
||||
StyleBox
|
||||
SurfaceTool
|
||||
TabContainer
|
||||
Tabs
|
||||
TCP_Server
|
||||
TextEdit
|
||||
TextFile
|
||||
Texture3D
|
||||
TextureArray
|
||||
TextureButton
|
||||
TextureLayered
|
||||
TextureProgress
|
||||
TextureRect
|
||||
Texture
|
||||
Theme
|
||||
Thread
|
||||
TileMap
|
||||
TileSet
|
||||
Timer
|
||||
ToolButton
|
||||
TouchScreenButton
|
||||
Transform2D
|
||||
Transform
|
||||
TranslationServer
|
||||
Translation
|
||||
TreeItem
|
||||
Tree
|
||||
TriangleMesh
|
||||
Tween
|
||||
UndoRedo
|
||||
Variant
|
||||
VBoxContainer
|
||||
Vector2
|
||||
Vector3
|
||||
VehicleBody
|
||||
VehicleWheel
|
||||
VideoPlayer
|
||||
VideoStream
|
||||
ViewportContainer
|
||||
ViewportTexture
|
||||
Viewport
|
||||
VisibilityEnabler2D
|
||||
VisibilityEnabler
|
||||
VisibilityNotifier2D
|
||||
VisibilityNotifier
|
||||
VisualInstance
|
||||
VisualServer
|
||||
VisualShaderNodeBooleanConstant
|
||||
VisualShaderNodeBooleanUniform
|
||||
VisualShaderNodeColorConstant
|
||||
VisualShaderNodeColorFunc
|
||||
VisualShaderNodeColorOp
|
||||
VisualShaderNodeColorUniform
|
||||
VisualShaderNodeCompare
|
||||
VisualShaderNodeCubeMapUniform
|
||||
VisualShaderNodeCubeMap
|
||||
VisualShaderNodeCustom
|
||||
VisualShaderNodeDeterminant
|
||||
VisualShaderNodeDotProduct
|
||||
VisualShaderNodeExpression
|
||||
VisualShaderNodeFaceForward
|
||||
VisualShaderNodeFresnel
|
||||
VisualShaderNodeGlobalExpression
|
||||
VisualShaderNodeGroupBase
|
||||
VisualShaderNodeIf
|
||||
VisualShaderNodeInput
|
||||
VisualShaderNodeIs
|
||||
VisualShaderNodeOuterProduct
|
||||
VisualShaderNodeOutput
|
||||
VisualShaderNodeScalarClamp
|
||||
VisualShaderNodeScalarConstant
|
||||
VisualShaderNodeScalarDerivativeFunc
|
||||
VisualShaderNodeScalarFunc
|
||||
VisualShaderNodeScalarInterp
|
||||
VisualShaderNodeScalarOp
|
||||
VisualShaderNodeScalarSmoothStep
|
||||
VisualShaderNodeScalarSwitch
|
||||
VisualShaderNodeScalarUniform
|
||||
VisualShaderNodeSwitch
|
||||
VisualShaderNodeTextureUniformTriplanar
|
||||
VisualShaderNodeTextureUniform
|
||||
VisualShaderNodeTexture
|
||||
VisualShaderNodeTransformCompose
|
||||
VisualShaderNodeTransformConstant
|
||||
VisualShaderNodeTransformDecompose
|
||||
VisualShaderNodeTransformFunc
|
||||
VisualShaderNodeTransformMult
|
||||
VisualShaderNodeTransformUniform
|
||||
VisualShaderNodeTransformVecMult
|
||||
VisualShaderNodeUniform
|
||||
VisualShaderNodeVec3Constant
|
||||
VisualShaderNodeVec3Uniform
|
||||
VisualShaderNodeVectorClamp
|
||||
VisualShaderNodeVectorCompose
|
||||
VisualShaderNodeVectorDecompose
|
||||
VisualShaderNodeVectorDerivativeFunc
|
||||
VisualShaderNodeVectorDistance
|
||||
VisualShaderNodeVectorFunc
|
||||
VisualShaderNodeVectorInterp
|
||||
VisualShaderNodeVectorLen
|
||||
VisualShaderNodeVectorOp
|
||||
VisualShaderNodeVectorRefract
|
||||
VisualShaderNodeVectorScalarMix
|
||||
VisualShaderNodeVectorScalarSmoothStep
|
||||
VisualShaderNodeVectorScalarStep
|
||||
VisualShaderNodeVectorSmoothStep
|
||||
VisualShaderNode
|
||||
VisualShader
|
||||
VScrollBar
|
||||
VSeparator
|
||||
VSlider
|
||||
VSplitContainer
|
||||
WeakRef
|
||||
WindowDialog
|
||||
World2D
|
||||
WorldEnvironment
|
||||
World
|
||||
X509Certificate
|
||||
XMLParser
|
||||
@@ -1,4 +0,0 @@
|
||||
PI
|
||||
TAU
|
||||
INF
|
||||
NAN
|
||||
@@ -1,70 +0,0 @@
|
||||
sin
|
||||
cos
|
||||
tan
|
||||
sinh
|
||||
cosh
|
||||
tanh
|
||||
asin
|
||||
acos
|
||||
atan
|
||||
atan2
|
||||
sqrt
|
||||
fmod
|
||||
fposmod
|
||||
floor
|
||||
ceil
|
||||
round
|
||||
abs
|
||||
sign
|
||||
pow
|
||||
log
|
||||
exp
|
||||
is_nan
|
||||
is_inf
|
||||
ease
|
||||
decimals
|
||||
stepify
|
||||
lerp
|
||||
dectime
|
||||
randomize
|
||||
randi
|
||||
randf
|
||||
rand_range
|
||||
seed
|
||||
rand_seed
|
||||
deg2rad
|
||||
rad2deg
|
||||
linear2db
|
||||
db2linear
|
||||
max
|
||||
min
|
||||
clamp
|
||||
nearest_po2
|
||||
weakref
|
||||
funcref
|
||||
convert
|
||||
typeof
|
||||
type_exists
|
||||
char
|
||||
str
|
||||
print
|
||||
printt
|
||||
prints
|
||||
printerr
|
||||
printraw
|
||||
var2str
|
||||
str2var
|
||||
var2bytes
|
||||
bytes2var
|
||||
range
|
||||
load
|
||||
inst2dict
|
||||
dict2inst
|
||||
hash
|
||||
Color8
|
||||
print_stack
|
||||
instance_from_id
|
||||
preload
|
||||
yield
|
||||
assert
|
||||
name
|
||||
@@ -1,5 +0,0 @@
|
||||
null
|
||||
void
|
||||
bool
|
||||
int
|
||||
float
|
||||
@@ -1,36 +0,0 @@
|
||||
if
|
||||
elif
|
||||
else
|
||||
for
|
||||
do
|
||||
while
|
||||
match
|
||||
switch
|
||||
case
|
||||
break
|
||||
continue
|
||||
pass
|
||||
return
|
||||
class
|
||||
class_name
|
||||
extends
|
||||
is
|
||||
self
|
||||
tool
|
||||
signal
|
||||
func
|
||||
static
|
||||
const
|
||||
enum
|
||||
var
|
||||
onready
|
||||
export
|
||||
setget
|
||||
breakpoint
|
||||
preload
|
||||
yield
|
||||
assert
|
||||
remote
|
||||
master
|
||||
slave
|
||||
sync
|
||||
111
gdscript-comint-gdformat.el
Normal file
111
gdscript-comint-gdformat.el
Normal file
@@ -0,0 +1,111 @@
|
||||
;;; gdscript-comint-gdformat.el --- gdformat mode based on comint mode -*- lexical-binding: t; -*-
|
||||
;;
|
||||
;; Copyright (C) 2020 GDQuest and contributors
|
||||
;;
|
||||
;; Author: Josef Vlach <vlach.josef@gmail.com>
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: June 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:
|
||||
;;
|
||||
;; gdformat-mode for handling stdout and stderr from gdformat executable.
|
||||
;;
|
||||
;; It supports quick navigation from errors to file location.
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(require 'ansi-color)
|
||||
(require 'comint)
|
||||
(require 'compile)
|
||||
(require 'gdscript-customization)
|
||||
(require 'gdscript-utils)
|
||||
|
||||
(defvar gdscript-comint-gdformat--mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(set-keymap-parent map
|
||||
(make-composed-keymap compilation-shell-minor-mode-map
|
||||
comint-mode-map))
|
||||
(define-key map (kbd "C-c r") 'gdscript-hydra-show)
|
||||
map)
|
||||
"Basic mode map for `gdformat-mode'.")
|
||||
|
||||
(defun gdscript-comint-gdformat--sentinel (process event)
|
||||
"Display result of formatting if gdformat PROCESS exited abnormal EVENT."
|
||||
(when (string-match "exited abnormally" event)
|
||||
(pop-to-buffer (process-buffer process))))
|
||||
|
||||
(defun gdscript-comint-gdformat--run (arguments)
|
||||
"Run gdformat in comint mode.
|
||||
|
||||
ARGUMENTS are command line arguments for gdformat executable.
|
||||
When run it will kill existing process if one exists."
|
||||
(let ((buffer-name (gdscript-util--get-gdformat-buffer-name))
|
||||
(inhibit-read-only t))
|
||||
|
||||
(when (not (executable-find gdscript-gdformat-executable))
|
||||
(error "Error: Could not find %s on PATH. Please customize the gdscript-gdformat-executable variable" gdscript-gdformat-executable))
|
||||
|
||||
(with-current-buffer (get-buffer-create buffer-name)
|
||||
(unless (derived-mode-p 'gdformat-mode)
|
||||
(gdformat-mode)
|
||||
(buffer-disable-undo))
|
||||
(erase-buffer)
|
||||
(let* ((line-length (list (format "--line-length=%s" gdscript-gdformat-line-length)))
|
||||
(buffer (comint-exec (current-buffer) buffer-name gdscript-gdformat-executable nil (append line-length arguments))))
|
||||
(set-process-sentinel (get-buffer-process buffer) 'gdscript-comint-gdformat--sentinel)
|
||||
buffer))))
|
||||
|
||||
(define-derived-mode gdformat-mode comint-mode "gdformat"
|
||||
"Major mode for gdformat.
|
||||
|
||||
\\{gdscript-comint-gdformat--mode-map}"
|
||||
(use-local-map gdscript-comint-gdformat--mode-map)
|
||||
(add-hook 'gdformat-mode-hook 'gdscript-comint-gdformat--initialize-for-comint-mode)
|
||||
(add-hook 'gdformat-mode-hook 'gdscript-comint-gdformat--initialize-for-compilation-mode))
|
||||
|
||||
(defun gdscript-comint-gdformat--initialize-for-comint-mode ()
|
||||
"Initialize buffer for comint mode support."
|
||||
(when (derived-mode-p 'comint-mode)
|
||||
(setq comint-process-echoes nil)
|
||||
(setq-local comint-buffer-maximum-size 4096)
|
||||
(setq-local comint-output-filter-functions '(ansi-color-process-output comint-postoutput-scroll-to-bottom))
|
||||
(setq ansi-color-for-comint-mode t)))
|
||||
|
||||
(defun gdscript-comint-gdformat--failed-file-name()
|
||||
"Find corresponding buffer name for error message: 'at line x col y'."
|
||||
(save-excursion
|
||||
(save-match-data
|
||||
(re-search-backward "exception during formatting of \\(.*\\)")
|
||||
(match-string-no-properties 1))))
|
||||
|
||||
(defun gdscript-comint-gdformat--initialize-for-compilation-mode ()
|
||||
"Initialize buffer for compilation mode support."
|
||||
(setq-local
|
||||
compilation-error-regexp-alist
|
||||
'(("at line \\([[:digit:]]+\\) col \\([[:digit:]]+\\)" gdscript-comint-gdformat--failed-file-name 1 2 nil nil)
|
||||
("exception during formatting of \\(.*\\)$" 1 nil nil nil 1)
|
||||
("reformatted \\(.*\\)$" 1 nil nil nil 1)))
|
||||
(setq-local compilation-mode-font-lock-keywords nil)
|
||||
(compilation-setup t))
|
||||
|
||||
(provide 'gdscript-comint-gdformat)
|
||||
;;; gdscript-comint-gdformat.el ends here
|
||||
128
gdscript-comint.el
Normal file
128
gdscript-comint.el
Normal file
@@ -0,0 +1,128 @@
|
||||
;;; gdscript-comint.el --- Support for comint mode -*- lexical-binding: t; -*-
|
||||
;;
|
||||
;; Copyright (C) 2020 GDQuest and contributors
|
||||
;;
|
||||
;; Author: Josef Vlach <vlach.josef@gmail.com>
|
||||
;; URL: https://github.com/godotengine/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:
|
||||
;;
|
||||
;; godot-mode for handling stdout and stderr from godot executable.
|
||||
;;
|
||||
;; It supports quick navigation from errors to file location.
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(require 'ansi-color)
|
||||
(require 'comint)
|
||||
(require 'compile)
|
||||
(require 'gdscript-customization)
|
||||
(require 'gdscript-debug)
|
||||
(require 'gdscript-format)
|
||||
(require 'gdscript-utils)
|
||||
|
||||
(defvar gdscript-comint--mode-map
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(set-keymap-parent map
|
||||
(make-composed-keymap compilation-shell-minor-mode-map
|
||||
comint-mode-map))
|
||||
(define-key map (kbd "C-a") 'comint-bol)
|
||||
(define-key map (kbd "C-c r") 'gdscript-hydra-show)
|
||||
(define-key map (kbd "C-c n") 'gdscript-debug-hydra)
|
||||
map)
|
||||
"Basic mode map for `godot-mode'.")
|
||||
|
||||
(defun gdscript-comint--run (arguments)
|
||||
"Run godot in comint mode.
|
||||
|
||||
ARGUMENTS are command line arguments for godot executable.
|
||||
When run it will kill existing process if one exists."
|
||||
(let ((buffer-name (gdscript-util--get-godot-buffer-name (member "-e" arguments)))
|
||||
(inhibit-read-only t)
|
||||
(godot-command gdscript-godot-executable))
|
||||
|
||||
;; support flatpak
|
||||
(when (string-match-p (rx "run" (+ space) "org.godotengine.Godot") godot-command)
|
||||
(let ((exec-split (split-string godot-command)))
|
||||
(setq godot-command (car exec-split))
|
||||
(setq arguments (append (cdr exec-split) arguments))))
|
||||
|
||||
(if (not (or (file-executable-p godot-command)
|
||||
(executable-find godot-command)))
|
||||
(error "Error: Could not execute '%s'. Please customize the `gdscript-godot-executable variable'" gdscript-godot-executable)
|
||||
(with-current-buffer (get-buffer-create buffer-name)
|
||||
(when gdscript-gdformat-save-and-format
|
||||
(gdscript-comint-gdformat--modified-buffers))
|
||||
(unless (derived-mode-p 'godot-mode)
|
||||
(godot-mode)
|
||||
(buffer-disable-undo))
|
||||
(erase-buffer)
|
||||
(comint-exec (current-buffer) buffer-name godot-command nil arguments)
|
||||
(set-process-sentinel (get-buffer-process (current-buffer)) 'gdscript-comint--sentinel)
|
||||
(pop-to-buffer (current-buffer))))))
|
||||
|
||||
(defun gdscript-comint--sentinel (process event)
|
||||
"Custom sentinel for PROCESS and EVENT.
|
||||
|
||||
Set process's buffer `inhibit-read-only' temporalily to value t,
|
||||
so that `internal-default-process-sentinel' can insert status
|
||||
message into the process’s buffer."
|
||||
(cond
|
||||
((string-match "hangup: 1\n" event)
|
||||
nil)
|
||||
(t
|
||||
(with-current-buffer (process-buffer process)
|
||||
(let ((inhibit-read-only t))
|
||||
(internal-default-process-sentinel process event))))))
|
||||
|
||||
(define-derived-mode godot-mode comint-mode "godot"
|
||||
"Major mode for godot.
|
||||
|
||||
\\{gdscript-comint--mode-map}"
|
||||
(use-local-map gdscript-comint--mode-map)
|
||||
(add-hook 'godot-mode-hook 'gdscript-comint--initialize-for-comint-mode)
|
||||
(add-hook 'godot-mode-hook 'gdscript-comint--initialize-for-compilation-mode))
|
||||
|
||||
(defun gdscript-comint--initialize-for-comint-mode ()
|
||||
"Initialize buffer for comint mode support."
|
||||
(when (derived-mode-p 'comint-mode)
|
||||
(setq comint-process-echoes nil)
|
||||
(setq comint-prompt-regexp "^debug> ")
|
||||
(setq-local comint-use-prompt-regexp t)
|
||||
(setq-local comint-prompt-read-only t)
|
||||
(setq-local comint-buffer-maximum-size 4096)
|
||||
(setq-local comint-output-filter-functions '(ansi-color-process-output comint-postoutput-scroll-to-bottom))
|
||||
(setq ansi-color-for-comint-mode t)))
|
||||
|
||||
(defun gdscript-comint--initialize-for-compilation-mode ()
|
||||
"Initialize buffer for compilation mode support."
|
||||
(setq-local
|
||||
compilation-error-regexp-alist
|
||||
'(
|
||||
("^ At: res://\\([-_[:word:]\/]+.gd\\):\\([[:digit:]]+\\)." 1 2 nil 2 1)
|
||||
("^*Frame [[:digit:]]+ - res://\\([-_[:word:]\/]+.gd\\):\\([[:digit:]]+\\)." 1 2 nil 2 1)))
|
||||
(setq-local compilation-mode-font-lock-keywords nil)
|
||||
(compilation-setup t))
|
||||
|
||||
(provide 'gdscript-comint)
|
||||
;;; gdscript-comint.el ends here
|
||||
@@ -1,11 +1,11 @@
|
||||
;;; gdscript-completion.el --- Autocompletion for GDScript -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2020 GDQuest
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>, Fabián E. Gallina <fgallina@gnu.org>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 0.1.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Feb 2020
|
||||
;; Keywords: languages
|
||||
@@ -23,7 +23,7 @@
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; For a full copy of the GNU General Public License
|
||||
;; see <http://www.gnu.org/licenses/>.
|
||||
;; see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
;;; Commentary:
|
||||
@@ -33,8 +33,13 @@
|
||||
;;; Code:
|
||||
|
||||
(require 'gdscript-syntax)
|
||||
(require 'gdscript-utils)
|
||||
(require 'projectile nil t)
|
||||
|
||||
(defvar-local gdscript-completion--all-keywords (append gdscript-keywords gdscript-built-in-classes gdscript-built-in-constants gdscript-built-in-functions gdscript-built-in-types))
|
||||
(defvar-local gdscript-completion--all-keywords
|
||||
(eval-when-compile (append gdscript-keywords gdscript-built-in-classes
|
||||
gdscript-built-in-constants gdscript-built-in-functions
|
||||
gdscript-built-in-types)))
|
||||
|
||||
(defun gdscript-completion-at-point ()
|
||||
"This is the function to be used for the hook `completion-at-point-functions'."
|
||||
@@ -45,6 +50,39 @@
|
||||
(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))
|
||||
(when-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)))
|
||||
(resource-path
|
||||
(if has-projectile
|
||||
file
|
||||
(concat (gdscript-util--get-godot-project-file-path-relative file)
|
||||
"." (file-name-extension file)))))
|
||||
(insert (concat "\"res://" resource-path "\"")))))
|
||||
|
||||
|
||||
(provide 'gdscript-completion)
|
||||
|
||||
;;; gdscript-completion.el ends here
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
;;; gdscript-customization.el --- Customizable variables for the GDScript language support -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2020 GDQuest
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 0.1.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Jan 2020
|
||||
;; Keywords: languages
|
||||
@@ -24,7 +24,7 @@
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; For a full copy of the GNU General Public License
|
||||
;; see <http://www.gnu.org/licenses/>.
|
||||
;; see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
;;; Commentary:
|
||||
@@ -41,8 +41,8 @@
|
||||
|
||||
(defcustom gdscript-use-type-hints t
|
||||
"If t, inserted snippets contain type hints."
|
||||
:group 'gdscript
|
||||
:type 'boolean)
|
||||
:type 'boolean
|
||||
:group 'gdscript)
|
||||
|
||||
;; gdscript-indent
|
||||
(defcustom gdscript-use-tab-indents t "Use tabs (t) or spaces (nil)."
|
||||
@@ -54,49 +54,110 @@
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-indent-offset 4 "Default indentation offset for Gdscript."
|
||||
:group 'gdscript
|
||||
:type 'integer
|
||||
:safe 'integerp)
|
||||
|
||||
(defcustom gdscript-indent-guess-indent-offset
|
||||
t "If t, tells GDScript mode to guess `gdscript-indent-offset' value."
|
||||
:type 'boolean
|
||||
:group 'gdscript
|
||||
:safe 'booleanp)
|
||||
|
||||
(defcustom gdscript-indent-guess-indent-offset-verbose
|
||||
t "If t, emit a warning when guessing indentation fails."
|
||||
:version "25.1"
|
||||
:type 'boolean
|
||||
:group 'gdscript
|
||||
:safe 'booleanp)
|
||||
:safe 'integerp
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-indent-trigger-commands '(indent-for-tab-command yas-expand yas/expand)
|
||||
"Commands that might trigger a `gdscript-indent-line' call."
|
||||
:type '(repeat symbol):group'gdscript)
|
||||
:type '(repeat symbol)
|
||||
:group'gdscript)
|
||||
|
||||
;; gdscript-fill-paragraph.el
|
||||
(defcustom gdscript-fill-comment-function 'gdscript-fill-paragraph-fill-comment
|
||||
(defcustom gdscript-fill-comment-function 'gdscript-fill-paragraph-fill-comment
|
||||
"Function to fill comments.
|
||||
This is the function used by `gdscript-fill-paragraph' to
|
||||
fill comments."
|
||||
:type 'symbol
|
||||
:group 'gdscript)
|
||||
|
||||
|
||||
(defcustom gdscript-fill-string-function 'gdscript-fill-paragraph-fill-string
|
||||
"Function to fill strings.
|
||||
This is the function used by `gdscript-fill-paragraph' to
|
||||
fill strings."
|
||||
:type 'symbol
|
||||
:group 'gdscript)
|
||||
|
||||
:group 'gdscript)
|
||||
(defcustom gdscript-fill-paren-function 'gdscript-fill-paragraph-fill-paren
|
||||
"Function to fill parens.
|
||||
This is the function used by `gdscript-fill-paragraph' to
|
||||
fill parens."
|
||||
:type 'symbol
|
||||
:group 'gdscript)
|
||||
|
||||
:type 'symbol
|
||||
(defcustom gdscript-indent-def-block-scale 2
|
||||
"Multiplier applied to indentation inside multi-line def blocks."
|
||||
:version "26.1"
|
||||
:type 'integer
|
||||
:safe 'natnump
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-indent-line-continuation-scale 1
|
||||
"Multiplier applied to indentation of line continuation in
|
||||
general (inside parentheses and after backslash)."
|
||||
:type 'integer
|
||||
:options '(1 2)
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-godot-executable "godot"
|
||||
"The godot executable which is either a full path such as '~/bin/godot2.2'
|
||||
or the name of an executable on the system PATH (usually 'godot')"
|
||||
: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)
|
||||
|
||||
(defcustom gdscript-gdformat-line-length 100
|
||||
"How many characters per line to allow when formatting gdscript by gdformat."
|
||||
:type 'integer
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-gdformat-save-and-format nil
|
||||
"If t, save all modified buffers and format them with gdformat.
|
||||
It happens anytime Godot executable is run. Formatting runs on background,
|
||||
so it is not slowing down Godot execution."
|
||||
:type 'boolean
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-docs-force-online-lookup nil
|
||||
"If true, calling commands like gdscript-docs-browse-api
|
||||
browses the online API reference, even if a local copy is
|
||||
available."
|
||||
:type 'boolean
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-docs-use-eww t
|
||||
"If set to false use the emacs configurable `browse-url'
|
||||
function rather than `eww' directly. `browse-url' can be
|
||||
configured to open the desktop default GUI browser, for example,
|
||||
via the variable `browse-url-browser-function'"
|
||||
:type 'boolean
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-docs-local-path ""
|
||||
"Optional path to a local build of the Godot documentation.
|
||||
If not set to an empty string, the commands `gdscript-docs-browse-api'
|
||||
and `gdscript-docs-browse-symbol-at-point' allow you to browse the local files.
|
||||
Must be the root directory of the website, that is to say, a
|
||||
directory path containing the file `index.html'."
|
||||
:type 'string
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-docs-online-search-api-url "https://docs.godotengine.org/en/stable/search.html?q=%s&check_keywords=yes&area=default"
|
||||
"Online Godot API search url"
|
||||
:type 'string
|
||||
:group 'gdscript)
|
||||
|
||||
(defcustom gdscript-debug-port 6010
|
||||
"Debugger server port."
|
||||
:type 'integer
|
||||
:group 'gdscript)
|
||||
|
||||
|
||||
(provide 'gdscript-customization)
|
||||
;;; gdscript-customization.el ends here
|
||||
|
||||
2444
gdscript-debug.el
Normal file
2444
gdscript-debug.el
Normal file
File diff suppressed because it is too large
Load Diff
138
gdscript-docs.el
Normal file
138
gdscript-docs.el
Normal file
@@ -0,0 +1,138 @@
|
||||
;;; 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/godotengine/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)
|
||||
(require 'gdscript-customization)
|
||||
|
||||
(defun gdscript-docs-open (url &rest _)
|
||||
"when `gdscript-docs-use-eww' is true use `eww' else use `browse-url'"
|
||||
(if gdscript-docs-use-eww
|
||||
(if (file-exists-p url) (eww-open-file url) (eww-browse-url url t))
|
||||
(browse-url url)))
|
||||
|
||||
;;;###autoload
|
||||
(defun gdscript-docs-browse-api (&optional force-online)
|
||||
"Open the main page of Godot API. Use the universal prefix (C-u) to force browsing the online API."
|
||||
(interactive)
|
||||
(if (and (or gdscript-docs-force-online-lookup current-prefix-arg force-online) (string= gdscript-docs-local-path ""))
|
||||
(gdscript-docs-open "https://docs.godotengine.org/en/stable/classes/index.html?#godot-api")
|
||||
(let ((file (concat (file-name-as-directory gdscript-docs-local-path) "classes/index.html")))
|
||||
(if (file-exists-p file)
|
||||
(gdscript-docs-open file)
|
||||
(message "\"%s\" not found" file)))))
|
||||
|
||||
(defun gdscript-docs-browse-symbol-at-point (&optional force-online)
|
||||
"Open the API reference for the symbol at point in the browser eww.
|
||||
If a page is already open, switch to its buffer. Use local docs if gdscripts-docs-local-path set. Use the universal prefix (C-u) to force browsing the online API."
|
||||
(interactive)
|
||||
|
||||
(let* ((symbol-at-point (thing-at-point 'symbol t))
|
||||
(symbol (if symbol-at-point (downcase symbol-at-point) ""))
|
||||
(buffer (if (not gdscript-docs-use-eww) nil
|
||||
(seq-find
|
||||
(lambda (current-buffer)
|
||||
(with-current-buffer current-buffer
|
||||
(when (derived-mode-p 'eww-mode)
|
||||
(string-suffix-p symbol (string-remove-suffix ".html" (plist-get eww-data :url)) t))))
|
||||
(buffer-list)))))
|
||||
(if buffer (pop-to-buffer-same-window buffer)
|
||||
(if (string= "" symbol)
|
||||
(message "No symbol at point or open API reference buffers.")
|
||||
(if (and (not gdscript-docs-force-online-lookup) (not (or current-prefix-arg force-online)) (not (string= gdscript-docs-local-path "")))
|
||||
(let ((file (concat (file-name-as-directory gdscript-docs-local-path) (file-name-as-directory "classes") "class_" symbol ".html")))
|
||||
(if (file-exists-p file)
|
||||
(gdscript-docs-open file)
|
||||
(message "No local API help for \"%s\"." symbol)))
|
||||
(let ((url (format "https://docs.godotengine.org/en/stable/classes/class_%s.html#%s" symbol symbol)))
|
||||
(gdscript-docs-open url)))))))
|
||||
|
||||
(defun gdscript-docs-online-search-api (&optional sym)
|
||||
"Search Godot docs online. Use the universal prefix (C-u) to prompt for search term."
|
||||
(interactive)
|
||||
(let ((symbol (if current-prefix-arg (read-string "API Search: ") (or sym (thing-at-point 'symbol t) ""))))
|
||||
(browse-url (format gdscript-docs-online-search-api-url (downcase symbol)))))
|
||||
|
||||
|
||||
(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."
|
||||
(when (string-match "docs.godotengine" (plist-get eww-data :url))
|
||||
(setq multi-isearch-next-buffer-function nil)
|
||||
(gdscript-docs--rename-eww-buffer)
|
||||
(gdscript-docs--filter-content-to-main-div)))
|
||||
|
||||
(advice-add 'eww-follow-link :around #'gdscript-docs--eww-follow-link)
|
||||
(add-hook 'eww-after-render-hook #'gdscript-docs--eww-setup)
|
||||
|
||||
(provide 'gdscript-docs)
|
||||
|
||||
;;; gdscript-docs.el ends here
|
||||
81
gdscript-eglot.el
Normal file
81
gdscript-eglot.el
Normal file
@@ -0,0 +1,81 @@
|
||||
;;; gdscript-eglot.el --- Integration with eglot -*- lexical-binding: t; -*-
|
||||
;;
|
||||
;; Copyright (C) 2023 GDQuest and contributors
|
||||
;;
|
||||
;; Author: Ruijie Yu <ruijie@netyu.xyz>
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: June 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:
|
||||
;;
|
||||
;; Handles the configuraiton of eglot.
|
||||
;; This supports `gdscript-mode' using `eglot'.
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
;;;###autoload
|
||||
(defgroup gdscript-eglot nil
|
||||
"Configurations in gdscript related to `eglot'."
|
||||
:group 'gdscript)
|
||||
|
||||
;;;###autoload
|
||||
(defcustom gdscript-eglot-version 4
|
||||
"The version of godot in use."
|
||||
:type 'integer)
|
||||
|
||||
;;;###autoload
|
||||
(defun gdscript-eglot-contact (_interactive)
|
||||
"Attempt to help `eglot' contact the running gdscript LSP.
|
||||
Returns a list (HOST PORT) if successful, nil otherwise. See the
|
||||
last definition of CONTACT in `eglot-server-programs' for
|
||||
definitions of HOST, PORT, and INTERACTIVE.
|
||||
|
||||
For more context, see
|
||||
https://lists.gnu.org/archive/html/bug-gnu-emacs/2023-04/msg01070.html."
|
||||
(save-excursion
|
||||
(let* ((cfg-dir (or (getenv "XDG_CONFIG_HOME")
|
||||
(pcase system-type
|
||||
('darwin "~/Library/Application Support/Godot/")
|
||||
('windows-nt "%APPDATA%\\Godot\\")
|
||||
('gnu/linux "~/.config/"))))
|
||||
(cfg-buffer
|
||||
(find-file-noselect
|
||||
(expand-file-name
|
||||
(format "godot/editor_settings-%d.tres"
|
||||
gdscript-eglot-version)
|
||||
cfg-dir)))
|
||||
(port
|
||||
(with-current-buffer cfg-buffer
|
||||
(goto-char 0)
|
||||
(and
|
||||
(re-search-forward
|
||||
(rx "network/language_server/remote_port"
|
||||
(* space) ?= (* space)
|
||||
(group (+ digit)))
|
||||
nil t)
|
||||
(string-to-number (match-string 1))))))
|
||||
(kill-buffer cfg-buffer)
|
||||
;; then return the host-port list when found
|
||||
(and port (list "localhost" port)))))
|
||||
|
||||
(provide 'gdscript-eglot)
|
||||
;;; gdscript-eglot.el ends here.
|
||||
@@ -1,11 +1,11 @@
|
||||
;;; gdscript-fill-paragraph.el --- GDScript fill paragraph functions -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2020 GDQuest
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 0.1.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Jan 2020
|
||||
;; Keywords: languages
|
||||
@@ -24,7 +24,7 @@
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; For a full copy of the GNU General Public License
|
||||
;; see <http://www.gnu.org/licenses/>.
|
||||
;; see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
;;; Commentary:
|
||||
@@ -35,11 +35,11 @@
|
||||
|
||||
(require 'gdscript-customization)
|
||||
(require 'gdscript-indent-and-nav)
|
||||
(require 'gdscript-rx)
|
||||
|
||||
;; NOTE: this and the fill docstring function can be simplified. They're
|
||||
;; originally from the Python package, which supports multiple docstrings fill
|
||||
;; style.
|
||||
(setq-local delimiters-style (cons nil 1))
|
||||
|
||||
(defun gdscript-fill-paragraph (&optional justify)
|
||||
"`fill-paragraph-function' handling multi-line strings and possibly comments.
|
||||
@@ -60,8 +60,7 @@ Optional argument JUSTIFY defines if the paragraph should be justified."
|
||||
(funcall gdscript-fill-string-function justify))
|
||||
;; Decorators
|
||||
((equal (char-after (save-excursion
|
||||
(gdscript-nav-beginning-of-statement))) ?@)
|
||||
(funcall gdscript-fill-decorator-function justify))
|
||||
(gdscript-nav-beginning-of-statement))) ?@))
|
||||
;; Parens
|
||||
((or (gdscript-syntax-context 'paren)
|
||||
(looking-at (gdscript-rx open-paren))
|
||||
@@ -94,39 +93,12 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'."
|
||||
(or (re-search-forward (rx (syntax string-delimiter)) nil t)
|
||||
(goto-char (point-max)))
|
||||
(point-marker)))
|
||||
(multi-line-p
|
||||
;; Docstring styles may vary for oneliners and multi-liners.
|
||||
(> (count-matches "\n" str-start-pos str-end-pos) 0))
|
||||
(fill-paragraph-function))
|
||||
|
||||
(save-restriction
|
||||
(narrow-to-region str-start-pos str-end-pos)
|
||||
(fill-paragraph justify))
|
||||
(save-excursion
|
||||
(when (and (gdscript-info-docstring-p) gdscript-fill-triple-string-style)
|
||||
;; Add the number of newlines indicated by the selected style
|
||||
;; at the start of the docstring.
|
||||
(goto-char (+ str-start-pos num-quotes))
|
||||
(delete-region (point) (progn
|
||||
(skip-syntax-forward "> ")
|
||||
(point)))
|
||||
(and (car delimiters-style)
|
||||
(or (newline (car delimiters-style)) t)
|
||||
;; Indent only if a newline is added.
|
||||
(indent-according-to-mode))
|
||||
;; Add the number of newlines indicated by the selected style
|
||||
;; at the end of the docstring.
|
||||
(goto-char (if (not (= str-end-pos (point-max)))
|
||||
(- str-end-pos num-quotes)
|
||||
str-end-pos))
|
||||
(delete-region (point) (progn
|
||||
(skip-syntax-backward "> ")
|
||||
(point)))
|
||||
(and (cdr delimiters-style)
|
||||
;; Add newlines only if string ends.
|
||||
(not (= str-end-pos (point-max)))
|
||||
(or (newline (cdr delimiters-style)) t)
|
||||
;; Again indent only if a newline is added.
|
||||
(indent-according-to-mode))))) t)
|
||||
(fill-paragraph justify)
|
||||
t)))
|
||||
|
||||
(defun gdscript-fill-paragraph-fill-paren (&optional justify)
|
||||
"Paren fill function for `gdscript-fill-paragraph'.
|
||||
@@ -137,9 +109,9 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'."
|
||||
(goto-char (1- (point))))
|
||||
(line-beginning-position))
|
||||
(progn
|
||||
(when (not (gdscript-syntax-context 'paren))
|
||||
(unless (gdscript-syntax-context 'paren)
|
||||
(end-of-line)
|
||||
(when (not (gdscript-syntax-context 'paren))
|
||||
(unless (gdscript-syntax-context 'paren)
|
||||
(skip-syntax-backward "^)")))
|
||||
(while (and (gdscript-syntax-context 'paren)
|
||||
(not (eobp)))
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
;; Copyright (C) 2020 GDQuest, Pawel Lampe
|
||||
|
||||
;; Author: Pawel Lampe <pawel.lampe@gmail.com>, Nathan Lovato <nathan@gdquest.com>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Feb 2020
|
||||
;; Keywords: languages
|
||||
@@ -31,62 +31,72 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defun gdscript-format--run-gdformat (buffer-input buffer-output buffer-error)
|
||||
"Call gdformat process."
|
||||
(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))))
|
||||
(require 'gdscript-comint-gdformat)
|
||||
|
||||
(defun gdscript-format-buffer ()
|
||||
"Formats current buffer using 'gdformat'."
|
||||
(defmacro gdscript-format--save-buffer (&rest body)
|
||||
"Execute the forms in BODY if current buffer is gdscript.
|
||||
|
||||
It also activates `auto-revert-mode' and saves the buffer if is it modified."
|
||||
(declare (indent 1) (debug t))
|
||||
`(when (and (buffer-file-name)
|
||||
(string-match ".*.gd$" (buffer-file-name)))
|
||||
(unless (bound-and-true-p auto-revert-mode)
|
||||
(auto-revert-mode))
|
||||
(when (buffer-modified-p)
|
||||
(save-buffer))
|
||||
,@body))
|
||||
|
||||
(defmacro gdscript-format--with-gdscripts (gdscript-buffers &rest body)
|
||||
"Execute the forms in BODY with GDSCRIPT-BUFFERS containing all gdscript buffers currently open."
|
||||
(declare (indent 1) (debug t))
|
||||
`(progn
|
||||
(dolist (buffer (buffer-list))
|
||||
(with-current-buffer buffer
|
||||
(gdscript-format--save-buffer
|
||||
(push (buffer-file-name) ,gdscript-buffers))))
|
||||
,@body))
|
||||
|
||||
(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-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 current buffer using `gdformat'."
|
||||
(interactive)
|
||||
(gdscript-format--save-buffer
|
||||
(gdscript-comint-gdformat--run (list (buffer-file-name)))))
|
||||
|
||||
(defun gdscript-comint-gdformat--modified-buffers ()
|
||||
"Save and format all modified buffers using `gdformat'."
|
||||
(let ((gdscript-buffers))
|
||||
(gdscript-format--with-gdscripts gdscript-buffers
|
||||
(when gdscript-buffers
|
||||
(gdscript-comint-gdformat--run gdscript-buffers)))))
|
||||
|
||||
(defun gdscript-format-all()
|
||||
"Save modified buffers and then format all gdscripts in the project."
|
||||
(interactive)
|
||||
(let ((gdscript-buffers))
|
||||
(gdscript-format--with-gdscripts gdscript-buffers
|
||||
(let* ((rl (gdscript-util--find-project-configuration-file))
|
||||
(gdscript-file-list (directory-files-recursively rl ".*.gd$" t)))
|
||||
(let ((all-gdscripts (delete-dups (append gdscript-file-list gdscript-buffers))))
|
||||
(when all-gdscripts
|
||||
(pop-to-buffer (gdscript-comint-gdformat--run all-gdscripts))))))))
|
||||
|
||||
(provide 'gdscript-format)
|
||||
|
||||
|
||||
183
gdscript-godot.el
Normal file
183
gdscript-godot.el
Normal file
@@ -0,0 +1,183 @@
|
||||
;;; gdscript-godot.el --- Open and run projects in Godot -*- lexical-binding: t; -*-
|
||||
;;
|
||||
;; Copyright (C) 2020 GDQuest and contributors
|
||||
;;
|
||||
;; Author: Franco Eusébio Garcia <francoegarcia@outlook.com>, Nathan Lovato <nathan@gdquest.com>
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Mar 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:
|
||||
;;
|
||||
;; Open files, projects, and run commands in the Godot engine or editor.
|
||||
;; This package contains commands that runs Godot processes.
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(require 'gdscript-comint)
|
||||
(require 'gdscript-customization)
|
||||
(require 'gdscript-debug)
|
||||
(require 'gdscript-history)
|
||||
(require 'gdscript-project)
|
||||
(require 'gdscript-utils)
|
||||
|
||||
;;;###autoload
|
||||
(defvar gdscript-godot--debug-options-hydra :not-list)
|
||||
|
||||
(defvar gdscript-godot--debug-selected-option 1)
|
||||
|
||||
(defvar gdscript-godot--debug-options-alist
|
||||
'((1 . ())
|
||||
(2 . ("--debug-collisions"))
|
||||
(3 . ("--debug-navigation"))
|
||||
(4 . ("--debug-collisions" "--debug-navigation"))))
|
||||
|
||||
(defmacro gdscript-godot--debug-options-handler (debug-options &rest body)
|
||||
"Execute the forms in BODY with DEBUG-OPTIONS being set.
|
||||
|
||||
DEBUG-OPTIONS will be set either by Hydra, or by prefix argument selection."
|
||||
(declare (indent 1) (debug t))
|
||||
`(let* ((debug-option-index
|
||||
(if current-prefix-arg
|
||||
(gdscript-godot--change-debug-options)
|
||||
gdscript-godot--debug-selected-option))
|
||||
(prefix-options (cdr (assoc debug-option-index gdscript-godot--debug-options-alist)))
|
||||
(use-hydra-options (listp gdscript-godot--debug-options-hydra)) ;; gdscript-godot--debug-options-hydra is a list when run from hydra
|
||||
(,debug-options (if use-hydra-options gdscript-godot--debug-options-hydra prefix-options)))
|
||||
,@body))
|
||||
|
||||
(defun gdscript-godot--run-command (&rest arguments)
|
||||
"Run a Godot process with ARGUMENTS.
|
||||
|
||||
The output of the process will be provided in a buffer named
|
||||
`*godot - <project-name>*'."
|
||||
(let ((args (gdscript-util--flatten arguments)))
|
||||
(gdscript-history--add-to-history args)
|
||||
(when (and gdscript-debug--breakpoints (not (member "-e" arguments)))
|
||||
;; Start debugger server if it is not running already
|
||||
(unless (get-process (gdscript-debug-process-name (gdscript-util--find-project-configuration-file)))
|
||||
(gdscript-debug-make-server))
|
||||
(push (mapconcat (lambda (breakpoint)
|
||||
(let ((file (gdscript-breakpoint->file breakpoint))
|
||||
(line (gdscript-breakpoint->line breakpoint)))
|
||||
(format "%s:%s" file line))) gdscript-debug--breakpoints ",") args)
|
||||
(push "--breakpoints" args)
|
||||
(push (format "127.0.0.1:%s" gdscript-debug-port) args)
|
||||
(push "--remote-debug" args))
|
||||
(gdscript-comint--run (append (gdscript-godot--build-shell-command) args))
|
||||
(setq gdscript-godot--debug-options-hydra :not-list)))
|
||||
|
||||
(defun gdscript-godot--build-shell-command (&optional path)
|
||||
"Build a shell command to with the Godot executable.
|
||||
|
||||
If PATH is not provided, try to find it using the current
|
||||
file's directory as starting point."
|
||||
(let ((project-path (or path (gdscript-util--find-project-configuration-file))))
|
||||
(list "--path" project-path)))
|
||||
|
||||
(defun gdscript-godot-open-project-in-editor ()
|
||||
"Run Godot Engine Editor."
|
||||
(interactive)
|
||||
(gdscript-godot--run-command "-e"))
|
||||
|
||||
(defun gdscript-godot-run-project ()
|
||||
"Run the current project in Godot Engine."
|
||||
(interactive)
|
||||
(gdscript-godot--run-command))
|
||||
|
||||
(defun gdscript-godot-run-project-debug ()
|
||||
"Run the current project in Godot Engine.
|
||||
|
||||
When run with prefix argument, it offers extra debug options to choose from."
|
||||
(interactive)
|
||||
(gdscript-godot--debug-options-handler debug-options
|
||||
(gdscript-godot--run-command "-d" debug-options)))
|
||||
|
||||
(defun gdscript-godot-run-current-scene ()
|
||||
"Run the current script file in Godot Engine. Use the universal prefix (C-u) to force a scene select."
|
||||
(interactive)
|
||||
(let ((scene (gdscript-godot--select-scene current-prefix-arg)))
|
||||
(when scene
|
||||
(gdscript-godot--run-command scene))))
|
||||
|
||||
(defun gdscript-godot-run-current-scene-debug ()
|
||||
"Run the current script file in Godot Engine.
|
||||
|
||||
When run with prefix argument, it offers extra debug options to choose from."
|
||||
(interactive)
|
||||
(let ((scene (gdscript-godot--select-scene current-prefix-arg)))
|
||||
(when scene
|
||||
(gdscript-godot--debug-options-handler debug-options
|
||||
(gdscript-godot--run-command "-d" debug-options scene)))))
|
||||
|
||||
(defun gdscript-godot-edit-current-scene ()
|
||||
"Run the current script file in Godot Engine."
|
||||
(interactive)
|
||||
(let ((scene (gdscript-godot--select-scene current-prefix-arg)))
|
||||
(when scene
|
||||
(gdscript-godot--run-command "-e" scene))))
|
||||
|
||||
(defun gdscript-godot--select-scene (&optional select-scene)
|
||||
"Select scene to run"
|
||||
(if select-scene
|
||||
(gdscript-project--select-scene)
|
||||
(let ((scene-name (gdscript-project--current-buffer-scene)))
|
||||
(if scene-name scene-name
|
||||
(gdscript-project--select-scene)))))
|
||||
|
||||
(defun gdscript-godot-run-current-script ()
|
||||
"Run the current script file in Godot Engine.
|
||||
|
||||
For this to work, the script must inherit either from
|
||||
\"SceneTree\" or \"MainLoop\"."
|
||||
(interactive)
|
||||
(let ((script-name (gdscript-project--current-buffer-script)))
|
||||
(if script-name
|
||||
(gdscript-godot--run-script script-name)
|
||||
(gdscript-project--get-all-scripts))))
|
||||
|
||||
(defun gdscript-godot--run-script (script-name)
|
||||
"Run SCRIPT-NAME script in Godot Engine."
|
||||
(gdscript-godot--run-command "-s" script-name))
|
||||
|
||||
(defun gdscript-godot--debug-options-to-string (index)
|
||||
"Return debug options from `gdscript-godot--debug-options-alist' for given INDEX as a string."
|
||||
(mapconcat 'identity (cdr (assoc index gdscript-godot--debug-options-alist)) " "))
|
||||
|
||||
(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" " ") (gdscript-godot--debug-options-to-string 2))
|
||||
(format "3) [%s] %s" (if (eq gdscript-godot--debug-selected-option 3) "X" " ") (gdscript-godot--debug-options-to-string 3))
|
||||
(format "4) [%s] %s" (if (eq gdscript-godot--debug-selected-option 4) "X" " ") (gdscript-godot--debug-options-to-string 4))))
|
||||
|
||||
(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-util--read (gdscript-godot--debug-options-collection)))
|
||||
(index (string-to-number option)))
|
||||
(setq gdscript-godot--debug-selected-option index)))
|
||||
|
||||
(provide 'gdscript-godot)
|
||||
;;; gdscript-godot.el ends here
|
||||
94
gdscript-history.el
Normal file
94
gdscript-history.el
Normal file
@@ -0,0 +1,94 @@
|
||||
;;; gdscript-history.el --- History -*- lexical-binding: t; -*-
|
||||
;;
|
||||
;; Copyright (C) 2020 GDQuest and contributors
|
||||
;;
|
||||
;; Author: Josef Vlach <vlach.josef@gmail.com>
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: June 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:
|
||||
;;
|
||||
;; Keep history of commands for later quick execution.
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(require 'gdscript-utils)
|
||||
|
||||
(defvar gdscript-history--previous-arguments-plist nil
|
||||
"Holds history of commands per project.")
|
||||
|
||||
(defmacro gdscript-history--with-project-history (project-history &rest body)
|
||||
"Execute the forms in BODY with PROJECT-HISTORY being set.
|
||||
|
||||
PROJECT-HISTORY will be history of current project."
|
||||
(declare (indent 1) (debug t))
|
||||
`(let* ((property (gdscript-util--find-project-configuration-file))
|
||||
(,project-history (lax-plist-get gdscript-history--previous-arguments-plist property)))
|
||||
,@body))
|
||||
|
||||
(defun gdscript-history--add-to-history (arguments)
|
||||
"Add ARGUMENTS to history for current project."
|
||||
(gdscript-history--with-project-history history
|
||||
(push arguments history)
|
||||
(delete-dups history)
|
||||
(setq gdscript-history--previous-arguments-plist
|
||||
(lax-plist-put gdscript-history--previous-arguments-plist property history))))
|
||||
|
||||
(defun gdscript-history--last-command ()
|
||||
"Return last command from history."
|
||||
(gdscript-history--with-project-history history
|
||||
(car history)))
|
||||
|
||||
(defun gdscript-history--line-data (command)
|
||||
"Pretty print COMMAND."
|
||||
(let* ((flat (gdscript-util--flatten command))
|
||||
(l (car (last flat))))
|
||||
(cond ((string-suffix-p ".tscn" l)
|
||||
(progn
|
||||
(string-match "\\(.*/\\)?\\(.*\\).tscn$" l)
|
||||
(list (format "Scene %s.tscn: %s " (match-string-no-properties 2 l) l) (butlast command))))
|
||||
((string-suffix-p ".gd" l)
|
||||
(progn
|
||||
(string-match "\\(.*/\\)?\\(.*\\).gd$" l)
|
||||
(list (format "Script %s.gd: %s " (match-string-no-properties 2 l) l) (butlast command))))
|
||||
(t
|
||||
(list (format "Project %s: " (gdscript-util--get-godot-project-name)) command)))))
|
||||
|
||||
(defun gdscript-history--line (command idx)
|
||||
"Render COMMAND as string starting with index IDX."
|
||||
(let* ((index (number-to-string (1+ idx)))
|
||||
(data (gdscript-history--line-data command))
|
||||
(name (car data))
|
||||
(args (cadr data)))
|
||||
(string-trim (concat index ") " name (mapconcat 'identity args " ")))))
|
||||
|
||||
(defun gdscript-history--select-from-history ()
|
||||
"Choose command from history."
|
||||
(gdscript-history--with-project-history history
|
||||
(let* ((history-data (seq-map-indexed #'gdscript-history--line history))
|
||||
(selected (gdscript-util--read history-data "Run again"))
|
||||
(index (string-to-number selected)))
|
||||
(nth (1- index) history))))
|
||||
|
||||
(provide 'gdscript-history)
|
||||
|
||||
;;; gdscript-history.el ends here
|
||||
157
gdscript-hydra.el
Normal file
157
gdscript-hydra.el
Normal file
@@ -0,0 +1,157 @@
|
||||
;;; gdscript-hydra.el --- Hydra for launching Godot -*- lexical-binding: t; -*-
|
||||
;;
|
||||
;; Copyright (C) 2020 GDQuest and contributors
|
||||
;;
|
||||
;; Author: Josef Vlach <vlach.josef@gmail.com>
|
||||
;; URL: https://github.com/godotengine/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:
|
||||
;;
|
||||
;; Hydra for launching Godot. It offers options to launch Godot in debug mode or open editor or run the script.
|
||||
;;
|
||||
;; When running in debug mode it offers two additional flags to pass to Godot:
|
||||
;; --debug-collisions
|
||||
;; --debug-navigation
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(require 'hydra nil t)
|
||||
(require 'gdscript-format)
|
||||
(require 'gdscript-godot)
|
||||
(require 'gdscript-history)
|
||||
(require 'gdscript-utils)
|
||||
|
||||
;;;###autoload
|
||||
(defvar gdscript-hydra--open nil)
|
||||
(defvar gdscript-hydra--debug nil)
|
||||
(defvar gdscript-hydra--editor nil)
|
||||
(defvar gdscript-hydra--debug-collisions nil)
|
||||
(defvar gdscript-hydra--debug-navigation nil)
|
||||
(defvar gdscript-hydra--hydra nil)
|
||||
|
||||
(defun gdscript-hydra-show ()
|
||||
"Show gdcript hydra."
|
||||
(interactive)
|
||||
(gdscript-util--with-available-hydra
|
||||
(unless gdscript-hydra--hydra
|
||||
(setq gdscript-hydra--hydra (gdscript-hydra--create)))
|
||||
(funcall gdscript-hydra--hydra)))
|
||||
|
||||
(defun gdscript-hydra--selected (selected)
|
||||
"Visual representation for (non)SELECTED checkboxes."
|
||||
(if selected "x" " "))
|
||||
|
||||
(defun gdscript-hydra--dispatch (run-default run-debug run-editor)
|
||||
"Run Godot with selected flag.
|
||||
|
||||
RUN-DEFAULT is a function to call when neither debug or scene flag
|
||||
is selected in hydra.
|
||||
RUN-DEBUG is a function to call when debug flag is selected in hydra.
|
||||
RUN-EDITOR is a function to call when editor flag is selected in hydra."
|
||||
(cond
|
||||
((and (not gdscript-hydra--debug)
|
||||
(not gdscript-hydra--editor)) (funcall run-default))
|
||||
(gdscript-hydra--debug (funcall run-debug))
|
||||
(gdscript-hydra--editor (funcall run-editor))))
|
||||
|
||||
(defun gdscript-hydra--run (project-or-scene)
|
||||
"Dispatcher from hydra heads to gdscript-godot-* commands.
|
||||
|
||||
PROJECT-OR-SCENE is symbol representing scene, project or script.
|
||||
It is setting variable `gdscript-godot--debug-options-hydra' based
|
||||
on hydra checkboxes."
|
||||
(setq gdscript-godot--debug-options-hydra
|
||||
(remove nil
|
||||
(list
|
||||
(when gdscript-hydra--debug-collisions "--debug-collisions")
|
||||
(when gdscript-hydra--debug-navigation "--debug-navigation"))))
|
||||
|
||||
(pcase project-or-scene
|
||||
(:project (gdscript-hydra--dispatch 'gdscript-godot-run-project
|
||||
'gdscript-godot-run-project-debug
|
||||
'gdscript-godot-open-project-in-editor))
|
||||
(:scene (gdscript-hydra--dispatch 'gdscript-godot-run-current-scene
|
||||
'gdscript-godot-run-current-scene-debug
|
||||
'gdscript-godot-edit-current-scene))
|
||||
(:script (gdscript-godot-run-current-script))))
|
||||
|
||||
(defun gdscript-hydra--open-godot-buffer ()
|
||||
"Find buffer named *godot - <project-name>* and if it exists open it in other window."
|
||||
(let* ((current-name (buffer-name (current-buffer)))
|
||||
(godot-buffer-name (gdscript-util--get-godot-buffer-name)))
|
||||
(unless (string= godot-buffer-name current-name)
|
||||
(let ((godot-buffer (seq-find
|
||||
(lambda (current-buffer)
|
||||
(with-current-buffer current-buffer
|
||||
(equal (buffer-name) godot-buffer-name))) (buffer-list))))
|
||||
(when godot-buffer (switch-to-buffer-other-window godot-buffer))))))
|
||||
|
||||
(defun gdscript-hydra--run-last ()
|
||||
"Run last command from history."
|
||||
(gdscript-godot--run-command (gdscript-history--last-command)))
|
||||
|
||||
(defun gdscript-hydra--select-from-history ()
|
||||
"Choose command to run from history of commands."
|
||||
(gdscript-godot--run-command (gdscript-history--select-from-history)))
|
||||
|
||||
(defun gdscript-hydra--create ()
|
||||
(defhydra gdscript-hydra--menu (:hint none
|
||||
:body-pre (setq gdscript-hydra--open t)
|
||||
:before-exit (setq gdscript-hydra--open nil))
|
||||
"
|
||||
_d_ (?d?) Debug _p_ run project _t_ run script _h_ run from history _a_ format all _q_ quit
|
||||
_e_ (?e?) Editor _s_ run scene _r_ run last _g_ switch to *godot* _b_ format buffer
|
||||
|
||||
_c_ [?c?] Visible collisions shapes
|
||||
_n_ [?n?] Visible navigation
|
||||
"
|
||||
("d" (progn
|
||||
(setq gdscript-hydra--debug (not gdscript-hydra--debug)
|
||||
gdscript-hydra--editor nil)
|
||||
(unless gdscript-hydra--debug
|
||||
(setq
|
||||
gdscript-hydra--debug-collisions nil
|
||||
gdscript-hydra--debug-navigation nil))) (gdscript-hydra--selected gdscript-hydra--debug))
|
||||
("e" (setq gdscript-hydra--editor (not gdscript-hydra--editor)
|
||||
gdscript-hydra--debug nil
|
||||
gdscript-hydra--debug-collisions nil
|
||||
gdscript-hydra--debug-navigation nil) (gdscript-hydra--selected gdscript-hydra--editor))
|
||||
("p" (gdscript-hydra--run :project))
|
||||
("s" (gdscript-hydra--run :scene))
|
||||
("t" (gdscript-hydra--run :script))
|
||||
("r" (gdscript-hydra--run-last))
|
||||
("h" (gdscript-hydra--select-from-history))
|
||||
("c" (setq gdscript-hydra--debug-collisions (not gdscript-hydra--debug-collisions)
|
||||
gdscript-hydra--debug t
|
||||
gdscript-hydra--editor nil) (gdscript-hydra--selected gdscript-hydra--debug-collisions))
|
||||
("n" (setq gdscript-hydra--debug-navigation (not gdscript-hydra--debug-navigation)
|
||||
gdscript-hydra--debug t
|
||||
gdscript-hydra--editor nil) (gdscript-hydra--selected gdscript-hydra--debug-navigation))
|
||||
("g" (gdscript-hydra--open-godot-buffer) :color blue)
|
||||
("a" (gdscript-format-all))
|
||||
("b" (gdscript-format-buffer))
|
||||
("q" nil)))
|
||||
|
||||
(provide 'gdscript-hydra)
|
||||
|
||||
;;; gdscript-hydra.el ends here
|
||||
@@ -1,11 +1,11 @@
|
||||
;;; gdscript-imenu.el --- Imenu support for GDScript -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2020 GDQuest
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>, Fabián E. Gallina <fgallina@gnu.org>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Feb 2020
|
||||
;; Keywords: languages
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'gdscript-indent-and-nav)
|
||||
|
||||
(defvar gdscript-imenu-format-item-label-function
|
||||
'gdscript-imenu-format-item-label
|
||||
"Imenu function used to format an item label.
|
||||
@@ -177,8 +179,8 @@ To this:
|
||||
(or alist
|
||||
(let* ((fn (lambda (_type name) name))
|
||||
(gdscript-imenu-format-item-label-function fn)
|
||||
(gdscript-imenu-format-parent-item-label-function fn)
|
||||
(gdscript-imenu-format-parent-item-jump-label-function fn))
|
||||
(gdscript-imenu-format-parent-item-label-function fn)
|
||||
(gdscript-imenu-format-parent-item-jump-label-function fn))
|
||||
(gdscript-imenu-create-index))))))
|
||||
|
||||
(provide 'gdscript-imenu)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
;;; gdscript-syntax.el --- Syntax highlighting for GDScript -*- lexical-binding: t; -*-
|
||||
;;; gdscript-indent-and-nav.el --- Syntax highlighting for GDScript -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2020 GDQuest
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>, Fabián E. Gallina <fgallina@gnu.org>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Feb 2020
|
||||
;; Keywords: languages
|
||||
@@ -26,52 +26,24 @@
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Sets up the syntax table and font-faces for GDScript.
|
||||
;; Functions copies from Emacs 27's built-in python.el to handle indents,
|
||||
;; querying info about the language's symbols or the context at point, and for
|
||||
;; navigation.
|
||||
;; There are dependencies between the *indent*, *info*, and *nav* functions that prevent us from splitting them into separate .el files at the moment.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'gdscript-customization)
|
||||
(require 'gdscript-utils)
|
||||
(require 'gdscript-rx)
|
||||
(require 'gdscript-syntax)
|
||||
(require 'cl-lib)
|
||||
|
||||
|
||||
;;; Indentation
|
||||
|
||||
(defun gdscript-indent-guess-indent-offset ()
|
||||
"Guess and set `gdscript-indent-offset' for the current buffer."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(save-restriction
|
||||
(widen)
|
||||
(goto-char (point-min))
|
||||
(let ((block-end))
|
||||
(while (and (not block-end)
|
||||
(re-search-forward
|
||||
(gdscript-rx line-start block-start) nil t))
|
||||
(when (and
|
||||
(not (gdscript-syntax-context-type))
|
||||
(progn
|
||||
(goto-char (line-end-position))
|
||||
(gdscript--util-forward-comment -1)
|
||||
(if (equal (char-before) ?:)
|
||||
t
|
||||
(forward-line 1)
|
||||
(when (gdscript-info-block-continuation-line-p)
|
||||
(while (and (gdscript-info-continuation-line-p)
|
||||
(not (eobp)))
|
||||
(forward-line 1))
|
||||
(gdscript--util-forward-comment -1)
|
||||
(when (equal (char-before) ?:)
|
||||
t)))))
|
||||
(setq block-end (point-marker))))
|
||||
(let ((indentation
|
||||
(when block-end
|
||||
(goto-char block-end)
|
||||
(gdscript--util-forward-comment)
|
||||
(current-indentation))))
|
||||
(if (and indentation (not (zerop indentation)))
|
||||
(set (make-local-variable 'gdscript-indent-offset) indentation)
|
||||
(when gdscript-indent-guess-indent-offset-verbose
|
||||
(message "Can't guess gdscript-indent-offset, using defaults: %s"
|
||||
gdscript-indent-offset))))))))
|
||||
(defvar gdscript-nav-beginning-of-defun-regexp
|
||||
(gdscript-rx line-start (* space) defun (+ space) (group symbol-name))
|
||||
"Regexp matching class or function definition.
|
||||
The name of the defun should be grouped so it can be retrieved
|
||||
via `match-string'.")
|
||||
|
||||
(defun gdscript-indent-context ()
|
||||
"Get information about the current indentation context.
|
||||
@@ -138,142 +110,142 @@ keyword
|
||||
:at-dedenter-block-start
|
||||
- Point is on a line starting a dedenter block.
|
||||
- START is the position where the dedenter block starts."
|
||||
(let ((ppss (save-excursion
|
||||
(beginning-of-line)
|
||||
(syntax-ppss))))
|
||||
(cond
|
||||
;; Beginning of buffer.
|
||||
((= (line-number-at-pos) 1)
|
||||
(cons :no-indent 0))
|
||||
;; Inside a string.
|
||||
((let ((start (gdscript-syntax-context 'string ppss)))
|
||||
(when start
|
||||
(cons :inside-string start))))
|
||||
;; Inside a paren.
|
||||
((let* ((start (gdscript-syntax-context 'paren ppss))
|
||||
(starts-in-newline
|
||||
(when start
|
||||
(save-excursion
|
||||
(goto-char start)
|
||||
(forward-char)
|
||||
(not
|
||||
(= (line-number-at-pos)
|
||||
(progn
|
||||
(gdscript--util-forward-comment)
|
||||
(line-number-at-pos))))))))
|
||||
(when start
|
||||
(cond
|
||||
;; Current line only holds the closing paren.
|
||||
((save-excursion
|
||||
(skip-syntax-forward " ")
|
||||
(when (and (gdscript-syntax-closing-paren-p)
|
||||
(progn
|
||||
(forward-char 1)
|
||||
(not (gdscript-syntax-context 'paren))))
|
||||
(cons :inside-paren-at-closing-paren start))))
|
||||
;; Current line only holds a closing paren for nested.
|
||||
((save-excursion
|
||||
(back-to-indentation)
|
||||
(gdscript-syntax-closing-paren-p))
|
||||
(cons :inside-paren-at-closing-nested-paren start))
|
||||
;; This line starts from an opening block in its own line.
|
||||
((save-excursion
|
||||
(goto-char start)
|
||||
(when (and
|
||||
starts-in-newline
|
||||
(save-excursion
|
||||
(back-to-indentation)
|
||||
(looking-at (gdscript-rx block-start))))
|
||||
(cons
|
||||
:inside-paren-newline-start-from-block start))))
|
||||
(let ((ppss (save-excursion
|
||||
(beginning-of-line)
|
||||
(syntax-ppss))))
|
||||
(cond
|
||||
;; Beginning of buffer.
|
||||
((= (line-number-at-pos) 1)
|
||||
(cons :no-indent 0))
|
||||
;; Inside a string.
|
||||
((let ((start (gdscript-syntax-context 'string ppss)))
|
||||
(when start
|
||||
(cons :inside-string start))))
|
||||
;; Inside a paren.
|
||||
((let* ((start (gdscript-syntax-context 'paren ppss))
|
||||
(starts-in-newline
|
||||
(cons :inside-paren-newline-start start))
|
||||
;; General case.
|
||||
(t (cons :inside-paren
|
||||
(save-excursion
|
||||
(goto-char (1+ start))
|
||||
(skip-syntax-forward "(" 1)
|
||||
(skip-syntax-forward " ")
|
||||
(point))))))))
|
||||
;; After backslash.
|
||||
((let ((start (when (not (gdscript-syntax-comment-or-string-p ppss))
|
||||
(gdscript-info-line-ends-backslash-p
|
||||
(1- (line-number-at-pos))))))
|
||||
(when start
|
||||
(cond
|
||||
;; Continuation of dotted expression.
|
||||
((save-excursion
|
||||
(back-to-indentation)
|
||||
(when (eq (char-after) ?\.)
|
||||
;; Move point back until it's not inside a paren.
|
||||
(while (prog2
|
||||
(forward-line -1)
|
||||
(and (not (bobp))
|
||||
(gdscript-syntax-context 'paren))))
|
||||
(goto-char (line-end-position))
|
||||
(while (and (search-backward
|
||||
"." (line-beginning-position) t)
|
||||
(gdscript-syntax-context-type)))
|
||||
;; Ensure previous statement has dot to align with.
|
||||
(when (and (eq (char-after) ?\.)
|
||||
(not (gdscript-syntax-context-type)))
|
||||
(cons :after-backslash-dotted-continuation (point))))))
|
||||
;; Continuation of block definition.
|
||||
((let ((block-continuation-start
|
||||
(gdscript-info-block-continuation-line-p)))
|
||||
(when block-continuation-start
|
||||
(save-excursion
|
||||
(goto-char block-continuation-start)
|
||||
(re-search-forward
|
||||
(gdscript-rx block-start (* space))
|
||||
(line-end-position) t)
|
||||
(cons :after-backslash-block-continuation (point))))))
|
||||
;; Continuation of assignment.
|
||||
((let ((assignment-continuation-start
|
||||
(gdscript-info-assignment-continuation-line-p)))
|
||||
(when assignment-continuation-start
|
||||
(save-excursion
|
||||
(goto-char assignment-continuation-start)
|
||||
(cons :after-backslash-assignment-continuation (point))))))
|
||||
;; First line after backslash continuation start.
|
||||
((save-excursion
|
||||
(goto-char start)
|
||||
(when (or (= (line-number-at-pos) 1)
|
||||
(not (gdscript-info-beginning-of-backslash
|
||||
(1- (line-number-at-pos)))))
|
||||
(cons :after-backslash-first-line start))))
|
||||
;; General case.
|
||||
(t (cons :after-backslash start))))))
|
||||
;; After beginning of block.
|
||||
((let ((start (save-excursion
|
||||
(when start
|
||||
(save-excursion
|
||||
(goto-char start)
|
||||
(forward-char)
|
||||
(not
|
||||
(= (line-number-at-pos)
|
||||
(progn
|
||||
(gdscript--util-forward-comment)
|
||||
(line-number-at-pos))))))))
|
||||
(when start
|
||||
(cond
|
||||
;; Current line only holds the closing paren.
|
||||
((save-excursion
|
||||
(skip-syntax-forward " ")
|
||||
(when (and (gdscript-syntax-closing-paren-p)
|
||||
(progn
|
||||
(forward-char 1)
|
||||
(not (gdscript-syntax-context 'paren))))
|
||||
(cons :inside-paren-at-closing-paren start))))
|
||||
;; Current line only holds a closing paren for nested.
|
||||
((save-excursion
|
||||
(back-to-indentation)
|
||||
(gdscript-syntax-closing-paren-p))
|
||||
(cons :inside-paren-at-closing-nested-paren start))
|
||||
;; This line starts from an opening block in its own line.
|
||||
((save-excursion
|
||||
(goto-char start)
|
||||
(when (and
|
||||
starts-in-newline
|
||||
(save-excursion
|
||||
(back-to-indentation)
|
||||
(gdscript--util-forward-comment -1)
|
||||
(when (equal (char-before) ?:)
|
||||
(gdscript-nav-beginning-of-block)))))
|
||||
(when start
|
||||
(cons :after-block-start start))))
|
||||
;; At dedenter statement.
|
||||
((let ((start (gdscript-info-dedenter-statement-p)))
|
||||
(when start
|
||||
(cons :at-dedenter-block-start start))))
|
||||
;; After normal line, comment or ender (default case).
|
||||
((save-excursion
|
||||
(back-to-indentation)
|
||||
(skip-chars-backward " \t\n")
|
||||
(if (bobp)
|
||||
(cons :no-indent 0)
|
||||
(gdscript-nav-beginning-of-statement)
|
||||
(cons
|
||||
(cond ((gdscript-info-current-line-comment-p)
|
||||
:after-comment)
|
||||
((save-excursion
|
||||
(goto-char (line-end-position))
|
||||
(gdscript--util-forward-comment -1)
|
||||
(gdscript-nav-beginning-of-statement)
|
||||
(looking-at (gdscript-rx block-ender)))
|
||||
:after-block-end)
|
||||
(t :after-line))
|
||||
(point))))))))
|
||||
(looking-at (gdscript-rx block-start))))
|
||||
(cons
|
||||
:inside-paren-newline-start-from-block start))))
|
||||
(starts-in-newline
|
||||
(cons :inside-paren-newline-start start))
|
||||
;; General case.
|
||||
(t (cons :inside-paren
|
||||
(save-excursion
|
||||
(goto-char (1+ start))
|
||||
(skip-syntax-forward "(" 1)
|
||||
(skip-syntax-forward " ")
|
||||
(point))))))))
|
||||
;; After backslash.
|
||||
((let ((start (unless (gdscript-syntax-comment-or-string-p (syntax-ppss))
|
||||
(gdscript-info-line-ends-backslash-p
|
||||
(1- (line-number-at-pos))))))
|
||||
(when start
|
||||
(cond
|
||||
;; Continuation of dotted expression.
|
||||
((save-excursion
|
||||
(back-to-indentation)
|
||||
(when (eq (char-after) ?\.)
|
||||
;; Move point back until it's not inside a paren.
|
||||
(while (prog2
|
||||
(forward-line -1)
|
||||
(and (not (bobp))
|
||||
(gdscript-syntax-context 'paren))))
|
||||
(goto-char (line-end-position))
|
||||
(while (and (search-backward
|
||||
"." (line-beginning-position) t)
|
||||
(gdscript-syntax-context-type)))
|
||||
;; Ensure previous statement has dot to align with.
|
||||
(when (and (eq (char-after) ?\.)
|
||||
(not (gdscript-syntax-context-type)))
|
||||
(cons :after-backslash-dotted-continuation (point))))))
|
||||
;; Continuation of block definition.
|
||||
((let ((block-continuation-start
|
||||
(gdscript-info-block-continuation-line-p)))
|
||||
(when block-continuation-start
|
||||
(save-excursion
|
||||
(goto-char block-continuation-start)
|
||||
(re-search-forward
|
||||
(gdscript-rx block-start (* space))
|
||||
(line-end-position) t)
|
||||
(cons :after-backslash-block-continuation (point))))))
|
||||
;; Continuation of assignment.
|
||||
((let ((assignment-continuation-start
|
||||
(gdscript-info-assignment-continuation-line-p)))
|
||||
(when assignment-continuation-start
|
||||
(save-excursion
|
||||
(goto-char assignment-continuation-start)
|
||||
(cons :after-backslash-assignment-continuation (point))))))
|
||||
;; First line after backslash continuation start.
|
||||
((save-excursion
|
||||
(goto-char start)
|
||||
(when (or (= (line-number-at-pos) 1)
|
||||
(not (gdscript-info-beginning-of-backslash
|
||||
(1- (line-number-at-pos)))))
|
||||
(cons :after-backslash-first-line start))))
|
||||
;; General case.
|
||||
(t (cons :after-backslash start))))))
|
||||
;; After beginning of block.
|
||||
((let ((start (save-excursion
|
||||
(back-to-indentation)
|
||||
(gdscript--util-forward-comment -1)
|
||||
(when (equal (char-before) ?:)
|
||||
(gdscript-nav-beginning-of-block)))))
|
||||
(when start
|
||||
(cons :after-block-start start))))
|
||||
;; At dedenter statement.
|
||||
((let ((start (gdscript-info-dedenter-statement-p)))
|
||||
(when start
|
||||
(cons :at-dedenter-block-start start))))
|
||||
;; After normal line, comment or ender (default case).
|
||||
((save-excursion
|
||||
(back-to-indentation)
|
||||
(skip-chars-backward " \t\n")
|
||||
(if (bobp)
|
||||
(cons :no-indent 0)
|
||||
(gdscript-nav-beginning-of-statement)
|
||||
(cons
|
||||
(cond ((gdscript-info-current-line-comment-p)
|
||||
:after-comment)
|
||||
((save-excursion
|
||||
(goto-char (line-end-position))
|
||||
(gdscript--util-forward-comment -1)
|
||||
(gdscript-nav-beginning-of-statement)
|
||||
(looking-at (gdscript-rx block-ender)))
|
||||
:after-block-end)
|
||||
(t :after-line))
|
||||
(point))))))))
|
||||
|
||||
(defun gdscript-indent--calculate-indentation ()
|
||||
"Internal implementation of `gdscript-indent-calculate-indentation'.
|
||||
@@ -281,56 +253,58 @@ May return an integer for the maximum possible indentation at
|
||||
current context or a list of integers. The latter case is only
|
||||
happening for :at-dedenter-block-start context since the
|
||||
possibilities can be narrowed to specific indentation points."
|
||||
(save-excursion
|
||||
(pcase (gdscript-indent-context)
|
||||
(`(:no-indent . ,_) (prog-first-column)) ; usually 0
|
||||
(`(,(or :after-line
|
||||
:after-comment
|
||||
:inside-string
|
||||
:after-backslash) . ,start)
|
||||
;; Copy previous indentation.
|
||||
(goto-char start)
|
||||
(current-indentation))
|
||||
(`(,(or :inside-paren-at-closing-paren
|
||||
:inside-paren-at-closing-nested-paren) . ,start)
|
||||
(goto-char (+ 1 start))
|
||||
(if (looking-at "[ \t]*\\(?:#\\|$\\)")
|
||||
;; Copy previous indentation.
|
||||
(current-indentation)
|
||||
;; Align with opening paren.
|
||||
(current-column)))
|
||||
(`(,(or :after-block-start
|
||||
:after-backslash-first-line
|
||||
:after-backslash-assignment-continuation
|
||||
:inside-paren-newline-start) . ,start)
|
||||
;; Add one indentation level.
|
||||
(goto-char start)
|
||||
(+ (current-indentation) gdscript-indent-offset))
|
||||
(`(,(or :inside-paren
|
||||
:after-backslash-block-continuation
|
||||
:after-backslash-dotted-continuation) . ,start)
|
||||
;; Use the column given by the context.
|
||||
(goto-char start)
|
||||
(current-column))
|
||||
(`(:after-block-end . ,start)
|
||||
;; Subtract one indentation level.
|
||||
(goto-char start)
|
||||
(- (current-indentation) gdscript-indent-offset))
|
||||
(`(:at-dedenter-block-start . ,_)
|
||||
;; List all possible indentation levels from opening blocks.
|
||||
(let ((opening-block-start-points
|
||||
(gdscript-info-dedenter-opening-block-positions)))
|
||||
(if (not opening-block-start-points)
|
||||
(prog-first-column) ; if not found default to first column
|
||||
(mapcar (lambda (pos)
|
||||
(save-excursion
|
||||
(goto-char pos)
|
||||
(current-indentation)))
|
||||
opening-block-start-points))))
|
||||
(`(,(or :inside-paren-newline-start-from-block) . ,start)
|
||||
(goto-char start)
|
||||
(+ (current-indentation)
|
||||
(* gdscript-indent-offset gdscript-indent-def-block-scale))))))
|
||||
(save-excursion
|
||||
(pcase (gdscript-indent-context)
|
||||
(`(:no-indent . ,_) (prog-first-column)) ; usually 0
|
||||
(`(,(or :after-line
|
||||
:after-comment
|
||||
:inside-string
|
||||
:after-backslash) . ,start)
|
||||
;; Copy previous indentation.
|
||||
(goto-char start)
|
||||
(current-indentation))
|
||||
(`(,(or :inside-paren-at-closing-paren
|
||||
:inside-paren-at-closing-nested-paren) . ,start)
|
||||
(goto-char (+ 1 start))
|
||||
(if (looking-at "[ \t]*\\(?:#\\|$\\)")
|
||||
;; Copy previous indentation.
|
||||
(current-indentation)
|
||||
;; Align with opening paren.
|
||||
(current-column)))
|
||||
(`(,(or :after-block-start
|
||||
:after-backslash-first-line
|
||||
:inside-paren-newline-start) . ,start)
|
||||
;; Add one indentation level.
|
||||
(goto-char start)
|
||||
(+ (current-indentation) gdscript-indent-offset))
|
||||
(`(,(or :inside-paren
|
||||
:after-backslash-block-continuation
|
||||
:after-backslash-dotted-continuation
|
||||
:after-backslash-assignment-continuation) . ,start)
|
||||
;; Use (possibly extra) indentation given by the configuration
|
||||
(goto-char start)
|
||||
(+ (current-indentation)
|
||||
(* gdscript-indent-offset
|
||||
gdscript-indent-line-continuation-scale)))
|
||||
(`(:after-block-end . ,start)
|
||||
;; Subtract one indentation level.
|
||||
(goto-char start)
|
||||
(- (current-indentation) gdscript-indent-offset))
|
||||
(`(:at-dedenter-block-start . ,_)
|
||||
;; List all possible indentation levels from opening blocks.
|
||||
(let ((opening-block-start-points
|
||||
(gdscript-info-dedenter-opening-block-positions)))
|
||||
(if (not opening-block-start-points)
|
||||
(prog-first-column) ; if not found default to first column
|
||||
(mapcar (lambda (pos)
|
||||
(save-excursion
|
||||
(goto-char pos)
|
||||
(current-indentation)))
|
||||
opening-block-start-points))))
|
||||
(`(,(or :inside-paren-newline-start-from-block) . ,start)
|
||||
(goto-char start)
|
||||
(+ (current-indentation)
|
||||
(* gdscript-indent-offset gdscript-indent-def-block-scale))))))
|
||||
|
||||
(defun gdscript-indent--calculate-levels (indentation)
|
||||
"Calculate levels list given INDENTATION.
|
||||
@@ -373,11 +347,7 @@ to the maximum available level. When indentation is the minimum
|
||||
possible and PREVIOUS is non-nil, cycle back to the maximum
|
||||
level."
|
||||
(let ((follow-indentation-p
|
||||
;; Check if point is within indentation.
|
||||
(and (<= (line-beginning-position) (point))
|
||||
(>= (+ (line-beginning-position)
|
||||
(current-indentation))
|
||||
(point)))))
|
||||
(<= (current-column) (current-indentation))))
|
||||
(save-excursion
|
||||
(indent-line-to
|
||||
(gdscript-indent-calculate-indentation previous))
|
||||
@@ -403,10 +373,10 @@ indentation levels from right to left."
|
||||
"De-indent current line."
|
||||
(interactive "*")
|
||||
(when (and (not (bolp))
|
||||
(not (gdscript-syntax-comment-or-string-p))
|
||||
(= (current-indentation) (current-column)))
|
||||
(gdscript-indent-line t)
|
||||
t))
|
||||
(not (gdscript-syntax-comment-or-string-p))
|
||||
(= (current-indentation) (current-column)))
|
||||
(gdscript-indent-line t)
|
||||
t))
|
||||
|
||||
(defun gdscript-indent-dedent-line-backspace (arg)
|
||||
"De-indent current line.
|
||||
@@ -545,9 +515,7 @@ the line will be re-indented automatically if needed."
|
||||
;; Reindent region if this is a multiline statement
|
||||
(gdscript-indent-region start end))))))))))
|
||||
|
||||
|
||||
;;; Misc helpers
|
||||
|
||||
(defun gdscript-info-current-defun (&optional include-type)
|
||||
"Return name of surrounding function with Gdscript compatible dotty syntax.
|
||||
Optional argument INCLUDE-TYPE indicates to include the type of the defun.
|
||||
@@ -608,7 +576,7 @@ since it returns nil if point is not inside a defun."
|
||||
(and (= (current-indentation) 0) (throw 'exit t))))
|
||||
(and names
|
||||
(concat (and type (format "%s " type))
|
||||
(mapconcat 'identity names ".")))))))
|
||||
(mapconcat #'identity names ".")))))))
|
||||
|
||||
(defun gdscript-info-current-symbol (&optional replace-self)
|
||||
"Return current symbol using dotty syntax.
|
||||
@@ -688,6 +656,19 @@ likely an invalid gdscript file."
|
||||
(setq positions (cdr positions)))))
|
||||
position))
|
||||
|
||||
(defun gdscript-indent--nav-block ()
|
||||
"Search backward for block start."
|
||||
(re-search-backward (gdscript-rx block-start) nil t)
|
||||
;; At this point `(match-string-no-properties 0)' doesn't match whole gdscript's block expression,
|
||||
;; due to how `re-search-backward' works.
|
||||
;; To make `(match-string-no-properties 0)' match whole gdscript's block expression
|
||||
;; let's use `re-search-forward' from beginning of a statement.
|
||||
(gdscript-nav-beginning-of-statement)
|
||||
(prog1
|
||||
(re-search-forward (gdscript-rx block-start) nil t)
|
||||
;; And let's put point at the beginning of the statement.
|
||||
(gdscript-nav-beginning-of-statement)))
|
||||
|
||||
(defun gdscript-info-dedenter-opening-block-positions ()
|
||||
"Return points of blocks the current line may close sorted by closer.
|
||||
Returns nil if point is not on a dedenter statement or no opening
|
||||
@@ -699,18 +680,13 @@ likely an invalid gdscript file."
|
||||
(goto-char dedenter-pos)
|
||||
(let* ((cur-line (line-beginning-position))
|
||||
(pairs '(("elif" "elif" "if")
|
||||
("else" "if" "elif" "except" "for" "while")
|
||||
("except" "except" "try")
|
||||
("finally" "else" "except" "try")))
|
||||
("else" "if" "elif")))
|
||||
(dedenter (match-string-no-properties 0))
|
||||
(possible-opening-blocks (cdr (assoc-string dedenter pairs)))
|
||||
(collected-indentations)
|
||||
(opening-blocks))
|
||||
(catch 'exit
|
||||
(while (gdscript-nav--syntactically
|
||||
(lambda ()
|
||||
(re-search-backward (gdscript-rx block-start) nil t))
|
||||
#'<)
|
||||
(while (gdscript-nav--syntactically #'gdscript-indent--nav-block #'<)
|
||||
(let ((indentation (current-indentation)))
|
||||
(when (and (not (memq indentation collected-indentations))
|
||||
(or (not collected-indentations)
|
||||
@@ -727,13 +703,17 @@ likely an invalid gdscript file."
|
||||
(while (and (< (point) cur-line)
|
||||
(setq no-back-indent
|
||||
(or (> (current-indentation) indentation)
|
||||
(gdscript-info-current-line-empty-p))))
|
||||
(gdscript-info-current-line-empty-p)
|
||||
(gdscript-info-current-line-comment-p)
|
||||
(not (equal :after-line (car (gdscript-indent-context)))))))
|
||||
(forward-line)))
|
||||
no-back-indent)))
|
||||
(setq collected-indentations
|
||||
(cons indentation collected-indentations))
|
||||
(when (member (match-string-no-properties 0)
|
||||
possible-opening-blocks)
|
||||
(when
|
||||
(seq-contains possible-opening-blocks
|
||||
(string-trim (match-string-no-properties 0))
|
||||
(lambda (elt e) (string-prefix-p e elt)))
|
||||
(setq opening-blocks (cons (point) opening-blocks))))
|
||||
(when (zerop indentation)
|
||||
(throw 'exit nil)))))
|
||||
@@ -744,10 +724,10 @@ likely an invalid gdscript file."
|
||||
"Message the first line of the block the current statement closes."
|
||||
(let ((point (gdscript-info-dedenter-opening-block-position)))
|
||||
(when point
|
||||
(message "Closes %s" (save-excursion
|
||||
(goto-char point)
|
||||
(buffer-substring
|
||||
(point) (line-end-position)))))))
|
||||
(message "Closes %s" (save-excursion
|
||||
(goto-char point)
|
||||
(buffer-substring
|
||||
(point) (line-end-position)))))))
|
||||
|
||||
(defun gdscript-info-dedenter-statement-p ()
|
||||
"Return point if current statement is a dedenter.
|
||||
@@ -763,61 +743,61 @@ statement."
|
||||
"Return non-nil if current line ends with backslash.
|
||||
With optional argument LINE-NUMBER, check that line instead."
|
||||
(save-excursion
|
||||
(when line-number
|
||||
(gdscript--util-goto-line line-number))
|
||||
(while (and (not (eobp))
|
||||
(goto-char (line-end-position))
|
||||
(gdscript-syntax-context 'paren)
|
||||
(not (equal (char-before (point)) ?\\)))
|
||||
(forward-line 1))
|
||||
(when (equal (char-before) ?\\)
|
||||
(point-marker))))
|
||||
(when line-number
|
||||
(gdscript--util-goto-line line-number))
|
||||
(while (and (not (eobp))
|
||||
(goto-char (line-end-position))
|
||||
(gdscript-syntax-context 'paren)
|
||||
(not (equal (char-before (point)) ?\\)))
|
||||
(forward-line 1))
|
||||
(when (equal (char-before) ?\\)
|
||||
(point-marker))))
|
||||
|
||||
(defun gdscript-info-beginning-of-backslash (&optional line-number)
|
||||
"Return the point where the backslashed line starts.
|
||||
"Return the point where the backslashed line start.
|
||||
Optional argument LINE-NUMBER forces the line number to check against."
|
||||
(save-excursion
|
||||
(when line-number
|
||||
(gdscript--util-goto-line line-number))
|
||||
(when (gdscript-info-line-ends-backslash-p)
|
||||
(while (save-excursion
|
||||
(goto-char (line-beginning-position))
|
||||
(gdscript-syntax-context 'paren))
|
||||
(forward-line -1))
|
||||
(back-to-indentation)
|
||||
(point-marker))))
|
||||
(when line-number
|
||||
(gdscript--util-goto-line line-number))
|
||||
(when (gdscript-info-line-ends-backslash-p)
|
||||
(while (save-excursion
|
||||
(goto-char (line-beginning-position))
|
||||
(gdscript-syntax-context 'paren))
|
||||
(forward-line -1))
|
||||
(back-to-indentation)
|
||||
(point-marker))))
|
||||
|
||||
(defun gdscript-info-continuation-line-p ()
|
||||
"Check if current line is continuation of another.
|
||||
When current line is continuation of another return the point
|
||||
where the continued line ends."
|
||||
(save-excursion
|
||||
(let* ((context-type (progn
|
||||
(back-to-indentation)
|
||||
(gdscript-syntax-context-type)))
|
||||
(line-start (line-number-at-pos))
|
||||
(context-start (when context-type
|
||||
(gdscript-syntax-context context-type))))
|
||||
(cond ((equal context-type 'paren)
|
||||
;; Lines inside a paren are always a continuation line
|
||||
;; (except the first one).
|
||||
(gdscript--util-forward-comment -1)
|
||||
(point-marker))
|
||||
((member context-type '(string comment))
|
||||
;; move forward an roll again
|
||||
(goto-char context-start)
|
||||
(gdscript--util-forward-comment)
|
||||
(gdscript-info-continuation-line-p))
|
||||
(t
|
||||
;; Not within a paren, string or comment, the only way
|
||||
;; we are dealing with a continuation line is that
|
||||
;; previous line contains a backslash, and this can
|
||||
;; only be the previous line from current
|
||||
(back-to-indentation)
|
||||
(gdscript--util-forward-comment -1)
|
||||
(when (and (equal (1- line-start) (line-number-at-pos))
|
||||
(gdscript-info-line-ends-backslash-p))
|
||||
(point-marker)))))))
|
||||
(let* ((context-type (progn
|
||||
(back-to-indentation)
|
||||
(gdscript-syntax-context-type)))
|
||||
(line-start (line-number-at-pos))
|
||||
(context-start (when context-type
|
||||
(gdscript-syntax-context context-type))))
|
||||
(cond ((equal context-type 'paren)
|
||||
;; Lines inside a paren are always a continuation line
|
||||
;; (except the first one).
|
||||
(gdscript--util-forward-comment -1)
|
||||
(point-marker))
|
||||
((member context-type '(string comment))
|
||||
;; move forward an roll again
|
||||
(goto-char context-start)
|
||||
(gdscript--util-forward-comment)
|
||||
(gdscript-info-continuation-line-p))
|
||||
(t
|
||||
;; Not within a paren, string or comment, the only way
|
||||
;; we are dealing with a continuation line is that
|
||||
;; previous line contains a backslash, and this can
|
||||
;; only be the previous line from current
|
||||
(back-to-indentation)
|
||||
(gdscript--util-forward-comment -1)
|
||||
(when (and (equal (1- line-start) (line-number-at-pos))
|
||||
(gdscript-info-line-ends-backslash-p))
|
||||
(point-marker)))))))
|
||||
|
||||
(defun gdscript-info-block-continuation-line-p ()
|
||||
"Return non-nil if current line is a continuation of a block."
|
||||
@@ -839,8 +819,8 @@ continuations, just check the if current line is an assignment."
|
||||
(gdscript-nav-beginning-of-statement))
|
||||
(while (and
|
||||
(re-search-forward (gdscript-rx not-simple-operator
|
||||
assignment-operator
|
||||
(group not-simple-operator))
|
||||
assignment-operator
|
||||
(group not-simple-operator))
|
||||
(line-end-position) t)
|
||||
(not found))
|
||||
(save-excursion
|
||||
@@ -873,7 +853,7 @@ operator."
|
||||
(defun gdscript-info-current-line-comment-p ()
|
||||
"Return non-nil if current line is a comment line."
|
||||
(char-equal
|
||||
(or (char-after (+ (line-beginning-position) (current-indentation))) ?_)
|
||||
(or (char-after (+ (line-beginning-position) (/ (current-indentation) gdscript-indent-offset))) ?_)
|
||||
?#))
|
||||
|
||||
(defun gdscript-info-current-line-empty-p ()
|
||||
@@ -882,19 +862,12 @@ operator."
|
||||
(beginning-of-line 1)
|
||||
(looking-at
|
||||
(gdscript-rx line-start (* whitespace)
|
||||
(group (* not-newline))
|
||||
(* whitespace) line-end))
|
||||
(group (* not-newline))
|
||||
(* whitespace) line-end))
|
||||
(string-equal "" (match-string-no-properties 1))))
|
||||
|
||||
|
||||
;;; Navigation
|
||||
|
||||
(defvar gdscript-nav-beginning-of-defun-regexp
|
||||
(gdscript-rx line-start (* space) defun (+ space) (group symbol-name))
|
||||
"Regexp matching class or function definition.
|
||||
The name of the defun should be grouped so it can be retrieved
|
||||
via `match-string'.")
|
||||
|
||||
(defun gdscript-nav--beginning-of-defun (&optional arg)
|
||||
"Internal implementation of `gdscript-nav-beginning-of-defun'.
|
||||
With positive ARG search backwards, else search forwards."
|
||||
@@ -999,7 +972,7 @@ be skipped."
|
||||
(throw 'found (point-marker)))
|
||||
((and newpos context)
|
||||
(setq prev-pos (point)))
|
||||
(t (when (not newpos) (goto-char start-pos))
|
||||
(t (unless newpos (goto-char start-pos))
|
||||
(throw 'found nil))))))))
|
||||
|
||||
(defun gdscript-nav--forward-defun (arg)
|
||||
@@ -1447,29 +1420,6 @@ This command assumes point is not in a string or comment."
|
||||
(or arg (setq arg 1))
|
||||
(gdscript-nav-up-list (- arg)))
|
||||
|
||||
(defun gdscript-nav-if-name-main ()
|
||||
"Move point at the beginning the __main__ block.
|
||||
When \"if __name__ == \\='__main__\\=':\" is found returns its
|
||||
position, else returns nil."
|
||||
(interactive)
|
||||
(let ((point (point))
|
||||
(found (catch 'found
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward
|
||||
(gdscript-rx line-start
|
||||
"if" (+ space)
|
||||
"__name__" (+ space)
|
||||
"==" (+ space)
|
||||
(group-n 1 (or ?\" ?\'))
|
||||
"__main__" (backref 1) (* space) ":")
|
||||
nil t)
|
||||
(when (not (gdscript-syntax-context-type))
|
||||
(beginning-of-line)
|
||||
(throw 'found t))))))
|
||||
(if found
|
||||
(point)
|
||||
(ignore (goto-char point)))))
|
||||
|
||||
(provide 'gdscript-indent-and-nav)
|
||||
|
||||
;;; gdscript-indent-and-nav.el ends here
|
||||
|
||||
167
gdscript-keywords.el
Normal file
167
gdscript-keywords.el
Normal file
@@ -0,0 +1,167 @@
|
||||
;;; gdscript-keywords.el --- Cached keywords for the GDScript language -*- lexical-binding: t; -*-
|
||||
;;
|
||||
;; Copyright (C) 2020 GDQuest
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 0.1.0
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Mar 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:
|
||||
;;
|
||||
;; Cached keywords for the GDScript language, used for syntax highlighting and auto-completion.
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(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" "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" "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"
|
||||
"AnimatedSprite" "AnimatedSprite3D" "AnimatedTexture" "Animation" "AnimationNode"
|
||||
"AnimationNodeAdd2" "AnimationNodeAdd3" "AnimationNodeAnimation" "AnimationNodeBlend2"
|
||||
"AnimationNodeBlend3" "AnimationNodeBlendSpace1D" "AnimationNodeBlendSpace2D"
|
||||
"AnimationNodeBlendTree" "AnimationNodeOneShot" "AnimationNodeOutput" "AnimationNodeStateMachine"
|
||||
"AnimationNodeStateMachinePlayback" "AnimationNodeStateMachineTransition" "AnimationNodeTimeScale"
|
||||
"AnimationNodeTimeSeek" "AnimationNodeTransition" "AnimationPlayer" "AnimationRootNode"
|
||||
"AnimationTrackEditPlugin" "AnimationTree" "AnimationTreePlayer" "Area" "Area2D" "Array"
|
||||
"ArrayMesh" "AtlasTexture" "AudioBusLayout" "AudioEffect" "AudioEffectAmplify"
|
||||
"AudioEffectBandLimitFilter" "AudioEffectBandPassFilter" "AudioEffectChorus"
|
||||
"AudioEffectCompressor" "AudioEffectDelay" "AudioEffectDistortion" "AudioEffectEQ"
|
||||
"AudioEffectEQ10" "AudioEffectEQ21" "AudioEffectEQ6" "AudioEffectFilter"
|
||||
"AudioEffectHighPassFilter" "AudioEffectHighShelfFilter" "AudioEffectInstance"
|
||||
"AudioEffectLimiter" "AudioEffectLowPassFilter" "AudioEffectLowShelfFilter"
|
||||
"AudioEffectNotchFilter" "AudioEffectPanner" "AudioEffectPhaser" "AudioEffectPitchShift"
|
||||
"AudioEffectRecord" "AudioEffectReverb" "AudioEffectSpectrumAnalyzer"
|
||||
"AudioEffectSpectrumAnalyzerInstance" "AudioEffectStereoEnhance" "AudioServer" "AudioStream"
|
||||
"AudioStreamGenerator" "AudioStreamGeneratorPlayback" "AudioStreamMicrophone"
|
||||
"AudioStreamPlayback" "AudioStreamPlaybackResampled" "AudioStreamPlayer" "AudioStreamPlayer2D"
|
||||
"AudioStreamPlayer3D" "AudioStreamRandomPitch" "AudioStreamSample" "BackBufferCopy"
|
||||
"BakedLightmap" "BakedLightmapData" "BaseButton" "Basis" "BitMap" "BitmapFont" "Bone2D"
|
||||
"BoneAttachment" "BoxContainer" "BoxShape" "Button" "ButtonGroup" "CPUParticles" "CPUParticles2D"
|
||||
"Camera" "Camera2D" "CameraFeed" "CameraServer" "CameraTexture" "CanvasItem" "CanvasItemMaterial"
|
||||
"CanvasLayer" "CanvasModulate" "CapsuleMesh" "CapsuleShape" "CapsuleShape2D" "CenterContainer"
|
||||
"CharFXTransform" "CheckBox" "CheckButton" "CircleShape2D" "ClassDB" "ClippedCamera"
|
||||
"CollisionObject" "CollisionObject2D" "CollisionPolygon" "CollisionPolygon2D" "CollisionShape"
|
||||
"CollisionShape2D" "Color" "ColorPicker" "ColorPickerButton" "ColorRect" "ConcavePolygonShape"
|
||||
"ConcavePolygonShape2D" "ConeTwistJoint" "ConfigFile" "ConfirmationDialog" "Container" "Control"
|
||||
"ConvexPolygonShape" "ConvexPolygonShape2D" "Crypto" "CryptoKey" "CubeMap" "CubeMesh" "Curve"
|
||||
"Curve2D" "Curve3D" "CurveTexture" "CylinderMesh" "CylinderShape" "DampedSpringJoint2D"
|
||||
"Dictionary" "DirectionalLight" "Directory" "DynamicFont" "DynamicFontData" "EditorExportPlugin"
|
||||
"EditorFeatureProfile" "EditorFileDialog" "EditorFileSystem" "EditorFileSystemDirectory"
|
||||
"EditorImportPlugin" "EditorInspector" "EditorInspectorPlugin" "EditorInterface"
|
||||
"EditorNavigationMeshGenerator" "EditorPlugin" "EditorProperty" "EditorResourceConversionPlugin"
|
||||
"EditorResourcePreview" "EditorResourcePreviewGenerator" "EditorSceneImporter"
|
||||
"EditorSceneImporterAssimp" "EditorScenePostImport" "EditorScript" "EditorSelection"
|
||||
"EditorSettings" "EditorSpatialGizmo" "EditorSpatialGizmoPlugin" "EditorSpinSlider"
|
||||
"EditorVCSInterface" "EncodedObjectAsID" "Engine" "Environment" "Expression" "File" "FileDialog"
|
||||
"Font" "FuncRef" "GIProbe" "GIProbeData" "Generic6DOFJoint" "Geometry" "GeometryInstance"
|
||||
"Gradient" "GradientTexture" "GraphEdit" "GraphNode" "GridContainer" "GrooveJoint2D"
|
||||
"HBoxContainer" "HScrollBar" "HSeparator" "HSlider" "HSplitContainer" "HTTPClient" "HTTPRequest"
|
||||
"HashingContext" "HeightMapShape" "HingeJoint" "IP" "IP_Unix" "Image" "ImageTexture"
|
||||
"ImmediateGeometry" "Input" "InputDefault" "InputEvent" "InputEventAction" "InputEventGesture"
|
||||
"InputEventJoypadButton" "InputEventJoypadMotion" "InputEventKey" "InputEventMIDI"
|
||||
"InputEventMagnifyGesture" "InputEventMouse" "InputEventMouseButton" "InputEventMouseMotion"
|
||||
"InputEventPanGesture" "InputEventScreenDrag" "InputEventScreenTouch" "InputEventWithModifiers"
|
||||
"InputMap" "InstancePlaceholder" "InterpolatedCamera" "ItemList" "JSON" "JSONParseResult"
|
||||
"JSONRPC" "JavaScript" "Joint" "Joint2D" "KinematicBody" "KinematicBody2D" "KinematicCollision"
|
||||
"KinematicCollision2D" "Label" "LargeTexture" "Light" "Light2D" "LightOccluder2D" "Line2D"
|
||||
"LineEdit" "LineShape2D" "LinkButton" "Listener" "MainLoop" "MarginContainer" "Marshalls"
|
||||
"Material" "MenuButton" "Mesh" "MeshDataTool" "MeshInstance" "MeshInstance2D" "MeshLibrary"
|
||||
"MeshTexture" "MultiMesh" "MultiMeshInstance" "MultiMeshInstance2D" "MultiplayerAPI" "Mutex"
|
||||
"Navigation" "Navigation2D" "NavigationMesh" "NavigationMeshInstance" "NavigationPolygon"
|
||||
"NavigationPolygonInstance" "NetworkedMultiplayerPeer" "Nil" "NinePatchRect" "Node" "Node2D"
|
||||
"NodePath" "OS" "Object" "OccluderPolygon2D" "OmniLight" "OptionButton" "PCKPacker"
|
||||
"PHashTranslation" "PackedDataContainer" "PackedDataContainerRef" "PackedScene" "PacketPeer"
|
||||
"PacketPeerStream" "PacketPeerUDP" "Panel" "PanelContainer" "PanoramaSky" "ParallaxBackground"
|
||||
"ParallaxLayer" "Particles" "Particles2D" "ParticlesMaterial" "Path" "Path2D" "PathFollow"
|
||||
"PathFollow2D" "Performance" "PhysicalBone" "Physics2DDirectBodyState"
|
||||
"Physics2DDirectBodyStateSW" "Physics2DDirectSpaceState" "Physics2DServer" "Physics2DServerSW"
|
||||
"Physics2DShapeQueryParameters" "Physics2DShapeQueryResult" "Physics2DTestMotionResult"
|
||||
"PhysicsBody" "PhysicsBody2D" "PhysicsDirectBodyState" "PhysicsDirectSpaceState" "PhysicsMaterial"
|
||||
"PhysicsServer" "PhysicsShapeQueryParameters" "PhysicsShapeQueryResult" "PinJoint" "PinJoint2D"
|
||||
"Plane" "PlaneMesh" "PlaneShape" "PointMesh" "Polygon2D" "PolygonPathFinder" "PoolByteArray"
|
||||
"PoolColorArray" "PoolIntArray" "PoolRealArray" "PoolStringArray" "PoolVector2Array"
|
||||
"PoolVector3Array" "Popup" "PopupDialog" "PopupMenu" "PopupPanel" "Position2D" "Position3D"
|
||||
"PrimitiveMesh" "PrismMesh" "ProceduralSky" "ProgressBar" "ProjectSettings" "ProximityGroup"
|
||||
"ProxyTexture" "QuadMesh" "Quat" "RID" "RandomNumberGenerator" "Range" "RayCast" "RayCast2D"
|
||||
"RayShape" "RayShape2D" "Rect2" "RectangleShape2D" "Reference" "ReferenceRect" "ReflectionProbe"
|
||||
"RemoteTransform" "RemoteTransform2D" "Resource" "ResourceFormatLoader"
|
||||
"ResourceFormatLoaderCrypto" "ResourceFormatSaver" "ResourceFormatSaverCrypto" "ResourceImporter"
|
||||
"ResourceInteractiveLoader" "ResourceLoader" "ResourcePreloader" "ResourceSaver" "RichTextEffect"
|
||||
"RichTextLabel" "RigidBody" "RigidBody2D" "RootMotionView" "SceneState" "SceneTree"
|
||||
"SceneTreeTimer" "Script" "ScriptCreateDialog" "ScriptEditor" "ScrollBar" "ScrollContainer"
|
||||
"SegmentShape2D" "Semaphore" "Separator" "Shader" "ShaderMaterial" "Shape" "Shape2D" "ShortCut"
|
||||
"Skeleton" "Skeleton2D" "SkeletonIK" "Skin" "SkinReference" "Sky" "Slider" "SliderJoint"
|
||||
"SoftBody" "Spatial" "SpatialGizmo" "SpatialMaterial" "SpatialVelocityTracker" "SphereMesh"
|
||||
"SphereShape" "SpinBox" "SplitContainer" "SpotLight" "SpringArm" "Sprite" "Sprite3D"
|
||||
"SpriteBase3D" "SpriteFrames" "StaticBody" "StaticBody2D" "StreamPeer" "StreamPeerBuffer"
|
||||
"StreamPeerSSL" "StreamPeerTCP" "StreamTexture" "String" "StyleBox" "StyleBoxEmpty" "StyleBoxFlat"
|
||||
"StyleBoxLine" "StyleBoxTexture" "SurfaceTool" "TCP_Server" "TabContainer" "Tabs" "TextEdit"
|
||||
"TextFile" "Texture" "Texture3D" "TextureArray" "TextureButton" "TextureLayered" "TextureProgress"
|
||||
"TextureRect" "Theme" "Thread" "TileMap" "TileSet" "Timer" "ToolButton" "TouchScreenButton"
|
||||
"Transform" "Transform2D" "Translation" "TranslationServer" "Tree" "TreeItem" "TriangleMesh"
|
||||
"Tween" "UndoRedo" "VBoxContainer" "VScrollBar" "VSeparator" "VSlider" "VSplitContainer" "Variant"
|
||||
"Vector2" "Vector3" "VehicleBody" "VehicleWheel" "VideoPlayer" "VideoStream" "Viewport"
|
||||
"ViewportContainer" "ViewportTexture" "VisibilityEnabler" "VisibilityEnabler2D"
|
||||
"VisibilityNotifier" "VisibilityNotifier2D" "VisualInstance" "VisualServer" "VisualShader"
|
||||
"VisualShaderNode" "VisualShaderNodeBooleanConstant" "VisualShaderNodeBooleanUniform"
|
||||
"VisualShaderNodeColorConstant" "VisualShaderNodeColorFunc" "VisualShaderNodeColorOp"
|
||||
"VisualShaderNodeColorUniform" "VisualShaderNodeCompare" "VisualShaderNodeCubeMap"
|
||||
"VisualShaderNodeCubeMapUniform" "VisualShaderNodeCustom" "VisualShaderNodeDeterminant"
|
||||
"VisualShaderNodeDotProduct" "VisualShaderNodeExpression" "VisualShaderNodeFaceForward"
|
||||
"VisualShaderNodeFresnel" "VisualShaderNodeGlobalExpression" "VisualShaderNodeGroupBase"
|
||||
"VisualShaderNodeIf" "VisualShaderNodeInput" "VisualShaderNodeIs" "VisualShaderNodeOuterProduct"
|
||||
"VisualShaderNodeOutput" "VisualShaderNodeScalarClamp" "VisualShaderNodeScalarConstant"
|
||||
"VisualShaderNodeScalarDerivativeFunc" "VisualShaderNodeScalarFunc" "VisualShaderNodeScalarInterp"
|
||||
"VisualShaderNodeScalarOp" "VisualShaderNodeScalarSmoothStep" "VisualShaderNodeScalarSwitch"
|
||||
"VisualShaderNodeScalarUniform" "VisualShaderNodeSwitch" "VisualShaderNodeTexture"
|
||||
"VisualShaderNodeTextureUniform" "VisualShaderNodeTextureUniformTriplanar"
|
||||
"VisualShaderNodeTransformCompose" "VisualShaderNodeTransformConstant"
|
||||
"VisualShaderNodeTransformDecompose" "VisualShaderNodeTransformFunc"
|
||||
"VisualShaderNodeTransformMult" "VisualShaderNodeTransformUniform"
|
||||
"VisualShaderNodeTransformVecMult" "VisualShaderNodeUniform" "VisualShaderNodeVec3Constant"
|
||||
"VisualShaderNodeVec3Uniform" "VisualShaderNodeVectorClamp" "VisualShaderNodeVectorCompose"
|
||||
"VisualShaderNodeVectorDecompose" "VisualShaderNodeVectorDerivativeFunc"
|
||||
"VisualShaderNodeVectorDistance" "VisualShaderNodeVectorFunc" "VisualShaderNodeVectorInterp"
|
||||
"VisualShaderNodeVectorLen" "VisualShaderNodeVectorOp" "VisualShaderNodeVectorRefract"
|
||||
"VisualShaderNodeVectorScalarMix" "VisualShaderNodeVectorScalarSmoothStep"
|
||||
"VisualShaderNodeVectorScalarStep" "VisualShaderNodeVectorSmoothStep" "WeakRef" "WindowDialog"
|
||||
"World" "World2D" "WorldEnvironment" "X509Certificate" "XMLParser" "YSort"))
|
||||
|
||||
(provide 'gdscript-keywords)
|
||||
;;; gdscript-keywords.el ends here
|
||||
155
gdscript-mode.el
155
gdscript-mode.el
@@ -1,11 +1,11 @@
|
||||
;;; gdscript-mode.el --- Major mode for Godot's GDScript language -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2020 GDQuest
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>, Fabián E. Gallina <fgallina@gnu.org>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 0.1.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Jan 2020
|
||||
;; Keywords: languages
|
||||
@@ -26,21 +26,26 @@
|
||||
;;; Commentary:
|
||||
|
||||
;; Adds support for the GDScript programming language from the Godot game
|
||||
;; engine. This is a domain-specific language dedicated to game programming.
|
||||
;; engine. This is a domain-specific language dedicated to game programming.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'gdscript-customization)
|
||||
(require 'gdscript-docs)
|
||||
(require 'gdscript-syntax)
|
||||
(require 'gdscript-indent-and-nav)
|
||||
(require 'gdscript-imenu)
|
||||
(require 'gdscript-fill-paragraph)
|
||||
(require 'gdscript-completion)
|
||||
(require 'gdscript-format)
|
||||
(require 'gdscript-rx)
|
||||
(require 'gdscript-godot)
|
||||
(require 'gdscript-hydra)
|
||||
(require 'gdscript-debug)
|
||||
(require 'gdscript-eglot)
|
||||
|
||||
;; gdscript-rx is a copy of Emacs 27's rx module, to ensure compatibility with
|
||||
;; Emacs 26
|
||||
(if (version< emacs-version "27")
|
||||
(require 'gdscript-rx))
|
||||
(when (version< "29" emacs-version)
|
||||
(require 'gdscript-ts-mode))
|
||||
|
||||
;;;###autoload
|
||||
(add-to-list 'auto-mode-alist '("\\.gd\\'" . gdscript-mode))
|
||||
@@ -48,6 +53,13 @@
|
||||
(add-to-list 'auto-mode-alist '("\\.tscn\\'" . conf-toml-mode))
|
||||
;;;###autoload
|
||||
(add-to-list 'auto-mode-alist '("\\.tres\\'" . conf-toml-mode))
|
||||
;;;###autoload
|
||||
(with-eval-after-load 'eglot
|
||||
(defvar eglot-server-programs)
|
||||
(unless (equal (alist-get 'gdscript-mode eglot-server-programs)
|
||||
#'gdscript-eglot-contact)
|
||||
(push (cons 'gdscript-mode #'gdscript-eglot-contact)
|
||||
eglot-server-programs)))
|
||||
|
||||
(defvar gdscript-mode-map (let ((map (make-sparse-keymap)))
|
||||
;; Movement
|
||||
@@ -55,57 +67,50 @@
|
||||
(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 (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 "<f5>") '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 "<f6>") '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)
|
||||
(define-key map (kbd "C-c C-b s") 'gdscript-docs-online-search-api)
|
||||
;; Hydra
|
||||
(define-key map (kbd "C-c r") 'gdscript-hydra-show)
|
||||
;; Debugger
|
||||
(define-key map (kbd "C-c C-d C-d s") 'gdscript-debug-display-stack-frame-vars-buffer)
|
||||
(define-key map (kbd "C-c C-d C-d d") 'gdscript-debug-display-stack-dump-buffer)
|
||||
(define-key map (kbd "C-c C-d C-d b") 'gdscript-debug-display-breakpoint-buffer)
|
||||
(define-key map (kbd "C-c C-d C-d i") 'gdscript-debug-display-inspector-buffer)
|
||||
(define-key map (kbd "<f9>") 'gdscript-debug-toggle-breakpoint)
|
||||
(define-key map (kbd "C-c C-d q") 'gdscript-debug-make-server)
|
||||
(define-key map (kbd "C-c C-d n") 'gdscript-debug-next)
|
||||
(define-key map (kbd "C-c C-d c") 'gdscript-debug-continue)
|
||||
(define-key map (kbd "<f7>") 'gdscript-debug-continue)
|
||||
(define-key map (kbd "C-c C-d s") 'gdscript-debug-step)
|
||||
;; Debugger Hydra
|
||||
(define-key map (kbd "C-c n") 'gdscript-debug-hydra)
|
||||
map)
|
||||
"Keymap for `gdscript-mode'.")
|
||||
|
||||
;;; GDScript regex
|
||||
(defmacro gdscript-rx (&rest regexps)
|
||||
"Gdscript mode specialized rx macro.
|
||||
This variant of `rx' supports common Gdscript named REGEXPS."
|
||||
`(rx-let ((block-start (seq symbol-start
|
||||
(or "func" "static" "class" "if" "elif" "else"
|
||||
"for" "while" "match")
|
||||
symbol-end))
|
||||
(dedenter (seq symbol-start
|
||||
(or "elif" "else")
|
||||
symbol-end))
|
||||
(block-ender (seq symbol-start
|
||||
(or "break" "continue" "pass" "return")
|
||||
symbol-end))
|
||||
(defun (seq symbol-start
|
||||
(or "func" "class" "static func")
|
||||
symbol-end))
|
||||
(symbol-name (seq (any letter ?_) (* (any word ?_))))
|
||||
(open-paren (or "{" "[" "("))
|
||||
(close-paren (or "}" "]" ")"))
|
||||
(simple-operator (any ?+ ?- ?/ ?& ?^ ?~ ?| ?* ?< ?> ?= ?%))
|
||||
(not-simple-operator (not simple-operator))
|
||||
;; TODO: clean up operators that don't exist in GDScript
|
||||
(operator (or "==" ">=" "is" "not"
|
||||
"**" "//" "<<" ">>" "<=" "!="
|
||||
"+" "-" "/" "&" "^" "~" "|" "*" "<" ">"
|
||||
"=" "%"))
|
||||
(assignment-operator (or "+=" "-=" "*=" "/=" "//=" "%=" "**="
|
||||
">>=" "<<=" "&=" "^=" "|="
|
||||
"="))
|
||||
(string-delimiter (seq
|
||||
;; Match even number of backslashes.
|
||||
(or (not (any ?\\ ?\' ?\")) point
|
||||
;; Quotes might be preceded by an
|
||||
;; escaped quote.
|
||||
(and (or (not (any ?\\)) point) ?\\
|
||||
(* ?\\ ?\\) (any ?\' ?\")))
|
||||
(* ?\\ ?\\)
|
||||
;; Match single or triple quotes of any kind.
|
||||
(group (or "\"\"\"" "\"" "'''" "'")))))
|
||||
(rx ,@regexps)))
|
||||
|
||||
(defun gdscript-hideshow-forward-sexp-function (_arg)
|
||||
"Gdscript specific `forward-sexp' function for `hs-minor-mode'.
|
||||
"Gdscript specific `forward-sexp' function for function `hs-minor-mode'.
|
||||
Argument ARG is ignored."
|
||||
(gdscript-nav-end-of-defun)
|
||||
(unless (gdscript-info-current-line-empty-p)
|
||||
@@ -127,15 +132,31 @@ the last command event was a string delimiter."
|
||||
(save-excursion
|
||||
(insert (make-string 2 last-command-event)))))
|
||||
|
||||
(defun gdscript-mark-defun ()
|
||||
"GDScript-specific version of `mark-defun'.
|
||||
|
||||
Put mark at end of this defun, point at beginning.
|
||||
The defun marked is the one that contains point or follows point.
|
||||
|
||||
If the mark is active, it marks the next defun after the one
|
||||
already marked."
|
||||
(interactive)
|
||||
(if (use-region-p)
|
||||
(gdscript-nav-forward-defun)
|
||||
(save-excursion
|
||||
(gdscript-nav-backward-defun)
|
||||
(set-mark (point))))
|
||||
(gdscript-nav-end-of-defun))
|
||||
|
||||
;;;###autoload
|
||||
(define-derived-mode gdscript-mode prog-mode "gdscript"
|
||||
"Major mode for editing Godot GDScript files."
|
||||
(setq-local tab-width gdscript-tab-width)
|
||||
(setq-local indent-tabs-mode gdscript-use-tab-indents)
|
||||
|
||||
(set-syntax-table gdscript-syntax-table)
|
||||
(modify-syntax-entry ?\# "\<" gdscript-syntax-table)
|
||||
(modify-syntax-entry ?\n ">" gdscript-syntax-table)
|
||||
(set-syntax-table gdscript-mode-syntax-table)
|
||||
(modify-syntax-entry ?\# "\<" gdscript-mode-syntax-table)
|
||||
(modify-syntax-entry ?\n ">" gdscript-mode-syntax-table)
|
||||
|
||||
(setq-local comment-start "# ")
|
||||
(setq-local comment-start-skip "#+\\s-*")
|
||||
@@ -189,27 +210,21 @@ the last command event was a string delimiter."
|
||||
#'gdscript-info-current-defun)
|
||||
|
||||
(add-hook 'which-func-functions #'gdscript-info-current-defun nil t)
|
||||
|
||||
(with-eval-after-load 'hideshow (add-to-list
|
||||
'hs-special-modes-alist
|
||||
'(gdscript-mode
|
||||
"\\s-*\\_<\\(?:func\\|class\\)\\_>"
|
||||
;; use the empty string as end regexp so it doesn't default to
|
||||
;; "\\s)". this way parens at end of defun are properly hidden.
|
||||
""
|
||||
"#"
|
||||
gdscript-hideshow-forward-sexp-function
|
||||
|
||||
(setq-local hs-special-modes-alist ''(gdscript-mode
|
||||
"\\s-*\\_<\\(?:func\\|class\\)\\_>"
|
||||
;; use the empty string as end regexp so it doesn't default to
|
||||
;; "\\s)". this way parens at end of defun are properly hidden.
|
||||
""
|
||||
"#"
|
||||
gdscript-hideshow-forward-sexp-function
|
||||
nil))
|
||||
|
||||
(setq-local outline-regexp
|
||||
(gdscript-rx (* space) block-start))
|
||||
(gdscript-rx (* space) block-start))
|
||||
(setq-local outline-level
|
||||
#'(lambda ()
|
||||
"`outline-level' function for gdscript mode."
|
||||
(1+ (/ (current-indentation) gdscript-indent-offset))))
|
||||
|
||||
(when gdscript-indent-guess-indent-offset
|
||||
"`outline-level' function for gdscript mode."
|
||||
(1+ (/ (current-indentation) gdscript-indent-offset)))))
|
||||
|
||||
(provide 'gdscript-mode)
|
||||
|
||||
94
gdscript-project.el
Normal file
94
gdscript-project.el
Normal file
@@ -0,0 +1,94 @@
|
||||
;;; gdscript-project.el --- Project -*- lexical-binding: t; -*-
|
||||
;;
|
||||
;; Copyright (C) 2020 GDQuest and contributors
|
||||
;;
|
||||
;; Author: Josef Vlach <vlach.josef@gmail.com>
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: June 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:
|
||||
;;
|
||||
;; Find all scenes/scripts functions.
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(require 'gdscript-utils)
|
||||
|
||||
(defun gdscript-project--current-buffer-scene ()
|
||||
"Return the name of current scene.
|
||||
|
||||
If current buffer is not visiting scene file return nil."
|
||||
(when buffer-file-name
|
||||
(let ((scene-name (concat
|
||||
(gdscript-util--find-project-configuration-file)
|
||||
(gdscript-util--get-godot-project-file-path-relative buffer-file-name) ".tscn")))
|
||||
(when (file-exists-p scene-name) scene-name))))
|
||||
|
||||
(defun gdscript-project--select-scene ()
|
||||
"Find all scenes files and let user choose one. Return `nil' if user cancels selection."
|
||||
(message "selecting scene")
|
||||
(let* ((rl (gdscript-util--find-project-configuration-file))
|
||||
(scene-list (mapcar (lambda (x) (file-relative-name x rl)) (directory-files-recursively rl ".*.tscn" t)))
|
||||
(prompt (format "Select scene to run" (buffer-name)))
|
||||
(selected-scene (gdscript-util--read scene-list prompt)))
|
||||
selected-scene))
|
||||
|
||||
(defun gdscript-project--current-buffer-script ()
|
||||
"Return the name of current script.
|
||||
|
||||
If current buffer is not visiting script file return nil."
|
||||
(when buffer-file-name
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(when (re-search-forward "^extends SceneTree\\|^extends MainLoop" nil t)
|
||||
(file-relative-name buffer-file-name (gdscript-util--find-project-configuration-file))))))
|
||||
|
||||
(defun gdscript-project--select-script (script-list)
|
||||
"Find all script files and let user choose one."
|
||||
(let ((hydra-open gdscript-hydra--open))
|
||||
(when hydra-open (gdscript-hydra--menu/nil))
|
||||
(unwind-protect
|
||||
(let* ((prompt (format "Buffer %s is not script file, select script to run" (buffer-name)))
|
||||
(script-name (gdscript-util--read script-list prompt)))
|
||||
(when script-name
|
||||
(string-match "^\\(.*.gd\\):" script-name)
|
||||
(gdscript-godot--run-script (match-string 1 script-name))))
|
||||
(when hydra-open (gdscript-hydra--menu/body)))))
|
||||
|
||||
(defun gdscript-project--get-all-scripts ()
|
||||
"Find all script files and let user choose one.
|
||||
|
||||
Since detection of script files require inspection of file contents,
|
||||
this use ag for performance."
|
||||
(if (executable-find "ag")
|
||||
(let ((default-directory (vc-git-root default-directory)))
|
||||
(with-temp-buffer
|
||||
(call-process "ag" nil (current-buffer) nil "--vimgrep" "-s" "^extends SceneTree|^extends MainLoop")
|
||||
(let ((available-standalone-scripts (split-string (buffer-string) "\n" t)))
|
||||
(if (null available-standalone-scripts)
|
||||
(message "No standalone script found. Look at https://docs.godotengine.org/en/stable/getting_started/editor/command_line_tutorial.html#running-a-script for details.")
|
||||
(gdscript-project--select-script available-standalone-scripts)))))
|
||||
(error (format "Buffer %s is no script file. To see all available scripts install 'ag' executable." (buffer-name)))))
|
||||
|
||||
(provide 'gdscript-project)
|
||||
|
||||
;;; gdscript-project.el ends here
|
||||
2915
gdscript-rx.el
2915
gdscript-rx.el
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,11 @@
|
||||
;;; gdscript-syntax.el --- Syntax highlighting for GDScript -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2020 GDQuest
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>, Fabián E. Gallina <fgallina@gnu.org>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Feb 2020
|
||||
;; Keywords: languages
|
||||
@@ -30,34 +30,10 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(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.
|
||||
(require 'cl-lib)
|
||||
(require 'gdscript-keywords)
|
||||
|
||||
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"))
|
||||
(defconst gdscript-built-in-functions (gdscript--get-package-file-content-as-string "data/built-in-functions.txt"))
|
||||
;; Contains all engine classes and node types, including vectors, transforms, etc.
|
||||
(defconst gdscript-built-in-classes (gdscript--get-package-file-content-as-string "data/built-in-classes.txt"))
|
||||
|
||||
(defun regex-maker (words)
|
||||
(defun gdscript-syntax-regex-maker (words)
|
||||
(regexp-opt words 'symbols))
|
||||
|
||||
;;; Font-lock and syntax
|
||||
@@ -80,14 +56,18 @@ structure."
|
||||
(_ form))))
|
||||
|
||||
;; Controls font-face mappings or colors to highlight groups of keywords
|
||||
(defvar gdscript-font-lock `((,(regex-maker gdscript-keywords)
|
||||
(defvar gdscript-font-lock `((,(rx (and "$" (one-or-more (or "/" (one-or-more word)))))
|
||||
(0 font-lock-constant-face))
|
||||
(,(rx (and (group "$") "\"" (zero-or-more nonl) "\""))
|
||||
(1 font-lock-constant-face))
|
||||
(,(gdscript-syntax-regex-maker gdscript-keywords)
|
||||
1
|
||||
font-lock-keyword-face)
|
||||
(,(regex-maker (concatenate 'list gdscript-built-in-constants
|
||||
gdscript-built-in-types gdscript-built-in-functions))
|
||||
(,(gdscript-syntax-regex-maker (append gdscript-built-in-constants
|
||||
gdscript-built-in-types gdscript-built-in-functions))
|
||||
1
|
||||
font-lock-builtin-face)
|
||||
(,(regex-maker gdscript-built-in-classes)
|
||||
(,(gdscript-syntax-regex-maker gdscript-built-in-classes)
|
||||
1
|
||||
font-lock-type-face)
|
||||
(,(rx symbol-start
|
||||
@@ -99,9 +79,12 @@ structure."
|
||||
(or "var" "const")
|
||||
(1+ space)
|
||||
(group (1+ (or word ?_))))
|
||||
(1 font-lock-variable-name-face))))
|
||||
|
||||
(defvar gdscript-syntax-table (make-syntax-table))
|
||||
(1 font-lock-variable-name-face))
|
||||
;; Function call
|
||||
(,(rx (group (1+ (or word ?_)))
|
||||
(0+ space)
|
||||
"(")
|
||||
(1 font-lock-function-name-face))))
|
||||
|
||||
(defun gdscript-syntax-context (type &optional syntax-ppss)
|
||||
"Return non-nil if point is on TYPE using SYNTAX-PPSS.
|
||||
@@ -137,7 +120,7 @@ The type returned can be `comment', `string' or `paren'."
|
||||
((rx (or "\"\"\"" "'''"))
|
||||
(0 (ignore (gdscript-syntax-stringify))))))
|
||||
|
||||
(define-inline gdscript-syntax-count-quotes (quote-char &optional point limit)
|
||||
(defun gdscript-syntax-count-quotes (quote-char &optional point limit)
|
||||
"Count number of quotes around point (max is 3).
|
||||
QUOTE-CHAR is the quote char to count. Optional argument POINT is
|
||||
the point where scan starts (defaults to current point), and LIMIT
|
||||
|
||||
341
gdscript-tests.el
Normal file
341
gdscript-tests.el
Normal file
@@ -0,0 +1,341 @@
|
||||
;;; gdscript-tests.el --- tests for gdscript mode -*- lexical-binding: t; -*-
|
||||
;;
|
||||
;; Copyright (C) 2020 GDQuest and contributors
|
||||
;;
|
||||
;; Author: Josef Vlach <vlach.josef@gmail.com>
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 1.0.0
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: June 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:
|
||||
;;
|
||||
;; To run the tests in terminal:
|
||||
;; > ./makem.sh test
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(require 'ert)
|
||||
(require 'gdscript-mode)
|
||||
|
||||
;; NOTE: `gdscript-tests--with-temp-buffer' and `gdscript-tests-look-at' are
|
||||
;; originally from the Python package
|
||||
|
||||
(defmacro gdscript-tests--with-temp-buffer (contents &rest body)
|
||||
"Create a `gdscript-mode' enabled temp buffer with CONTENTS.
|
||||
BODY is code to be executed within the temp buffer. Point is
|
||||
always located at the beginning of buffer."
|
||||
(declare (indent 1) (debug t))
|
||||
`(with-temp-buffer
|
||||
(let ()
|
||||
(gdscript-mode)
|
||||
(insert ,contents)
|
||||
(goto-char (point-min))
|
||||
,@body)))
|
||||
|
||||
(defun gdscript-tests-look-at (string &optional num restore-point)
|
||||
"Move point at beginning of STRING in the current buffer.
|
||||
Optional argument NUM defaults to 1 and is an integer indicating
|
||||
how many occurrences must be found, when positive the search is
|
||||
done forwards, otherwise backwards. When RESTORE-POINT is
|
||||
non-nil the point is not moved but the position found is still
|
||||
returned. When searching forward and point is already looking at
|
||||
STRING, it is skipped so the next STRING occurrence is selected."
|
||||
(let* ((num (or num 1))
|
||||
(starting-point (point))
|
||||
(string (regexp-quote string))
|
||||
(search-fn (if (> num 0) #'re-search-forward #'re-search-backward))
|
||||
(deinc-fn (if (> num 0) #'1- #'1+))
|
||||
(found-point))
|
||||
(prog2
|
||||
(catch 'exit
|
||||
(while (not (= num 0))
|
||||
(when (and (> num 0)
|
||||
(looking-at string))
|
||||
;; Moving forward and already looking at STRING, skip it.
|
||||
(forward-char (length (match-string-no-properties 0))))
|
||||
(and (not (funcall search-fn string nil t))
|
||||
(throw 'exit t))
|
||||
(when (> num 0)
|
||||
;; `re-search-forward' leaves point at the end of the
|
||||
;; occurrence, move back so point is at the beginning
|
||||
;; instead.
|
||||
(forward-char (- (length (match-string-no-properties 0)))))
|
||||
(setq
|
||||
num (funcall deinc-fn num)
|
||||
found-point (point))))
|
||||
found-point
|
||||
(and restore-point (goto-char starting-point)))))
|
||||
|
||||
(defun gdscript-tests-self-insert (char-or-str)
|
||||
"Call `self-insert-command' for chars in CHAR-OR-STR."
|
||||
(let ((chars
|
||||
(cond
|
||||
((characterp char-or-str)
|
||||
(list char-or-str))
|
||||
((stringp char-or-str)
|
||||
(string-to-list char-or-str))
|
||||
((not
|
||||
(cl-remove-if #'characterp char-or-str))
|
||||
char-or-str)
|
||||
(t (error "CHAR-OR-STR must be a char, string, or list of char")))))
|
||||
(mapc
|
||||
(lambda (char)
|
||||
(let ((last-command-event char))
|
||||
(call-interactively 'self-insert-command)))
|
||||
chars)))
|
||||
|
||||
(ert-deftest gdscript-indent--comment-line ()
|
||||
"Test if current line is comment."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
# aaa
|
||||
bbb
|
||||
"
|
||||
(gdscript-tests-look-at "aaa")
|
||||
(should (gdscript-info-current-line-comment-p))
|
||||
(gdscript-tests-look-at "bbb")
|
||||
(should (not (gdscript-info-current-line-comment-p)))))
|
||||
|
||||
(ert-deftest gdscript-indent--electric-colon-4 ()
|
||||
"Test indentation case where there is one more-indented previous open block."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
if true or true:
|
||||
a = 5
|
||||
|
||||
if true and true:
|
||||
a = 10
|
||||
|
||||
b = 3
|
||||
|
||||
else
|
||||
"
|
||||
(gdscript-tests-look-at "else")
|
||||
(goto-char (line-end-position))
|
||||
(gdscript-tests-self-insert ":")
|
||||
(gdscript-tests-look-at "else" -1)
|
||||
(should (= (current-indentation) 4))))
|
||||
|
||||
(ert-deftest gdscript-tests--indent-electric-colon-8 ()
|
||||
"Test indentation case where there is one more-indented previous open block, but it is comment."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
if true or true:
|
||||
a = 5
|
||||
|
||||
if true and true:
|
||||
a = 10
|
||||
|
||||
# b = 3
|
||||
|
||||
else
|
||||
"
|
||||
(gdscript-tests-look-at "else")
|
||||
(goto-char (line-end-position))
|
||||
(gdscript-tests-self-insert ":")
|
||||
(gdscript-tests-look-at "else" -1)
|
||||
(should (= (current-indentation) 8))))
|
||||
|
||||
(ert-deftest gdscript-tests--dedent-if-else ()
|
||||
"Test dedentation case where else is dedented from inner if to outer if."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
if true:
|
||||
if true:
|
||||
a = 5
|
||||
else:
|
||||
"
|
||||
(gdscript-tests-look-at "else")
|
||||
(let ((last-command 'indent-for-tab-command)
|
||||
(this-command 'indent-for-tab-command))
|
||||
(should (= (current-indentation) 8))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 4)))))
|
||||
|
||||
(ert-deftest gdscript-tests--dedent-if-elif ()
|
||||
"Test dedentation case where elif is dedented from inner if to outer if."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
if true:
|
||||
if true:
|
||||
a = 5
|
||||
elif true:
|
||||
"
|
||||
(gdscript-tests-look-at "elif")
|
||||
(let ((last-command 'indent-for-tab-command)
|
||||
(this-command 'indent-for-tab-command))
|
||||
(should (= (current-indentation) 8))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 4)))))
|
||||
|
||||
(ert-deftest gdscript-tests--dedent-elif-else ()
|
||||
"Test dedentation case where else is dedented from inner elif to outer if."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
if true:
|
||||
if true:
|
||||
a = 5
|
||||
elif true:
|
||||
a = 6
|
||||
else:
|
||||
"
|
||||
(gdscript-tests-look-at "else")
|
||||
(let ((last-command 'indent-for-tab-command)
|
||||
(this-command 'indent-for-tab-command))
|
||||
(should (= (current-indentation) 8))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 4)))))
|
||||
|
||||
(ert-deftest gdscript-tests--indent-if-with-parens ()
|
||||
"Test indentation where if is followed by expression in parens."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
if (
|
||||
true
|
||||
):
|
||||
aaa = 5
|
||||
"
|
||||
(gdscript-tests-look-at "aaa")
|
||||
(let ((last-command 'indent-for-tab-command)
|
||||
(this-command 'indent-for-tab-command))
|
||||
(should (= (current-indentation) 0))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 8))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 4)))))
|
||||
|
||||
(ert-deftest gdscript-tests--indent-elif-with-parens ()
|
||||
"Test indentation where elif is followed by expression in parens."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
if (
|
||||
true
|
||||
):
|
||||
aaa = 5
|
||||
elif(
|
||||
true
|
||||
):
|
||||
aaa = 6
|
||||
"
|
||||
(gdscript-tests-look-at "aaa = 6")
|
||||
(let ((last-command 'indent-for-tab-command)
|
||||
(this-command 'indent-for-tab-command))
|
||||
(should (= (current-indentation) 0))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 8))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 4)))))
|
||||
|
||||
(ert-deftest gdscript-tests--indent-while-with-parens ()
|
||||
"Test indentation case where while is followed by expression in parens."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
while (
|
||||
true
|
||||
):
|
||||
aaa = 5
|
||||
"
|
||||
(gdscript-tests-look-at "aaa")
|
||||
(let ((last-command 'indent-for-tab-command)
|
||||
(this-command 'indent-for-tab-command))
|
||||
(should (= (current-indentation) 0))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 8))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 4)))))
|
||||
|
||||
(ert-deftest gdscript-tests--indent-func-with-parens ()
|
||||
"Test indentation case where function params span multiple lines."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f(
|
||||
i: int
|
||||
):
|
||||
pass
|
||||
"
|
||||
(gdscript-tests-look-at "pass")
|
||||
(let ((last-command 'indent-for-tab-command)
|
||||
(this-command 'indent-for-tab-command))
|
||||
(should (= (current-indentation) 0))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 4)))))
|
||||
|
||||
(ert-deftest gdscript-tests--indent-nested-ifs-with-parens ()
|
||||
"Test indentation where if is nested."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
if (
|
||||
true
|
||||
):
|
||||
if (
|
||||
true
|
||||
):
|
||||
aaa
|
||||
"
|
||||
(gdscript-tests-look-at "aaa")
|
||||
(let ((last-command 'indent-for-tab-command)
|
||||
(this-command 'indent-for-tab-command))
|
||||
(should (= (current-indentation) 0))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 12))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 8))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 4))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 0))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 12)))))
|
||||
|
||||
(ert-deftest gdscript-tests--dedent-nested-ifs-with-parens ()
|
||||
"Test dedentation where if is nested."
|
||||
(gdscript-tests--with-temp-buffer
|
||||
"
|
||||
func f():
|
||||
if (
|
||||
true
|
||||
):
|
||||
if (
|
||||
true
|
||||
):
|
||||
aaa
|
||||
else:
|
||||
"
|
||||
(gdscript-tests-look-at "else")
|
||||
(let ((last-command 'indent-for-tab-command)
|
||||
(this-command 'indent-for-tab-command))
|
||||
(should (= (current-indentation) 0))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 8))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 4))
|
||||
(indent-for-tab-command)
|
||||
(should (= (current-indentation) 8)))))
|
||||
244
gdscript-ts-mode.el
Normal file
244
gdscript-ts-mode.el
Normal file
@@ -0,0 +1,244 @@
|
||||
;;; gdscript-ts-mode.el --- Summary -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2023 GDQuest and contributors
|
||||
|
||||
;; Author: xiliuya <xiliuya@aliyun.com>
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 0.1.0
|
||||
;; Maintainer: xiliuya <xiliuya@aliyun.com>
|
||||
;; Created: 2023-05-22 19:14:43
|
||||
|
||||
;; Keywords: languages
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
|
||||
|
||||
;; 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
;;
|
||||
;; Tree-sitter mode for Gdscript.(Refer to python-ts-mode)
|
||||
;; That supports the use tree-sitter for font-lock, imenu, indentation,
|
||||
;; and navigation of Gdscript files.
|
||||
|
||||
;;
|
||||
;;; Code:
|
||||
|
||||
(when (version< "29" emacs-version)
|
||||
(require 'treesit))
|
||||
|
||||
|
||||
;;; Imenu
|
||||
|
||||
(defvar gdscript-ts-imenu-format-item-label-function
|
||||
'gdscript-ts-imenu-format-item-label
|
||||
"Imenu function used to format an item label.
|
||||
It must be a function with two arguments: TYPE and NAME.")
|
||||
|
||||
(defvar gdscript-ts-imenu-format-parent-item-label-function
|
||||
'gdscript-ts-imenu-format-parent-item-label
|
||||
"Imenu function used to format a parent item label.
|
||||
It must be a function with two arguments: TYPE and NAME.")
|
||||
|
||||
(defvar gdscript-ts-imenu-format-parent-item-jump-label-function
|
||||
'gdscript-ts-imenu-format-parent-item-jump-label
|
||||
"Imenu function used to format a parent jump item label.
|
||||
It must be a function with two arguments: TYPE and NAME.")
|
||||
|
||||
(defun gdscript-ts-imenu-format-item-label (type name)
|
||||
"Return Imenu label for single node using TYPE and NAME."
|
||||
(format "%s (%s)" name type))
|
||||
|
||||
(defun gdscript-ts-imenu-format-parent-item-label (type name)
|
||||
"Return Imenu label for parent node using TYPE and NAME."
|
||||
(format "%s..." (gdscript-ts-imenu-format-item-label type name)))
|
||||
|
||||
(defun gdscript-ts-imenu-format-parent-item-jump-label (type _name)
|
||||
"Return Imenu label for parent node jump using TYPE and NAME."
|
||||
(if (string= type "class")
|
||||
"*class definition*"
|
||||
"*function definition*"))
|
||||
|
||||
;;; Keywords
|
||||
|
||||
(defvar gdscript-ts--treesit-keywords '("and" "as" "break" "class" "class_name"
|
||||
"const" "continue" "elif" "else" "enum" "export" "extends" "for" "func" "if" "in" "is"
|
||||
"master" "match" "not" "onready" "or" "pass" "puppet" "remote" "remotesync" "return" "setget" "signal"
|
||||
"var" "while"))
|
||||
|
||||
|
||||
;;; Setting
|
||||
|
||||
(defvar gdscript-ts--treesit-settings
|
||||
(treesit-font-lock-rules
|
||||
:language 'gdscript
|
||||
:feature 'comment
|
||||
'((comment) @font-lock-comment-face)
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'definition
|
||||
'((function_definition (name) @font-lock-function-name-face)
|
||||
(class_definition
|
||||
(name) @font-lock-function-name-face)
|
||||
(parameters (identifier) @font-lock-variable-name-face))
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'keyword
|
||||
`(([,@gdscript-ts--treesit-keywords] @font-lock-keyword-face)
|
||||
([(false) (true)] @font-lock-keyword-face))
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'string
|
||||
'((string) @font-lock-string-face)
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'type
|
||||
'(((type) @font-lock-type-face)
|
||||
(get_node) @font-lock-type-face)
|
||||
|
||||
:feature 'function
|
||||
:language 'gdscript
|
||||
'((call (identifier) @font-lock-function-call-face)
|
||||
(attribute_call (identifier) @font-lock-function-call-face))
|
||||
|
||||
:language 'gdscript
|
||||
:feature 'variable
|
||||
'((_ (name) @font-lock-variable-name-face))
|
||||
|
||||
:feature 'number
|
||||
:language 'gdscript
|
||||
'(([(integer) (float)] @font-lock-number-face))
|
||||
|
||||
:feature 'property
|
||||
:language 'gdscript
|
||||
'((attribute (identifier) (identifier) @font-lock-property-use-face))
|
||||
|
||||
:feature 'operator
|
||||
:language 'gdscript
|
||||
`(["+" "-" "*" "/" "^" ">" "<" "="] @font-lock-operator-face)))
|
||||
|
||||
|
||||
;;; Funtion
|
||||
|
||||
(defun gdscript-ts--treesit-defun-name (node)
|
||||
"Return the defun name of NODE."
|
||||
(treesit-node-text (treesit-search-subtree node "^name$" nil t) t))
|
||||
|
||||
(defun gdscript-ts--imenu-treesit-create-index-1 (node)
|
||||
"Given a sparse tree, create an imenu alist.
|
||||
|
||||
NODE is the root node of the tree returned by
|
||||
`treesit-induce-sparse-tree' (not a tree-sitter node, its car is
|
||||
a tree-sitter node). Walk that tree and return an imenu alist.
|
||||
|
||||
Return a list of ENTRY where
|
||||
|
||||
ENTRY := (NAME . MARKER)
|
||||
| (NAME . ((JUMP-LABEL . MARKER)
|
||||
ENTRY
|
||||
...)
|
||||
|
||||
NAME is the function/class's name, JUMP-LABEL is like \"*function
|
||||
definition*\"."
|
||||
(let* ((ts-node (car node))
|
||||
(children (cdr node))
|
||||
(subtrees (mapcan #'gdscript-ts--imenu-treesit-create-index-1
|
||||
children))
|
||||
(type (pcase (treesit-node-type ts-node)
|
||||
("function_definition" 'def)
|
||||
("export_variable_statement" 'e-var)
|
||||
("onready_variable_statement" 'o-var)
|
||||
("variable_statement" 'var)
|
||||
("class_definition" 'class)))
|
||||
;; The root of the tree could have a nil ts-node.
|
||||
(name (when ts-node
|
||||
(or (treesit-defun-name ts-node)
|
||||
"Anonymous")))
|
||||
(marker (when ts-node
|
||||
(set-marker (make-marker)
|
||||
(treesit-node-start ts-node)))))
|
||||
(cond
|
||||
((null ts-node)
|
||||
subtrees)
|
||||
(subtrees
|
||||
(let ((parent-label
|
||||
(funcall gdscript-ts-imenu-format-parent-item-label-function
|
||||
type name))
|
||||
(jump-label
|
||||
(funcall
|
||||
gdscript-ts-imenu-format-parent-item-jump-label-function
|
||||
type name)))
|
||||
`((,parent-label
|
||||
,(cons jump-label marker)
|
||||
,@subtrees))))
|
||||
(t (let ((label
|
||||
(funcall gdscript-ts-imenu-format-item-label-function
|
||||
type name)))
|
||||
(list (cons label marker)))))))
|
||||
|
||||
(defun gdscript-ts-imenu-treesit-create-index (&optional node)
|
||||
"Return tree Imenu alist for the current Gdscript buffer.
|
||||
|
||||
Change `gdscript-ts-imenu-format-item-label-function',
|
||||
`gdscript-ts-imenu-format-parent-item-label-function',
|
||||
`gdscript-ts-imenu-format-parent-item-jump-label-function' to
|
||||
customize how labels are formatted.
|
||||
|
||||
NODE is the root node of the subtree you want to build an index
|
||||
of. If nil, use the root node of the whole parse tree.
|
||||
|
||||
Similar to `gdscript-imenu-create-index' but use tree-sitter."
|
||||
(let* ((node (or node (treesit-buffer-root-node 'gdscript)))
|
||||
(tree (treesit-induce-sparse-tree
|
||||
node
|
||||
(rx (or (seq bol
|
||||
(or "onready_" "export_" "")
|
||||
"variable_statement"
|
||||
eol)
|
||||
(seq bol
|
||||
(or "function" "class")
|
||||
"_definition"
|
||||
eol)))
|
||||
nil 1000)))
|
||||
(gdscript-ts--imenu-treesit-create-index-1 tree)))
|
||||
|
||||
;;;###autoload
|
||||
(define-derived-mode gdscript-ts-mode gdscript-mode "Gdscript"
|
||||
"Major mode for editing gdscript files, using tree-sitter library.
|
||||
|
||||
\\{gdscript-ts-mode-map}"
|
||||
:syntax-table gdscript-mode-syntax-table
|
||||
(when (treesit-ready-p 'gdscript)
|
||||
(treesit-parser-create 'gdscript)
|
||||
(setq-local treesit-font-lock-feature-list
|
||||
'(( comment definition)
|
||||
( keyword string type)
|
||||
( function variable number property operator)))
|
||||
(setq-local treesit-font-lock-settings gdscript-ts--treesit-settings)
|
||||
;;; TODO: create-imenu
|
||||
(setq-local imenu-create-index-function
|
||||
#'gdscript-ts-imenu-treesit-create-index)
|
||||
(setq-local treesit-defun-type-regexp (rx (seq bol
|
||||
(or "function" "class")
|
||||
"_definition"
|
||||
eol)))
|
||||
(setq-local treesit-defun-name-function
|
||||
#'gdscript-ts--treesit-defun-name)
|
||||
(treesit-major-mode-setup)
|
||||
|
||||
|
||||
(add-to-list 'auto-mode-alist '("\\.gd\\'" . gdscript-ts-mode))
|
||||
(add-to-list 'interpreter-mode-alist '("gdscript[0-9.]*" . gdscript-ts-mode))))
|
||||
|
||||
(provide 'gdscript-ts-mode)
|
||||
;;; gdscript-ts-mode.el ends here
|
||||
@@ -1,11 +1,11 @@
|
||||
;;; gdscript-utils.el --- Utility functions for gdscript-mode -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2020 GDQuest, Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2020 GDQuest
|
||||
|
||||
;; Author: Nathan Lovato <nathan@gdquest.com>, Fabián E. Gallina <fgallina@gnu.org>
|
||||
;; URL: https://github.com/GDQuest/emacs-gdscript-mode/
|
||||
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
|
||||
;; Version: 0.1.0
|
||||
;; Package-Requires: ((emacs "26.0"))
|
||||
;; Package-Requires: ((emacs "26.3"))
|
||||
;; Maintainer: nathan@gdquest.com
|
||||
;; Created: Jan 2020
|
||||
;; Keywords: languages
|
||||
@@ -30,6 +30,9 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'gdscript-syntax)
|
||||
(require 'gdscript-customization)
|
||||
|
||||
(defun gdscript--util-goto-line (line-number)
|
||||
"Move point to LINE-NUMBER."
|
||||
(goto-char (point-min))
|
||||
@@ -88,6 +91,78 @@ allowed files."
|
||||
(list full-file-name))))
|
||||
(directory-files dir-name)))))
|
||||
|
||||
|
||||
(defun gdscript-util--find-project-configuration-file (&optional start-path)
|
||||
"Return the path to the file \"project.godot\".
|
||||
|
||||
Start the search from START-PATH if provided. Otherwise, the search
|
||||
starts from the current buffer path.
|
||||
|
||||
WARNING: the Godot project must exist for this function to work."
|
||||
(let* ((base-path (or start-path default-directory))
|
||||
(dominating-file
|
||||
(locate-dominating-file base-path
|
||||
(lambda (parent)
|
||||
(directory-files parent t "project.godot")))))
|
||||
(when dominating-file (expand-file-name dominating-file))))
|
||||
|
||||
(defun gdscript-util--get-godot-project-name ()
|
||||
"Retrieve the project name from Godot's configuration file."
|
||||
(with-temp-buffer
|
||||
(insert-file-contents (concat (gdscript-util--find-project-configuration-file) "project.godot"))
|
||||
(goto-char (point-min))
|
||||
(if (re-search-forward "config/name=\"\\([^\"]*\\)\"" nil t)
|
||||
(match-string 1)
|
||||
(error "Could not find the name of the project"))))
|
||||
|
||||
(defun gdscript-util--get-godot-buffer-name (&optional editor)
|
||||
"Return buffer name for godot's stdout/stderr output."
|
||||
(format (if editor "*godot - %s - Editor*" "*godot - %s*") (gdscript-util--get-godot-project-name)))
|
||||
|
||||
(defun gdscript-util--get-gdformat-buffer-name ()
|
||||
"Return buffer name for godot's stdout/stderr output."
|
||||
(format "*gdformat - %s*" (gdscript-util--get-godot-project-name)))
|
||||
|
||||
(defun gdscript-util--get-godot-project-file-path-relative (file-path)
|
||||
"Return the relative path of `FILE-PATH' to Godot's configuration file."
|
||||
(let ((project-configuration-file (gdscript-util--find-project-configuration-file)))
|
||||
(when project-configuration-file
|
||||
(concat (file-name-sans-extension
|
||||
(file-relative-name file-path project-configuration-file))))))
|
||||
|
||||
(defun gdscript-util--flatten (xs)
|
||||
"Flatten deeply nested list.
|
||||
|
||||
For example:
|
||||
> (gdscript-util--flatten (list 1 2 (list 3 (list 4 5)) nil))
|
||||
> (1 2 3 4 5)
|
||||
"
|
||||
(cond
|
||||
((null xs) nil)
|
||||
((listp xs) (append (gdscript-util--flatten (car xs)) (gdscript-util--flatten (cdr xs))))
|
||||
(t (list xs))))
|
||||
|
||||
(defun gdscript-util--read (items &optional prompt)
|
||||
"Let's choose single item from ITEMS from mini-buffer.
|
||||
PROMPT is prompt for read command. Return `nil' if user aborts."
|
||||
(let* ((p (if prompt prompt "Options"))
|
||||
(result (cond ((and (featurep 'projectile) )
|
||||
(projectile-completing-read (format "%s: " p) items))
|
||||
((fboundp 'ivy-read)
|
||||
(ivy-read (format "%s: " p) items))
|
||||
((fboundp 'ido-completing-read)
|
||||
(ido-completing-read (format "%s: " p) items))
|
||||
(t
|
||||
(completing-read (format "%s (hit TAB to auto-complete): " p) items nil t)))))
|
||||
(if quit-flag nil result)))
|
||||
|
||||
(defmacro gdscript-util--with-available-hydra (&rest body)
|
||||
""
|
||||
`(progn
|
||||
(when (not (featurep 'hydra))
|
||||
(error "No `hydra.el' available. To execute `gdscript-hydra-show' command you need to install hydra.el"))
|
||||
,@body))
|
||||
|
||||
(provide 'gdscript-utils)
|
||||
|
||||
;;; gdscript-utils.el ends here
|
||||
|
||||
Reference in New Issue
Block a user