From b974eb01b316a06cf1f76cdfbe364f8b2160a381 Mon Sep 17 00:00:00 2001 From: Alex Vear Date: Sun, 10 Jan 2021 18:35:46 +0000 Subject: [PATCH] Fix indentation of subforms inside `letfn` forms Fixes: guns/vim-clojure-static#56 Related: guns/vim-clojure-static#83 --- indent/clojure.vim | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/indent/clojure.vim b/indent/clojure.vim index ffa5820..75d82a0 100644 --- a/indent/clojure.vim +++ b/indent/clojure.vim @@ -169,7 +169,35 @@ if exists("*searchpairpos") call search('\S', 'W') let w = s:strip_namespace_and_macro_chars(s:current_word()) + if g:clojure_special_indent_words =~# '\V\<' . w . '\>' + + " `letfn` is a special-special-case. + if w ==# 'letfn' + " Earlier code left the cursor at: + " (letfn [...] ...) + " ^ + + " Search and get coordinates of first `[` + " (letfn [...] ...) + " ^ + call search('\[', 'W') + let pos = getcurpos() + let letfn_bracket = [pos[1], pos[2]] + + " Move cursor to start of the form this function was + " initially called on. Grab the coordinates of the + " closest outer `[`. + call cursor(a:position) + let outer_bracket = s:match_pairs('\[', '\]', 0) + + " If the located square brackets are not the same, + " don't use special-case formatting. + if outer_bracket != letfn_bracket + return 0 + endif + endif + return 1 endif