Mercurial > vim
annotate runtime/indent/clojure.vim @ 6880:bcc0909b379e v7.4.760
patch 7.4.760
Problem: Spelling mistakes are not displayed after ":syn spell".
Solution: Force a redraw after ":syn spell" command. (Christian Brabandt)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 25 Jun 2015 18:36:26 +0200 |
parents | c52a655d927d |
children | 9f7bcc2c3b97 |
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 |
5763 | 9 " Last Change: 27 March 2014 |
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 | |
5734 | 24 let b:undo_indent = 'setlocal autoindent< smartindent< expandtab< softtabstop< shiftwidth< indentexpr< indentkeys<' |
4098 | 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() |
5763 | 73 return s:CurrentChar() =~# '\v[\(\)\[\]\{\}]' && |
5362
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 |
5763 | 85 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
|
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 |
5763 | 151 function! s:StripNamespaceAndMacroChars(word) |
152 return substitute(a:word, "\\v%(.*/|[#'`~@^,]*)(.*)", '\1', '') | |
153 endfunction | |
154 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
155 function! s:ClojureIsMethodSpecialCaseWorker(position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
156 " Find the next enclosing form. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
157 call search('\S', 'Wb') |
4098 | 158 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
159 " Special case: we are at a '(('. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
160 if s:CurrentChar() == '(' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
161 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
162 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
163 call cursor(a:position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
164 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
165 let nextParen = s:MatchPairs('(', ')', 0) |
4098 | 166 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
167 " Special case: we are now at toplevel. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
168 if nextParen == [0, 0] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
169 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
170 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
171 call cursor(nextParen) |
4098 | 172 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
173 call search('\S', 'W') |
5763 | 174 let w = s:StripNamespaceAndMacroChars(s:CurrentWord()) |
175 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
|
176 return 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
177 endif |
4098 | 178 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
179 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
180 endfunction |
4098 | 181 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
182 function! s:IsMethodSpecialCase(position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
183 let pos = getpos('.') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
184 try |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
185 let val = s:ClojureIsMethodSpecialCaseWorker(a:position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
186 finally |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
187 call setpos('.', pos) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
188 endtry |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
189 return val |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
190 endfunction |
4098 | 191 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
192 function! GetClojureIndent() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
193 " Get rid of special case. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
194 if line(".") == 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
195 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
196 endif |
4098 | 197 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
198 " 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
|
199 " normal lisp indenting or not. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
200 let i = s:CheckForString() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
201 if i > -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
202 return i + !!g:clojure_align_multiline_strings |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
203 endif |
4098 | 204 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
205 call cursor(0, 1) |
4098 | 206 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
207 " 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
|
208 " 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
|
209 " zero and we search for an enclosing {. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
210 let paren = s:MatchPairs('(', ')', 0) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
211 let bracket = s:MatchPairs('\[', '\]', paren[0]) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
212 let curly = s:MatchPairs('{', '}', bracket[0]) |
4098 | 213 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
214 " 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
|
215 " 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
|
216 " curly indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
217 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
|
218 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
|
219 return curly[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
220 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
221 endif |
4098 | 222 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
223 " 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
|
224 " there was one. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
225 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
|
226 return bracket[1] |
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 " 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
|
230 if paren == [0, 0] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
231 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
232 endif |
4098 | 233 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
234 " 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
|
235 " 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
|
236 " |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
237 " - 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
|
238 " 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
|
239 " - Get the next keyword after the (. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
240 " - 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
|
241 " 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
|
242 " - 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
|
243 " the ( + sw. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
244 " - 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
|
245 " we again use ( + sw for indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
246 " - 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
|
247 call cursor(paren) |
4098 | 248 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
249 if s:IsMethodSpecialCase(paren) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
250 return paren[1] + &shiftwidth - 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 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
|
254 if col("$") - 1 == paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
255 return paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
256 endif |
4098 | 257 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
258 " 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
|
259 call cursor(0, col('.') + 1) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
260 if s:CurrentChar() == ' ' |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
261 call search('\v\S', 'W') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
262 endif |
4098 | 263 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
264 " 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
|
265 " use the ( position for indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
266 if line(".") > paren[0] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
267 return paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
268 endif |
4098 | 269 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
270 " 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
|
271 " 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
|
272 let w = s:CurrentWord() |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
273 if stridx('([{', w[0]) > -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
274 return paren[1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
275 endif |
4098 | 276 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
277 " 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
|
278 " metacharacters. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
279 " |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
280 " e.g. clojure.core/defn and #'defn should both indent like defn. |
5763 | 281 let ww = s:StripNamespaceAndMacroChars(w) |
4098 | 282 |
5763 | 283 if &lispwords =~# '\V\<' . ww . '\>' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
284 return paren[1] + &shiftwidth - 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
285 endif |
4098 | 286 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
287 if g:clojure_fuzzy_indent |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
288 \ && !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
|
289 \ && 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
|
290 return paren[1] + &shiftwidth - 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
291 endif |
4098 | 292 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
293 call search('\v\_s', 'cW') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
294 call search('\v\S', 'W') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
295 if paren[0] < line(".") |
5577 | 296 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
|
297 endif |
4098 | 298 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
299 call search('\v\S', 'bW') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
300 return virtcol(".") + 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
301 endfunction |
4098 | 302 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
303 setlocal indentexpr=GetClojureIndent() |
4098 | 304 |
305 else | |
306 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
307 " 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
|
308 " normal lisp indenting. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
309 setlocal indentexpr= |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
310 setlocal lisp |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
311 let b:undo_indent .= '| setlocal lisp<' |
4098 | 312 |
313 endif | |
314 | |
315 let &cpo = s:save_cpo | |
316 unlet! s:save_cpo | |
317 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
318 " vim:sts=8:sw=8:ts=8:noet |