• Stars
    star
    303
  • Rank 137,655 (Top 3 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created almost 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Emacs package to get GDScript support and syntax highlighting.

GDScript mode for Emacs

banner showing the "GDScript mode" title with GDScript code in the background

This package adds support for the GDScript programming language from the Godot game engine in Emacs. It gives syntax highlighting and indentations. Contributors are welcome!

Table of Contents

Features

This mode features all the essentials:

  • Syntax highlighting.
  • Code folding.
  • Debugger support.
  • Imenu.
  • 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.
  • 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 .

Code folding in action.

Contributing

Contributors are welcome! Check the issues tab for tasks to work on and open a PR anytime.

If you find a bug or would like to suggest an improvement, open a new issue.

For code style, we follow the Emacs lisp style guide by Bozhidar Batsov, and the tips and conventions 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 installed.

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:

eask lint checkdoc && eask lint package

How to install

The package is available in the MELPA package archive. Once you set up MELPA you can install the package from Emacs:

M-x package-install gdscript-mode

Then, in your init.el file, you can require the package:

(require 'gdscript-mode)

Installing in Spacemacs

  1. Add the package to the dotspacemacs-additional-packages. You can find it under the dotspacemacs/layers function:
(defun dotspacemacs/layers ()
  "Configuration Layers declaration..."
  (setq-default
   ;; ...
   dotspacemacs-additional-packages '(gdscript-mode)
   ;; ...
   ))
  1. In your dotspacemacs/user-config function, require the package.
(defun dotspacemacs/user-config ()
  (require 'gdscript-mode))

Installing in Doom Emacs

Doom Emacs comes with a Godot GDScript module.

You just need to add the "lang: gdscript" keyword to your .doom.d/init.el file.

:lang
(gdscript +lsp)          ; the language you waited for

The +lsp flag adds language server support for game development with Godot.

To see the module's documentation in Emacs, place your cursor over the word gdscript and press k.

Installing with use-package + straight.el

Add the call to use-package to your Emacs configuration:

(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 to your computer.
  2. In your init.el file, add a call to load and require the package.
(add-to-list 'load-path "/path/to/gdscript-mode")
(require 'gdscript-mode)

Auto-completion with the Language Server Protocol (LSP)

For auto-completion, we rely on either the eglot or lsp-mode packages, and the GDScript language server which is built into Godot.

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:

(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.

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):

(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 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 :

sudo pacman -S tree-sitter

Install grammar

To support Gdscript, we must install gdscript-grammar:

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 )

(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.

If you don't have godot available there, you can set a custom executable name or path to use instead:

(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 C-u 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 (C-c r) opens a 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

Browsing the Godot API with eww

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.

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 or download a build from Hugo Lourcio's website.
  2. Set gdscript-docs-local-path to the docs' directory, that contains the docs' index.html file.

For example:

(setq gdscript-docs-local-path "/home/gdquest/Documents/docs/godot")

Keyboard shortcuts

The following shortcuts are available by default:

  • Inserting:
    • C-c i gdscript-completion-insert-file-path-at-point
  • Formatting:
    • C-c C-f r gdscript-format-region
    • C-c C-f b gdscript-format-buffer
  • Running the project and scenes in Godot:
    • C-c C-r p gdscript-godot-open-project-in-editor
    • C-c C-r r gdscript-godot-run-project
    • C-c C-r d gdscript-godot-run-project-debug
    • C-c C-r s gdscript-godot-run-current-scene
    • C-c C-r q gdscript-godot-run-current-scene-debug
    • C-c C-r e gdscript-godot-edit-current-scene
    • C-c C-r x gdscript-godot-run-current-script
  • Browsing the code reference:
    • C-c C-b a gdscript-docs-browse-api
    • C-c C-b o gdscript-docs-browse-symbol-at-point
  • Open hydra:
    • C-c r gdscript-hydra-show (require hydra package to be installed)
    • C-c n 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:

(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 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 (F9).

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 D on a breakpoint line deletes the breakpoint. Pressing RET 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 RET 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 d 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 C-c n.

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
  • n - Steps to the next line of code.
  • c - Continue program execution until the next breakpoint.
  • m - Steps into the code.
  • s - Shows the * Stack dump * buffer.
  • v - Shows the * Stack frame vars * buffer.
  • i - Shows the * Inspector * buffer.
  • t - Shows the * Scene tree * buffer.
  • d - Fetches details for all object present in the * Stack frame vars * and * Inspector * buffers and redisplay the buffers.
  • o - Pins self in the * Inspector * buffer. It stays displayed until Godot frees the instance or you unpin it.
  • u - Unpins the currently pinned object.
  • q - 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:

  • TAB toggles multi-line display for selected types.
  • RET on an object line to display its details in the * Inspector *buffer.
  • l displays the * Stack dump * buffer.
  • d displays additional details for ObjectId variables.
  • p goes to the previous line.
  • n goes to the next line.
  • o pins the current object in the * Inspector * buffer.
  • u unpins the currently pinned object.
  • q 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 TAB to toggle multi-line display for selected typess.
  • Press RET on object line to display its detailss.
  • Press RET on Node/path line (second line from the top) to show given object in * Scene Tree * buffers.
  • Press l 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 d to display additional details for object variabless.
  • Press p to go to the previous lines.
  • Press n to go to the next lines.
  • Press o to pin current object in * Inspector * buffers.
  • Press u to unpin currently pinned objects.
  • Press q to close the buffers.

* Stack dump * buffer

Contains stack dump information.

  • Press SPC to jump to gdscript file where stack frame points to.
  • Press RET to jump to the gdscript file and show * Stack frame vars *, * Inspector * buffers, and a debug hydra.
  • Press l to display the * Stack frame vars * buffer.
  • Press p to go to the previous line.
  • Press n to go to the next line.
  • Press q to close the buffer.

* Breakpoints * buffer

Lists all existing breakpoints in the project.

  • Press SPC to enable or disable all breakpoints.
  • Press RET to jump to the file and line corresponding to the breakpoint..
  • Press TAB to display the * Stack dump * buffer.
  • Press D to delete the breakpoint.
  • Press q to close the buffer.

* Scene tree * buffer

Contains a tree visualisation of all objects in the running program.

  • Press RET to open the corresponding object in the * Inspector * buffer.
  • Press p to go to the previous line.
  • Press n to go to the next line.
  • Press q to close the buffer.

More Repositories

1

godot

Godot Engine – Multi-platform 2D and 3D game engine
C++
88,512
star
2

awesome-godot

A curated list of free/libre plugins, scripts and add-ons for Godot
6,841
star
3

godot-demo-projects

Demonstration and Template Projects
GDScript
5,567
star
4

godot-docs

Godot Engine official documentation
reStructuredText
3,655
star
5

godot-cpp

C++ bindings for the Godot script API
C++
1,607
star
6

godot-vscode-plugin

Godot development tools for VSCode
TypeScript
1,517
star
7

godot-blender-exporter

Addon for Blender to directly export to a Godot Scene
Python
1,154
star
8

godot-proposals

Godot Improvement Proposals (GIPs)
1,089
star
9

tps-demo

Godot Third Person Shooter with high quality assets and lighting
GDScript
972
star
10

godot-git-plugin

Git implementation of the VCS interface in Godot
C++
669
star
11

collada-exporter

"Better" Collada exporter for Blender, orignally developed by the Godot Engine community
Python
416
star
12

godot-syntax-themes

Syntax themes for the Godot Engine script editor
397
star
13

godot-headers

Headers for the Godot API supplied by the GDNative module.
C
376
star
14

FBX2glTF

A command-line tool for the conversion of 3D model assets on the FBX file format to the glTF file format.
C++
326
star
15

godot-asset-library

PHP frontend for Godot Engine's asset library
PHP
289
star
16

godot-website

The code for the official Godot Engine website. A static site built using Jekyll.
HTML
283
star
17

godot-csharp-visualstudio

Godot C# extension for Visual Studio
C#
234
star
18

build-containers

Godot engine build containers
Shell
207
star
19

webrtc-native

The official GDNative WebRTC implementation for non-html exports.
C++
205
star
20

godot-design

Visual design specific stuff for the godot engine
202
star
21

gdnative-demos

Demo projects for GDNative
Python
191
star
22

godot-old-gsoc-ideas

Old ideas for Google Summer of Code (no longer relevant)
165
star
23

godot-google-play-billing

Godot Android plugin for the Google Play Billing library
Java
146
star
24

godot-csharp-vscode

Debugger and utilities for working with Godot C# projects in VSCode
TypeScript
141
star
25

godot-ios-plugins

Objective-C++
128
star
26

godot-benchmarks

Collection of benchmarks to test performance of different areas of Godot
GDScript
121
star
27

godot-visual-script

VisualScript as a Godot Engine c++ module
C++
118
star
28

godot-cpp-template

Quickstart template for GDExtension development with Godot
Python
109
star
29

godot-3d-dodge-the-creeps

This project was moved to https://github.com/godotengine/godot-demo-projects/tree/master/3d/squash_the_creeps
GDScript
91
star
30

godot-build-scripts

Build scripts used for official Godot Engine builds with https://github.com/godotengine/build-containers
Shell
79
star
31

godot-mono-builds

Mono build scripts for Godot
Python
56
star
32

godot-builds

Official pre-releases, dev snapshots, and custom builds of the Godot engine.
Python
54
star
33

godot-docs-l10n

Localization of the Godot documentation – Translations should be done on Weblate (see link)
Shell
51
star
34

godot-3d-platformer-demo

3D platformer, developed as part of the Mozilla Grant 2019
44
star
35

godot-tests

Repository for Godot benchmarks, regression tests, etc.
GDScript
35
star
36

godot-interactive-changelog

An interactive tool to view a changelog for each version of Godot Engine
JavaScript
30
star
37

godot-monodevelop-addin

Godot Add-in for MonoDevelop and Visual Studio for Mac
C#
30
star
38

godot-docs-project-starters

A collection of project templates and assets used by tutorials in the official Godot documentation. https://github.com/godotengine/godot-docs
GDScript
27
star
39

mousse

High quality 3D platform demo, designed to make the best use of Godot 4.0
24
star
40

doc-status

Online Godot class reference status
JavaScript
21
star
41

godot-platform-haiku

Godot Engine platform port for the Haiku operating system // UNMAINTAINED, for reference / forks.
C++
19
star
42

webrtc-actions

A set of github actions to build WebRTC as a single static library.
18
star
43

regression-test-project

Godot engine regression test project
GDScript
17
star
44

godot-team-reports

Browse Godot PR backlog for each maintenance team
JavaScript
17
star
45

godot-editor-l10n

Localization of the Godot editor and class reference – Translations should be done on Weblate (see link)
Python
14
star
46

gdscript-tests

Tests for the GDScript module implementation
HTML
13
star
47

godot-showreel-voting

A Django app to review and vote videos
Python
12
star
48

godot-prs-by-file

JavaScript
12
star
49

.github

Godot community health files
10
star
50

community-map

Map of regional community locations, submit your community here
9
star
51

issue-bot

Issuebot for chat.godotengine.org
Python
8
star
52

godot-commit-artifacts

A tool providing quick links to latest CI builds of development branches
JavaScript
8
star
53

godot-nir-static

C++
8
star
54

godot-benchmarks-results

Website to display godot-benchmarks results
6
star
55

godot-website-cover-generator

JavaScript
5
star
56

moltenvk-osxcross

Custom MoltenVK builds with `-fno-objc-msgsend-selector-stubs` to be compatible with osxcross
4
star
57

godot-question2answer

A repository hosting the current platform used at https://ask.godotengine.org
PHP
4
star
58

godot-docs-user-notes

User notes for the Godot Engine official documentation
4
star
59

issue-stats

Gather hardware and software information based on Godot GitHub issue reports
Python
3
star
60

discourse-theme

A custom Godot styled theme for discourse
SCSS
2
star