From f4d3a4364bfd799e0974daf28d6ae4a2b3077e78 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Sat, 19 Oct 2024 17:57:47 +0200 Subject: [PATCH] vim:xdg: Fix updating spellfile through modeline Setting `&spellfile` from the modeline is not allowed and will result in an `E523: not allowed here` error. Fix the updating of the file by additionally having an autocommand on BufWinEnter (i.e. after the modeline was read). TODO: Also get rid of the error message when rereading the modeline (:e) --- .config/vim/xdg.vim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.config/vim/xdg.vim b/.config/vim/xdg.vim index 1db7e4a..46303a8 100644 --- a/.config/vim/xdg.vim +++ b/.config/vim/xdg.vim @@ -46,8 +46,15 @@ endif let &spellfile = $XDG_DATA_HOME . '/vim/spell/' . &spelllang . '.utf-8.add' augroup xdg_spellfile au! + " TODO: This throws `E523: not allowed here` on `:e` as the modeline is + " reread. Suppress or better check for sandbox/modeline before + " executing au OptionSet spelllang let &spellfile = \ $XDG_DATA_HOME . '/vim/spell/' . v:option_new . '.utf-8.add' + " NOTE: Changing &spellfile is not allowed from a modeline, so we need to + " update it manually after the modeline was read + au BufWinEnter * let &spellfile = + \ $XDG_DATA_HOME . '/vim/spell/' . &spelllang . '.utf-8.add' augroup end set runtimepath-=~/.vim runtimepath^=$XDG_CONFIG_HOME/vim