mirror of
https://github.com/preservim/vim-pencil.git
synced 2025-11-12 11:53:47 -05:00
Merge pull request #81 from reedes/lint-vimscript
This commit is contained in:
16
.github/workflows/vint.yml
vendored
Normal file
16
.github/workflows/vint.yml
vendored
Normal file
@@ -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 .
|
||||||
5
.vintrc.yaml
Normal file
5
.vintrc.yaml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
cmdargs:
|
||||||
|
severity: style_problem
|
||||||
|
color: true
|
||||||
|
env:
|
||||||
|
neovim: false
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
# vim-pencil
|
# vim-pencil
|
||||||
|
|
||||||
|
[](https://github.com/reedes/vim-pencil/actions?workflow=Vint)
|
||||||
|
|
||||||
> Rethinking Vim as a tool for writers
|
> Rethinking Vim as a tool for writers
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
" Created: December 28, 2013
|
" Created: December 28, 2013
|
||||||
" License: The MIT License (MIT)
|
" 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 autoloaded_pencil = 1
|
||||||
|
|
||||||
let s:WRAP_MODE_DEFAULT = -1
|
let s:WRAP_MODE_DEFAULT = -1
|
||||||
@@ -46,9 +49,9 @@ endf
|
|||||||
|
|
||||||
fun! s:imap(preserve_completion, key, icmd) abort
|
fun! s:imap(preserve_completion, key, icmd) abort
|
||||||
if a:preserve_completion
|
if a:preserve_completion
|
||||||
exe ":ino <buffer> <silent> <expr> " . a:key . " pumvisible() ? \"" . a:key . "\" : \"" . a:icmd . "\""
|
exe ':ino <buffer> <silent> <expr> ' . a:key . " pumvisible() ? '" . a:key . "' : '" . a:icmd . "'"
|
||||||
el
|
el
|
||||||
exe ":ino <buffer> <silent> " . a:key . " " . a:icmd
|
exe ':ino <buffer> <silent> ' . a:key . ' ' . a:icmd
|
||||||
en
|
en
|
||||||
endf
|
endf
|
||||||
|
|
||||||
@@ -62,8 +65,8 @@ fun! s:maybe_enable_autoformat() abort
|
|||||||
return
|
return
|
||||||
en
|
en
|
||||||
|
|
||||||
let l:ft = get(g:pencil#autoformat_aliases, &ft, &ft)
|
let l:filetype = get(g:pencil#autoformat_aliases, &filetype, &filetype)
|
||||||
let l:af_cfg = get(g:pencil#autoformat_config, l:ft, {})
|
let l:af_cfg = get(g:pencil#autoformat_config, l:filetype, {})
|
||||||
let l:black = get(l:af_cfg, 'black', [])
|
let l:black = get(l:af_cfg, 'black', [])
|
||||||
let l:white = get(l:af_cfg, 'white', [])
|
let l:white = get(l:af_cfg, 'white', [])
|
||||||
let l:has_black_re = len(l:black) > 0
|
let l:has_black_re = len(l:black) > 0
|
||||||
@@ -172,7 +175,7 @@ fun! pencil#setAutoFormat(af) abort
|
|||||||
sil! au! pencil_autoformat * <buffer>
|
sil! au! pencil_autoformat * <buffer>
|
||||||
if l:nu_af && !l:is_hard
|
if l:nu_af && !l:is_hard
|
||||||
echohl WarningMsg
|
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
|
echohl NONE
|
||||||
return
|
return
|
||||||
en
|
en
|
||||||
@@ -192,7 +195,7 @@ fun! pencil#init(...) abort
|
|||||||
if !exists('b:pencil_wrap_mode')
|
if !exists('b:pencil_wrap_mode')
|
||||||
let b:pencil_wrap_mode = s:WRAP_MODE_OFF
|
let b:pencil_wrap_mode = s:WRAP_MODE_OFF
|
||||||
en
|
en
|
||||||
if !exists("b:max_textwidth")
|
if !exists('b:max_textwidth')
|
||||||
let b:max_textwidth = -1
|
let b:max_textwidth = -1
|
||||||
en
|
en
|
||||||
|
|
||||||
@@ -245,7 +248,7 @@ fun! pencil#init(...) abort
|
|||||||
" flag to suspend autoformat for next Insert
|
" flag to suspend autoformat for next Insert
|
||||||
" optional user-defined mapping
|
" optional user-defined mapping
|
||||||
if exists('g:pencil#map#suspend_af') &&
|
if exists('g:pencil#map#suspend_af') &&
|
||||||
\ g:pencil#map#suspend_af != ''
|
\ g:pencil#map#suspend_af !=# ''
|
||||||
exe 'no <buffer> <silent> ' . g:pencil#map#suspend_af . ' :let b:pencil_suspend_af=1<CR>'
|
exe 'no <buffer> <silent> ' . g:pencil#map#suspend_af . ' :let b:pencil_suspend_af=1<CR>'
|
||||||
en
|
en
|
||||||
|
|
||||||
@@ -405,10 +408,10 @@ fun! pencil#init(...) abort
|
|||||||
en
|
en
|
||||||
|
|
||||||
if b:pencil_wrap_mode
|
if b:pencil_wrap_mode
|
||||||
exe 'nn <buffer> <silent> ' . Mapkey("j", "n") . ' gj'
|
exe 'nn <buffer> <silent> ' . Mapkey('j', 'n') . ' gj'
|
||||||
exe 'nn <buffer> <silent> ' . Mapkey("k", "n") . ' gk'
|
exe 'nn <buffer> <silent> ' . Mapkey('k', 'n') . ' gk'
|
||||||
exe 'vn <buffer> <silent> ' . Mapkey("j", "v") . ' gj'
|
exe 'vn <buffer> <silent> ' . Mapkey('j', 'v') . ' gj'
|
||||||
exe 'vn <buffer> <silent> ' . Mapkey("k", "v") . ' gk'
|
exe 'vn <buffer> <silent> ' . Mapkey('k', 'v') . ' gk'
|
||||||
no <buffer> <silent> <Up> gk
|
no <buffer> <silent> <Up> gk
|
||||||
no <buffer> <silent> <Down> gj
|
no <buffer> <silent> <Down> gj
|
||||||
nn <buffer> <silent> gj j
|
nn <buffer> <silent> gj j
|
||||||
@@ -475,7 +478,7 @@ endf
|
|||||||
fun! s:doOne(item) abort
|
fun! s:doOne(item) abort
|
||||||
let l:matches = matchlist(a:item, '^\([a-z]\+\)=\([a-zA-Z0-9_\-.]\+\)$')
|
let l:matches = matchlist(a:item, '^\([a-z]\+\)=\([a-zA-Z0-9_\-.]\+\)$')
|
||||||
if len(l:matches) > 1
|
if len(l:matches) > 1
|
||||||
if l:matches[1] =~ 'textwidth\|tw'
|
if l:matches[1] =~# 'textwidth\|tw'
|
||||||
let l:tw = str2nr(l:matches[2])
|
let l:tw = str2nr(l:matches[2])
|
||||||
if l:tw > b:max_textwidth
|
if l:tw > b:max_textwidth
|
||||||
let b:max_textwidth = l:tw
|
let b:max_textwidth = l:tw
|
||||||
@@ -504,22 +507,22 @@ endf
|
|||||||
" modeline(s) and max line length
|
" modeline(s) and max line length
|
||||||
" Hat tip to https://github.com/ciaranm/securemodelines
|
" Hat tip to https://github.com/ciaranm/securemodelines
|
||||||
fun! s:doModelines() abort
|
fun! s:doModelines() abort
|
||||||
if line("$") > &modelines
|
if line('$') > &modelines
|
||||||
let l:lines={ }
|
let l:lines={ }
|
||||||
call map(filter(getline(1, &modelines) +
|
call map(filter(getline(1, &modelines) +
|
||||||
\ getline(line("$") - &modelines, "$"),
|
\ getline(line('$') - &modelines, '$'),
|
||||||
\ 'v:val =~ ":"'), 'extend(l:lines, { v:val : 0 } )')
|
\ 'v:val =~# ":"'), 'extend(l:lines, { v:val : 0 } )')
|
||||||
for l:line in keys(l:lines)
|
for l:line in keys(l:lines)
|
||||||
call s:doModeline(l:line)
|
call s:doModeline(l:line)
|
||||||
endfo
|
endfo
|
||||||
el
|
el
|
||||||
for l:line in getline(1, "$")
|
for l:line in getline(1, '$')
|
||||||
call s:doModeline(l:line)
|
call s:doModeline(l:line)
|
||||||
endfo
|
endfo
|
||||||
en
|
en
|
||||||
endf
|
endf
|
||||||
|
|
||||||
function! Mapkey (keys, mode)
|
function! Mapkey (keys, mode) abort
|
||||||
" Pass in a key sequence and the first letter of a vim mode.
|
" 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.
|
" Returns key mapping mapped to it in that mode, else 0 if none.
|
||||||
" example:
|
" example:
|
||||||
|
|||||||
@@ -5,13 +5,15 @@
|
|||||||
" Created: December 28, 2013
|
" Created: December 28, 2013
|
||||||
" License: The MIT License (MIT)
|
" 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
|
let g:loaded_pencil = 1
|
||||||
|
|
||||||
" Save 'cpoptions' and set Vim default to enable line continuations.
|
" Save 'cpoptions' and set Vim default to enable line continuations.
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpoptions = &cpoptions
|
||||||
set cpo&vim
|
set cpoptions&vim
|
||||||
|
|
||||||
let s:WRAP_MODE_DEFAULT = -1
|
let s:WRAP_MODE_DEFAULT = -1
|
||||||
let s:WRAP_MODE_OFF = 0
|
let s:WRAP_MODE_OFF = 0
|
||||||
@@ -31,7 +33,7 @@ fun! PencilMode()
|
|||||||
if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT
|
if b:pencil_wrap_mode ==# s:WRAP_MODE_SOFT
|
||||||
return get(g:pencil#mode_indicators, 'soft', 'S')
|
return get(g:pencil#mode_indicators, 'soft', 'S')
|
||||||
elsei b:pencil_wrap_mode ==# s:WRAP_MODE_HARD
|
elsei b:pencil_wrap_mode ==# s:WRAP_MODE_HARD
|
||||||
if &fo =~ 'a'
|
if &formatoptions =~# 'a'
|
||||||
return get(g:pencil#mode_indicators, 'auto', 'A')
|
return get(g:pencil#mode_indicators, 'auto', 'A')
|
||||||
el
|
el
|
||||||
return get(g:pencil#mode_indicators, 'hard', 'H')
|
return get(g:pencil#mode_indicators, 'hard', 'H')
|
||||||
@@ -203,7 +205,7 @@ if g:pencil#legacyCommands
|
|||||||
com -nargs=0 ShiftPencil call pencil#setAutoFormat(-1)
|
com -nargs=0 ShiftPencil call pencil#setAutoFormat(-1)
|
||||||
en
|
en
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
let &cpoptions = s:save_cpoptions
|
||||||
unlet s:save_cpo
|
unlet s:save_cpoptions
|
||||||
|
|
||||||
" vim:ts=2:sw=2:sts=2
|
" vim:ts=2:sw=2:sts=2
|
||||||
|
|||||||
Reference in New Issue
Block a user