-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathgdscript-snippet.el
More file actions
109 lines (81 loc) · 3.44 KB
/
Copy pathgdscript-snippet.el
File metadata and controls
109 lines (81 loc) · 3.44 KB
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
;;; gdscript-snippet.el --- Snippets for GDScript -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2026 GDQuest and contributors
;; Author: John Charman <jchar@mailfence.com>
;; Maintainer: John Charman <jchar@mailfence.com>
;; 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:
;; Defines `skeleton's (a.k.a. snippets) for code insertion in GDScript.
;; Also provides the `transient': `gdscript-snippet-menu', for quick access.
;;; Code:
(require 'skeleton) ; Built-in
(require 'transient) ; Built-in
;; Transient Menu for inserting skeletons
(transient-define-prefix gdscript-snippet-menu ()
"Menu for GDScript Code Snippets."
["GDScript Code Snippets"
("f" "function" gdscript-snippet-function)
("l" "load" gdscript-snippet-load)
("p" "preload" gdscript-snippet-preload)
("t" "one-shot timer" gdscript-snippet-timer)
("v" "member variable" gdscript-snippet-variable)])
;; Skeleton Definitions
;; str, v1 and v2 are local-variables scoped within `skeleton-insert'.
;; str is set by the interactor (the first argument) if non-nil.
;; v1 and v2 are for memorizing anything you need during expansion.
(define-skeleton gdscript-snippet-function
"Insert a skeleton for a function"
;; interactor
"function name: "
;; skeleton
(when (y-or-n-p "static?") "static ")
"func " str "()"
(progn
(setq v1 (completing-read "return: " `(,@gdscript-built-in-types
,@gdscript-built-in-classes)))
(unless (string-empty-p v1) (skeleton-insert '(nil " -> " str) nil v1)))
":" \n >)
(define-skeleton gdscript-snippet-load
"Inserts a skeleton for loading a file"
;; interactor
nil
;; skeleton
"load(" (gdscript-completion-insert-file-path-at-point) ")")
(define-skeleton gdscript-snippet-preload
"Inserts a skeleton for preloading a file"
;; interactor
nil
;; skeleton
"preload(" (gdscript-completion-insert-file-path-at-point) ")")
(define-skeleton gdscript-snippet-timer
"Inserts a skeleton for awaiting a one-shot SceneTreeTimer."
;; interactor
(read-string "duration (default 1.0): " nil nil "1.0")
;; skeleton
"await get_tree().create_timer(" str ").timeout")
(define-skeleton gdscript-snippet-variable
"Inserts a skeleton for a member variable."
;; interactor
"variable name: "
;; skeleton
"var " str
(progn
(setq v1 (completing-read "type: " `(,@gdscript-built-in-types
,@gdscript-built-in-classes)))
(unless (string-empty-p v1) (skeleton-insert '(nil ": " str) nil v1)))
(when (y-or-n-p "getter?")
(setq v2 t)
(skeleton-insert '(nil ":" \n "get():" \n "return " str) nil str))
(when (y-or-n-p "setter?")
(unless v2 (skeleton-insert '(nil ":")))
(skeleton-insert '(nil \n "set(v):" \n str " = v") nil str)))
(provide 'gdscript-snippet)
;;; gdscript-snippet.el ends here