Skip to content

Commit 8b98b7c

Browse files
committed
Fix indentation with multibyte characters
Instead of sometimes using virtcol() to get the screen position, work with the file as single-byte characters, then adjust the final indentation by the difference of col and virtcol. There may be some outstanding edge cases.
1 parent a0a4eb9 commit 8b98b7c

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(let [Δt (if foo
2+
bar
3+
baz)])
4+
5+
;; vim:ft=clojure:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(let [Δt (if foo
2+
bar
3+
baz)])
4+
5+
;; vim:ft=clojure:

clj/test/vim_clojure_static/indent_test.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
(test-indent "is inherited from previous element"
77
:in "test-inherit-indent.in"
88
:out "test-inherit-indent.out"
9-
:keys "\\<CR>s\\<C-O>Oa\\<Esc>/β\\<CR>s\\<CR>\\<CR>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>b\\<CR>c\\<CR>\\<CR>d\\<Esc>"))
9+
:keys "\\<CR>s\\<C-O>Oa\\<Esc>/β\\<CR>s\\<CR>\\<CR>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>\\<C-H>b\\<CR>c\\<CR>\\<CR>d\\<Esc>")
10+
(test-indent "with multibyte characters"
11+
:in "test-multibyte-indent.in"
12+
:out "test-multibyte-indent.out"))

indent/clojure.vim

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
" License: Same as Vim
99
" Last Change: %%RELEASE_DATE%%
1010

11-
" TODO: Indenting after multibyte characters is broken:
12-
" (let [Δ (if foo
13-
" bar ; Indent error
14-
" baz)])
15-
1611
if exists("b:did_indent")
1712
finish
1813
endif
@@ -99,7 +94,7 @@ if exists("*searchpairpos")
9994
endif
10095

10196
let pos = searchpairpos(a:open, '', a:close, 'bWn', "!s:is_paren()", stopat)
102-
return [pos[0], virtcol(pos)]
97+
return [pos[0], col(pos)]
10398
endfunction
10499

105100
function! s:clojure_check_for_string_worker()
@@ -306,12 +301,13 @@ if exists("*searchpairpos")
306301
endif
307302

308303
call search('\v\S', 'bW')
309-
return [line('.'), virtcol('.') + 1]
304+
return [line('.'), col('.') + 1]
310305
endfunction
311306

312307
function! GetClojureIndent()
313308
let lnum = line('.')
314309
let [opening_lnum, indent] = s:clojure_indent_pos()
310+
let indent -= indent - virtcol([opening_lnum, indent])
315311

316312
" Return if there are no previous lines to inherit from
317313
if opening_lnum < 1 || opening_lnum >= lnum - 1

0 commit comments

Comments
 (0)