Last active
October 2, 2020 16:21
-
-
Save tamago324/6d4681429f227600212563c99909222e to your computer and use it in GitHub Desktop.
LeaderFのソースに独自のコマンドを追加する (popup は非対応)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
./leaderf/ghq.py | |
""" | |
from functools import wraps | |
from ghqExpl import GhqExplManager | |
from leaderf.utils import lfCmd | |
def command(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
return func(*args, **kwargs) | |
setattr(GhqExplManager, func.__name__, func) | |
return wrapper | |
@command | |
def open_browser(self, *args, **kwargs): | |
instance = self._getInstance() | |
line = instance.currentLine | |
url = "https://github.com/" + line.split(" ", 1)[0] | |
lfCmd(f'call openbrowser#open("{url}")') | |
@command | |
def packget(self, *args, **kwargs): | |
""" | |
:PackGet | |
""" | |
instance = self._getInstance() | |
line = instance.currentLine | |
name = line.split(" ", 1)[0] | |
lfCmd(f'PackGet {name}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" ==================== | |
" LeaderF に独自のコマンドを追加する | |
" ==================== | |
let s:script_file_dir = expand('<sfile>:h') | |
function! s:custom_leaderf() abort | |
" autoload を実行させるため | |
call leaderf#versionCheck() | |
" LeaderF の拡張を sys.path に入れる | |
exec 'py3 import sys' | |
for [l:key, l:val] in items(g:plugs) | |
let l:lf_ext_dir = substitute(l:val.dir, '\', '/', 'g') . 'autoload/leaderf/python' | |
if isdirectory(l:lf_ext_dir) | |
exec printf('py3 sys.path.insert(0, "%s")', l:lf_ext_dir) | |
endif | |
endfor | |
" ./leaderf/*.py のファイルを読み込む | |
for l:file in glob(s:script_file_dir . '/leaderf/*.py', v:false, v:true) | |
echo l:file | |
exec 'py3file' l:file | |
endfor | |
endfunction | |
call s:custom_leaderf() | |
let g:Lf_NormalMap = get(g:, 'Lf_NormalMap') | |
let g:Lf_NormalMap.Ghq = [ | |
\ ['B', ':exec g:Lf_py "ghqExplManager.open_browser()"<CR>'], | |
\] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment