Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leaderf 自定义 扩展与vim python3 出现兼容性问题 #209

Closed
tracyone opened this issue Sep 3, 2018 · 8 comments
Closed

leaderf 自定义 扩展与vim python3 出现兼容性问题 #209

tracyone opened this issue Sep 3, 2018 · 8 comments
Labels

Comments

@tracyone
Copy link

tracyone commented Sep 3, 2018

https://github.com/tracyone/vinux/blob/leaderf_extend/autoload/te/leaderf/dir.vim#L1-L50

https://github.com/tracyone/vinux/blob/leaderf_extend/rc/jump.vim#L34-L41

    nnoremap <Leader>ff :Leaderf dir<cr>

注意把代码里面的te#compatiable#systemlist换成systemlist函数即可。

问题描述:

vim 最新版本(几乎),使能python3,echo has('python3)为1.

leaderf插件的版本为最新dev分支。

执行上面的Leaderf dir的时候,首次进入界面没有错误,但是一开始输入字就出现下面截图错误:

error

这个问题可以在ubuntu 16.04.4和macOS 10.13.6上复现。

@Yggdroot Yggdroot added the bug label Sep 3, 2018
Yggdroot added a commit that referenced this issue Sep 4, 2018
@Yggdroot
Copy link
Owner

Yggdroot commented Sep 4, 2018

fix了,试一下,在dev branch。

@Yggdroot
Copy link
Owner

Yggdroot commented Sep 4, 2018

function! te#leaderf#dir#accept(line, args) abort
    let l:file_or_dir=matchstr(a:line,".*[^@]")
    if isdirectory(l:file_or_dir)
        execute 'cd 'l:file_or_dir
        :Leaderf dir
    else
        execute 'e '.l:file_or_dir
    endif
endfunction

这个函数调用:Leaderf dir 这样实现,是退出去再进来有点不舒服,我增加了一个函数:
\ "need_exit": funcref (line, arguments),
你只要写一个函数返回0,就不会退出了。
例如:

function! te#leaderf#dir#needExit(line, args) abort
    let l:file_or_dir=matchstr(a:line,".*[^@]")
    if isdirectory(l:file_or_dir)
        return 0   "不退出
    else
        return 1
    endif
endfunction
let g:Lf_Extensions = {
			\ "dir": {
			\       "source": function("te#leaderf#dir#source"),
			\       "need_exit": function("te#leaderf#dir#needExit"),
			\       "accept": function("te#leaderf#dir#accept"),
			\       "supports_name_only": 1,
			\       "supports_multi": 0,
			\ },

@tracyone
Copy link
Author

tracyone commented Sep 4, 2018

题目的问题确认解决了。

你说的这个need_exit,有个问题:

按照我这个扩展

首先选择一个目录进去,然后在该目录选择一个文件打开,这个时候出现下图的情况,leaderf似乎没有离开

screen shot 2018-09-04 at 21 00 24

@Yggdroot
Copy link
Owner

Yggdroot commented Sep 4, 2018

accept函数也要相应的修改。
例如:

function! te#leaderf#dir#accept(line, args) abort
    let l:file_or_dir=matchstr(a:line,".*[^@]")
    if isdirectory(l:file_or_dir)
        execute 'cd 'l:file_or_dir
        把这个目录下的文件或目录再列出来
    else
        execute 'e '.l:file_or_dir
    endif
endfunction

@Yggdroot
Copy link
Owner

Yggdroot commented Sep 4, 2018

function! te#leaderf#dir#accept(line, args) abort
    let l:file_or_dir=matchstr(a:line,".*[^@]")
    if isdirectory(l:file_or_dir)
        execute 'cd 'l:file_or_dir
        let source = te#leaderf#dir#source(0)
        norm! ggdG
        call setline(1, source)
    else
        execute 'e '.l:file_or_dir
    endif
endfunction

我的意思大致就是这个函数,不过高亮好像有bug,我再看看。

@Yggdroot
Copy link
Owner

Yggdroot commented Sep 5, 2018

使用最新的dev branch,应该没什么问题了。

@Yggdroot
Copy link
Owner

Yggdroot commented Sep 5, 2018

Leaderf dir 这个功能我打算原生支持了,也许可以吸引一些用户,到时候希望能提出一些建议。

@tracyone
Copy link
Author

tracyone commented Sep 5, 2018

Awesome!,问题解决。

@tracyone tracyone closed this as completed Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants