# http://dlang.org/ # # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*\.di? %{ set-option buffer filetype d } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=d %{ require-module d set-option window static_words %opt{d_static_words} # cleanup trailing whitespaces when exiting insert mode hook window ModeChange insert:.* -group d-trim-indent %{ try %{ execute-keys -draft s^\h+$d } } hook window InsertChar \n -group d-indent d-indent-on-new-line hook window InsertChar \{ -group d-indent d-indent-on-opening-curly-brace hook window InsertChar \} -group d-indent d-indent-on-closing-curly-brace hook -once -always window WinSetOption filetype=.* %{ remove-hooks window d-.+ } } hook -group d-highlight global WinSetOption filetype=d %{ add-highlighter window/d ref d hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/d } } provide-module d %🦀 # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/d regions add-highlighter shared/d/code default-region group add-highlighter shared/d/string region %{(? } # indent after lines ending with { or ( try %[ execute-keys -draft k [{(]\h*$ j ] # cleanup trailing white spaces on the previous line try %{ execute-keys -draft k s \h+$ d } # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } # copy // comments prefix try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # indent after if|else|while|for try %[ execute-keys -draft \;)MB \A(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\z s \A|.\z 11 ] = ~ define-command -hidden d-indent-on-opening-curly-brace %[ # align indent with opening paren when { is entered on a new line after the closing paren try %[ execute-keys -draft -itersel h)M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] ] define-command -hidden d-indent-on-closing-curly-brace %[ # align to opening curly brace when alone on a line try %[ execute-keys -itersel -draft ^\h+\}$hms\A|.\z1 ] ] 🦀