Mercurial > vim
annotate runtime/indent/clojure.vim @ 5577:de28b1568fc2
Updated runtime files.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Tue, 07 Jan 2014 06:09:28 +0100 |
parents | ab1508486b12 |
children | 657ade71d395 |
rev | line source |
---|---|
4098 | 1 " Vim indent file |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
2 " Language: Clojure |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
3 " Author: Meikel Brandmeyer <mb@kotka.de> |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
4 " URL: http://kotka.de/projects/clojure/vimclojure.html |
4098 | 5 " |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
6 " Maintainer: Sung Pae <self@sungpae.com> |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
7 " URL: https://github.com/guns/vim-clojure-static |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
8 " License: Same as Vim |
5577 | 9 " Last Change: 16 December 2013 |
4098 | 10 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
11 " TODO: Indenting after multibyte characters is broken: |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
12 " (let [Δ (if foo |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
13 " bar ; Indent error |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
14 " baz)]) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
15 |
4098 | 16 if exists("b:did_indent") |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
17 finish |
4098 | 18 endif |
19 let b:did_indent = 1 | |
20 | |
21 let s:save_cpo = &cpo | |
22 set cpo&vim | |
23 | |
24 let b:undo_indent = 'setlocal autoindent< smartindent< lispwords< expandtab< softtabstop< shiftwidth< indentexpr< indentkeys<' | |
25 | |
26 setlocal noautoindent nosmartindent | |
27 setlocal softtabstop=2 shiftwidth=2 expandtab | |
28 setlocal indentkeys=!,o,O | |
29 | |
30 if exists("*searchpairpos") | |
31 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
32 if !exists('g:clojure_maxlines') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
33 let g:clojure_maxlines = 100 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
34 endif |
4098 | 35 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
36 if !exists('g:clojure_fuzzy_indent') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
37 let g:clojure_fuzzy_indent = 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
38 endif |
4098 | 39 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
40 if !exists('g:clojure_fuzzy_indent_patterns') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
41 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
|
42 endif |
4098 | 43 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
44 if !exists('g:clojure_fuzzy_indent_blacklist') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
45 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
|
46 endif |
4098 | 47 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
48 if !exists('g:clojure_special_indent_words') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
49 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
|
50 endif |
4098 | 51 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
52 if !exists('g:clojure_align_multiline_strings') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
53 let g:clojure_align_multiline_strings = 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
54 endif |
4098 | 55 |
5577 | 56 if !exists('g:clojure_align_subforms') |
57 let g:clojure_align_subforms = 0 | |
58 endif | |
59 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
60 function! s:SynIdName() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
61 return synIDattr(synID(line("."), col("."), 0), "name") |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
62 endfunction |
4098 | 63 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
64 function! s:CurrentChar() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
65 return getline('.')[col('.')-1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
66 endfunction |
4098 | 67 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
68 function! s:CurrentWord() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
69 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
|
70 endfunction |
4098 | 71 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
72 function! s:IsParen() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
73 return s:CurrentChar() =~ '\v[\(\)\[\]\{\}]' && |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
74 \ s:SynIdName() !~? '\vstring|regex|comment|character' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
75 endfunction |
4098 | 76 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
77 " 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
|
78 " 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
|
79 " patterns. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
80 function! s:MatchesOne(patterns, string) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
81 let list = type(a:patterns) == type([]) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
82 \ ? a:patterns |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
83 \ : map(split(a:patterns, ','), '"^" . v:val . "$"') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
84 for pat in list |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
85 if a:string =~ pat | return 1 | endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
86 endfor |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
87 endfunction |
4098 | 88 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
89 function! s:MatchPairs(open, close, stopat) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
90 " 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
|
91 " comments. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
92 if a:stopat == 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
93 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
|
94 else |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
95 let stopat = a:stopat |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
96 endif |
4098 | 97 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
98 let pos = searchpairpos(a:open, '', a:close, 'bWn', "!s:IsParen()", stopat) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
99 return [pos[0], virtcol(pos)] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
100 endfunction |
4098 | 101 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
102 function! s:ClojureCheckForStringWorker() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
103 " 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
|
104 " 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
|
105 " 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
|
106 " 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
|
107 " 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
|
108 let nb = prevnonblank(v:lnum - 1) |
4098 | 109 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
110 if nb == 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
111 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
112 endif |
4098 | 113 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
114 call cursor(nb, 0) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
115 call cursor(0, col("$") - 1) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
116 if s:SynIdName() !~? "string" |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
117 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
118 endif |
4098 | 119 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
120 " This will not work for a " in the first column... |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
121 if s:CurrentChar() == '"' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
122 call cursor(0, col("$") - 2) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
123 if s:SynIdName() !~? "string" |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
124 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
125 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
126 if s:CurrentChar() != '\\' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
127 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
128 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
129 call cursor(0, col("$") - 1) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
130 endif |
4098 | 131 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
132 let p = searchpos('\(^\|[^\\]\)\zs"', 'bW') |
4098 | 133 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
134 if p != [0, 0] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
135 return p[1] - 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
136 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
137 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
138 return indent(".") |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
139 endfunction |
4098 | 140 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
141 function! s:CheckForString() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
142 let pos = getpos('.') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
143 try |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
144 let val = s:ClojureCheckForStringWorker() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
145 finally |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
146 call setpos('.', pos) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
147 endtry |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
148 return val |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
149 endfunction |
4098 | 150 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
151 function! s:ClojureIsMethodSpecialCaseWorker(position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
152 " Find the next enclosing form. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
153 call search('\S', 'Wb') |
4098 | 154 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
155 " Special case: we are at a '(('. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
156 if s:CurrentChar() == '(' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
157 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
158 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
159 call cursor(a:position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
160 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
161 let nextParen = s:MatchPairs('(', ')', 0) |
4098 | 162 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
163 " Special case: we are now at toplevel. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
164 if nextParen == [0, 0] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
165 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
166 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
167 call cursor(nextParen) |
4098 | 168 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
169 call search('\S', 'W') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
170 if g:clojure_special_indent_words =~ '\<' . s:CurrentWord() . '\>' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
171 return 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
172 endif |
4098 | 173 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
174 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
175 endfunction |
4098 | 176 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
177 function! s:IsMethodSpecialCase(position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
178 let pos = getpos('.') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
179 try |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
180 let val = s:ClojureIsMethodSpecialCaseWorker(a:position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
181 finally |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
182 call setpos('.', pos) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
183 endtry |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
184 return val |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
185 endfunction |
4098 | 186 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
187 function! GetClojureIndent() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
188 " Get rid of special case. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
189 if line(".") == 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
190 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
191 endif |
4098 | 192 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
193 " 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
|
194 " normal lisp indenting or not. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
195 let i = s:CheckForString() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
196 if i > -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
197 return i + !!g:clojure_align_multiline_strings |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
198 endif |
4098 | 199 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
200 call cursor(0, 1) |
4098 | 201 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
202 " 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
|
203 " 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
|
204 " zero and we search for an enclosing {. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
205 let paren = s:MatchPairs('(', ')', 0) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
206 let bracket = s:MatchPairs('\[', '\]', paren[0]) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
207 let curly = s:MatchPairs('{', '}', bracket[0]) |
4098 | 208 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
209 " 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
|
210 " 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
|
211 " curly indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
212 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
|
213 if curly[0] > paren[0] || curly[1] > paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
214 return curly[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
215 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
216 endif |
4098 | 217 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
218 " 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
|
219 " there was one. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
220 if bracket[0] > paren[0] || bracket[1] > paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
221 return bracket[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
222 endif |
4098 | 223 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
224 " 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
|
225 if paren == [0, 0] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
226 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
227 endif |
4098 | 228 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
229 " 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
|
230 " 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
|
231 " |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
232 " - 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
|
233 " 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
|
234 " - Get the next keyword after the (. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
235 " - 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
|
236 " 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
|
237 " - 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
|
238 " the ( + sw. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
239 " - 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
|
240 " we again use ( + sw for indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
241 " - 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
|
242 call cursor(paren) |
4098 | 243 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
244 if s:IsMethodSpecialCase(paren) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
245 return paren[1] + &shiftwidth - 1 |
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 " 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
|
249 if col("$") - 1 == paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
250 return paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
251 endif |
4098 | 252 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
253 " 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
|
254 call cursor(0, col('.') + 1) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
255 if s:CurrentChar() == ' ' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
256 call search('\v\S', 'W') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
257 endif |
4098 | 258 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
259 " 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
|
260 " use the ( position for indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
261 if line(".") > paren[0] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
262 return paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
263 endif |
4098 | 264 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
265 " 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
|
266 " In that case we use the ( position for indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
267 let w = s:CurrentWord() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
268 if stridx('([{', w[0]) > -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
269 return paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
270 endif |
4098 | 271 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
272 " 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
|
273 " metacharacters. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
274 " |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
275 " e.g. clojure.core/defn and #'defn should both indent like defn. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
276 let ww = substitute(w, "\\v%(.*/|[#'`~@^,]*)(.*)", '\1', '') |
4098 | 277 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
278 if &lispwords =~ '\V\<' . ww . '\>' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
279 return paren[1] + &shiftwidth - 1 |
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 g:clojure_fuzzy_indent |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
283 \ && !s:MatchesOne(g:clojure_fuzzy_indent_blacklist, ww) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
284 \ && s:MatchesOne(g:clojure_fuzzy_indent_patterns, ww) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
285 return paren[1] + &shiftwidth - 1 |
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 call search('\v\_s', 'cW') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
289 call search('\v\S', 'W') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
290 if paren[0] < line(".") |
5577 | 291 return 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
|
292 endif |
4098 | 293 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
294 call search('\v\S', 'bW') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
295 return virtcol(".") + 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
296 endfunction |
4098 | 297 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
298 setlocal indentexpr=GetClojureIndent() |
4098 | 299 |
300 else | |
301 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
302 " 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
|
303 " normal lisp indenting. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
304 setlocal indentexpr= |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
305 setlocal lisp |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
306 let b:undo_indent .= '| setlocal lisp<' |
4098 | 307 |
308 endif | |
309 | |
310 " Specially indented symbols from clojure.core and clojure.test. | |
311 " | |
312 " Clojure symbols are indented in the defn style when they: | |
313 " | |
314 " * Define vars and anonymous functions | |
315 " * Create new lexical scopes or scopes with altered environments | |
316 " * Create conditional branches from a predicate function or value | |
317 " | |
318 " The arglists for these functions are generally in the form of [x & body]; | |
319 " Functions that accept a flat list of forms do not treat the first argument | |
320 " specially and hence are not indented specially. | |
321 | |
322 " Definitions | |
323 setlocal lispwords= | |
324 setlocal lispwords+=bound-fn | |
325 setlocal lispwords+=def | |
326 setlocal lispwords+=definline | |
327 setlocal lispwords+=definterface | |
328 setlocal lispwords+=defmacro | |
329 setlocal lispwords+=defmethod | |
330 setlocal lispwords+=defmulti | |
331 setlocal lispwords+=defn | |
332 setlocal lispwords+=defn- | |
333 setlocal lispwords+=defonce | |
334 setlocal lispwords+=defprotocol | |
335 setlocal lispwords+=defrecord | |
336 setlocal lispwords+=defstruct | |
337 setlocal lispwords+=deftest " clojure.test | |
338 setlocal lispwords+=deftest- " clojure.test | |
339 setlocal lispwords+=deftype | |
340 setlocal lispwords+=extend | |
341 setlocal lispwords+=extend-protocol | |
342 setlocal lispwords+=extend-type | |
343 setlocal lispwords+=fn | |
344 setlocal lispwords+=ns | |
345 setlocal lispwords+=proxy | |
346 setlocal lispwords+=reify | |
347 setlocal lispwords+=set-test " clojure.test | |
348 | |
349 " Binding forms | |
350 setlocal lispwords+=as-> | |
351 setlocal lispwords+=binding | |
352 setlocal lispwords+=doall | |
353 setlocal lispwords+=dorun | |
354 setlocal lispwords+=doseq | |
355 setlocal lispwords+=dotimes | |
356 setlocal lispwords+=doto | |
357 setlocal lispwords+=for | |
358 setlocal lispwords+=if-let | |
359 setlocal lispwords+=let | |
360 setlocal lispwords+=letfn | |
361 setlocal lispwords+=locking | |
362 setlocal lispwords+=loop | |
363 setlocal lispwords+=testing " clojure.test | |
364 setlocal lispwords+=when-first | |
365 setlocal lispwords+=when-let | |
366 setlocal lispwords+=with-bindings | |
367 setlocal lispwords+=with-in-str | |
368 setlocal lispwords+=with-local-vars | |
369 setlocal lispwords+=with-open | |
370 setlocal lispwords+=with-precision | |
371 setlocal lispwords+=with-redefs | |
372 setlocal lispwords+=with-redefs-fn | |
373 setlocal lispwords+=with-test " clojure.test | |
374 | |
375 " Conditional branching | |
376 setlocal lispwords+=case | |
377 setlocal lispwords+=cond-> | |
378 setlocal lispwords+=cond->> | |
379 setlocal lispwords+=condp | |
380 setlocal lispwords+=if | |
381 setlocal lispwords+=if-not | |
382 setlocal lispwords+=when | |
383 setlocal lispwords+=when-not | |
384 setlocal lispwords+=while | |
385 | |
386 " Exception handling | |
387 setlocal lispwords+=catch | |
388 | |
389 let &cpo = s:save_cpo | |
390 unlet! s:save_cpo | |
391 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
392 " vim:sts=8:sw=8:ts=8:noet |