Mercurial > vim
annotate runtime/indent/clojure.vim @ 34786:e27831e54542 v9.1.0267
patch 9.1.0267: File name entered in GUI dialog is ignored
Commit: https://github.com/vim/vim/commit/c20bdf1107d48a1c14713709d12d429e761132af
Author: zeertzjq <zeertzjq@outlook.com>
Date: Fri Apr 5 20:02:55 2024 +0200
patch 9.1.0267: File name entered in GUI dialog is ignored
Problem: File name entered in GUI dialog is ignored (after v9.1.0265)
Solution: Only set file name to "Untitled" if GUI dialog didn't set it.
(zeertzjq)
closes: #14417
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 05 Apr 2024 20:15:03 +0200 |
parents | e3d6184b89fa |
children |
rev | line source |
---|---|
4098 | 1 " Vim indent file |
23931 | 2 " Language: Clojure |
26100 | 3 " Maintainer: Alex Vear <alex@vear.uk> |
23931 | 4 " Former Maintainers: Sung Pae <self@sungpae.com> |
5 " Meikel Brandmeyer <mb@kotka.de> | |
6 " URL: https://github.com/clojure-vim/clojure.vim | |
7 " License: Vim (see :h license) | |
28246 | 8 " Last Change: 2022-03-24 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
9 |
4098 | 10 if exists("b:did_indent") |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
11 finish |
4098 | 12 endif |
13 let b:did_indent = 1 | |
14 | |
15 let s:save_cpo = &cpo | |
16 set cpo&vim | |
17 | |
5734 | 18 let b:undo_indent = 'setlocal autoindent< smartindent< expandtab< softtabstop< shiftwidth< indentexpr< indentkeys<' |
4098 | 19 |
20 setlocal noautoindent nosmartindent | |
21 setlocal softtabstop=2 shiftwidth=2 expandtab | |
22 setlocal indentkeys=!,o,O | |
23 | |
24 if exists("*searchpairpos") | |
25 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
26 if !exists('g:clojure_maxlines') |
26100 | 27 let g:clojure_maxlines = 300 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
28 endif |
4098 | 29 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
30 if !exists('g:clojure_fuzzy_indent') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
31 let g:clojure_fuzzy_indent = 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
32 endif |
4098 | 33 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
34 if !exists('g:clojure_fuzzy_indent_patterns') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
35 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
|
36 endif |
4098 | 37 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
38 if !exists('g:clojure_fuzzy_indent_blacklist') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
39 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
|
40 endif |
4098 | 41 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
42 if !exists('g:clojure_special_indent_words') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
43 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
|
44 endif |
4098 | 45 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
46 if !exists('g:clojure_align_multiline_strings') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
47 let g:clojure_align_multiline_strings = 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
48 endif |
4098 | 49 |
5577 | 50 if !exists('g:clojure_align_subforms') |
51 let g:clojure_align_subforms = 0 | |
52 endif | |
53 | |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
54 function! s:syn_id_name() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
55 return synIDattr(synID(line("."), col("."), 0), "name") |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
56 endfunction |
4098 | 57 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
58 function! s:ignored_region() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
59 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
|
60 endfunction |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
61 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
62 function! s:current_char() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
63 return getline('.')[col('.')-1] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
64 endfunction |
4098 | 65 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
66 function! s:current_word() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
67 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
|
68 endfunction |
4098 | 69 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
70 function! s:is_paren() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
71 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
|
72 endfunction |
4098 | 73 |
26100 | 74 " Returns 1 if string matches a pattern in 'patterns', which should be |
75 " a list of patterns. | |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
76 function! s:match_one(patterns, string) |
26100 | 77 for pat in a:patterns |
5763 | 78 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
|
79 endfor |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
80 endfunction |
4098 | 81 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
82 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
|
83 " 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
|
84 " comments. |
23931 | 85 if a:stopat == 0 && g:clojure_maxlines > 0 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
86 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
|
87 else |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
88 let stopat = a:stopat |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
89 endif |
4098 | 90 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
91 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
|
92 return [pos[0], col(pos)] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
93 endfunction |
4098 | 94 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
95 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
|
96 " 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
|
97 " 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
|
98 " 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
|
99 " 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
|
100 " 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
|
101 let nb = prevnonblank(v:lnum - 1) |
4098 | 102 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
103 if nb == 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
104 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
105 endif |
4098 | 106 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
107 call cursor(nb, 0) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
108 call cursor(0, col("$") - 1) |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
109 if s:syn_id_name() !~? "string" |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
110 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
111 endif |
4098 | 112 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
113 " 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
|
114 if s:current_char() == '"' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
115 call cursor(0, col("$") - 2) |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
116 if s:syn_id_name() !~? "string" |
5362
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 |
23931 | 119 if s:current_char() != '\' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
120 return -1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
121 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
122 call cursor(0, col("$") - 1) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
123 endif |
4098 | 124 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
125 let p = searchpos('\(^\|[^\\]\)\zs"', 'bW') |
4098 | 126 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
127 if p != [0, 0] |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
128 return p[1] - 1 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
129 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
130 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
131 return indent(".") |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
132 endfunction |
4098 | 133 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
134 function! s:check_for_string() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
135 let pos = getpos('.') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
136 try |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
137 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
|
138 finally |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
139 call setpos('.', pos) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
140 endtry |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
141 return val |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
142 endfunction |
4098 | 143 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
144 function! s:strip_namespace_and_macro_chars(word) |
5763 | 145 return substitute(a:word, "\\v%(.*/|[#'`~@^,]*)(.*)", '\1', '') |
146 endfunction | |
147 | |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
148 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
|
149 " Find the next enclosing form. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
150 call search('\S', 'Wb') |
4098 | 151 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
152 " 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
|
153 if s:current_char() == '(' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
154 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
155 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
156 call cursor(a:position) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
157 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
158 let next_paren = s:match_pairs('(', ')', 0) |
4098 | 159 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
160 " 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
|
161 if next_paren == [0, 0] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
162 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
163 endif |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
164 call cursor(next_paren) |
4098 | 165 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
166 call search('\S', 'W') |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
167 let w = s:strip_namespace_and_macro_chars(s:current_word()) |
23931 | 168 |
5763 | 169 if g:clojure_special_indent_words =~# '\V\<' . w . '\>' |
23931 | 170 |
171 " `letfn` is a special-special-case. | |
172 if w ==# 'letfn' | |
173 " Earlier code left the cursor at: | |
174 " (letfn [...] ...) | |
175 " ^ | |
176 | |
177 " Search and get coordinates of first `[` | |
178 " (letfn [...] ...) | |
179 " ^ | |
180 call search('\[', 'W') | |
181 let pos = getcurpos() | |
182 let letfn_bracket = [pos[1], pos[2]] | |
183 | |
184 " Move cursor to start of the form this function was | |
185 " initially called on. Grab the coordinates of the | |
186 " closest outer `[`. | |
187 call cursor(a:position) | |
188 let outer_bracket = s:match_pairs('\[', '\]', 0) | |
189 | |
190 " If the located square brackets are not the same, | |
191 " don't use special-case formatting. | |
192 if outer_bracket != letfn_bracket | |
193 return 0 | |
194 endif | |
195 endif | |
196 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
197 return 1 |
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 return 0 |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
201 endfunction |
4098 | 202 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
203 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
|
204 let pos = getpos('.') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
205 try |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
206 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
|
207 finally |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
208 call setpos('.', pos) |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
209 endtry |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
210 return val |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
211 endfunction |
4098 | 212 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
213 " Check if form is a reader conditional, that is, it is prefixed by #? |
26100 | 214 " or #?@ |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
215 function! s:is_reader_conditional_special_case(position) |
23931 | 216 return getline(a:position[0])[a:position[1] - 3 : a:position[1] - 2] == "#?" |
26100 | 217 \|| getline(a:position[0])[a:position[1] - 4 : a:position[1] - 2] == "#?@" |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
218 endfunction |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
219 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
220 " 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
|
221 function! s:bracket_type(char) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
222 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
|
223 endfunction |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
224 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
225 " Returns: [opening-bracket-lnum, indent] |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
226 function! s:clojure_indent_pos() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
227 " Get rid of special case. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
228 if line(".") == 1 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
229 return [0, 0] |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
230 endif |
4098 | 231 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
232 " 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
|
233 " normal lisp indenting or not. |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
234 let i = s:check_for_string() |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
235 if i > -1 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
236 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
|
237 endif |
4098 | 238 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
239 call cursor(0, 1) |
4098 | 240 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
241 " 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
|
242 " 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
|
243 " 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
|
244 let paren = s:match_pairs('(', ')', 0) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
245 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
|
246 let curly = s:match_pairs('{', '}', bracket[0]) |
4098 | 247 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
248 " 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
|
249 " 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
|
250 " curly indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
251 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
|
252 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
|
253 return curly |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
254 endif |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
255 endif |
4098 | 256 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
257 " 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
|
258 " there was one. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
259 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
|
260 return bracket |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
261 endif |
4098 | 262 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
263 " 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
|
264 if paren == [0, 0] |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
265 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
266 endif |
4098 | 267 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
268 " 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
|
269 " 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
|
270 " |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
271 " - 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
|
272 " 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
|
273 " - Get the next keyword after the (. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
274 " - 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
|
275 " 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
|
276 " - 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
|
277 " the ( + sw. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
278 " - 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
|
279 " we again use ( + sw for indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
280 " - 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
|
281 call cursor(paren) |
4098 | 282 |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
283 if s:is_method_special_case(paren) |
23931 | 284 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
|
285 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
286 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
287 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
|
288 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
289 endif |
4098 | 290 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
291 " 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
|
292 if col("$") - 1 == paren[1] |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
293 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
294 endif |
4098 | 295 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
296 " 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
|
297 call cursor(0, col('.') + 1) |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
298 if s:current_char() == ' ' |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
299 call search('\v\S', 'W') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
300 endif |
4098 | 301 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
302 " 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
|
303 " use the ( position for indent. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
304 if line(".") > paren[0] |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
305 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
306 endif |
4098 | 307 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
308 " 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
|
309 " 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
|
310 let w = s:current_word() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
311 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
|
312 return paren |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
313 endif |
4098 | 314 |
23931 | 315 " If the keyword begins with #, check if it is an anonymous |
316 " function or set, in which case we indent by the shiftwidth | |
317 " (minus one if g:clojure_align_subforms = 1), or if it is | |
318 " ignored, in which case we use the ( position for indent. | |
319 if w[0] == "#" | |
320 " TODO: Handle #=() and other rare reader invocations? | |
321 if w[1] == '(' || w[1] == '{' | |
322 return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)] | |
323 elseif w[1] == '_' | |
324 return paren | |
325 endif | |
326 endif | |
327 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
328 " 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
|
329 " metacharacters. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
330 " |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
331 " 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
|
332 let ww = s:strip_namespace_and_macro_chars(w) |
4098 | 333 |
5763 | 334 if &lispwords =~# '\V\<' . ww . '\>' |
23931 | 335 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
|
336 endif |
4098 | 337 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
338 if g:clojure_fuzzy_indent |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
339 \ && !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
|
340 \ && s:match_one(g:clojure_fuzzy_indent_patterns, ww) |
23931 | 341 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
|
342 endif |
4098 | 343 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
344 call search('\v\_s', 'cW') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
345 call search('\v\S', 'W') |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
346 if paren[0] < line(".") |
23931 | 347 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
|
348 endif |
4098 | 349 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
350 call search('\v\S', 'bW') |
9644
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
351 return [line('.'), col('.') + 1] |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
352 endfunction |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
353 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
354 function! GetClojureIndent() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
355 let lnum = line('.') |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
356 let orig_lnum = lnum |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
357 let orig_col = col('.') |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
358 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
|
359 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
360 " Account for multibyte characters |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
361 if opening_lnum > 0 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
362 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
|
363 endif |
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 " 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
|
366 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
|
367 call cursor(orig_lnum, orig_col) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
368 return indent |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
369 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
370 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
371 let bracket_count = 0 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
372 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
373 " 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
|
374 " 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
|
375 while 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
376 let lnum = prevnonblank(lnum - 1) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
377 let col = 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
378 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
379 if lnum <= opening_lnum |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
380 break |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
381 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
382 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
383 call cursor(lnum, col) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
384 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
385 " Handle bracket counting edge case |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
386 if s:is_paren() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
387 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
|
388 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
389 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
390 while 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
391 if search('\v[(\[{}\])]', '', lnum) < 1 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
392 break |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
393 elseif !s:ignored_region() |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
394 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
|
395 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
396 endwhile |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
397 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
398 if bracket_count == 0 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
399 " 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
|
400 call cursor(lnum, 1) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
401 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
|
402 call cursor(orig_lnum, orig_col) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
403 return indent(lnum) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
404 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
405 endif |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
406 endwhile |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
407 |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
408 call cursor(orig_lnum, orig_col) |
9f7bcc2c3b97
commit https://github.com/vim/vim/commit/6f1d9a096bf22d50c727dca73abbfb8e3ff55176
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
409 return indent |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
410 endfunction |
4098 | 411 |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
412 setlocal indentexpr=GetClojureIndent() |
4098 | 413 |
414 else | |
415 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
416 " 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
|
417 " normal lisp indenting. |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
418 setlocal indentexpr= |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
419 setlocal lisp |
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
420 let b:undo_indent .= '| setlocal lisp<' |
4098 | 421 |
422 endif | |
423 | |
424 let &cpo = s:save_cpo | |
425 unlet! s:save_cpo | |
426 | |
5362
ab1508486b12
Update runtime files. Add support for J.
Bram Moolenaar <bram@vim.org>
parents:
4098
diff
changeset
|
427 " vim:sts=8:sw=8:ts=8:noet |