kakoune/rc/filetype/gdscript.kak

111 lines
15 KiB
Plaintext
Raw Normal View History

2021-06-04 01:00:05 +02:00
# http://godotengine.org
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*[.](gd) %{
set-option buffer filetype gdscript
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=gdscript %{
require-module gdscript
set-option window static_words %opt{gdscript_static_words}
hook window InsertChar \n -group gdscript-insert gdscript-insert-on-new-line
hook window InsertChar \n -group gdscript-indent gdscript-indent-on-new-line
# cleanup trailing whitespaces on current line insert end
hook window ModeChange pop:insert:.* -group gdscript-trim-indent %{ try %{ execute-keys -draft <semicolon> <a-x> s ^\h+$ <ret> d } }
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window gdscript-.+ }
}
hook -group gdscript-highlight global WinSetOption filetype=gdscript %{
add-highlighter window/gdscript ref gdscript
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/gdscript }
}
provide-module gdscript %§
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/gdscript regions
add-highlighter shared/gdscript/code default-region group
add-highlighter shared/gdscript/double_string region '"' (?<!\\)(\\\\)*" fill string
add-highlighter shared/gdscript/single_string region "'" (?<!\\)(\\\\)*' fill string
add-highlighter shared/gdscript/comment region '#' '$' fill comment
# integers
add-highlighter shared/gdscript/code/ regex '(?i)\b0b[01]+l?\b' 0:value
add-highlighter shared/gdscript/code/ regex '(?i)\b0x[\da-f]+l?\b' 0:value
add-highlighter shared/gdscript/code/ regex '(?i)\b0o?[0-7]+l?\b' 0:value
add-highlighter shared/gdscript/code/ regex '(?i)\b([1-9]\d*|0)l?\b' 0:value
# floats
add-highlighter shared/gdscript/code/ regex '\b\d+[eE][+-]?\d+\b' 0:value
add-highlighter shared/gdscript/code/ regex '(\b\d+)?\.\d+\b' 0:value
add-highlighter shared/gdscript/code/ regex '\b\d+\.' 0:value
# functions
add-highlighter shared/gdscript/code/ regex _?[a-zA-Z]\w*\s*(?=\() 0:function
add-highlighter shared/gdscript/code/ regex (?:func\h+)(_?\w+)(?:<[^>]+?>)?\( 1:function
add-highlighter shared/gdscript/code/ regex '(?:\+|-|\*|/|%|=|<|>|&|\||\^|~|:=)' 0:operator
evaluate-commands %sh{
keywords="if elif else for while match break continue pass return class
class_name extends is as self tool signal func static const enum var onready
export setget breakpoint preload yield assert remote master puppet
remotesync mastersync puppetsync PI TAU INF NAN"
values="false true null"
types="bool int float void null Vector2 Rect2 Vector3 Transform2D Plane Quat
AABB Basis Transform Color NodePath RID Object Array Dictionary"
builtin_classes="@GDScript @GlobalScope AABB 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 ARVRAnchor ARVRCamera ARVRController ARVRInterface ARVRInterfaceGDNative ARVROrigin ARVRPositionalTracker ARVRServer AspectRatioContainer AStar AStar2D AtlasTexture AudioBusLayout AudioEffect AudioEffectAmplify AudioEffectBandLimitFilter AudioEffectBandPassFilter AudioEffectCapture 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 AudioStreamMP3 AudioStreamOGGVorbis AudioStreamPlayback AudioStreamPlaybackResampled AudioStreamPlayer AudioStreamPlayer2D AudioStreamPlayer3D AudioStreamRandomPitch AudioStreamSample BackBufferCopy BakedLightmap BakedLightmapData BaseButton Basis BitMap BitmapFont Bone2D BoneAttachment bool BoxContainer BoxShape BulletPhysicsServer Button ButtonGroup 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 CPUParticles CPUParticles2D Crypto CryptoKey CSGBox CSGCombiner CSGCylinder CSGMesh CSGPolygon CSGPrimitive CSGShape CSGSphere CSGTorus CSharpScript CubeMap CubeMesh Curve Curve2D Curve3D CurveTexture CylinderMesh CylinderShape DampedSpringJoint2D Dictionary DirectionalLight Directory DTLSServer DynamicFont DynamicFontData EditorExportPlugin EditorFeatureProfile EditorFileDialog EditorFileSystem EditorFileSystemDirectory EditorImportPlugin EditorInspector EditorInspectorPlugin EditorInterface EditorNavigationMeshGenerator EditorPlugin EditorProperty EditorResourceConversionPlugin EditorResourcePreview EditorResourcePreviewGenerator EditorSceneImporter EditorSceneImporterFBX EditorScenePostImport EditorScript EditorSelection EditorSettings EditorSpatialGizmo EditorSpatialGizmoPlugin EditorSpinSlider EditorVCSInterface EncodedObjectAsID Engine Environment Expression ExternalTexture File FileDialog FileSystemDock float Font FuncRef GDNative GDNativeLibrary GDScript GDScriptFunctionState Generic6DOFJoint Geometry GeometryInstance GIProbe GIProbeData GodotSharp Gradient GradientTexture GraphEdit GraphNode GridContainer GridMap GrooveJoint2D HashingContext HBoxContainer HeightMapShape HingeJoint HScrollBar HSeparator HSlider HSplitContainer HTTPClient HTTPRequest Image ImageTexture ImmediateGeometry Input InputEvent InputEventAction InputEventGesture InputEventJoypadButton InputEventJoypadMotion InputEventKey InputEventMagnifyGesture InputEventMIDI InputEventMouse InputEventMouseButton InputEventMouseMotion InputEventPanGesture InputEventScreenDrag InputEventScreenTouch InputEventWithModifiers InputMap InstancePlaceholder int InterpolatedCamera IP ItemList JavaClas
join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
# Add the language's grammar to the static completion list
printf %s\\n "declare-option str-list gdscript_static_words $(join "${keywords} ${values} ${types} ${builtin_classes}" ' ')"
printf %s "
add-highlighter shared/gdscript/code/ regex '\b($(join "${keywords}" '|'))\b' 0:keyword
add-highlighter shared/gdscript/code/ regex '\b($(join "${values}" '|'))\b' 0:value
add-highlighter shared/gdscript/code/ regex '\b($(join "${types}" '|'))\b' 0:type
add-highlighter shared/gdscript/code/ regex '\b($(join "${builtin_classes}" '|'))\b' 0:type
"
}
# nodes
add-highlighter shared/gdscript/code/ regex '\$[\w/]*' 0:module
# Commands
# ‾‾‾‾‾‾‾‾
define-command -hidden gdscript-insert-on-new-line %{
evaluate-commands -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
}
}
define-command -hidden gdscript-indent-on-new-line %<
evaluate-commands -draft -itersel %<
# preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
# indent after line ending with :
try %{ execute-keys -draft <space> k <a-x> <a-k> :$ <ret> <a-K> ^\h*# <ret> j <a-gt> }
# deindent closing brace/bracket when after cursor (for arrays and dictionaries)
try %< execute-keys -draft <a-x> <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
>
>
§