aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--VERSION4
-rw-r--r--X/xsession.sh4
-rw-r--r--vim/after/ftplugin/html.vim18
-rw-r--r--vim/after/ftplugin/python.vim27
-rw-r--r--vim/autoload/html/spelllang.vim57
-rw-r--r--vim/compiler/pyflakes.vim9
-rw-r--r--vim/compiler/pylint.vim9
-rw-r--r--vim/filetype.vim4
-rw-r--r--vim/syntax/jinja2.vim2
9 files changed, 130 insertions, 4 deletions
diff --git a/VERSION b/VERSION
index 34785012..d86b9a7e 100644
--- a/VERSION
+++ b/VERSION
@@ -1,2 +1,2 @@
-tejr dotfiles v11.21.0
-Sat, 30 Apr 2022 13:02:16 +0000
+tejr dotfiles v11.22.0
+Wed, 04 May 2022 13:32:08 +0000
diff --git a/X/xsession.sh b/X/xsession.sh
index 9c0dcab7..91f23d9d 100644
--- a/X/xsession.sh
+++ b/X/xsession.sh
@@ -20,12 +20,12 @@ for program in xrandr xwallpaper ; do (
) ; done
# Set a few keyboard map options
-# - Remap right Alt as a Compose key
# - Remap Caps Lock as another Control key
+# - Remap right Alt as a Compose key
# - Kill X server with Ctrl+Alt+Backspace
setxkbmap \
+ -option caps:ctrl_modifier \
-option compose:ralt \
- -option ctrl:nocaps \
-option terminate:ctrl_alt_bksp &
# Set fast mouse acceleration with a natural threshold
diff --git a/vim/after/ftplugin/html.vim b/vim/after/ftplugin/html.vim
index 21a84a42..741f7b65 100644
--- a/vim/after/ftplugin/html.vim
+++ b/vim/after/ftplugin/html.vim
@@ -32,6 +32,24 @@ 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/after/ftplugin/python.vim b/vim/after/ftplugin/python.vim
new file mode 100644
index 00000000..b5071e3b
--- /dev/null
+++ b/vim/after/ftplugin/python.vim
@@ -0,0 +1,27 @@
+" Use pyflakes for syntax checking and autopep8 for tidying
+compiler pyflakes
+if executable('autopep8')
+ setlocal equalprg=autopep8\ -aaa\ --\ -
+ let b:undo_ftplugin .= '|setlocal equalprg<'
+endif
+
+" Stop here if the user doesn't want ftplugin mappings
+if exists('no_plugin_maps') || exists('no_python_maps')
+ finish
+endif
+
+" Mappings to choose compiler
+nnoremap <buffer> <LocalLeader>c
+ \ :<C-U>compiler pyflakes<CR>
+nnoremap <buffer> <LocalLeader>l
+ \ :<C-U>compiler pylint<CR>
+let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>c'
+ \ . '|nunmap <buffer> <LocalLeader>l'
+
+" Mappings to choose 'equalprg'
+nnoremap <buffer> <LocalLeader>t
+ \ :<C-U>setlocal equalprg=equalprg=autopep8\ -aaa\ --\ -<CR>
+nnoremap <buffer> <LocalLeader>i
+ \ :<C-U>setlocal equalprg<<CR>
+let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>t'
+ \ . '|nunmap <buffer> <LocalLeader>i'
diff --git a/vim/autoload/html/spelllang.vim b/vim/autoload/html/spelllang.vim
new file mode 100644
index 00000000..c01a57b2
--- /dev/null
+++ b/vim/autoload/html/spelllang.vim
@@ -0,0 +1,57 @@
+" Crude regular expression to match an <html> or <body> 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\)\>[^>]*\<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/compiler/pyflakes.vim b/vim/compiler/pyflakes.vim
new file mode 100644
index 00000000..727fbd76
--- /dev/null
+++ b/vim/compiler/pyflakes.vim
@@ -0,0 +1,9 @@
+" :compiler support for Python syntax checking with pyflakes
+" <https://pypi.org/project/pyflakes/>
+if exists('current_compiler') || &compatible || !has('patch-7.4.191')
+ finish
+endif
+let current_compiler = 'pyflakes'
+
+CompilerSet makeprg=pyflakes\ %:S
+CompilerSet errorformat=%f:%l:%c:\ %m
diff --git a/vim/compiler/pylint.vim b/vim/compiler/pylint.vim
new file mode 100644
index 00000000..589f78e3
--- /dev/null
+++ b/vim/compiler/pylint.vim
@@ -0,0 +1,9 @@
+" :compiler support for Python linting with pylint
+" <https://pypi.org/project/pyflakes/>
+if exists('current_compiler') || &compatible || !has('patch-7.4.191')
+ finish
+endif
+let current_compiler = 'pylint'
+
+CompilerSet makeprg=pylint\ --output-format=parseable\ --score=n\ %:S
+CompilerSet errorformat=%f:%l:\ %m
diff --git a/vim/filetype.vim b/vim/filetype.vim
index 15603885..60221c83 100644
--- a/vim/filetype.vim
+++ b/vim/filetype.vim
@@ -162,6 +162,10 @@ augroup filetypedetect
\ ?*.java
\,?*.jav
\ setfiletype java
+ " Jinja2 templates
+ autocmd BufNewFile,BufRead
+ \ ?*.j2
+ \ setfiletype jinja2
" JSON files
autocmd BufNewFile,BufRead
\ ?*.js
diff --git a/vim/syntax/jinja2.vim b/vim/syntax/jinja2.vim
new file mode 100644
index 00000000..2b4aef1a
--- /dev/null
+++ b/vim/syntax/jinja2.vim
@@ -0,0 +1,2 @@
+" Django is similar enough to Jinja2 to be useful for highlighting
+runtime! syntax/django.vim