--- /dev/null
+function! buftabline#do()
+ let bufsRaw = execute("buffers", "silent")
+ let bufs = []
+ for buf in split(bufsRaw, "\n")[:16]
+ let leftIdx = stridx(buf, '"')
+ let rightIdx = strridx(buf, '"')
+ let filename = substitute(buf[leftIdx + 1 : rightIdx - 1], "%", "%%", "g")
+ let linenum = split(buf[rightIdx:], " ")[-1]
+ let attrs = split(buf[:leftIdx-1], '\s\+')
+ let attrs = map(attrs, 'substitute(v:val, "%", "%%", "g")')
+ let attrs = (len(attrs) == 1) ? attrs[0] : attrs[0] . ":" . join(attrs[1:], "")
+ let attrs = "%#TabLine#" . attrs . "%*"
+ if len(filename) > 20 | let filename = "<" . filename[-(20-1):] | endif
+ let hl = (match(attrs, "%%") == -1) ? "%#TabLine#:" : "%#TabLineSel#"
+ let bufs = add(bufs, attrs . hl . filename . ":" . linenum . "%*")
+ endfor
+ return join(bufs, " ")
+endfunction
--- /dev/null
+function! chnglstnav#do(...)
+ if a:0 == 0 | return | endif
+ execute "normal " . a:1 . (a:1 > 0 ? "g;" : "g,")
+endfunction
--- /dev/null
+" Universal Ctags creator
+" Maintainer: Sergey Matveev <stargrave@stargrave.org>
+" License: GNU General Public License version 3 of the License or later
+"
+" Create "tags" file in your project's root first.
+" Then :Ctags LANG to fill it.
+
+function! ctags#do(lang, onlyCmd, verbose) abort
+ let dst = tagfiles()
+ if len(dst) == 0
+ echohl WarningMsg | echomsg "No tagfiles" | echohl None
+ return
+ endif
+ let dst = sort(dst, {a, b -> len(a) > len(b) ? 1 : len(a) == len(b) ? 0 : -1})[0]
+ let src = "/" . join(split(dst, "/")[:-3], "/")
+ if dst[0] != "/"
+ let dst = getcwd() . "/.tags/tags"
+ let src = getcwd()
+ endif
+ let cmdline = [
+ \"uctags",
+ \"--languages=" . a:lang,
+ \"--python-kinds=-i",
+ \"--c++-kinds=+p",
+ \"--recurse",
+ \]
+ if a:verbose == v:true | let cmdline += ["--verbose"] | endif
+ let cmdline += ["-f", dst, src]
+ if a:onlyCmd == v:true
+ echo join(cmdline, " ")
+ return
+ endif
+ execute "!" . join(cmdline, " ")
+ if a:verbose != v:true | redraw! | endif
+endfunction
--- /dev/null
+" Python function call splitter
+" Maintainer: Sergey Matveev <stargrave@stargrave.org>
+" License: GNU General Public License version 3 of the License or later
+"
+" This plugin splits Python function call on several lines.
+"
+" def foobar(self, foo: str, bar: Some[thing, too]) -> None:
+" to
+" def foobar(
+" self,
+" foo: str,
+" bar: Some[thing, too],
+" ) -> None:
+"
+" foo(bar, baz)[0]
+" to
+" foo(
+" bar,
+" baz,
+" )[0]
+"
+" You can un-split it using :Undefsplit command on the line where
+" splitting starts.
+"
+" :Defsplit has optional argument specifying how many opening round
+" parenthesis must be skipped.
+" :Defsplit 1 on foo(baz(baz(...))) produces
+" foo(baz(
+" baz(...),
+" ))
+"
+" Also there is :Brsplit command behaving similarly, but it splits other
+" types of brackets: "{}", "[]".
+
+function! s:bracket_find(brs_allowable, line, offset)
+ let possible = []
+ for bracket in a:brs_allowable
+ let found = stridx(a:line, bracket, a:offset)
+ if found != -1 | let possible += [found] | endif
+ endfor
+ return min(possible)
+endfunction
+
+function! defsplit#do(brs_allowable, single_line_comma, ...) abort
+ if a:0 == 0 | let skip = 0 | else | let skip = str2nr(a:1) | endif
+ let shift = get(b:, "defsplit_shift", " ")
+ let line = getline(".")
+ for i in range(len(line))
+ if line[i] != shift[0]
+ let prfx = strpart(line, 0, i)
+ if line[i : i+3] ==# "def " ||
+ \line[i : i+5] ==# "class " ||
+ \line[i : i+9] ==# "async def "
+ let shift .= shift
+ endif
+ break
+ endif
+ endfor
+ let brs = {"(": ")", "[": "]", "{": "}"}
+ let brfirst = s:bracket_find(a:brs_allowable, line, 0)
+ let brlast = strridx(line, brs[line[brfirst]])
+ while skip > 0
+ let brfirst = s:bracket_find(a:brs_allowable, line, brfirst + 1)
+ let brlast = strridx(line, brs[line[brfirst]], brlast - 1)
+ let skip -= 1
+ endwhile
+ let [curly, round, squar, outbuf] = [0, 0, 0, ""]
+ let ready = [strpart(line, 0, brfirst + 1)]
+ let trailing_comma = 1
+ for c in split(line[brfirst + 1 : brlast-1], '\zs')
+ if c ==# "*" | let trailing_comma = 0 | endif
+ if outbuf ==# "" && c ==# " " | continue | endif
+ let outbuf .= c
+ if c ==# "," && !curly && !round && !squar
+ let ready = add(ready, prfx . shift . outbuf)
+ let outbuf = ""
+ elseif c ==# "[" | let squar += 1
+ elseif c ==# "]" | let squar -= 1
+ elseif c ==# "(" | let round += 1
+ elseif c ==# ")" | let round -= 1
+ elseif c ==# "{" | let curly += 1
+ elseif c ==# "}" | let curly -= 1
+ endif
+ endfor
+ if trailing_comma && !(a:single_line_comma == v:true && len(ready) == 1)
+ let outbuf = outbuf . ","
+ endif
+ let ready = add(ready, prfx . shift . outbuf)
+ let ready = add(ready, prfx . strpart(line, brlast))
+ call append(line("."), ready)
+ normal "_dd
+endfunction
" Simplified version of http://www.vim.org/scripts/script.php?script_id=2184
" that does not replace current window
-if exists('*<SID>gotoline') | finish | endif
-
-function! s:gotoline()
+function! fileline#goto() abort
let file = bufname("%")
if filereadable(file) | return | endif
let names = matchlist(file, '\(.\{-1,}\):\%(\(\d\+\)\%(:\(\d*\):\?\)\?\)\?$')
exec "normal! " . col_num . "|"
exec "bdelete " . nr
endfunction
-
-autocmd! BufNewFile *:* nested call s:gotoline()
-autocmd! BufRead *:* nested call s:gotoline()
--- /dev/null
+" Popup documentation of specified object under the cursor
+" Requires github.com/zmb3/gogetdoc in the $PATH
+
+function! go#getdoc#status()
+ if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return "GD" | endif
+ return ""
+endfunction
+
+function! go#getdoc#got(ch) abort
+ let msgs = []
+ while ch_status(a:ch) == "buffered"
+ let msgs = add(msgs, ch_read(a:ch))
+ endwhile
+ if exists("b:godocid") | call popup_close(b:godocid) | endif
+ if len(msgs) == 0
+ echohl WarningMsg | echomsg "No go doc" | echohl None
+ return
+ endif
+ let msgs = msgs[2:]
+ let b:godocid = popup_atcursor(msgs[2:-2],
+ \ {"wrap": 0, "title": msgs[0], "move": "word"})
+endfunction
+
+function! go#getdoc#do() abort
+ if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return | endif
+ let pos = line2byte(line(".")) + col(".") - 2
+ let cmdline = "gogetdoc -pos " . expand("%p") . ":#" . pos
+ echomsg cmdline
+ let b:gogetdoc_job = job_start(cmdline, {
+ \"in_mode": "nl",
+ \"err_io": "null",
+ \"close_cb": "go#getdoc#got",
+ \})
+endfunction
--- /dev/null
+" Python imports insert completion
+" Maintainer: Sergey Matveev <stargrave@stargrave.org>
+" License: GNU General Public License version 3 of the License or later
+"
+" This plugin is intended for quick import-line insertion.
+" For example you have got "from foo.bar import Baz" import somewhere in
+" your Git-versioned code. In another file you can write "Baz" and then
+" press <F3> in insert mode. Completion menu will show you suggestions
+" of all import lines from your code containing Baz import.
+"
+" If you have Pylint or Pyflakes output in quickfix window, containing
+" unfedined variables errors, then you can you :call AllImportCompl()
+" function. It will go through the quickfix list and find all possible
+" imports, sort them and insert under current cursor position.
+"
+" It uses external "git grep" call and assumes that "canonical" Python
+" import format is used (single import per line).
+" You can use http://www.git.stargrave.org/?p=pyimportcan.git;a=blob;f=pyimportcan.pl
+" utility to convert existing imports to that format.
+
+let s:git_grep_cmd = "git grep -H --line-number --ignore-case --no-color "
+
+function! python#importcompl#sortByLen(s1, s2)
+ if len(a:s1) == len(a:s2) | return a:s1 > a:s2 | endif
+ return 1 ? len(a:s1) > len(a:s2) : -1
+endfunction
+
+function! python#importcompl#do() abort
+ normal diw
+ let output = system(s:git_grep_cmd . '"^from .* import .*' . @" . '" -- "*.py" "**/*.py"')
+ let suggestions = []
+ for line in split(output, "\n")
+ if stridx(line, "unused-import") != -1 | continue | endif
+ let m = matchlist(line, '^.*:\d\+:\(.*\)$')
+ if len(m) == 0 | continue | endif
+ call insert(suggestions, m[1])
+ endfor
+ call sort(suggestions, "python#importcompl#sortByLen")
+ call uniq(suggestions)
+ call reverse(suggestions)
+ call complete(col('.'), suggestions)
+ return ''
+endfunction
+
+function! python#importcompl#all() abort
+ let output = system(s:git_grep_cmd . '"^from .* import" -- "*.py" "**/*.py"')
+ let imports = {}
+ for line in split(output, "\n")
+ if stridx(line, "unused-import") != -1 | continue | endif
+ for regexp in [
+ \'^.*:\d\+:\(from .* import \(\w\+\).*\)$',
+ \'^.*:\d\+:\(from .* import \w\+ as \(\w\+\).*\)$',
+ \]
+ let m = matchlist(line, regexp)
+ if len(m) == 0 | break | endif
+ let imports[m[2]] = m[1]
+ endfor
+ endfor
+ let lines = getloclist(winnr())
+ if len(lines) == 0 | let lines = getqflist() | endif
+ let result = []
+ for line in lines
+ let m = matchlist(line.text, '\(E0602\|F821\).*' . "'" . '\(\w\+\)' . "'$")
+ if len(m) == 0 || !has_key(imports, m[2]) | continue | endif
+ call insert(result, imports[m[2]])
+ endfor
+ call sort(result, "i")
+ call uniq(result)
+ call append(".", result)
+endfunction
"
" This plugin allows you to asynchronously call pylint.
"
-" * Add %{LintStatus()} to your statusline to see if pylint is running
" * Press <F6> to start pylint on current file
" * Press <S-F6> to open quickfix window with messages from pylint
" * All lines with corresponding pylint existing warning will be highlighted
" Start pylint manually (<F6>) to force its filling
" * After Python file is saved, pylint is automatically started
-if exists('g:loaded_pylint') | finish | endif
-let g:loaded_pylint = 1
-
-function! LintStatus()
- if exists("b:lint_job") && job_status(b:lint_job) == "run" | return "LN" | endif
+function! python#lint#status()
+ if exists("b:pylint_job") && job_status(b:pylint_job) == "run" | return "LN" | endif
return ""
endfunction
-function! s:qffill(ch)
+function! s:qffill(ch) abort
let msgs = []
while ch_status(a:ch) == 'buffered'
let msgs = add(msgs, ch_read(a:ch))
sign define LN text=LN texthl=Error
-function! PylintFinish(ch)
+function! python#lint#finish(ch) abort
let l:errorformat_bak = &errorformat
set errorformat=%f:%l:\ [%t]%m,%f:%l:%m
call s:qffill(a:ch)
endif
endfunction
-function! PylintStart()
- if exists("g:pylint_disable") || (exists("b:lint_job") && job_status(b:lint_job) == "run")
+function! python#lint#start() abort
+ if exists("g:pylint_disable") ||
+ \ (exists("b:pylint_job") &&
+ \ job_status(b:pylint_job) == "run")
return
endif
let ignores = [
\"too-many-public-methods",
\"no-value-for-parameter",
\]
- if !exists("g:pylint_linter") | let g:pylint_linter = "pylint" | endif
- if g:pylint_linter == "flake8"
+ let linter = get(g:, "pylint_linter", "pylint")
+ if linter == "flake8"
let cmdline = [
\"flake8",
\"--ignore=E501",
\"--max-line-length=90",
\expand("%p")
\]
- elseif g:pylint_linter == "pylint"
+ elseif linter == "pylint"
let cmdline = [
\"pylint",
\"--jobs=4",
echohl WarningMsg | echomsg "Unknown linter specified" | echohl None
return
endif
- let b:lint_job = job_start(cmdline, {"in_mode": "nl", "err_io": "null", "close_cb": "PylintFinish"})
-endfunction()
-
-map <F6> :unlet! g:pylint_disable<CR>:call PylintStart()<CR>
-map \e[32~ :redraw!<CR>:copen<CR>
-autocmd BufWritePost *.py call PylintStart()
+ let b:pylint_job = job_start(cmdline,
+ \ {"in_mode": "nl", "err_io": "null", "close_cb": "python#lint#finish"})
+endfunction
--- /dev/null
+" PEP8 caller
+" Maintainer: Sergey Matveev <stargrave@stargrave.org>
+" License: GNU General Public License version 3 of the License or later
+"
+" Call pycodestyle utility and fill quickfix window with its results.
+
+function! python#pep8#do() abort
+ set makeprg=PATH=$PATH\ pycodestyle\ --select=E,W\ %
+ silent make
+ sign unplace *
+ let l:id = 1
+ for item in getqflist()
+ execute(':sign place '.l:id.' name=P8 line='.l:item.lnum.' buffer='.l:item.bufnr)
+ let l:id = l:id + 2
+ endfor
+ redraw!
+ copen
+endfunction
--- /dev/null
+" Nose-compatible test name preparer
+" Maintainer: Sergey Matveev <stargrave@stargrave.org>
+" License: GNU General Public License version 3 of the License or later
+"
+" When standing inside TestCase's test method, type <leader>t and full
+" Python (your.project.tests:TestCaseName.test_method_name) path will be
+" copied to clipboard ("*) register.
+
+function! python#testname#get() abort
+ normal mm
+ normal ?.*\s*def .*[Tt]est\r
+ normal ^f(Byw
+ let postfix = @"
+ normal [[f(Byw
+ let postfix = @" . "." . postfix
+ normal `m
+ let base = join([""] + split(getcwd(), "/")[:-1], "/")
+ let prefix = substitute(expand("%:p:r")[len(base)+1:], "/", ".", "g")
+ let name = prefix . ":" . postfix
+ let @* = name
+ echomsg name
+endfunction
--- /dev/null
+function! python#unused#remove() abort
+ call setqflist(filter(getqflist(), {idx, val ->
+ \ stridx(val.text, "unused-import") != -1 ||
+ \ stridx(val.text, "imported but unused") != -1}))
+ cdo d
+endfunction
--- /dev/null
+function! whereami#pwdLoad()
+ let g:whereami_pwdL=trim(system("pwd -L"))
+ let g:whereami_pwdP=trim(system("pwd -P"))
+endfunction
+
+function! whereami#do(fmt) abort
+ let fullpath = expand("%:p")
+ if fullpath[:len(g:whereami_pwdP)-1] ==# g:whereami_pwdP
+ let fullpath = g:whereami_pwdL . fullpath[len(g:whereami_pwdP):]
+ endif
+ let where = printf(a:fmt, fullpath, line("."))
+ let @* = where
+ echomsg where
+endfunction
-function! s:KillSignature()
+function! s:KillSignature() abort
call cursor(1, 1)
call search('^[>|] \?-- \?$')
if getpos(".")[1] != 1
setlocal commentstring=//\ %s
-abbreviate UCC unsigned char
-abbreviate u8 uint8_t *
-abbreviate U8 (uint8_t *)
+abbreviate <buffer> UCC unsigned char
+abbreviate <buffer> u8 uint8_t *
+abbreviate <buffer> U8 (uint8_t *)
let @e = "ywoassert(\epA!= NULL);\e"
setlocal equalprg=cfmt.sh
-set noexpandtab
-let g:defsplit_shift=" "
+setlocal noexpandtab
+let b:defsplit_shift=" "
let @e = "^iif err = \eA; err != nil {\eo "
let @r = "oif err != nil {\r}\eO "
let g:go_fmt_commands = 1
endif
-if !exists("g:gofmt_command")
- let g:gofmt_command = "goimports"
-endif
+let g:gofmt_command = get(g:, "gofmt_command", "goimports")
if g:go_fmt_commands
command! -buffer Fmt call s:GoFormat()
-" Popup documentation of specified object under the cursor
-" Requires github.com/zmb3/gogetdoc in the $PATH
-
-function! LintStatus()
- if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return "GD" | endif
- return ""
-endfunction
-
-function! GoGetDocGot(ch)
- let msgs = []
- while ch_status(a:ch) == "buffered"
- let msgs = add(msgs, ch_read(a:ch))
- endwhile
- if exists("b:godocid") | call popup_close(b:godocid) | endif
- if len(msgs) == 0
- echohl WarningMsg | echomsg "No go doc" | echohl None
- return
- endif
- let msgs = msgs[2:]
- let b:godocid = popup_atcursor(msgs[2:-2], {"wrap": 0, "title": msgs[0], "move": "word"})
-endfunction
-
-function! s:GoGetDoc()
- if exists("b:gogetdoc_job") && job_status(b:gogetdoc_job) == "run" | return | endif
- let pos = line2byte(line(".")) + col(".") - 2
- let cmdline = "gogetdoc -pos " . expand("%p") . ":#" . pos
- echomsg cmdline
- let b:gogetdoc_job = job_start(cmdline, {
- \"in_mode": "nl",
- \"err_io": "null",
- \"close_cb": "GoGetDocGot",
- \})
-endfunction
-
-nmap <buffer> <silent> <CR> :call <SID>GoGetDoc()<CR>
+if exists("*go#getdoc#do") | finish | endif
+let b:lint_status_func=function("go#getdoc#status")
+nmap <buffer> <silent> <CR> :call go#getdoc#do()<CR>
-abbreviate tto <em></em><ESC>F<i
+abbreviate <buffer> tto <em></em><ESC>F<i
-iabbrev #u # coding: utf-8
-iabbrev tt # type:
-iabbrev tti # type: ignore
-iabbrev trace import pdb ; pdb.set_trace()<CR>pass
-iabbrev embed import code ; code.interact(local=locals())
-iabbrev kargs *args, **kwargs
-iabbrev pyldis # pylint: disable=
-iabbrev deff def () -> None:<ESC>F(i
-iabbrev """ """<ESC>o"<ESC>2i"<ESC>kA
-nmap <leader>ss :set lazyredraw<CR>vip:sort u<CR>:'<,'>sort i<CR>:set nolazyredraw<CR>
+iabbrev <buffer> #u # coding: utf-8
+iabbrev <buffer> tt # type:
+iabbrev <buffer> tti # type: ignore
+iabbrev <buffer> trace import pdb ; pdb.set_trace()<CR>pass
+iabbrev <buffer> embed import code ; code.interact(local=locals())
+iabbrev <buffer> kargs *args, **kwargs
+iabbrev <buffer> pyldis # pylint: disable=
+iabbrev <buffer> deff def () -> None:<ESC>F(i
+iabbrev <buffer> """ """<ESC>o"<ESC>2i"<ESC>kA
+nmap <buffer> <leader>ss :set lazyredraw<CR>vip:sort u<CR>:'<,'>sort i<CR>:set nolazyredraw<CR>
let @b = ">gvctry:\e<<oexcept Exception as err:\rimport pdb ; pdb.set_trace()\rpass\e>>k>>kP"
let @n = "ddV/except.*:\r<n3dd"
-set wildignore+=**/_build/*,**/.hypothesis
+setlocal wildignore+=**/_build/*,**/.hypothesis
-" Python imports insert completion
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" License: GNU General Public License version 3 of the License or later
-"
-" This plugin is intended for quick import-line insertion.
-" For example you have got "from foo.bar import Baz" import somewhere in
-" your Git-versioned code. In another file you can write "Baz" and then
-" press <F3> in insert mode. Completion menu will show you suggestions
-" of all import lines from your code containing Baz import.
-"
-" If you have Pylint or Pyflakes output in quickfix window, containing
-" unfedined variables errors, then you can you :call AllImportCompl()
-" function. It will go through the quickfix list and find all possible
-" imports, sort them and insert under current cursor position.
-"
-" It uses external "git grep" call and assumes that "canonical" Python
-" import format is used (single import per line).
-" You can use http://www.git.stargrave.org/?p=pyimportcan.git;a=blob;f=pyimportcan.pl
-" utility to convert existing imports to that format.
-
-let s:git_grep_cmd = "git grep -H --line-number --ignore-case --no-color "
-
-if exists('g:loaded_importcompl') | finish | endif
-let g:loaded_importcompl = 1
-
-function! SortByLen(s1, s2)
- if len(a:s1) == len(a:s2) | return a:s1 > a:s2 | endif
- return 1 ? len(a:s1) > len(a:s2) : -1
-endfunction
-
-function! ImportCompl()
- normal diw
- let output = system(s:git_grep_cmd . '"^from .* import .*' . @" . '" -- "*.py" "**/*.py"')
- let suggestions = []
- for line in split(output, "\n")
- if stridx(line, "unused-import") != -1 | continue | endif
- let m = matchlist(line, '^.*:\d\+:\(.*\)$')
- if len(m) == 0 | continue | endif
- call insert(suggestions, m[1])
- endfor
- call sort(suggestions, "SortByLen")
- call uniq(suggestions)
- call reverse(suggestions)
- call complete(col('.'), suggestions)
- return ''
-endfunction
-
-inoremap <F3> <C-R>=ImportCompl()<CR>
-
-function! AllImportCompl()
- let output = system(s:git_grep_cmd . '"^from .* import" -- "*.py" "**/*.py"')
- let imports = {}
- for line in split(output, "\n")
- if stridx(line, "unused-import") != -1 | continue | endif
- for regexp in [
- \'^.*:\d\+:\(from .* import \(\w\+\).*\)$',
- \'^.*:\d\+:\(from .* import \w\+ as \(\w\+\).*\)$',
- \]
- let m = matchlist(line, regexp)
- if len(m) == 0 | break | endif
- let imports[m[2]] = m[1]
- endfor
- endfor
- let lines = getloclist(winnr())
- if len(lines) == 0 | let lines = getqflist() | endif
- let result = []
- for line in lines
- let m = matchlist(line.text, '\(E0602\|F821\).*' . "'" . '\(\w\+\)' . "'$")
- if len(m) == 0 || !has_key(imports, m[2]) | continue | endif
- call insert(result, imports[m[2]])
- endfor
- call sort(result, "i")
- call uniq(result)
- call append(".", result)
-endfunction
+if exists("*python#importcompl#do") | finish | endif
+inoremap <F3> <C-R>=python#importcompl#do()<CR>
--- /dev/null
+if exists("*python#lint#start") | finish | endif
+let b:lint_status_func=function("python#lint#status")
+sign define LN text=LN texthl=Error
+map <F6> :unlet! g:pylint_disable<CR>:call python#lint#start()<CR>
+map \e[32~ :redraw!<CR>:copen<CR>
+autocmd BufWritePost *.py call python#lint#start()
-" PEP8 caller
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" License: GNU General Public License version 3 of the License or later
-"
-" Call pycodestyle utility and fill quickfix window with its results.
-
+if exists("*python#pep8#do") | finish | endif
sign define P8 text=P8 texthl=Error
-function! s:pep8()
- set makeprg=PATH=$PATH\ pycodestyle\ --select=E,W\ %
- silent make
- sign unplace *
- let l:id = 1
- for item in getqflist()
- execute(':sign place '.l:id.' name=P8 line='.l:item.lnum.' buffer='.l:item.bufnr)
- let l:id = l:id + 2
- endfor
- redraw!
- copen
-endfunction
-
-map <F5> :call <SID>pep8()<CR>
+map <buffer> <F5> :call python#pep8#do()<CR>
-" Nose-compatible test name preparer
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" License: GNU General Public License version 3 of the License or later
-"
-" When standing inside TestCase's test method, type <leader>t and full
-" Python (your.project.tests:TestCaseName.test_method_name) path will be
-" copied to clipboard ("*) register.
-
-function! TestName()
- normal mm
- normal ?.*\s*def .*[Tt]est\r
- normal ^f(Byw
- let postfix = @"
- normal [[f(Byw
- let postfix = @" . "." . postfix
- normal `m
- let base = join([""] + split(getcwd(), "/")[:-1], "/")
- let prefix = substitute(expand("%:p:r")[len(base)+1:], "/", ".", "g")
- let name = prefix . ":" . postfix
- let @* = name
- echomsg name
-endfunction
-
-nmap <leader>t :call TestName()<CR>
+if exists("*python#testname#get") | finish | endif
+nmap <buffer> <leader>t :call python#testname#get()<CR>
+++ /dev/null
-function! UnusedImportsRemover()
- call setqflist(filter(getqflist(), "stridx(v:val.text, \"unused-import\") != -1 || stridx(v:val.text, \"imported but unused\") != -1"))
- cdo d
-endfunction
-abbreviate \t @tab
+abbreviate <buffer> \t @tab
setlocal commentstring=@c\ %s
--- /dev/null
+let &t_BE = "\e[?2004h"
+let &t_BD = "\e[?2004l"
+exec "set t_PS=\e[200~"
+exec "set t_PE=\e[201~"
-if exists('*<SID>BufTabLine') | finish | endif
-
-function! s:BufTabline()
- redir => bufsRaw
- silent buffers
- redir END
- let bufs = []
- for buf in split(bufsRaw, "\n")[:16]
- let leftIdx = stridx(buf, '"')
- let rightIdx = strridx(buf, '"')
- let filename = substitute(buf[leftIdx + 1 : rightIdx - 1], "%", "%%", "g")
- let linenum = split(buf[rightIdx:], " ")[-1]
- let attrs = split(buf[:leftIdx-1], '\s\+')
- let attrs = map(attrs, 'substitute(v:val, "%", "%%", "g")')
- let attrs = (len(attrs) == 1) ? attrs[0] : attrs[0] . ":" . join(attrs[1:], "")
- let attrs = "%#TabLine#" . attrs . "%*"
- if len(filename) > 20 | let filename = "<" . filename[-(20-1):] | endif
- let hl = (match(attrs, "%%") == -1) ? "%#TabLine#:" : "%#TabLineSel#"
- let bufs = add(bufs, attrs . hl . filename . ":" . linenum . "%*")
- endfor
- return join(bufs, " ")
-endfunction
-
-function! BufTabline()
- return s:BufTabline()
-endfunction
-
+if exists("*buftabline#do") | finish | endif
set showtabline=2
-set tabline=%!BufTabline()
+set tabline=%!buftabline#do()
-if exists('*<SID>Chng') | finish | endif
-
-function! s:Chng(...)
- if a:0 == 0 | return | endif
- execute "normal " . a:1 . (a:1 > 0 ? "g;" : "g,")
-endfunction
-
-command! -nargs=? Chng call s:Chng(<args>)
-nmap <End> :changes<CR>:Chng<Space>
+if exists("*chnglstnav#do") | finish | endif
+nmap <End> :changes<CR>:call chnglstnav#do()<Left>
-" Universal Ctags creator
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" License: GNU General Public License version 3 of the License or later
-"
-" Create "tags" file in your project's root first.
-" Then :Ctags LANG to fill it.
-
-if exists('*<SID>Ctags') | finish | endif
-
-function! s:Ctags(lang, onlyCmd, verbose)
- let dst = tagfiles()
- if len(dst) == 0
- echohl WarningMsg | echomsg "No tagfiles" | echohl None
- return
- endif
- let dst = sort(dst, {a, b -> len(a) > len(b) ? 1 : len(a) == len(b) ? 0 : -1})[0]
- let src = "/" . join(split(dst, "/")[:-3], "/")
- if dst[0] != "/"
- let dst = getcwd() . "/.tags/tags"
- let src = getcwd()
- endif
- let cmdline = [
- \"uctags",
- \"--languages=" . a:lang,
- \"--python-kinds=-i",
- \"--c++-kinds=+p",
- \"--recurse",
- \]
- if a:verbose == v:true | let cmdline += ["--verbose"] | endif
- let cmdline += ["-f", dst, src]
- if a:onlyCmd == v:true
- echo join(cmdline, " ")
- return
- endif
- execute "!" . join(cmdline, " ")
- if a:verbose != v:true | redraw! | endif
-endfunction
-
-command! -nargs=1 Ctags silent call s:Ctags(<f-args>, v:false, v:false)
-command! -nargs=1 Ctagsv silent call s:Ctags(<f-args>, v:true, v:false)
-command! -nargs=1 Ctagscmd call s:Ctags(<f-args>, v:true, v:true)
+if exists("*ctags#do") | finish | endif
+command! -nargs=1 Ctags silent call ctags#do(<f-args>, v:false, v:false)
+command! -nargs=1 Ctagsv silent call ctags#do(<f-args>, v:true, v:false)
+command! -nargs=1 Ctagscmd call ctags#do(<f-args>, v:true, v:true)
-" Python function call splitter
-" Maintainer: Sergey Matveev <stargrave@stargrave.org>
-" License: GNU General Public License version 3 of the License or later
-"
-" This plugin splits Python function call on several lines.
-"
-" def foobar(self, foo: str, bar: Some[thing, too]) -> None:
-" to
-" def foobar(
-" self,
-" foo: str,
-" bar: Some[thing, too],
-" ) -> None:
-"
-" foo(bar, baz)[0]
-" to
-" foo(
-" bar,
-" baz,
-" )[0]
-"
-" You can un-split it using :Undefsplit command on the line where
-" splitting starts.
-"
-" :Defsplit has optional argument specifying how many opening round
-" parenthesis must be skipped.
-" :Defsplit 1 on foo(baz(baz(...))) produces
-" foo(baz(
-" baz(...),
-" ))
-"
-" Also there is :Brsplit command behaving similarly, but it splits other
-" types of brackets: "{}", "[]".
-
-if !exists("g:defsplit_shift") | let g:defsplit_shift = " " | endif
-if exists('*<SID>Defsplit') | finish | endif
-
-function! s:bracket_find(brs_allowable, line, offset)
- let possible = []
- for bracket in a:brs_allowable
- let found = stridx(a:line, bracket, a:offset)
- if found != -1 | let possible += [found] | endif
- endfor
- return min(possible)
-endfunction
-
-function! s:Defsplit(brs_allowable, single_line_comma, ...)
- if a:0 == 0 | let skip = 0 | else | let skip = str2nr(a:1) | endif
- let shift = g:defsplit_shift
- let line = getline(".")
- for i in range(len(line))
- if line[i] != g:defsplit_shift[0]
- let prfx = strpart(line, 0, i)
- if line[i : i+3] ==# "def " ||
- \line[i : i+5] ==# "class " ||
- \line[i : i+9] ==# "async def "
- let shift .= shift
- endif
- break
- endif
- endfor
- let brs = {"(": ")", "[": "]", "{": "}"}
- let brfirst = s:bracket_find(a:brs_allowable, line, 0)
- let brlast = strridx(line, brs[line[brfirst]])
- while skip > 0
- let brfirst = s:bracket_find(a:brs_allowable, line, brfirst + 1)
- let brlast = strridx(line, brs[line[brfirst]], brlast - 1)
- let skip -= 1
- endwhile
- let [curly, round, squar, outbuf] = [0, 0, 0, ""]
- let ready = [strpart(line, 0, brfirst + 1)]
- let trailing_comma = 1
- for c in split(line[brfirst + 1 : brlast-1], '\zs')
- if c ==# "*" | let trailing_comma = 0 | endif
- if outbuf ==# "" && c ==# " " | continue | endif
- let outbuf .= c
- if c ==# "," && !curly && !round && !squar
- let ready = add(ready, prfx . shift . outbuf)
- let outbuf = ""
- elseif c ==# "[" | let squar += 1
- elseif c ==# "]" | let squar -= 1
- elseif c ==# "(" | let round += 1
- elseif c ==# ")" | let round -= 1
- elseif c ==# "{" | let curly += 1
- elseif c ==# "}" | let curly -= 1
- endif
- endfor
- if trailing_comma && !(a:single_line_comma == v:true && len(ready) == 1)
- let outbuf = outbuf . ","
- endif
- let ready = add(ready, prfx . shift . outbuf)
- let ready = add(ready, prfx . strpart(line, brlast))
- call append(line("."), ready)
- normal "_dd
-endfunction
-
-command! -nargs=? Defsplit call s:Defsplit(["("], v:false, <f-args>)
-command! -nargs=? Brsplit call s:Defsplit(["(", "[", "{"], v:false, <f-args>)
-command! -nargs=? Defsplits call s:Defsplit(["("], v:true, <f-args>)
-command! -nargs=? Brsplits call s:Defsplit(["(", "[", "{"], v:true, <f-args>)
-
+if exists("*defsplit#do") | finish | endif
+command! -nargs=? Defsplit call defsplit#do(["("], v:false, <f-args>)
+command! -nargs=? Brsplit call defsplit#do(["(", "[", "{"], v:false, <f-args>)
+command! -nargs=? Defsplits call defsplit#do(["("], v:true, <f-args>)
+command! -nargs=? Brsplits call defsplit#do(["(", "[", "{"], v:true, <f-args>)
command! Undefsplit normal ^v%$J:keepp s/^\(.*\)\([([{]\) \(.*[^,]\),\?\([)\]}]\)\(.*\)$/\1\2\3\4\5<CR>:keepp s/, \?\([)\]}]\+\)$/\1/e<CR>:<CR>
-if exists('*<SID>exted') | finish | endif
+if exists("*<SID>exted") | finish | endif
function! s:exted(ext)
execute "edit %<." . a:ext
--- /dev/null
+if exists("*fileline#goto") | finish | endif
+autocmd! BufNewFile *:* nested call fileline#goto()
+autocmd! BufRead *:* nested call fileline#goto()
-if exists('*<SID>Vmg') | finish | endif
+if exists("*<SID>Vmg") | finish | endif
function! s:Vmg(pattern)
silent execute 'Ggrep "' . a:pattern . '"'
-if exists('*<SID>Vim') | finish | endif
+if exists("*<SID>Vim") | finish | endif
function! s:Vim(pattern)
set grepprg=grep\ -Rns\ --binary-files=without-match\ --exclude-dir=.git\ --exclude-dir=.tags\ $*\ /dev/null\ .
-if exists('*<SID>on_lsp_buffer_enabled') | finish | endif
+if exists("*<SID>on_lsp_buffer_enabled") | finish | endif
let g:lsp_auto_enable = 1
+++ /dev/null
-if exists("g:loaded_mein_pastemode") | finish | endif
-let g:loaded_mein_pastemode = 1
-
-if &term =~ "screen.*"
- let &t_ti = &t_ti . "\e[?2004h"
- let &t_te = "\e[?2004l" . &t_te
- function! XTermPasteBegin(ret)
- set pastetoggle=<Esc>[201~
- set paste
- return a:ret
- endfunction
- map <expr> <Esc>[200~ XTermPasteBegin("i")
- imap <expr> <Esc>[200~ XTermPasteBegin("")
- cmap <Esc>[200~ <nop>
- cmap <Esc>[201~ <nop>
-endif
-if exists('*<SID>pwdLoad') | finish | endif
-
-function! s:pwdLoad()
- let g:mein_pwdL=trim(system("pwd -L"))
- let g:mein_pwdP=trim(system("pwd -P"))
-endfunction
-
-autocmd VimEnter * call s:pwdLoad()
-
-function! s:WhereAmI(fmt)
- let fullpath = expand("%:p")
- if fullpath[:len(g:mein_pwdP)-1] ==# g:mein_pwdP
- let fullpath = g:mein_pwdL . fullpath[len(g:mein_pwdP):]
- endif
- if a:fmt == "gnu"
- let where = fullpath . ":" . line(".")
- elseif a:fmt == "lldb"
- let where = "breakpoint set --file " . fullpath . " --line " . line(".")
- else
- let where = "unknown fmt"
- endif
- let @* = where
- echomsg where
-endfunction
-
-nmap <leader>w :call <SID>WhereAmI("gnu")<CR>
-nmap <leader>W :call <SID>WhereAmI("lldb")<CR>
+if exists("*whereami#pwdLoad") | finish | endif
+autocmd VimEnter * call whereami#pwdLoad()
+nmap <leader>w :call whereami#do("%s:%d")<CR>
+nmap <leader>W :call whereami#do("breakpoint set --file %s --line %d")<CR>
" Maintainer: Sergey Matveev <stargrave@stargrave.org>
" License: GNU General Public License version 3 of the License or later
-if exists('*<SID>zshfe') | finish | endif
+if exists("*<SID>zshfe") | finish | endif
if !exists("g:zshfe_path") | let g:zshfe_path=expand("~/.vim/plugin/zshfe.zsh") | endif
function! s:zshfe(query, opencmd)
" }}}
" Statusline {{{
+let LintStatus = {-> exists("b:lint_status_func") ? b:lint_status_func() : ""}
set laststatus=2
set statusline=%F\ %m%r%h%w%k
set statusline+=%{len(getqflist())?'[Q]':''}
set statusline+=%#Comment#%o
set statusline+=%#Error#%{LintStatus()}
set statusline+=%*\ %P
-
-function! LintStatus() " it is overrided in ftplugins
- return ""
-endfunction
" }}}
" View saving {{{