From 07df7903af79af6701a5fa64d2680d8be7ed290d Mon Sep 17 00:00:00 2001 From: leafOfTree Date: Wed, 21 Oct 2026 12:12:56 +0000 Subject: [PATCH] Undo ftplugin and indent settings when filetype changes Set b:undo_ftplugin for matchpairs, matchit variables, b:syng_str and the foldexpr settings, and b:undo_indent for indent settings, instead of relying on whichever indent file was loaded last. --- ftplugin/vue.vim | 5 +++++ ftplugin/vue/fold.vim | 2 ++ indent/vue.vim | 1 + test/cases/undo.vim | 17 +++++++++++++++++ test/cases/undo.vue | 3 +++ 5 files changed, 28 insertions(+) create mode 100644 test/cases/undo.vim create mode 100644 test/cases/undo.vue diff --git a/ftplugin/vue.vim b/ftplugin/vue.vim index aaa6d52..b9f4251 100644 --- a/ftplugin/vue.vim +++ b/ftplugin/vue.vim @@ -1,8 +1,12 @@ if exists("b:did_ftplugin") | finish | endif let b:did_ftplugin = 1 +let b:undo_ftplugin = (exists('b:undo_ftplugin') ? b:undo_ftplugin.' | ' : '') + \ . 'unlet! b:syng_str b:syng_strcom' + if !has('nvim') setlocal matchpairs+=<:> + let b:undo_ftplugin .= ' | setlocal matchpairs<' endif if exists("loaded_matchit") @@ -11,6 +15,7 @@ if exists("loaded_matchit") \ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' . \ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' . \ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>' + let b:undo_ftplugin .= ' | unlet! b:match_ignorecase b:match_words' endif " Indent correctly with template string for vim-javascript/built-in diff --git a/ftplugin/vue/fold.vim b/ftplugin/vue/fold.vim index 63a58ae..5be3061 100644 --- a/ftplugin/vue/fold.vim +++ b/ftplugin/vue/fold.vim @@ -14,6 +14,8 @@ function! VueFoldMain(...) setlocal foldexpr=GetVueFold(v:lnum) setlocal foldmethod=expr + let b:undo_ftplugin = (exists('b:undo_ftplugin') ? b:undo_ftplugin.' | ' : '') + \ . 'setlocal foldexpr< foldmethod<' endif endfunction diff --git a/indent/vue.vim b/indent/vue.vim index 5f3c60b..710b391 100644 --- a/indent/vue.vim +++ b/indent/vue.vim @@ -36,6 +36,7 @@ function! s:SetVueIndent() " XML indentkeys setlocal indentkeys+=*,<>>,<<>,/ setlocal indentexpr=GetVueIndent() + let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent<' endfunction function! s:GetIndentFile(syntax) diff --git a/test/cases/undo.vim b/test/cases/undo.vim new file mode 100644 index 0000000..5271406 --- /dev/null +++ b/test/cases/undo.vim @@ -0,0 +1,17 @@ +" Undo settings when filetype changes +let g:vim_vue_plugin_config = {'foldexpr': 1} +packadd matchit + +function! Check() + call ExpectEqual(&l:foldmethod, 'expr', 'foldmethod') + call ExpectEqual(&l:indentexpr, 'GetVueIndent()', 'indentexpr') + call ExpectEqual(exists('b:match_words'), 1, 'b:match_words') + setlocal filetype=text + call ExpectEqual(&l:foldmethod, 'manual', 'foldmethod after undo') + call ExpectEqual(&l:indentexpr, '', 'indentexpr after undo') + call ExpectEqual(exists('b:match_words'), 0, 'b:match_words after undo') + call ExpectEqual(exists('b:syng_str'), 0, 'b:syng_str after undo') + if !has('nvim') + call ExpectEqual(&l:matchpairs, &g:matchpairs, 'matchpairs after undo') + endif +endfunction diff --git a/test/cases/undo.vue b/test/cases/undo.vue new file mode 100644 index 0000000..8991778 --- /dev/null +++ b/test/cases/undo.vue @@ -0,0 +1,3 @@ +