-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
gdscript-hydra.el
157 lines (139 loc) · 6.43 KB
/
gdscript-hydra.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
;;; gdscript-hydra.el --- Hydra for launching Godot -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020 GDQuest and contributors
;;
;; Author: Josef Vlach <[email protected]>
;; URL: https://github.com/godotengine/emacs-gdscript-mode/
;; Version: 1.0.0
;; Package-Requires: ((emacs "26.3"))
;; Maintainer: [email protected]
;; 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