Mercurial > vim
annotate runtime/indent/clojure.vim @ 20525:42e5347ff9b6
Added tag v8.2.0816 for changeset bed30e6b5a095706cba0ca717d52588156c2b391
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 24 May 2020 17:30:04 +0200 |
parents | 63b0b7b79b25 |
children | 5b37a0bf7e3a |
rev | line source |
---|---|
4098 | 1 " Vim indent file |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
2 " Language: Clojure |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
3 " Author: Meikel Brandmeyer <mb@kotka.de> |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
4 " URL: http://kotka.de/projects/clojure/vimclojure.html |
4098 | 5 " |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
6 " Maintainer: Sung Pae <self@sungpae.com> |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
7 " URL: https://github.com/guns/vim-clojure-static |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
8 " License: Same as Vim |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
9 " Last Change: 18 July 2016 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
10 |
4098 | 11 if exists("b:did_indent") |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
12 finish |
4098 | 13 endif |
14 let b:did_indent = 1 | |
15 | |
16 let s:save_cpo = &cpo | |
17 set cpo&vim | |
18 | |
5734 | 19 let b:undo_indent = 'setlocal autoindent< smartindent< expandtab< softtabstop< shiftwidth< indentexpr< indentkeys<' |
4098 | 20 |
21 setlocal noautoindent nosmartindent | |
22 setlocal softtabstop=2 shiftwidth=2 expandtab | |
23 setlocal indentkeys=!,o,O | |
24 | |
25 if exists("*searchpairpos") | |
26 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
27 if !exists('g:clojure_maxlines') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
28 let g:clojure_maxlines = 100 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
29 endif |
4098 | 30 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
31 if !exists('g:clojure_fuzzy_indent') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
32 let g:clojure_fuzzy_indent = 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
33 endif |
4098 | 34 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
35 if !exists('g:clojure_fuzzy_indent_patterns') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
36 let g:clojure_fuzzy_indent_patterns = ['^with', '^def', '^let'] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
37 endif |
4098 | 38 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
39 if !exists('g:clojure_fuzzy_indent_blacklist') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
40 let g:clojure_fuzzy_indent_blacklist = ['-fn$', '\v^with-%(meta|out-str|loading-context)$'] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
41 endif |
4098 | 42 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
43 if !exists('g:clojure_special_indent_words') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
44 let g:clojure_special_indent_words = 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
45 endif |
4098 | 46 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
47 if !exists('g:clojure_align_multiline_strings') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
48 let g:clojure_align_multiline_strings = 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
49 endif |
4098 | 50 |
5577 | 51 if !exists('g:clojure_align_subforms') |
52 let g:clojure_align_subforms = 0 | |
53 endif | |
54 | |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
55 function! s:syn_id_name() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
56 return synIDattr(synID(line("."), col("."), 0), "name") |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
57 endfunction |
4098 | 58 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
59 function! s:ignored_region() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
60 return s:syn_id_name() =~? '\vstring|regex|comment|character' |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
61 endfunction |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
62 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
63 function! s:current_char() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
64 return getline('.')[col('.')-1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
65 endfunction |
4098 | 66 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
67 function! s:current_word() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
68 return getline('.')[col('.')-1 : searchpos('\v>', 'n', line('.'))[1]-2] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
69 endfunction |
4098 | 70 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
71 function! s:is_paren() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
72 return s:current_char() =~# '\v[\(\)\[\]\{\}]' && !s:ignored_region() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
73 endfunction |
4098 | 74 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
75 " Returns 1 if string matches a pattern in 'patterns', which may be a |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
76 " list of patterns, or a comma-delimited string of implicitly anchored |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
77 " patterns. |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
78 function! s:match_one(patterns, string) |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
79 let list = type(a:patterns) == type([]) |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
80 \ ? a:patterns |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
81 \ : map(split(a:patterns, ','), '"^" . v:val . "$"') |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
82 for pat in list |
5763 | 83 if a:string =~# pat | return 1 | endif |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
84 endfor |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
85 endfunction |
4098 | 86 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
87 function! s:match_pairs(open, close, stopat) |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
88 " Stop only on vector and map [ resp. {. Ignore the ones in strings and |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
89 " comments. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
90 if a:stopat == 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
91 let stopat = max([line(".") - g:clojure_maxlines, 0]) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
92 else |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
93 let stopat = a:stopat |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
94 endif |
4098 | 95 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
96 let pos = searchpairpos(a:open, '', a:close, 'bWn', "!s:is_paren()", stopat) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
97 return [pos[0], col(pos)] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
98 endfunction |
4098 | 99 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
100 function! s:clojure_check_for_string_worker() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
101 " Check whether there is the last character of the previous line is |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
102 " highlighted as a string. If so, we check whether it's a ". In this |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
103 " case we have to check also the previous character. The " might be the |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
104 " closing one. In case the we are still in the string, we search for the |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
105 " opening ". If this is not found we take the indent of the line. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
106 let nb = prevnonblank(v:lnum - 1) |
4098 | 107 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
108 if nb == 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
109 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
110 endif |
4098 | 111 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
112 call cursor(nb, 0) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
113 call cursor(0, col("$") - 1) |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
114 if s:syn_id_name() !~? "string" |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
115 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
116 endif |
4098 | 117 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
118 " This will not work for a " in the first column... |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
119 if s:current_char() == '"' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
120 call cursor(0, col("$") - 2) |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
121 if s:syn_id_name() !~? "string" |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
122 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
123 endif |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
124 if s:current_char() != '\\' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
125 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
126 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
127 call cursor(0, col("$") - 1) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
128 endif |
4098 | 129 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
130 let p = searchpos('\(^\|[^\\]\)\zs"', 'bW') |
4098 | 131 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
132 if p != [0, 0] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
133 return p[1] - 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
134 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
135 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
136 return indent(".") |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
137 endfunction |
4098 | 138 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
139 function! s:check_for_string() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
140 let pos = getpos('.') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
141 try |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
142 let val = s:clojure_check_for_string_worker() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
143 finally |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
144 call setpos('.', pos) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
145 endtry |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
146 return val |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
147 endfunction |
4098 | 148 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
149 function! s:strip_namespace_and_macro_chars(word) |
5763 | 150 return substitute(a:word, "\\v%(.*/|[#'`~@^,]*)(.*)", '\1', '') |
151 endfunction | |
152 | |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
153 function! s:clojure_is_method_special_case_worker(position) |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
154 " Find the next enclosing form. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
155 call search('\S', 'Wb') |
4098 | 156 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
157 " Special case: we are at a '(('. |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
158 if s:current_char() == '(' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
159 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
160 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
161 call cursor(a:position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
162 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
163 let next_paren = s:match_pairs('(', ')', 0) |
4098 | 164 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
165 " Special case: we are now at toplevel. |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
166 if next_paren == [0, 0] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
167 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
168 endif |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
169 call cursor(next_paren) |
4098 | 170 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
171 call search('\S', 'W') |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
172 let w = s:strip_namespace_and_macro_chars(s:current_word()) |
5763 | 173 if g:clojure_special_indent_words =~# '\V\<' . w . '\>' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
174 return 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
175 endif |
4098 | 176 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
177 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
178 endfunction |
4098 | 179 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
180 function! s:is_method_special_case(position) |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
181 let pos = getpos('.') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
182 try |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
183 let val = s:clojure_is_method_special_case_worker(a:position) |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
184 finally |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
185 call setpos('.', pos) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
186 endtry |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
187 return val |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
188 endfunction |
4098 | 189 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
190 " Check if form is a reader conditional, that is, it is prefixed by #? |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
191 " or @#? |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
192 function! s:is_reader_conditional_special_case(position) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
193 if getline(a:position[0])[a:position[1] - 3 : a:position[1] - 2] == "#?" |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
194 return 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
195 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
196 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
197 return 0 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
198 endfunction |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
199 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
200 " Returns 1 for opening brackets, -1 for _anything else_. |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
201 function! s:bracket_type(char) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
202 return stridx('([{', a:char) > -1 ? 1 : -1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
203 endfunction |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
204 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
205 " Returns: [opening-bracket-lnum, indent] |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
206 function! s:clojure_indent_pos() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
207 " Get rid of special case. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
208 if line(".") == 1 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
209 return [0, 0] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
210 endif |
4098 | 211 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
212 " We have to apply some heuristics here to figure out, whether to use |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
213 " normal lisp indenting or not. |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
214 let i = s:check_for_string() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
215 if i > -1 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
216 return [0, i + !!g:clojure_align_multiline_strings] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
217 endif |
4098 | 218 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
219 call cursor(0, 1) |
4098 | 220 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
221 " Find the next enclosing [ or {. We can limit the second search |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
222 " to the line, where the [ was found. If no [ was there this is |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
223 " zero and we search for an enclosing {. |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
224 let paren = s:match_pairs('(', ')', 0) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
225 let bracket = s:match_pairs('\[', '\]', paren[0]) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
226 let curly = s:match_pairs('{', '}', bracket[0]) |
4098 | 227 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
228 " In case the curly brace is on a line later then the [ or - in |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
229 " case they are on the same line - in a higher column, we take the |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
230 " curly indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
231 if curly[0] > bracket[0] || curly[1] > bracket[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
232 if curly[0] > paren[0] || curly[1] > paren[1] |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
233 return curly |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
234 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
235 endif |
4098 | 236 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
237 " If the curly was not chosen, we take the bracket indent - if |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
238 " there was one. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
239 if bracket[0] > paren[0] || bracket[1] > paren[1] |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
240 return bracket |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
241 endif |
4098 | 242 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
243 " There are neither { nor [ nor (, ie. we are at the toplevel. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
244 if paren == [0, 0] |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
245 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
246 endif |
4098 | 247 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
248 " Now we have to reimplement lispindent. This is surprisingly easy, as |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
249 " soon as one has access to syntax items. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
250 " |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
251 " - Check whether we are in a special position after a word in |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
252 " g:clojure_special_indent_words. These are special cases. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
253 " - Get the next keyword after the (. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
254 " - If its first character is also a (, we have another sexp and align |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
255 " one column to the right of the unmatched (. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
256 " - In case it is in lispwords, we indent the next line to the column of |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
257 " the ( + sw. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
258 " - If not, we check whether it is last word in the line. In that case |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
259 " we again use ( + sw for indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
260 " - In any other case we use the column of the end of the word + 2. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
261 call cursor(paren) |
4098 | 262 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
263 if s:is_method_special_case(paren) |
11518 | 264 return [paren[0], paren[1] + shiftwidth() - 1] |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
265 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
266 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
267 if s:is_reader_conditional_special_case(paren) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
268 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
269 endif |
4098 | 270 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
271 " In case we are at the last character, we use the paren position. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
272 if col("$") - 1 == paren[1] |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
273 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
274 endif |
4098 | 275 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
276 " In case after the paren is a whitespace, we search for the next word. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
277 call cursor(0, col('.') + 1) |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
278 if s:current_char() == ' ' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
279 call search('\v\S', 'W') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
280 endif |
4098 | 281 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
282 " If we moved to another line, there is no word after the (. We |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
283 " use the ( position for indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
284 if line(".") > paren[0] |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
285 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
286 endif |
4098 | 287 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
288 " We still have to check, whether the keyword starts with a (, [ or {. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
289 " In that case we use the ( position for indent. |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
290 let w = s:current_word() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
291 if s:bracket_type(w[0]) == 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
292 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
293 endif |
4098 | 294 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
295 " Test words without namespace qualifiers and leading reader macro |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
296 " metacharacters. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
297 " |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
298 " e.g. clojure.core/defn and #'defn should both indent like defn. |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
299 let ww = s:strip_namespace_and_macro_chars(w) |
4098 | 300 |
5763 | 301 if &lispwords =~# '\V\<' . ww . '\>' |
11518 | 302 return [paren[0], paren[1] + shiftwidth() - 1] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
303 endif |
4098 | 304 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
305 if g:clojure_fuzzy_indent |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
306 \ && !s:match_one(g:clojure_fuzzy_indent_blacklist, ww) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
307 \ && s:match_one(g:clojure_fuzzy_indent_patterns, ww) |
11518 | 308 return [paren[0], paren[1] + shiftwidth() - 1] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
309 endif |
4098 | 310 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
311 call search('\v\_s', 'cW') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
312 call search('\v\S', 'W') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
313 if paren[0] < line(".") |
11518 | 314 return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : shiftwidth() - 1)] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
315 endif |
4098 | 316 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
317 call search('\v\S', 'bW') |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
318 return [line('.'), col('.') + 1] |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
319 endfunction |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
320 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
321 function! GetClojureIndent() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
322 let lnum = line('.') |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
323 let orig_lnum = lnum |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
324 let orig_col = col('.') |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
325 let [opening_lnum, indent] = s:clojure_indent_pos() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
326 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
327 " Account for multibyte characters |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
328 if opening_lnum > 0 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
329 let indent -= indent - virtcol([opening_lnum, indent]) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
330 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
331 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
332 " Return if there are no previous lines to inherit from |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
333 if opening_lnum < 1 || opening_lnum >= lnum - 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
334 call cursor(orig_lnum, orig_col) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
335 return indent |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
336 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
337 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
338 let bracket_count = 0 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
339 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
340 " Take the indent of the first previous non-white line that is |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
341 " at the same sexp level. cf. src/misc1.c:get_lisp_indent() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
342 while 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
343 let lnum = prevnonblank(lnum - 1) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
344 let col = 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
345 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
346 if lnum <= opening_lnum |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
347 break |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
348 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
349 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
350 call cursor(lnum, col) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
351 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
352 " Handle bracket counting edge case |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
353 if s:is_paren() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
354 let bracket_count += s:bracket_type(s:current_char()) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
355 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
356 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
357 while 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
358 if search('\v[(\[{}\])]', '', lnum) < 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
359 break |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
360 elseif !s:ignored_region() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
361 let bracket_count += s:bracket_type(s:current_char()) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
362 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
363 endwhile |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
364 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
365 if bracket_count == 0 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
366 " Check if this is part of a multiline string |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
367 call cursor(lnum, 1) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
368 if s:syn_id_name() !~? '\vstring|regex' |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
369 call cursor(orig_lnum, orig_col) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
370 return indent(lnum) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
371 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
372 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
373 endwhile |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
374 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
375 call cursor(orig_lnum, orig_col) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
376 return indent |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
377 endfunction |
4098 | 378 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
379 setlocal indentexpr=GetClojureIndent() |
4098 | 380 |
381 else | |
382 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
383 " In case we have searchpairpos not available we fall back to |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
384 " normal lisp indenting. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
385 setlocal indentexpr= |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
386 setlocal lisp |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
387 let b:undo_indent .= '| setlocal lisp<' |
4098 | 388 |
389 endif | |
390 | |
391 let &cpo = s:save_cpo | |
392 unlet! s:save_cpo | |
393 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
394 " vim:sts=8:sw=8:ts=8:noet |