kakoune/rc/filetype/gdscript.kak

127 lines
21 KiB
Plaintext
Raw Permalink 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> x s ^\h+$ <ret> d } }
2021-06-04 01:00:05 +02:00
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/string region -match-capture ("|'|"""|''') (?<!\\)(?:\\\\)*("|'|"""|''') group
add-highlighter shared/gdscript/string/ fill string
add-highlighter shared/gdscript/string/ regex \\[abfnrtv\n\\] 0:meta
add-highlighter shared/gdscript/string/ regex '%%' 0:meta
add-highlighter shared/gdscript/string/ regex '%[cs]' 0:value
add-highlighter shared/gdscript/string/ regex '%0?[+-]?([\d]*|\*?)\.?([\d]*|\*?)[dfoxX]' 0:value
add-highlighter shared/gdscript/string/ regex '%0?([\d]*|\*?)\.?([\d]*|\*?)[+-]?[dfoxX]' 0:value
add-highlighter shared/gdscript/comment region '#' $ fill comment
2021-06-04 01:00:05 +02:00
# 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
2021-06-04 01:00:05 +02:00
# 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
2021-06-04 01:00:05 +02:00
# 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
# operators
add-highlighter shared/gdscript/code/ regex \+|-|\*|/|%|=|<|>|&|\||\^|~|:= 0:operator
# constants & enums
add-highlighter shared/gdscript/code/ regex \b[A-Z_][A-Z0-9_]*\b 0:variable
# annotations
add-highlighter shared/gdscript/code/ regex @\w+ 0:attribute
# special case of get =, set =
add-highlighter shared/gdscript/code/ regex \b(get)\h*=\h*(\w+) 1:keyword 2:function
add-highlighter shared/gdscript/code/ regex \b(set)\h*=\h*(\w+) 1:keyword 2:function
# keywords and built-ins
2021-06-04 01:00:05 +02:00
evaluate-commands %sh{
keywords="as await break breakpoint class class_name const continue elif else enum extends for func if in is match pass return self signal static super var void while"
2021-06-04 01:00:05 +02:00
values="false true null"
# Built in `nushell` with `ls doc/classes | each {open $in.name | get attributes.name} | str join " "`, the rest are built similarly
builtin_classes="AABB AESContext AStar2D AStar3D AStarGrid2D AcceptDialog AnimatableBody2D AnimatableBody3D AnimatedSprite2D AnimatedSprite3D AnimatedTexture Animation AnimationLibrary AnimationNode AnimationNodeAdd2 AnimationNodeAdd3 AnimationNodeAnimation AnimationNodeBlend2 AnimationNodeBlend3 AnimationNodeBlendSpace1D AnimationNodeBlendSpace2D AnimationNodeBlendTree AnimationNodeOneShot AnimationNodeOutput AnimationNodeStateMachine AnimationNodeStateMachinePlayback AnimationNodeStateMachineTransition AnimationNodeSync AnimationNodeTimeScale AnimationNodeTimeSeek AnimationNodeTransition AnimationPlayer AnimationRootNode AnimationTrackEditPlugin AnimationTree Area2D Area3D Array ArrayMesh ArrayOccluder3D AspectRatioContainer 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 AudioListener2D AudioListener3D AudioServer AudioStream AudioStreamGenerator AudioStreamGeneratorPlayback AudioStreamMicrophone AudioStreamPlayback AudioStreamPlaybackPolyphonic AudioStreamPlaybackResampled AudioStreamPlayer AudioStreamPlayer2D AudioStreamPlayer3D AudioStreamPolyphonic AudioStreamRandomizer AudioStreamWAV BackBufferCopy BaseButton BaseMaterial3D Basis BitMap Bone2D BoneAttachment3D BoneMap BoxContainer BoxMesh BoxOccluder3D BoxShape3D Button ButtonGroup CPUParticles2D CPUParticles3D Callable CallbackTweener Camera2D Camera3D CameraAttributes CameraAttributesPhysical CameraAttributesPractical CameraFeed CameraServer CameraTexture CanvasGroup CanvasItem CanvasItemMaterial CanvasLayer CanvasModulate CanvasTexture CapsuleMesh CapsuleShape2D CapsuleShape3D CenterContainer CharFXTransform CharacterBody2D CharacterBody3D CheckBox CheckButton CircleShape2D ClassDB CodeEdit CodeHighlighter CollisionObject2D CollisionObject3D CollisionPolygon2D CollisionPolygon3D CollisionShape2D CollisionShape3D Color ColorPicker ColorPickerButton ColorRect CompressedCubemap CompressedCubemapArray CompressedTexture2D CompressedTexture2DArray CompressedTexture3D CompressedTextureLayered ConcavePolygonShape2D ConcavePolygonShape3D ConeTwistJoint3D ConfigFile ConfirmationDialog Container Control ConvexPolygonShape2D ConvexPolygonShape3D Crypto CryptoKey Cubemap CubemapArray Curve Curve2D Curve3D CurveTexture CurveXYZTexture CylinderMesh CylinderShape3D DTLSServer DampedSpringJoint2D Decal Dictionary DirAccess DirectionalLight2D DirectionalLight3D DisplayServer EditorCommandPalette EditorDebuggerPlugin EditorDebuggerSession EditorExportPlatform EditorExportPlugin EditorFeatureProfile EditorFileDialog EditorFileSystem EditorFileSystemDirectory EditorFileSystemImportFormatSupportQuery EditorImportPlugin EditorInspector EditorInspectorPlugin EditorInterface EditorNode3DGizmo EditorNode3DGizmoPlugin EditorPaths EditorPlugin EditorProperty EditorResourceConversionPlugin EditorResourcePicker EditorResourcePreview EditorResourcePreviewGenerator EditorSceneFormatImporter EditorScenePostImport EditorScenePostImportPlugin EditorScript EditorScriptPicker EditorSelection EditorSettings EditorSpinSlider EditorSyntaxHighlighter EditorTranslationParserPlugin EditorUndoRedoManager EditorVCSInterface EncodedObjectAsID Engine EngineDebugger EngineProfiler Environment Expression FileAccess FileDialog FileSystemDock FlowContainer FogMaterial FogVolume Font FontFile FontVariation GDExtension GDExtensionManager GPUParticles2D GPUParticles3D GPUParticlesAttractor3D GPUParticlesAttractorBox3D GPUParticlesAttractorSphere3D GPUParticlesAttractorVectorField3D GPUParticlesCollision3D GPUParticlesCollisionBox
builtin_methods="abs absf absi acos asin atan atan2 bezier_derivative bezier_interpolate bytes_to_var bytes_to_var_with_objects ceil ceilf ceili clamp clampf clampi cos cosh cubic_interpolate cubic_interpolate_angle cubic_interpolate_angle_in_time cubic_interpolate_in_time db_to_linear deg_to_rad ease error_string exp floor floorf floori fmod fposmod hash instance_from_id inverse_lerp is_equal_approx is_finite is_inf is_instance_id_valid is_instance_valid is_nan is_same is_zero_approx lerp lerp_angle lerpf linear_to_db log max maxf maxi min minf mini move_toward nearest_po2 pingpong posmod pow print print_rich print_verbose printerr printraw prints printt push_error push_warning rad_to_deg rand_from_seed randf randf_range randfn randi randi_range randomize remap rid_allocate_id rid_from_int64 round roundf roundi seed sign signf signi sin sinh smoothstep snapped snappedf snappedi sqrt step_decimals str str_to_var tan tanh typeof var_to_bytes var_to_bytes_with_objects var_to_str weakref wrap wrapf wrapi"
gdscript_methods="Color8 assert char convert dict_to_inst get_stack inst_to_dict is_instance_of len load preload print_debug print_stack range type_exists"
2021-06-04 01:00:05 +02:00
gdscript_constants="PI TAU INF NAN"
2021-06-04 01:00:05 +02:00
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} ${builtin_classes} ${builtin_methods} ${gdscript_methods} ${gdscript_constants}" ' ')"
2021-06-04 01:00:05 +02:00
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 "${builtin_classes}" '|'))\b' 0:type
add-highlighter shared/gdscript/code/ regex '\b($(join "${builtin_methods}" '|'))\b\(' 1:builtin
add-highlighter shared/gdscript/code/ regex '\b($(join "${gdscript_methods}" '|'))\b\(' 1:builtin
add-highlighter shared/gdscript/code/ regex '\b($(join "${gdscript_constants}" '|'))\b' 0:keyword
2021-06-04 01:00:05 +02:00
"
}
# nodes
add-highlighter shared/gdscript/code/ regex \$[\w/]+\b 0:module
add-highlighter shared/gdscript/code/ regex \%\w+(?!/)\b 0:string
2021-06-04 01:00:05 +02:00
# 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 x s ^\h*#\h* <ret> y jgh P }
2021-06-04 01:00:05 +02:00
}
}
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 x s \h+$ <ret> d }
2021-06-04 01:00:05 +02:00
# indent after line ending with :
try %{ execute-keys -draft , k x <a-k> :$ <ret> <a-K> ^\h*# <ret> j <a-gt> }
2021-06-04 01:00:05 +02:00
# deindent closing brace/bracket when after cursor (for arrays and dictionaries)
try %< execute-keys -draft x <a-k> ^\h*[}\]] <ret> gh / [}\]] <ret> m <a-S> 1<a-&> >
2021-06-04 01:00:05 +02:00
>
>
§