From ba672623bcf1e50bc7c733fd6399a44c7822db64 Mon Sep 17 00:00:00 2001 From: Jason Felice Date: Tue, 30 Jul 2019 11:14:40 -0400 Subject: [PATCH] Insert Clojure ns directive for new files --- rc/filetype/clojure.kak | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 ")' + } +} + }