From d9eab5526fdaf67a8ef676b6946eace72780da39 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 25 Oct 2019 14:25:48 +0200 Subject: [PATCH] [UPDATE][VIM] Factorise `b:undo_ftplugin` Instead of re-writing the same condition each time, I put the function in an autoload plugin instead (which is going to be loaded just about every time I start writing code, but that's neither here nor there) to stop repeating myself. --- vim/.vim/after/ftplugin/bash.vim | 5 ++--- vim/.vim/after/ftplugin/c.vim | 5 ++--- vim/.vim/after/ftplugin/cpp.vim | 5 ++--- vim/.vim/after/ftplugin/d.vim | 5 ++--- vim/.vim/after/ftplugin/fugitive.vim | 5 ++--- vim/.vim/after/ftplugin/gitcommit.vim | 5 ++--- vim/.vim/after/ftplugin/json.vim | 5 ++--- vim/.vim/after/ftplugin/make.vim | 5 ++--- vim/.vim/after/ftplugin/netrw.vim | 5 ++--- vim/.vim/after/ftplugin/pandoc.vim | 5 ++--- vim/.vim/after/ftplugin/python.vim | 5 ++--- vim/.vim/after/ftplugin/qf.vim | 5 ++--- vim/.vim/after/ftplugin/rust.vim | 5 ++--- vim/.vim/after/ftplugin/sh.vim | 5 ++--- vim/.vim/after/ftplugin/zsh.vim | 5 ++--- vim/.vim/autoload/ftplugined.vim | 6 ++++++ 16 files changed, 36 insertions(+), 45 deletions(-) create mode 100644 vim/.vim/autoload/ftplugined.vim diff --git a/vim/.vim/after/ftplugin/bash.vim b/vim/.vim/after/ftplugin/bash.vim index ba61116..07ff9e5 100644 --- a/vim/.vim/after/ftplugin/bash.vim +++ b/vim/.vim/after/ftplugin/bash.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Use shfmt as ALE fixer for bash let b:ale_fixers=[ 'shfmt' ] diff --git a/vim/.vim/after/ftplugin/c.vim b/vim/.vim/after/ftplugin/c.vim index 70c9c27..1b699e2 100644 --- a/vim/.vim/after/ftplugin/c.vim +++ b/vim/.vim/after/ftplugin/c.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " More warnings and the usual version in flags for Clang let b:ale_c_clang_options='-Wall -Wextra -pedantic -std=c99' diff --git a/vim/.vim/after/ftplugin/cpp.vim b/vim/.vim/after/ftplugin/cpp.vim index 81fd012..fc54454 100644 --- a/vim/.vim/after/ftplugin/cpp.vim +++ b/vim/.vim/after/ftplugin/cpp.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " More warnings and the usual version in flags for Clang let b:ale_cpp_clang_options='-Wall -Wextra -pedantic -std=c++17' diff --git a/vim/.vim/after/ftplugin/d.vim b/vim/.vim/after/ftplugin/d.vim index a9e13dc..aee25a1 100644 --- a/vim/.vim/after/ftplugin/d.vim +++ b/vim/.vim/after/ftplugin/d.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Use my desired ALE fixer for D let b:ale_fixers=[ 'dfmt' ] diff --git a/vim/.vim/after/ftplugin/fugitive.vim b/vim/.vim/after/ftplugin/fugitive.vim index 40e791f..95aba2b 100644 --- a/vim/.vim/after/ftplugin/fugitive.vim +++ b/vim/.vim/after/ftplugin/fugitive.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Don't highlight trailing whitespace in fugitive windows let b:better_whitespace_enabled=0 diff --git a/vim/.vim/after/ftplugin/gitcommit.vim b/vim/.vim/after/ftplugin/gitcommit.vim index 478a1b6..f785ff8 100644 --- a/vim/.vim/after/ftplugin/gitcommit.vim +++ b/vim/.vim/after/ftplugin/gitcommit.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Enable spell checking on commit messages setlocal spell diff --git a/vim/.vim/after/ftplugin/json.vim b/vim/.vim/after/ftplugin/json.vim index f6d443b..4856a8d 100644 --- a/vim/.vim/after/ftplugin/json.vim +++ b/vim/.vim/after/ftplugin/json.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Use my desired ALE fixer for JSON let b:ale_fixers=[ 'jq' ] diff --git a/vim/.vim/after/ftplugin/make.vim b/vim/.vim/after/ftplugin/make.vim index 848c308..6785116 100644 --- a/vim/.vim/after/ftplugin/make.vim +++ b/vim/.vim/after/ftplugin/make.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Makefiles should use tabs to indent setlocal noexpandtab diff --git a/vim/.vim/after/ftplugin/netrw.vim b/vim/.vim/after/ftplugin/netrw.vim index d907f44..e3689f8 100644 --- a/vim/.vim/after/ftplugin/netrw.vim +++ b/vim/.vim/after/ftplugin/netrw.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Don't show Netrw in buffer list setlocal bufhidden=delete diff --git a/vim/.vim/after/ftplugin/pandoc.vim b/vim/.vim/after/ftplugin/pandoc.vim index 9aa0d8b..3754bd7 100644 --- a/vim/.vim/after/ftplugin/pandoc.vim +++ b/vim/.vim/after/ftplugin/pandoc.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Let ALE know that I want Markdown linters let b:ale_linter_aliases=[ 'markdown' ] diff --git a/vim/.vim/after/ftplugin/python.vim b/vim/.vim/after/ftplugin/python.vim index 0347fcc..2dddbad 100644 --- a/vim/.vim/after/ftplugin/python.vim +++ b/vim/.vim/after/ftplugin/python.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Use my desired ALE fixers for python let b:ale_fixers=[ 'black', 'isort' ] diff --git a/vim/.vim/after/ftplugin/qf.vim b/vim/.vim/after/ftplugin/qf.vim index a4cf9a6..01036f9 100644 --- a/vim/.vim/after/ftplugin/qf.vim +++ b/vim/.vim/after/ftplugin/qf.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Use h/l to go to the previous/next non-empty quickfix or location list nnoremap h :call quickfixed#older() diff --git a/vim/.vim/after/ftplugin/rust.vim b/vim/.vim/after/ftplugin/rust.vim index 35472f6..7120205 100644 --- a/vim/.vim/after/ftplugin/rust.vim +++ b/vim/.vim/after/ftplugin/rust.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Check tests too let b:ale_rust_cargo_check_tests=1 diff --git a/vim/.vim/after/ftplugin/sh.vim b/vim/.vim/after/ftplugin/sh.vim index 4cd9e82..91fb389 100644 --- a/vim/.vim/after/ftplugin/sh.vim +++ b/vim/.vim/after/ftplugin/sh.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Use shfmt as ALE fixer for sh let b:ale_fixers=[ 'shfmt' ] diff --git a/vim/.vim/after/ftplugin/zsh.vim b/vim/.vim/after/ftplugin/zsh.vim index f0f811f..b9af12c 100644 --- a/vim/.vim/after/ftplugin/zsh.vim +++ b/vim/.vim/after/ftplugin/zsh.vim @@ -1,6 +1,5 @@ -if !exists("b:undo_ftplugin") - let b:undo_ftplugin='' -endif +" Create the `b:undo_ftplugin` variable if it doesn't exist +call ftplugined#check_undo_ft() " Use shfmt as ALE fixer for zsh let b:ale_fixers=[ 'shfmt' ] diff --git a/vim/.vim/autoload/ftplugined.vim b/vim/.vim/autoload/ftplugined.vim new file mode 100644 index 0000000..1205ddc --- /dev/null +++ b/vim/.vim/autoload/ftplugined.vim @@ -0,0 +1,6 @@ +" Create the `b:undo_ftplugin` variable if it doesn't exist +function! ftplugined#check_undo_ft() + if !exists("b:undo_ftplugin") + let b:undo_ftplugin='' + endif +endfunction