diff --git a/rc/filetype/clojure.kak b/rc/filetype/clojure.kak index 8f2cc488..3db3e429 100644 --- a/rc/filetype/clojure.kak +++ b/rc/filetype/clojure.kak @@ -26,6 +26,11 @@ hook -group clojure-highlight global WinSetOption filetype=clojure %{ hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/clojure } } +hook -group clojure-insert global BufNewFile .*[.](clj|cljc|cljs|cljx) %{ + require-module clojure + clojure-insert-ns +} + provide-module clojure %{ require-module lisp @@ -212,4 +217,19 @@ define-command -hidden clojure-indent-on-new-line %{ } } +declare-option -docstring %{top-level directories which can contain clojure files +e.g. '(src|test|dev)'} regex clojure_source_directories '(src|test|dev)' + +define-command -docstring %{clojure-insert-ns: Insert namespace directive at top of Clojure source file} \ + clojure-insert-ns %{ + evaluate-commands -draft %{ + execute-keys -save-regs '' 'gk\O' "%val{bufname}" 'giZ' + try %{ execute-keys 'zs\.clj[csx]?$' } + try %{ execute-keys 'zs^' "%opt{clojure_source_directories}" '/' } + try %{ execute-keys 'zs/r.' } + try %{ execute-keys 'zs_r-' } + execute-keys 'z\c(ns ")' + } +} + }