Skip to content

Commit b0bbf25

Browse files
committed
Set b:undo_ftplugin to revert filetype settings
This commit adds a definition for b:undo_ftplugin (see `:help undo_ftplugin`) that reverts local options to their defaults and clears away buffer maps and variables. Without this, if the same buffer is changed to a different filetype having loaded this plugin, then option changes, buffer-local maps, and buffer variables remain set, potentially interfering with configuration for the new filetype, or breaking ftplugin scripts that assume the variable has been set.
1 parent b4a5f32 commit b0bbf25

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

python.vim

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Maintainer: Tom Picton <tom@tompicton.co.uk>
44
" Previous Maintainer: James Sully <sullyj3@gmail.com>
55
" Previous Maintainer: Johannes Zellner <johannes@zellner.org>
6-
" Last Change: Tue, 26 June 2018
6+
" Last Change: Tue, 05 July 2018
77
" https://github.com/tpict/vim-ftplugin-python
88

99
if exists("b:did_ftplugin") | finish | endif
@@ -129,5 +129,60 @@ if g:pydoc_executable
129129
setlocal keywordprg=pydoc
130130
endif
131131

132+
" Script for filetype switching to undo the local stuff we may have changed
133+
let b:undo_ftplugin = 'setlocal cinkeys<'
134+
\ . '|setlocal comments<'
135+
\ . '|setlocal commentstring<'
136+
\ . '|setlocal expandtab<'
137+
\ . '|setlocal include<'
138+
\ . '|setlocal includeexpr<'
139+
\ . '|setlocal indentkeys<'
140+
\ . '|setlocal keywordprg<'
141+
\ . '|setlocal omnifunc<'
142+
\ . '|setlocal shiftwidth<'
143+
\ . '|setlocal softtabstop<'
144+
\ . '|setlocal suffixesadd<'
145+
\ . '|setlocal tabstop<'
146+
\ . '|silent! nunmap <buffer> [M'
147+
\ . '|silent! nunmap <buffer> [['
148+
\ . '|silent! nunmap <buffer> []'
149+
\ . '|silent! nunmap <buffer> [m'
150+
\ . '|silent! nunmap <buffer> ]M'
151+
\ . '|silent! nunmap <buffer> ]['
152+
\ . '|silent! nunmap <buffer> ]]'
153+
\ . '|silent! nunmap <buffer> ]m'
154+
\ . '|silent! ounmap <buffer> [M'
155+
\ . '|silent! ounmap <buffer> [['
156+
\ . '|silent! ounmap <buffer> []'
157+
\ . '|silent! ounmap <buffer> [m'
158+
\ . '|silent! ounmap <buffer> ]M'
159+
\ . '|silent! ounmap <buffer> ]['
160+
\ . '|silent! ounmap <buffer> ]]'
161+
\ . '|silent! ounmap <buffer> ]m'
162+
\ . '|silent! xunmap <buffer> [M'
163+
\ . '|silent! xunmap <buffer> [['
164+
\ . '|silent! xunmap <buffer> []'
165+
\ . '|silent! xunmap <buffer> [m'
166+
\ . '|silent! xunmap <buffer> ]M'
167+
\ . '|silent! xunmap <buffer> ]['
168+
\ . '|silent! xunmap <buffer> ]]'
169+
\ . '|silent! xunmap <buffer> ]m'
170+
\ . '|unlet! b:browsefilter'
171+
\ . '|unlet! b:child_match'
172+
\ . '|unlet! b:child_sub'
173+
\ . '|unlet! b:grandparent_match'
174+
\ . '|unlet! b:grandparent_sub'
175+
\ . '|unlet! b:next'
176+
\ . '|unlet! b:next_end'
177+
\ . '|unlet! b:next_endtoplevel'
178+
\ . '|unlet! b:next_toplevel'
179+
\ . '|unlet! b:parent_match'
180+
\ . '|unlet! b:parent_sub'
181+
\ . '|unlet! b:prev'
182+
\ . '|unlet! b:prev_end'
183+
\ . '|unlet! b:prev_endtoplevel'
184+
\ . '|unlet! b:prev_toplevel'
185+
\ . '|unlet! b:undo_ftplugin'
186+
132187
let &cpo = s:keepcpo
133188
unlet s:keepcpo

0 commit comments

Comments
 (0)