aboutsummaryrefslogtreecommitdiff
path: root/runtime/indent/clojure.vim
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-05-04 19:18:16 -0400
committerGitHub <noreply@github.com>2021-05-04 19:18:16 -0400
commit4ad30f775e5564c539324b4818886f067d2ecd99 (patch)
tree97a554379bda7e5fc77e58c690db3f5a72db8c74 /runtime/indent/clojure.vim
parent63d8a8f4e8b02e524d85aed08aa16c5d9815598c (diff)
parentd5b063aec1db95704b37a77fdbd968cb6b48cc3b (diff)
downloadrneovim-4ad30f775e5564c539324b4818886f067d2ecd99.tar.gz
rneovim-4ad30f775e5564c539324b4818886f067d2ecd99.tar.bz2
rneovim-4ad30f775e5564c539324b4818886f067d2ecd99.zip
Merge pull request #14424 from janlazo/vim-8.1.1726
vim-patch:8.1.1726,8.2.{296,860,1827,2388,2788,2790,2801}
Diffstat (limited to 'runtime/indent/clojure.vim')
-rw-r--r--runtime/indent/clojure.vim74
1 files changed, 55 insertions, 19 deletions
diff --git a/runtime/indent/clojure.vim b/runtime/indent/clojure.vim
index 7c4186e29b..30a0b478e2 100644
--- a/runtime/indent/clojure.vim
+++ b/runtime/indent/clojure.vim
@@ -1,12 +1,11 @@
" Vim indent file
-" Language: Clojure
-" Author: Meikel Brandmeyer <mb@kotka.de>
-" URL: http://kotka.de/projects/clojure/vimclojure.html
-"
-" Maintainer: Sung Pae <self@sungpae.com>
-" URL: https://github.com/guns/vim-clojure-static
-" License: Same as Vim
-" Last Change: 18 July 2016
+" Language: Clojure
+" Maintainer: Alex Vear <av@axvr.io>
+" Former Maintainers: Sung Pae <self@sungpae.com>
+" Meikel Brandmeyer <mb@kotka.de>
+" URL: https://github.com/clojure-vim/clojure.vim
+" License: Vim (see :h license)
+" Last Change: 2021-02-13
if exists("b:did_indent")
finish
@@ -87,7 +86,7 @@ if exists("*searchpairpos")
function! s:match_pairs(open, close, stopat)
" Stop only on vector and map [ resp. {. Ignore the ones in strings and
" comments.
- if a:stopat == 0
+ if a:stopat == 0 && g:clojure_maxlines > 0
let stopat = max([line(".") - g:clojure_maxlines, 0])
else
let stopat = a:stopat
@@ -121,7 +120,7 @@ if exists("*searchpairpos")
if s:syn_id_name() !~? "string"
return -1
endif
- if s:current_char() != '\\'
+ if s:current_char() != '\'
return -1
endif
call cursor(0, col("$") - 1)
@@ -170,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
@@ -190,11 +217,7 @@ if exists("*searchpairpos")
" Check if form is a reader conditional, that is, it is prefixed by #?
" or @#?
function! s:is_reader_conditional_special_case(position)
- if getline(a:position[0])[a:position[1] - 3 : a:position[1] - 2] == "#?"
- return 1
- endif
-
- return 0
+ return getline(a:position[0])[a:position[1] - 3 : a:position[1] - 2] == "#?"
endfunction
" Returns 1 for opening brackets, -1 for _anything else_.
@@ -261,7 +284,7 @@ if exists("*searchpairpos")
call cursor(paren)
if s:is_method_special_case(paren)
- return [paren[0], paren[1] + shiftwidth() - 1]
+ return [paren[0], paren[1] + &shiftwidth - 1]
endif
if s:is_reader_conditional_special_case(paren)
@@ -292,6 +315,19 @@ if exists("*searchpairpos")
return paren
endif
+ " If the keyword begins with #, check if it is an anonymous
+ " function or set, in which case we indent by the shiftwidth
+ " (minus one if g:clojure_align_subforms = 1), or if it is
+ " ignored, in which case we use the ( position for indent.
+ if w[0] == "#"
+ " TODO: Handle #=() and other rare reader invocations?
+ if w[1] == '(' || w[1] == '{'
+ return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)]
+ elseif w[1] == '_'
+ return paren
+ endif
+ endif
+
" Test words without namespace qualifiers and leading reader macro
" metacharacters.
"
@@ -299,19 +335,19 @@ if exists("*searchpairpos")
let ww = s:strip_namespace_and_macro_chars(w)
if &lispwords =~# '\V\<' . ww . '\>'
- return [paren[0], paren[1] + shiftwidth() - 1]
+ return [paren[0], paren[1] + &shiftwidth - 1]
endif
if g:clojure_fuzzy_indent
\ && !s:match_one(g:clojure_fuzzy_indent_blacklist, ww)
\ && s:match_one(g:clojure_fuzzy_indent_patterns, ww)
- return [paren[0], paren[1] + shiftwidth() - 1]
+ return [paren[0], paren[1] + &shiftwidth - 1]
endif
call search('\v\_s', 'cW')
call search('\v\S', 'W')
if paren[0] < line(".")
- return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : shiftwidth() - 1)]
+ return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)]
endif
call search('\v\S', 'bW')