-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdscript-mode.el
11349 lines (9505 loc) · 371 KB
/
gdscript-mode.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; TODO HEADER LICENSE COPYRIGHT
;; THIS IS PYTHON-MODE.el below with a lot of replacements and cuts
;; EXPECT TO FIND GARBAGE UNTI WORK IS DONE
;; IT`S A 20k-line file after all
(defgroup gdscript-mode nil
"Support for the GDScript programming language, <http://www.godotengine.org/>"
:group 'languages
:prefix "gd-")
(defconst gd-version "0.0.1")
(defcustom gdscript-mode-modeline-display "GDScript"
"String to display in Emacs modeline "
:type 'string
:tag "gdscript-mode-modeline-display"
:group 'gdscript-mode)
;; (defcustom gd-which-def-or-class-function gd-which-def-or-class
;; "If which-function-mode should use `gd-which-def-or-class'.
;; Alternatively use built-in `which-function', which queries the index
;; or `gdscript-info-current-defun' from python.el"
;; :type '(choice
;; (const :tag "default" gd-which-def-or-class)
;; (const :tag "built-in which-function" nil)
;; (const :tag "gdscript-info-current-defun" gdscript-info-current-defun))
;; :group 'gdscript-mode)
;; (defcustom gd-which-def-or-class-function gd-which-def-or-class
;; "If which-function-mode should use `gd-which-def-or-class'.
;; Alternatively use built-in `which-function', which queries the index
;; or `gdscript-info-current-defun' from python.el"
;; :type '(choice
;; (const :tag "default" gd-which-def-or-class)
;; (const :tag "built-in which-function" nil)
;; (const :tag "gdscript-info-current-defun" gdscript-info-current-defun))
;; :group 'gdscript-mode)
(defcustom gd-sexp-use-expression-p nil
"If non-nil, C-M-s call gd-forward-expression.
Respective C-M-b will call gd-backward-expression
Default is t"
:type 'boolean
:group 'gdscript-mode)
(defcustom gd-empty-line-closes-p nil
"When non-nil, dedent after empty line following block
if True:
print(\"Part of the if-statement\")
print(\"Not part of the if-statement\")
Default is nil
If non-nil, a C-j from empty line dedents."
:type 'boolean
:tag "gd-empty-line-closes-p"
:group 'gdscript-mode)
(defvar gd--match-paren-forward-p nil
"Internally used by `gd-match-paren'. ")
(defcustom gd-electric-close-active-p nil
"Close completion buffer when it's sure, it's no longer needed, i.e. when inserting a space.
Works around a bug in `choose-completion'.
Default is `nil'"
:type 'boolean
:group 'gdscript-mode)
(defcustom gd-hide-show-minor-mode-p nil
"If hide-show minor-mode should be on, default is nil. "
:type 'boolean
:tag "gd-hide-show-minor-mode-p"
:group 'gdscript-mode)
(defcustom gd-load-skeletons-p nil
"If skeleton definitions should be loaded, default is nil.
If non-nil and abbrev-mode on, block-skeletons will inserted.
Pressing \"if<SPACE>\" for example will prompt for the if-condition.
"
:type 'boolean
:tag "gd-load-skeletons-p"
:group 'gdscript-mode)
(defcustom gd-use-font-lock-doc-face-p nil
"If documention string inside of def or class get `font-lock-doc-face'.
`font-lock-doc-face' inherits `font-lock-string-face'.
Call M-x `customize-face' in order to have a visible effect. "
:type 'boolean
:tag "gd-use-font-lock-doc-face-p"
:group 'gdscript-mode)
(defcustom gd-empty-comment-line-separates-paragraph-p t
"Consider paragraph start/end lines with nothing inside but comment sign.
Default is non-nil"
:type 'boolean
:tag "gd-empty-comment-line-separates-paragraph-p"
:group 'gdscript-mode)
(defcustom gd-indent-honors-inline-comment nil
"If non-nil, indents to column of inlined comment start.
Default is nil. "
:type 'boolean
:tag "gd-indent-honors-inline-comment"
:group 'gdscript-mode)
;; WP 1
(defvar gd-edit-docstring-orig-pos nil
"Internally used by `gd-edit-docstring'. ")
(defcustom gd-tab-shifts-region-p nil
"If `t', TAB will indent/cycle the region, not just the current line.
Default is nil
See also `gd-tab-indents-region-p'"
:type 'boolean
:tag "gd-tab-shifts-region-p"
:group 'gdscript-mode)
(defcustom gd-tab-indents-region-p nil
"When `t' and first TAB doesn't shift, indent-region is called.
Default is nil
See also `gd-tab-shifts-region-p'"
:type 'boolean
:tag "gd-tab-indents-region-p"
:group 'gdscript-mode)
(defcustom gd-block-comment-prefix-p t
"If gd-comment inserts gd-block-comment-prefix.
Default is t"
:type 'boolean
:tag "gd-block-comment-prefix-p"
:group 'gdscript-mode)
(defcustom gd-outline-minor-mode-p t
"If outline minor-mode should be on, default is `t'. "
:type 'boolean
:tag "gd-outline-minor-mode-p"
:group 'gdscript-mode)
(defcustom gd-verbose-p nil
"If functions should report results.
Default is nil. "
:type 'boolean
:tag "gd-verbose-p"
:group 'gdscript-mode)
(defcustom gd-sexp-function nil
"When set, it's value is called instead of `forward-sexp', `backward-sexp'
Default is nil. "
:type '(choice
(const :tag "default" nil)
(const :tag "gd-end-of-partial-expression" gd-end-of-partial-expression)
(const :tag "gd-end-of-expression" gd-end-of-expression))
:tag "gd-sexp-function"
:group 'gdscript-mode)
(defcustom gd-close-provides-newline t
"If a newline is inserted, when line after block isn't empty. Default is non-nil.
When non-nil, `gd-end-of-def' and related will work faster"
:type 'boolean
:tag "gd-close-provides-newline"
:group 'gdscript-mode)
(defcustom gd-dedent-keep-relative-column t
"If point should follow dedent or kind of electric move to end of line. Default is t - keep relative position. "
:type 'boolean
:tag "gd-dedent-keep-relative-column"
:group 'gdscript-mode)
(defcustom gd-indent-honors-multiline-listing nil
"If `t', indents to 1+ column of opening delimiter. If `nil', indent adds one level to the beginning of statement. Default is `nil'. "
:type 'boolean
:tag "gd-indent-honors-multiline-listing"
:group 'gdscript-mode)
(defcustom gd-indent-paren-spanned-multilines-p t
"If non-nil, indents elements of list a value of `gd-indent-offset' to first element:
def foo():
if (foo &&
baz):
bar()
Default lines up with first element:
def foo():
if (foo &&
baz):
bar()
Default is `t'"
:type 'boolean
:tag "gd-indent-paren-spanned-multilines-p"
:group 'gdscript-mode)
(defcustom gd-closing-list-dedents-bos nil
"When non-nil, indent list's closing delimiter like start-column.
It will be lined up under the first character of
the line that starts the multi-line construct, as in:
my_list = [
1, 2, 3,
4, 5, 6,
]
result = some_function_that_takes_arguments(
'a', 'b', 'c',
'd', 'e', 'f',
)
Default is nil, i.e.
my_list = [
1, 2, 3,
4, 5, 6,
]
result = some_function_that_takes_arguments(
'a', 'b', 'c',
'd', 'e', 'f',
)
Examples from PEP8"
:type 'boolean
:tag "gd-closing-list-dedents-bos"
:group 'gdscript-mode)
(defvar gd-imenu-max-items 99)
(defcustom gd-imenu-max-items 99
"GDScript-mode specific `imenu-max-items'"
:type 'number
:group 'gdscript-mode)
(defcustom gd-closing-list-space 1
"Number of chars, closing parenthesis outdent from opening, default is 1 "
:type 'number
:tag "gd-closing-list-space"
:group 'gdscript-mode)
(defcustom gd-max-specpdl-size max-specpdl-size
"Heuristic exit. Limiting number of recursive calls by gd-forward-statement and related functions. Default is max-specpdl-size.
This threshold is just an approximation. It might set far higher maybe.
See lp:1235375. In case code is not to navigate due to errors, `which-function-mode' and others might make Emacs hang. Rather exit than. "
:type 'number
:tag "gd-max-specpdl-size"
:group 'gdscript-mode)
(defcustom gd-closing-list-keeps-space nil
"If non-nil, closing parenthesis dedents onto column of opening plus `gd-closing-list-space', default is nil "
:type 'boolean
:tag "gd-closing-list-keeps-space"
:group 'gdscript-mode)
(defcustom gd-electric-kill-backward-p nil
"Affects `gd-electric-backspace'. Default is nil.
If behind a delimited form of braces, brackets or parentheses,
backspace will kill it's contents
With when cursor after
my_string[0:1]
--------------^
==>
my_string[]
----------^
In result cursor is insided emptied delimited form."
:type 'boolean
:tag "gd-electric-kill-backward-p"
:group 'gdscript-mode)
(defcustom gd-electric-colon-active-p nil
"`gd-electric-colon' feature. Default is `nil'. See lp:837065 for discussions.
See also `gd-electric-colon-bobl-only' "
:type 'boolean
:tag "gd-electric-colon-active-p"
:group 'gdscript-mode)
(defcustom gd-electric-colon-bobl-only t
"When inserting a colon, do not indent lines unless at beginning of block
See lp:1207405 resp. `gd-electric-colon-active-p' "
:type 'boolean
:tag "gd-electric-colon-bobl-only"
:group 'gdscript-mode)
(defcustom gd-electric-yank-active-p nil
" When non-nil, `yank' will be followed by an `indent-according-to-mode'.
Default is nil"
:type 'boolean
:tag "gd-electric-yank-active-p"
:group 'gdscript-mode)
(defcustom gd-electric-colon-greedy-p nil
"If gd-electric-colon should indent to the outmost reasonable level.
If nil, default, it will not move from at any reasonable level. "
:type 'boolean
:tag "gd-electric-colon-greedy-p"
:group 'gdscript-mode)
(defcustom gd-electric-colon-newline-and-indent-p nil
"If non-nil, `gd-electric-colon' will call `newline-and-indent'. Default is `nil'. "
:type 'boolean
:tag "gd-electric-colon-newline-and-indent-p"
:group 'gdscript-mode)
(defcustom gd-electric-comment-p nil
"If \"#\" should call `gd-electric-comment'. Default is `nil'. "
:type 'boolean
:tag "gd-electric-comment-p"
:group 'gdscript-mode)
(defcustom gd-electric-comment-add-space-p nil
"If gd-electric-comment should add a space. Default is `nil'. "
:type 'boolean
:tag "gd-electric-comment-add-space-p"
:group 'gdscript-mode)
(defcustom gd-mark-decorators nil
"If gd-mark-def-or-class functions should mark decorators too. Default is `nil'. "
:type 'boolean
:tag "gd-mark-decorators"
:group 'gdscript-mode)
(defcustom gd-defun-use-top-level-p nil
"When non-nil, keys C-M-a, C-M-e address top-level form.
Default is nil.
Beginning- end-of-defun forms use
commands `gd-beginning-of-top-level', `gd-end-of-top-level'
mark-defun marks top-level form at point etc."
:type 'boolean
:tag "gd-defun-use-top-level-p"
:group 'gdscript-mode)
(defcustom gd-tab-indent t
"Non-nil means TAB in GDScript mode calls `gd-indent-line'."
:type 'boolean
:tag "gd-tab-indent"
:group 'gdscript-mode)
(defcustom gd-return-key 'newline
"Which command <return> should call. "
:type '(choice
(const :tag "default" gd-newline-and-indent)
(const :tag "newline" newline)
(const :tag "gd-newline-and-indent" gd-newline-and-indent)
(const :tag "gd-newline-and-dedent" gd-newline-and-dedent)
)
:tag "gd-return-key"
:group 'gdscript-mode)
(defcustom gd-encoding-string " # -*- coding: utf-8 -*-"
"Default string specifying encoding of a GDScript file. "
:type 'string
:tag "gd-encoding-string"
:group 'gdscript-mode)
(defcustom gd-lhs-inbound-indent 1
"When line starts a multiline-assignment: How many colums indent should be more than opening bracket, brace or parenthesis. "
:type 'integer
:tag "gd-lhs-inbound-indent"
:group 'gdscript-mode)
(defcustom gd-continuation-offset 2
"Additional amount of offset to give for some continuation lines.
Continuation lines are those that immediately follow a backslash
terminated line. "
:type 'integer
:tag "gd-continuation-offset"
:group 'gdscript-mode)
(defcustom gd-indent-tabs-mode t
"GDScript-mode starts `indent-tabs-mode' with the value specified here, default is nil. "
:type 'boolean
:tag "gd-indent-tabs-mode"
:group 'gdscript-mode)
(defcustom gd-smart-indentation t
"Should `gdscript-mode' try to automagically set some indentation variables?
When this variable is non-nil, two things happen when a buffer is set
to `gdscript-mode':
1. `gd-indent-offset' is guessed from existing code in the buffer.
Only guessed values between 2 and 8 are considered. If a valid
guess can't be made (perhaps because you are visiting a new
file), then the value in `gd-indent-offset' is used.
2. `tab-width' is setq to `gd-indent-offset' if not equal
already. `indent-tabs-mode' inserts one tab one
indentation level, otherwise spaces are used.
Note that both these settings occur *after* `gdscript-mode-hook' is run,
so if you want to defeat the automagic configuration, you must also
set `gd-smart-indentation' to nil in your `gdscript-mode-hook'."
:type 'boolean
:tag "gd-smart-indentation"
:group 'gdscript-mode)
(defcustom gd-block-comment-prefix "##"
"String used by \\[comment-region] to comment out a block of code.
This should follow the convention for non-indenting comment lines so
that the indentation commands won't get confused (i.e., the string
should be of the form `#x...' where `x' is not a blank or a tab, and
`...' is arbitrary). However, this string should not end in whitespace."
:type 'string
:tag "gd-block-comment-prefix"
:group 'gdscript-mode)
(defcustom gd-indent-offset 4
"Amount of offset per level of indentation.
`\\[gd-guess-indent-offset]' can usually guess a good value when
you're editing someone else's GDScript code."
:type 'integer
:tag "gd-indent-offset"
:group 'gdscript-mode)
(make-variable-buffer-local 'gd-indent-offset)
(defcustom gd-backslashed-lines-indent-offset 5
"Amount of offset per level of indentation of backslashed.
No semantic indent, which diff to `gd-indent-offset' indicates "
:type 'integer
:tag "gd-backslashed-lines-indent-offset"
:group 'gdscript-mode)
(defcustom gd-indent-comments t
"When t, comment lines are indented. "
:type 'boolean
:tag "gd-indent-comments"
:group 'gdscript-mode)
(defcustom gd-uncomment-indents-p nil
"When non-nil, after uncomment indent lines. "
:type 'boolean
:tag "gd-uncomment-indents-p"
:group 'gdscript-mode)
(defcustom gd-separator-char 47
"The character, which separates the system file-path components.
Precedes guessing when not empty, returned by function `gd-separator-char'. "
:type 'character
:tag "gd-separator-char"
:group 'gdscript-mode)
(and
;; used as a string finally
;; kept a character not to break existing customizations
(characterp gd-separator-char)(setq gd-separator-char (char-to-string gd-separator-char)))
;; WP 2
(defcustom gd-delete-function 'delete-char
"Function called by `gd-electric-delete' when deleting forwards."
:type 'function
:tag "gd-delete-function"
:group 'gdscript-mode)
(defcustom gd-current-defun-show t
"If `gd-current-defun' should jump to the definition, highlight it while waiting PY-WHICH-FUNC-DELAY seconds, before returning to previous position.
Default is `t'."
:type 'boolean
:tag "gd-current-defun-show"
:group 'gdscript-mode)
(defcustom gd-current-defun-delay 2
"When called interactively, `gd-current-defun' should wait PY-WHICH-FUNC-DELAY seconds at the definition name found, before returning to previous position. "
:type 'number
:tag "gd-current-defun-delay"
:group 'gdscript-mode)
(defcustom gd-shell-fontify-style 'all
"Fontify current input resp. output in GDScript shell. Default is nil.
INPUT will leave output unfontified.
ALL keeps output fontified.
At any case only current input gets fontified.
"
:type '(choice (const :tag "Default" all)
(const :tag "Input" input)
(const :tag "Nil" nil)
)
:tag "gd-shell-fontify-style"
:group 'gdscript-mode)
(defcustom gd-hide-show-keywords
'("class" "func" "elif" "else" "except"
"for" "if" "while" "finally" "try"
"with")
"Keywords composing visible heads. "
:type '(repeat string)
:tag "gd-hide-show-keywords
"
:group 'gdscript-mode)
(defcustom gd-hide-show-hide-docstrings t
"Controls if doc strings can be hidden by hide-show"
:type 'boolean
:tag "gd-hide-show-hide-docstrings"
:group 'gdscript-mode)
(defcustom gd-hide-comments-when-hiding-all t
"Hide the comments too when you do an `hs-hide-all'."
:type 'boolean
:tag "gd-hide-comments-when-hiding-all"
:group 'gdscript-mode)
(defcustom gd-outline-mode-keywords
'("class" "func" "elif" "else" "except"
"for" "if" "while" "finally" "try"
"with")
"Keywords composing visible heads. "
:type '(repeat string)
:tag "gd-outline-mode-keywords
"
:group 'gdscript-mode)
(defcustom gdscript-mode-hook nil
"Hook run when entering GDScript mode."
:type 'hook
:tag "gdscript-mode-hook"
:group 'gdscript-mode
)
(defcustom gd--imenu-create-index-p nil
"Non-nil means GDScript mode creates and displays an index menu of functions and global variables. "
:type 'boolean
:tag "gd--imenu-create-index-p"
:group 'gdscript-mode)
(defvar gd-history-filter-regexp "\\`\\s-*\\S-?\\S-?\\s-*\\'\\|'''/tmp/"
"Input matching this regexp is not saved on the history list.
Default ignores all inputs of 0, 1, or 2 non-blank characters.")
(defcustom gd-match-paren-mode nil
"Non-nil means, cursor will jump to beginning or end of a block.
This vice versa, to beginning first.
Sets `gd-match-paren-key' in gdscript-mode-map.
Customize `gd-match-paren-key' which key to use. "
:type 'boolean
:tag "gd-match-paren-mode"
:group 'gdscript-mode)
(defcustom gd-match-paren-key "%"
"String used by \\[comment-region] to comment out a block of code.
This should follow the convention for non-indenting comment lines so
that the indentation commands won't get confused (i.e., the string
should be of the form `#x...' where `x' is not a blank or a tab, and
`...' is arbitrary). However, this string should not end in whitespace."
:type 'string
:tag "gd-match-paren-key"
:group 'gdscript-mode)
(defcustom gd-kill-empty-line t
"If t, gd-indent-forward-line kills empty lines. "
:type 'boolean
:tag "gd-kill-empty-line"
:group 'gdscript-mode)
(defcustom gd-imenu-show-method-args-p nil
"Controls echoing of arguments of functions & methods in the Imenu buffer.
When non-nil, arguments are printed."
:type 'boolean
:tag "gd-imenu-show-method-args-p"
:group 'gdscript-mode)
(defcustom gd-trailing-whitespace-smart-delete-p nil
"Default is nil. When t, gdscript-mode calls
(add-hook 'before-save-hook 'delete-trailing-whitespace nil 'local)
Also commands may delete trailing whitespace by the way.
When editing other peoples code, this may produce a larger diff than expected "
:type 'boolean
:tag "gd-trailing-whitespace-smart-delete-p"
:group 'gdscript-mode)
(defcustom gd-newline-delete-trailing-whitespace-p t
"Delete trailing whitespace maybe left by `gd-newline-and-indent'.
Default is `t'. See lp:1100892 "
:type 'boolean
:tag "gd-newline-delete-trailing-whitespace-p"
:group 'gdscript-mode)
(defcustom gd--warn-tmp-files-left-p nil
"Messages a warning, when `gd-temp-directory' contains files susceptible being left by previous GDScript-mode sessions. See also lp:987534 "
:type 'boolean
:tag "gd--warn-tmp-files-left-p"
:group 'gdscript-mode)
(defcustom gd-gdscript-edit-version ""
"When not empty, fontify according to GDScript version specified.
Default is the empty string, a useful value \"python3\" maybe.
When empty, version is guessed via `gd-choose-shell'. "
:type 'string
:tag "gd-gdscript-edit-version"
:group 'gdscript-mode)
(defcustom gd--imenu-create-index-function 'gd--imenu-create-index-new
"Switch between `gd--imenu-create-index-new', which also lists modules variables, and series 5. index-machine"
:type '(choice (const :tag "'gd--imenu-create-index-new, also lists modules variables " gd--imenu-create-index-new)
(const :tag "gd--imenu-create-index, series 5. index-machine" gd-imenu-create-index))
:tag "gd--imenu-create-index-function"
:group 'gdscript-mode)
(defvar gd-input-filter-re "\\`\\s-*\\S-?\\S-?\\s-*\\'"
"Input matching this regexp is not saved on the history list.
Default ignores all inputs of 0, 1, or 2 non-blank characters.")
(defvaralias 'inferior-gdscript-filter-regexp 'gd-input-filter-re)
(defvar strip-chars-before "\\`[ \t\r\n]*"
"Regexp indicating which chars shall be stripped before STRING - which is defined by `string-chars-preserve'.")
(defvar strip-chars-after "[ \t\r\n]*\\'"
"Regexp indicating which chars shall be stripped after STRING - which is defined by `string-chars-preserve'.")
(defvar gd-this-abbrevs-changed nil
"Internally used by gdscript-mode-hook")
;; WP 3
(defvar gd-underscore-word-syntax-p t
"This is set later by defcustom, only initial value here.
If underscore chars should be of syntax-class `word', not of `symbol'.
Underscores in word-class makes `forward-word' etc. travel the indentifiers. Default is `t'.
See also command `toggle-gd-underscore-word-syntax-p' ")
(defvar gdscript-mode-message-string
(if (or (string= "gdscript-mode.el" (buffer-name))
(ignore-errors (string-match "gdscript-mode.el" (gd--buffer-filename-remote-maybe))))
"gdscript-mode.el"
"gdscript-components-mode.el")
"Internally used. Reports the gdscript-mode branch")
(unless (fboundp 'string-to-syntax)
;; Skip's XE workaround
(defun string-to-syntax (s)
(cond
((equal s "|") '(15))
((equal s "_") '(3))
(t (error "Unhandled string: %s" s)))))
(defvar gdscript-mode-syntax-table nil
"Give punctuation syntax to ASCII that normally has symbol
syntax or has word syntax and isn't a letter.")
(setq gdscript-mode-syntax-table
(let ((table (make-syntax-table)))
;; Give punctuation syntax to ASCII that normally has symbol
;; syntax or has word syntax and isn't a letter.
(let ((symbol (string-to-syntax "_"))
(sst (standard-syntax-table)))
(dotimes (i 128)
(unless (= i ?_)
(if (equal symbol (aref sst i))
(modify-syntax-entry i "." table)))))
(modify-syntax-entry ?$ "." table)
(modify-syntax-entry ?% "." table)
;; exceptions
(modify-syntax-entry ?# "<" table)
(modify-syntax-entry ?\n ">" table)
(modify-syntax-entry ?' "\"" table)
(modify-syntax-entry ?` "$" table)
(if gd-underscore-word-syntax-p
(modify-syntax-entry ?\_ "w" table)
(modify-syntax-entry ?\_ "_" table))
table))
(defvar gd-separator-char "/"
"Values set by defcustom only will not be seen in batch-mode. ")
;; WP 4
(defvar gd-mode-output-map nil
"Keymap used in *GDScript Output* buffers.")
(defvar hs-hide-comments-when-hiding-all t
"Defined in hideshow.el, silence compiler warnings here. ")
(defcustom gd-debug-p nil
"When non-nil, keep resp. store information useful for debugging.
Temporary files are not deleted. Other functions might implement
some logging etc. "
:type 'boolean
:tag "gd-debug-p"
:group 'gdscript-mode)
(defcustom gd-section-start "# {{"
"Delimit arbitrary chunks of code. "
:type 'string
:tag "gd-section-start"
:group 'gdscript-mode)
(defcustom gd-section-end "# }}"
"Delimit arbitrary chunks of code. "
:type 'string
:tag "gd-section-end"
:group 'gdscript-mode)
(defvar gd-section-re gd-section-start)
(defvar gd-string-delim-re "\\(\"\"\"\\|'''\\|\"\\|'\\)"
"When looking at beginning of string. ")
(defvar gd-labelled-re "[ \\t]*:[[:graph:]]+"
"When looking at label. ")
(defvar gd-expression-skip-regexp "[^ (=:#\t\r\n\f]"
"gd-expression assumes chars indicated possible composing a gd-expression, skip it. ")
(defvar gd-expression-skip-chars "^ (=#\t\r\n\f"
"gd-expression assumes chars indicated possible composing a gd-expression, skip it. ")
(setq gd-expression-skip-chars "^ [{(=#\t\r\n\f")
(defvar gd-expression-re "[^ =#\t\r\n\f]+"
"gd-expression assumes chars indicated possible composing a gd-expression, when looking-at or -back. ")
(defcustom gd-paragraph-re "\\`[ \t\f]*\\'\n[^ \n\r\t\f]"
"An empty line followed by a non-whitespace at column 1"
:type 'string
:tag "gd-paragraph-re"
:group 'gdscript-mode)
(defvar gd-not-expression-regexp "[ .=#\t\r\n\f)]+"
"gd-expression assumes chars indicated probably will not compose a gd-expression. ")
(defvar gd-not-expression-chars " #\t\r\n\f"
"gd-expression assumes chars indicated probably will not compose a gd-expression. ")
(defvar gd-partial-expression-backward-chars "^ .=,\"'()[]{}:#\t\r\n\f"
"gd-partial-expression assumes chars indicated possible composing a gd-partial-expression, skip it. ")
;; (setq gd-partial-expression-backward-chars "^ .=,\"'()[]{}:#\t\r\n\f")
(defvar gd-partial-expression-forward-chars "^ .\"')}]:#\t\r\n\f")
;; (setq gd-partial-expression-forward-chars "^ .\"')}]:#\t\r\n\f")
(defvar gd-operator-re "[ \t]*\\(\\.\\|+\\|-\\|*\\|//\\|!\\|//\\|||\\|&&\\|&\\|%\\||\\|\\^\\|>>\\|<<\\|<\\|<=\\|>\\|>=\\|==\\|!=\\|=\\)[ \t]*"
"Matches most of GDScript syntactical meaningful characters, inclusive whitespaces around.
See also `gd-assignment-re' ")
;; (setq gd-operator-re "[ \t]*\\(\\.\\|+\\|-\\|*\\|//\\|//\\|&\\|%\\||\\|\\^\\|>>\\|<<\\|<\\|<=\\|>\\|>=\\|==\\|!=\\|=\\)[ \t]*")
(defvar gd-assignment-re "[ \t]*=[^=]"
"Matches assignment operator inclusive whitespaces around.
See also `gd-operator-re' ")
(defvar gd-delimiter-re "\\(\\.[[:alnum:]]\\|,\\|;\\|:\\)[ \t\n]"
"Delimiting elements of lists or other programming constructs. ")
(defvar gd-match-paren-no-use-syntax-pps nil)
(defvar gd-XXX-tag-face 'gd-XXX-tag-face)
(defvar gd-pseudo-keyword-face 'gd-pseudo-keyword-face)
(defvar gd-variable-name-face 'gd-variable-name-face)
(defvar gd-number-face 'gd-number-face)
(defvar gd-decorators-face 'gd-decorators-face)
(defvar gd-object-reference-face 'gd-object-reference-face)
(defvar gd-builtins-face 'gd-builtins-face)
(defvar gd-class-name-face 'gd-class-name-face)
(defvar gd-exception-name-face 'gd-exception-name-face)
(defvar gd-import-from-face 'gd-import-from-face)
(defvar gd-def-class-face 'gd-def-class-face)
(defvar gd-try-if-face 'gd-try-if-face)
(defvar gd-file-queue nil
"Queue of GDScript temp files awaiting execution.
Currently-active file is at the head of the list.")
(defvar gdscript-font-lock-keywords nil)
(defvar gd-dotted-expression-syntax-table
(let ((table (make-syntax-table gdscript-mode-syntax-table)))
(modify-syntax-entry ?_ "_" table)
(modify-syntax-entry ?. "_" table)
table)
"Syntax table used to identify GDScript dotted expressions.")
(defvar gdscript-default-template "if"
"Default template to expand by `gdscript-expand-template'.
Updated on each expansion.")
(defvar gd-already-guessed-indent-offset nil
"Internal use by gd-indent-line.
When `this-command' is `eq' to `last-command', use the guess already computed. ")
(make-variable-buffer-local 'gd-already-guessed-indent-offset)
;; Constants
(defconst gd-block-closing-keywords-re
"[ \t]*\\_<\\(return\\|raise\\|break\\|continue\\|pass\\)\\_>[ \n\t]"
"Matches the beginning of a class, method or compound statement. ")
(setq gd-block-closing-keywords-re
"[ \t]*\\_<return\\|raise\\|break\\|continue\\|pass\\_>[ \n\t]")
(defconst gd-finally-re
"[ \t]*\\_<finally\\_>[: \n\t]"
"Regular expression matching keyword which closes a try-block. ")
(defconst gd-except-re
"[ \t]*\\_<except\\_>[:( \n\t]*"
"Regular expression matching keyword which composes a try-block. ")
(defconst gd-else-re
"[ \t]*\\_<else\\_>[: \n\t]*"
"Regular expression matching keyword which closes a for- if- or try-block. ")
(defconst gd-return-re
".*:?[ \t]*\\_<\\(return\\)\\_>[ \n\t]*"
"Regular expression matching keyword which typically closes a function. ")
(defcustom gd-outdent-re-raw
(list
"static func"
"class"
"func"
"elif"
"else"
"except"
"for"
"if"
"try"
"while"
"with"
)
"")
(defconst gd-outdent-re
(concat
"[ \t]*\\_<"
(regexp-opt gd-outdent-re-raw)
"\\_>[)\t]*")
"Regular expression matching lines not to augment indent after.
See gd-no-outdent-re-raw for better readable content ")
(defcustom gd-no-outdent-re-raw
(list
"break"
"continue"
"import"
"pass"
"raise"
"return"
)
"")
(defconst gd-no-outdent-re
(concat
"[ \t]*\\_<"
(regexp-opt gd-no-outdent-re-raw)
"\\_>[)\t]*$")
"Regular expression matching lines not to augment indent after.
See gd-no-outdent-re-raw for better readable content ")
(defconst gd-assignment-re "\\_<\\w+\\_>[ \t]*\\(=\\|+=\\|*=\\|%=\\|&=\\|^=\\|<<=\\|-=\\|/=\\|**=\\||=\\|>>=\\|//=\\)"
"If looking at the beginning of an assignment. ")
(defconst gd-block-re "[ \t]*\\_<\\(class\\|func\\|static func\\|async for\\|for\\|if\\|try\\|while\\|with\\|async with\\)\\_>[:( \n\t]*"
"Matches the beginning of a compound statement. ")
(defconst gd-minor-block-re "[ \t]*\\_<\\(for\\|async for\\|if\\|try\\|with\\|async with\\|except\\)\\_>[:( \n\t]*"
"Matches the beginning of an `for', `if', `try', `except' or `with' block. ")
(defconst gd-try-block-re "[ \t]*\\_<try\\_>[: \n\t]"
"Matches the beginning of a `try' block. ")
(defconst gd-except-block-re "[ \t]*\\_<except\\_> *a?s? *[[:print:]]*[: \n\t]"
"Matches the beginning of a `except' block. ")
(defconst gd-for-block-re "[ \t]*\\_<\\(for\\|async for\\)\\_> +[[:alpha:]_][[:alnum:]_]* +in +[[:alpha:]_][[:alnum:]_()]* *[: \n\t]"
"Matches the beginning of a `try' block. ")
(defconst gd-if-block-re "[ \t]*\\_<if\\_> +[[:alpha:]_][[:alnum:]_]* *[: \n\t]"
"Matches the beginning of an `if' block. ")
(defconst gd-elif-block-re "[ \t]*\\_<elif\\_> +[[:alpha:]_][[:alnum:]_]* *[: \n\t]"
"Matches the beginning of an `elif' block. ")
(defconst gd-class-re "[ \t]*\\_<\\(class\\)\\_>[ \n\t]"
"Matches the beginning of a class definition. ")
(defconst gd-def-or-class-re "[ \t]*\\_<\\(static func\\|class\\|func\\)\\_>[ \n\t]"
"Matches the beginning of a class- or functions definition. ")
;; (setq gd-def-or-class-re "[ \t]*\\_<\\(static func\\|class\\|func\\)\\_>[ \n\t]")
;; (defconst gd-def-re "[ \t]*\\_<\\(static func\\|func\\)\\_>[ \n\t]"
(defconst gd-def-re "[ \t]*\\_<\\(func\\|static func\\)\\_>[ \n\t]"
"Matches the beginning of a functions definition. ")
(defcustom gd-block-or-clause-re-raw
(list
"elif"
"else"
"except"
"finally"
"for"
"if"
"try"