Skip to content

Commit 9d84632

Browse files
committed
Merge pull request #71 from itchyny/fix-for-tab-indent
Fix for tab indent
2 parents fd08c72 + 2929163 commit 9d84632

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

autoload/ghcmod/command.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ endfunction "}}}
2020

2121
function! ghcmod#command#type(force) "{{{
2222
let l:line = line('.')
23-
let l:col = col('.')
23+
let l:col = ghcmod#util#getcol()
2424

2525
if exists('b:ghcmod_type')
2626
if b:ghcmod_type.spans(l:line, l:col)
@@ -69,7 +69,7 @@ function! ghcmod#command#type_insert(force) "{{{
6969
endif
7070

7171
let l:module = ghcmod#detect_module()
72-
let l:types = ghcmod#type(line('.'), col('.'), l:path, l:module)
72+
let l:types = ghcmod#type(line('.'), ghcmod#util#getcol(), l:path, l:module)
7373
if empty(l:types) " Everything failed so let's just abort
7474
call ghcmod#util#print_error('ghcmod#command#type_insert: Cannot guess type')
7575
return

autoload/ghcmod/type.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ function! s:ghcmod_type.highlight() "{{{
5252
endif
5353
call self.clear_highlight()
5454
let [l:line1, l:col1, l:line2, l:col2] = self.types[self.ix][0]
55+
let l:col1 = ghcmod#util#tocol(l:line1, l:col1)
56+
let l:col2 = ghcmod#util#tocol(l:line2, l:col2)
5557
let self.match_id = matchadd(self.group, '\%' . l:line1 . 'l\%' . l:col1 . 'c\_.*\%' . l:line2 . 'l\%' . l:col2 . 'c')
5658
endfunction "}}}
5759

autoload/ghcmod/util.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ function! ghcmod#util#join_path(dir, path) "{{{
4646
endif
4747
endfunction "}}}
4848

49+
function! ghcmod#util#getcol() "{{{
50+
let l:line = line('.')
51+
let l:col = col('.')
52+
let l:str = getline(l:line)[:(l:col - 1)]
53+
let l:tabcnt = len(substitute(l:str, '[^\t]', '', 'g'))
54+
return l:col + 7 * l:tabcnt
55+
endfunction "}}}
56+
57+
function! ghcmod#util#tocol(line, col) "{{{
58+
let l:str = getline(a:line)
59+
let l:col = 0
60+
for l:i in range(1, len(l:str))
61+
let l:col += (l:str[l:i - 1] ==# "\t" ? 8 : 1)
62+
if l:col >= a:col
63+
return l:i
64+
endif
65+
endfor
66+
return l:i + 1
67+
endfunction "}}}
68+
4969
function! ghcmod#util#wait(proc) "{{{
5070
if has_key(a:proc, 'checkpid')
5171
return a:proc.checkpid()

0 commit comments

Comments
 (0)