# http://dlang.org/ # # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*\.di? %{ set buffer mimetype "" set buffer filetype d } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ addhl -group / regions -default code d \ string '"' (? } # indent after lines ending with { or ( try %[ exec -draft k [{(]\h*$ j ] # cleanup trailing white spaces on the previous line try %{ exec -draft k s \h+$ d } # align to opening paren of previous line try %{ exec -draft [( \`\([^\n]+\n[^\n]*\n?\' s \`\(\h*.|.\' '' & } # copy // comments prefix try %{ exec -draft \;k s ^\h*\K/{2,} yP } # indent after a switch's case/default statements try %[ exec -draft k ^\h*(case|default).*:$ j ] # indent after if|else|while|for try %[ exec -draft \;)MB \`(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\' s \`|.\' 11 ] = ~ def -hidden _d-indent-on-opening-curly-brace %[ # align indent with opening paren when { is entered on a new line after the closing paren try %[ exec -draft -itersel h)M \`\(.*\)\h*\n\h*\{\' s \`|.\' 1 ] ] def -hidden _d-indent-on-closing-curly-brace %[ # align to opening curly brace when alone on a line try %[ exec -itersel -draft ^\h+\}$hms\`|.\'1 ] ] # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group d-highlight global WinSetOption filetype=d %{ addhl ref d } hook global WinSetOption filetype=d %{ # cleanup trailing whitespaces when exiting insert mode hook window InsertEnd .* -group d-hooks %{ try %{ exec -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 -group d-highlight global WinSetOption filetype=(?!d).* %{ rmhl d } hook global WinSetOption filetype=(?!d).* %{ rmhooks window d-hooks rmhooks window d-indent }