diff --git a/.github/workflows/vint.yml b/.github/workflows/vint.yml new file mode 100644 index 0000000..1f38411 --- /dev/null +++ b/.github/workflows/vint.yml @@ -0,0 +1,16 @@ +name: Vint +on: [push, pull_request] +jobs: + vint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Setup dependencies + run: pip install vim-vint + - name: Run Vimscript Linter + run: vint . diff --git a/.vintrc.yaml b/.vintrc.yaml new file mode 100644 index 0000000..c44b6ab --- /dev/null +++ b/.vintrc.yaml @@ -0,0 +1,5 @@ +cmdargs: + severity: style_problem + color: true + env: + neovim: false diff --git a/README.markdown b/README.markdown index 136ba5e..bdbc4a0 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,7 @@ # vim-pencil +[![Vint](https://github.com/reedes/vim-pencil/workflows/Vint/badge.svg)](https://github.com/reedes/vim-pencil/actions?workflow=Vint) + > Rethinking Vim as a tool for writers
diff --git a/autoload/pencil.vim b/autoload/pencil.vim index 25d59e5..63dd0d8 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -5,7 +5,10 @@ " Created: December 28, 2013 " License: The MIT License (MIT) " ============================================================================ -if exists("autoloaded_pencil") | fini | en + +scriptencoding utf-8 + +if exists('autoloaded_pencil') | fini | en let autoloaded_pencil = 1 let s:WRAP_MODE_DEFAULT = -1 @@ -46,9 +49,9 @@ endf fun! s:imap(preserve_completion, key, icmd) abort if a:preserve_completion - exe ":ino " . a:key . " pumvisible() ? \"" . a:key . "\" : \"" . a:icmd . "\"" + exe ':ino ' . a:key . " pumvisible() ? '" . a:key . "' : '" . a:icmd . "'" el - exe ":ino " . a:key . " " . a:icmd + exe ':ino ' . a:key . ' ' . a:icmd en endf @@ -62,8 +65,8 @@ fun! s:maybe_enable_autoformat() abort return en - let l:ft = get(g:pencil#autoformat_aliases, &ft, &ft) - let l:af_cfg = get(g:pencil#autoformat_config, l:ft, {}) + let l:filetype = get(g:pencil#autoformat_aliases, &filetype, &filetype) + let l:af_cfg = get(g:pencil#autoformat_config, l:filetype, {}) let l:black = get(l:af_cfg, 'black', []) let l:white = get(l:af_cfg, 'white', []) let l:has_black_re = len(l:black) > 0 @@ -172,7 +175,7 @@ fun! pencil#setAutoFormat(af) abort sil! au! pencil_autoformat * if l:nu_af && !l:is_hard echohl WarningMsg - echo "autoformat can only be enabled in hard line break mode" + echo 'autoformat can only be enabled in hard line break mode' echohl NONE return en @@ -192,7 +195,7 @@ fun! pencil#init(...) abort if !exists('b:pencil_wrap_mode') let b:pencil_wrap_mode = s:WRAP_MODE_OFF en - if !exists("b:max_textwidth") + if !exists('b:max_textwidth') let b:max_textwidth = -1 en @@ -245,7 +248,7 @@ fun! pencil#init(...) abort " flag to suspend autoformat for next Insert " optional user-defined mapping if exists('g:pencil#map#suspend_af') && - \ g:pencil#map#suspend_af != '' + \ g:pencil#map#suspend_af !=# '' exe 'no ' . g:pencil#map#suspend_af . ' :let b:pencil_suspend_af=1' en @@ -405,10 +408,10 @@ fun! pencil#init(...) abort en if b:pencil_wrap_mode - exe 'nn ' . Mapkey("j", "n") . ' gj' - exe 'nn ' . Mapkey("k", "n") . ' gk' - exe 'vn ' . Mapkey("j", "v") . ' gj' - exe 'vn ' . Mapkey("k", "v") . ' gk' + exe 'nn ' . Mapkey('j', 'n') . ' gj' + exe 'nn ' . Mapkey('k', 'n') . ' gk' + exe 'vn ' . Mapkey('j', 'v') . ' gj' + exe 'vn ' . Mapkey('k', 'v') . ' gk' no gk no gj nn gj j @@ -475,7 +478,7 @@ endf fun! s:doOne(item) abort let l:matches = matchlist(a:item, '^\([a-z]\+\)=\([a-zA-Z0-9_\-.]\+\)$') if len(l:matches) > 1 - if l:matches[1] =~ 'textwidth\|tw' + if l:matches[1] =~# 'textwidth\|tw' let l:tw = str2nr(l:matches[2]) if l:tw > b:max_textwidth let b:max_textwidth = l:tw @@ -504,22 +507,22 @@ endf " modeline(s) and max line length " Hat tip to https://github.com/ciaranm/securemodelines fun! s:doModelines() abort - if line("$") > &modelines + if line('$') > &modelines let l:lines={ } call map(filter(getline(1, &modelines) + - \ getline(line("$") - &modelines, "$"), - \ 'v:val =~ ":"'), 'extend(l:lines, { v:val : 0 } )') + \ getline(line('$') - &modelines, '$'), + \ 'v:val =~# ":"'), 'extend(l:lines, { v:val : 0 } )') for l:line in keys(l:lines) call s:doModeline(l:line) endfo el - for l:line in getline(1, "$") + for l:line in getline(1, '$') call s:doModeline(l:line) endfo en endf -function! Mapkey (keys, mode) +function! Mapkey (keys, mode) abort " Pass in a key sequence and the first letter of a vim mode. " Returns key mapping mapped to it in that mode, else 0 if none. " example: diff --git a/plugin/pencil.vim b/plugin/pencil.vim index 55cdbc3..ab5b905 100644 --- a/plugin/pencil.vim +++ b/plugin/pencil.vim @@ -5,13 +5,15 @@ " Created: December 28, 2013 " License: The MIT License (MIT) " ============================================================================ -" -if exists('g:loaded_pencil') || &cp | fini | en + +scriptencoding utf-8 + +if exists('g:loaded_pencil') || &compatible | fini | en let g:loaded_pencil = 1 " Save 'cpoptions' and set Vim default to enable line continuations. -let s:save_cpo = &cpo -set cpo&vim +let s:save_cpoptions = &cpoptions +set cpoptions&vim let s:WRAP_MODE_DEFAULT = -1 let s:WRAP_MODE_OFF = 0 @@ -31,7 +33,7 @@ fun! PencilMode() if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT return get(g:pencil#mode_indicators, 'soft', 'S') elsei b:pencil_wrap_mode ==# s:WRAP_MODE_HARD - if &fo =~ 'a' + if &formatoptions =~# 'a' return get(g:pencil#mode_indicators, 'auto', 'A') el return get(g:pencil#mode_indicators, 'hard', 'H') @@ -203,7 +205,7 @@ if g:pencil#legacyCommands com -nargs=0 ShiftPencil call pencil#setAutoFormat(-1) en -let &cpo = s:save_cpo -unlet s:save_cpo +let &cpoptions = s:save_cpoptions +unlet s:save_cpoptions " vim:ts=2:sw=2:sts=2