diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2022-05-09 17:05:24 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2022-05-09 17:05:24 +1200 |
commit | b6e36348a69231c80b0030132b28012ec0c99d4f (patch) | |
tree | 393a363d17b5f49499d9a97f52943039f012d14a | |
parent | Merge branch 'release/v12.1.0' into develop (diff) | |
download | dotfiles-b6e36348a69231c80b0030132b28012ec0c99d4f.tar.gz dotfiles-b6e36348a69231c80b0030132b28012ec0c99d4f.zip |
Spin Vim HTML lang switching out into plugin
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | vim/after/ftplugin/html.vim | 18 | ||||
-rw-r--r-- | vim/autoload/html/spelllang.vim | 57 | ||||
m--------- | vim/bundle/html_spelllang | 0 |
4 files changed, 3 insertions, 75 deletions
diff --git a/.gitmodules b/.gitmodules index 4a63f718..e0ef1bf5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -26,6 +26,9 @@ [submodule "vim/bundle/foldlevelstart_stdin"] path = vim/bundle/foldlevelstart_stdin url = https://dev.sanctum.geek.nz/code/vim-foldlevelstart-stdin.git +[submodule "vim/bundle/html_spelllang"] + path = vim/bundle/html_spelllang + url = https://dev.sanctum.geek.nz/code/vim-html-spelllang.git [submodule "vim/bundle/insert_cancel"] path = vim/bundle/insert_cancel url = https://dev.sanctum.geek.nz/code/vim-insert-cancel.git diff --git a/vim/after/ftplugin/html.vim b/vim/after/ftplugin/html.vim index 741f7b65..21a84a42 100644 --- a/vim/after/ftplugin/html.vim +++ b/vim/after/ftplugin/html.vim @@ -32,24 +32,6 @@ augroup END let b:undo_ftplugin .= '|execute ''autocmd! html_timestamp''' \ . '|augroup! html_timestamp' -" Set up hooks for divining 'spelllang' from lang= attributes -augroup html_spelllang - if exists('##TextChanged') - autocmd TextChanged * - \ if &modified - \| call html#spelllang#Set() - \|endif - else - autocmd InsertLeave * - \ if &modified - \| call html#spelllang#Set() - \|endif - endif -augroup END -call html#spelllang#Set() -let b:undo_ftplugin .= '|execute ''autocmd! html_spelllang''' - \ . '|augroup! html_spelllang' - " Stop here if the user doesn't want ftplugin mappings if exists('no_plugin_maps') || exists('no_html_maps') finish diff --git a/vim/autoload/html/spelllang.vim b/vim/autoload/html/spelllang.vim deleted file mode 100644 index e451f8a1..00000000 --- a/vim/autoload/html/spelllang.vim +++ /dev/null @@ -1,57 +0,0 @@ -" Crude regular expression to match an <html>, <body>, or <main> tag on one -" line with a lang= attribute set. This isn't exact, by any means, but -" I don't want to write an actual HTML parser for a mere 'spelllang' hook -" nicety that fails silently anyway. -" -" The first submatch is the language code, e.g. "en", "es". The second -" submatch is optional and follows a hyphen and is for the regional code, -" e.g. "US", "GB", "AR". -" -let s:pattern = '\m\c<\%(html\|body\|main\)\>[^>]*\<lang=["'']\=' - \ . '\([a-z-]\{2,}\)\%(-\([a-z]\{2,}\)\)' - -" The line count limit for looking for the pattern; no sense churning through -" the whole document every time it's changed. -" -let s:lines = 128 - -" Look for a language code in the first lines of the current buffer, and if it -" looks understandable, adopt an appropriate spelling language. -" -function! html#spelllang#Set() abort - - " Loop through the first s:lines of the buffer - for line in getline(1, s:lines) - - " Check if this line has an <html lang=""> tag, or skip it - let matches = matchlist(line, s:pattern) - if empty(matches) - continue - endif - - " The line seems to match our pattern, and so we have a language code in - " matches[1], and possibly a region code in matches[2]. - " - " Next we need to check whether we'll attempt to use this to set - " a spelling language. Build the expected path for a spellfile; looks - " like `$VIMRUNTIME/spell/en.utf-8.spl`. Note that this path doesn't - " include any language region, per documentation. - " - let spellfile = 'spell/' . join([ - \ tolower(matches[1]), - \ &encoding, - \ 'spl', - \], '.') - - " If a spelling list file of the expected name exists in &runtimepath, try - " setting the local value of 'spelllang' to reflect what was in the lang= - " attribute; force it to lowercase and separate the region with an - " underscore rather than a hyphen (if there is a region). - " - if strlen(globpath(&runtimepath, spellfile)) - let &l:spelllang = tolower(join(matches[1:2], '_')) - endif - - endfor - -endfunction diff --git a/vim/bundle/html_spelllang b/vim/bundle/html_spelllang new file mode 160000 +Subproject d4818329bf021e015ea92705b7bb417e78edbde |