Skip to content

Commit 6942e9b

Browse files
committed
Fix bug when filetype changes
1 parent b761011 commit 6942e9b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

doc/context-commentstring.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ plugin author.
140140
==============================================================================
141141
CHANGELOG *context-commentstring-changelog*
142142

143+
0.1.1 2014-06-06
144+
- Clear the autocommand always, in case the filetype is changed for
145+
whatever reason.
146+
143147
0.1.0 2013-06-06
144148
- First public release.
145149

plugin/context-commentstring.vim

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
" This file is part of vim-context_commentstring.
2-
" Copyright: © 2013 Alejandro Exojo Piqueras <http://disperso.net/>
2+
" Copyright: © 2013-2014 Alejandro Exojo Piqueras <http://disperso.net/>
33
" License: MIT (see doc for details).
44

55
if exists('g:loaded_context_commentstring')
@@ -9,18 +9,20 @@ endif
99

1010
augroup ContextCommentstringBootstrap
1111
autocmd!
12-
autocmd FileType * call <SID>Bootstrap()
12+
autocmd FileType * call <SID>Setup()
1313
augroup END
1414

1515

16-
function! s:Bootstrap()
17-
if !empty(&filetype) && has_key(g:context#commentstring#table, &filetype)
18-
let b:original_commentstring=&l:commentstring
19-
augroup ContextCommentstringEnabled
20-
autocmd!
16+
function! s:Setup()
17+
augroup ContextCommentstringEnabled
18+
" Clear previous autocommands first in all cases, in case the filetype
19+
" changed from something in the table, to something NOT in the table.
20+
autocmd! CursorMoved <buffer>
21+
if !empty(&filetype) && has_key(g:context#commentstring#table, &filetype)
22+
let b:original_commentstring=&l:commentstring
2123
autocmd CursorMoved <buffer> call <SID>UpdateCommentString()
22-
augroup END
23-
endif
24+
endif
25+
augroup END
2426
endfunction
2527

2628

0 commit comments

Comments
 (0)