1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 22:20:06 +08:00

Enable fold code

This commit is contained in:
wsdjeg 2018-01-25 22:57:56 +08:00
parent a973535dd1
commit ca42327356
18 changed files with 108 additions and 69 deletions

View File

@ -1,48 +1,19 @@
" Loadding SpaceVim api {{{
scriptencoding utf-8
let s:MPT = SpaceVim#api#import('prompt')
let s:JOB = SpaceVim#api#import('job')
let s:SYS = SpaceVim#api#import('system')
let s:BUFFER = SpaceVim#api#import('vim#buffer')
let s:grepid = 0
let s:MPT._prompt.mpt = '➭ '
" keys:
" files: files for grep, @buffers means listed buffer.
" dir: specific a directory for grep
function! SpaceVim#plugins#flygrep#open(agrv) abort
noautocmd rightbelow split __flygrep__
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
let save_tve = &t_ve
setlocal t_ve=
" setlocal nomodifiable
setf SpaceVimFlyGrep
redraw!
let s:MPT._prompt.begin = get(a:agrv, 'input', '')
let fs = get(a:agrv, 'files', '')
if fs ==# '@buffers'
let s:grep_files = map(s:BUFFER.listed_buffers(), 'bufname(v:val)')
elseif !empty(fs)
let s:grep_files = fs
else
let s:grep_files = ''
endif
let dir = expand(get(a:agrv, 'dir', ''))
if !empty(dir) && isdirectory(dir)
let s:grep_dir = dir
else
let s:grep_dir = ''
endif
let s:grep_exe = get(a:agrv, 'cmd', s:grep_default_exe)
let s:grep_opt = get(a:agrv, 'opt', s:grep_default_opt)
let s:grep_ropt = get(a:agrv, 'ropt', s:grep_default_ropt)
call s:MPT.open()
let &t_ve = save_tve
endfunction
"}}}
" Init local options: {{{
let s:grep_expr = ''
let [s:grep_default_exe, s:grep_default_opt, s:grep_default_ropt] = SpaceVim#mapping#search#default_tool()
let s:grep_timer_id = 0
let s:grepid = 0
" }}}
" grep local funcs:{{{
" @vimlint(EVL103, 1, a:timer)
function! s:grep_timer(timer) abort
let cmd = s:get_search_cmd(join(split(s:grep_expr), '.*'))
@ -54,6 +25,41 @@ function! s:grep_timer(timer) abort
\ 'on_exit' : function('s:grep_exit'),
\ })
endfunction
function! s:get_search_cmd(expr) abort
let cmd = [s:grep_exe] + s:grep_opt
if !empty(s:grep_files) && type(s:grep_files) == 3
return cmd + [a:expr] + s:grep_files
elseif !empty(s:grep_files) && type(s:grep_files) == 1
return cmd + [a:expr] + [s:grep_files]
elseif !empty(s:grep_dir)
return cmd + [a:expr] + [s:grep_dir]
else
return cmd + [a:expr] + s:grep_ropt
endif
endfunction
function! s:flygrep(expr) abort
call s:MPT._build_prompt()
if a:expr ==# ''
redrawstatus
return
endif
try
call matchdelete(s:hi_id)
catch
endtr
hi def link FlyGrepPattern MoreMsg
let s:hi_id = matchadd('FlyGrepPattern', '\c' . join(split(a:expr), '\|'), 1)
let s:grep_expr = a:expr
let s:grep_timer_id = timer_start(200, function('s:grep_timer'), {'repeat' : 1})
endfunction
" set default handle func: s:flygrep
let s:MPT._handle_fly = function('s:flygrep')
" }}}
" filter local funcs: {{{
" @vimlint(EVL103, 0, a:timer)
let s:filter_file = ''
function! s:start_filter() abort
@ -104,25 +110,13 @@ function! s:get_filter_cmd(expr) abort
let cmd = [s:grep_exe] + SpaceVim#mapping#search#getFopt(s:grep_exe)
return cmd + [a:expr] + [s:filter_file]
endfunction
" }}}
function! s:flygrep(expr) abort
call s:MPT._build_prompt()
if a:expr ==# ''
redrawstatus
return
endif
try
call matchdelete(s:hi_id)
catch
endtr
hi def link FlyGrepPattern MoreMsg
let s:hi_id = matchadd('FlyGrepPattern', '\c' . join(split(a:expr), '\|'), 1)
let s:grep_expr = a:expr
let s:grep_timer_id = timer_start(200, function('s:grep_timer'), {'repeat' : 1})
endfunction
let s:MPT._handle_fly = function('s:flygrep')
" API: MPT._prompt {{{
let s:MPT._prompt.mpt = '➭ '
" }}}
" API: MPT._onclose {{{
function! s:close_buffer() abort
if s:grepid != 0
call s:JOB.stop(s:grepid)
@ -132,10 +126,10 @@ function! s:close_buffer() abort
endif
q
endfunction
let s:MPT._onclose = function('s:close_buffer')
" }}}
" API: MPT._oninputpro {{{
function! s:close_grep_job() abort
if s:grepid != 0
call s:JOB.stop(s:grepid)
@ -147,7 +141,9 @@ function! s:close_grep_job() abort
endfunction
let s:MPT._oninputpro = function('s:close_grep_job')
" }}}
" FlyGrep job handles: {{{
" @vimlint(EVL103, 1, a:data)
" @vimlint(EVL103, 1, a:id)
" @vimlint(EVL103, 1, a:event)
@ -176,24 +172,12 @@ function! s:grep_exit(id, data, event) abort
redrawstatus
let s:grepid = 0
endfunction
" @vimlint(EVL103, 0, a:data)
" @vimlint(EVL103, 0, a:id)
" @vimlint(EVL103, 0, a:event)
"}}}
function! s:get_search_cmd(expr) abort
let cmd = [s:grep_exe] + s:grep_opt
if !empty(s:grep_files) && type(s:grep_files) == 3
return cmd + [a:expr] + s:grep_files
elseif !empty(s:grep_files) && type(s:grep_files) == 1
return cmd + [a:expr] + [s:grep_files]
elseif !empty(s:grep_dir)
return cmd + [a:expr] + [s:grep_dir]
else
return cmd + [a:expr] + s:grep_ropt
endif
endfunction
" FlyGrep Key prompt key bindings: {{{
function! s:next_item() abort
if line('.') == line('$')
normal! gg
@ -292,8 +276,45 @@ if has('nvim')
\ }
\ )
endif
" }}}
" statusline api
" Public API: SpaceVim#plugins#flygrep#open(argv) {{{
" keys:
" files: files for grep, @buffers means listed buffer.
" dir: specific a directory for grep
function! SpaceVim#plugins#flygrep#open(agrv) abort
noautocmd rightbelow split __flygrep__
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
let save_tve = &t_ve
setlocal t_ve=
" setlocal nomodifiable
setf SpaceVimFlyGrep
redraw!
let s:MPT._prompt.begin = get(a:agrv, 'input', '')
let fs = get(a:agrv, 'files', '')
if fs ==# '@buffers'
let s:grep_files = map(s:BUFFER.listed_buffers(), 'bufname(v:val)')
elseif !empty(fs)
let s:grep_files = fs
else
let s:grep_files = ''
endif
let dir = expand(get(a:agrv, 'dir', ''))
if !empty(dir) && isdirectory(dir)
let s:grep_dir = dir
else
let s:grep_dir = ''
endif
let s:grep_exe = get(a:agrv, 'cmd', s:grep_default_exe)
let s:grep_opt = get(a:agrv, 'opt', s:grep_default_opt)
let s:grep_ropt = get(a:agrv, 'ropt', s:grep_default_ropt)
call s:MPT.open()
let &t_ve = save_tve
endfunction
" }}}
" Plugin API: SpaceVim#plugins#flygrep#lineNr() {{{
function! SpaceVim#plugins#flygrep#lineNr() abort
if getline(1) ==# ''
return ''
@ -301,3 +322,4 @@ function! SpaceVim#plugins#flygrep#lineNr() abort
return line('.') . '/' . line('$')
endif
endfunction
" }}}

View File

@ -3,6 +3,7 @@ title: SpaceVim release v0.1.0
categories: changelog
excerpt: "Here you can check what has been done so far."
type: NewsArticle
comments: true
---
# [Changelogs](https://spacevim.org/development#changelog) > SpaceVim release v0.1.0

View File

@ -4,6 +4,7 @@ categories: tutorials
excerpt: "I am a vimmer and a java developer. Here are some useful plugins for developing java in vim/neovim."
redirect_from: "/2017/02/11/use-vim-as-a-java-ide.html"
type: BlogPosting
comments: true
---
# [Blogs](https://spacevim.org/community#blogs) > Use Vim as a Java IDE

View File

@ -2,6 +2,7 @@
title: "VIM 8 新特性之旅: 定时器 (timers)"
categories: tutorials_cn
excerpt: "VIM 8 新特性之旅系列教程 - 定时器, 介绍定时器具体使用方法以及场景"
comments: true
---
## 定时器( timer

View File

@ -2,6 +2,7 @@
title: "Install vim/neovim with python support"
categories: tutorials
excerpt: "How to build vim or neovim from source with python enabled?"
comments: true
---

View File

@ -3,6 +3,7 @@ title: SpaceVim release v0.2.0
categories: changelog
excerpt: "Mnemonic key bindings in SpaceVim"
type: NewsArticle
comments: true
---
# [Changelogs](https://spacevim.org/development#changelog) > SpaceVim release v0.2.0

View File

@ -3,6 +3,7 @@ title: "Mnemonic key bindings navigation"
categories: feature
excerpt: "Key bindings are organized using mnemonic prefixes like b for buffer, p for project, s for search, h for help, etc…"
image: https://user-images.githubusercontent.com/13142418/31550099-c8173ff8-b062-11e7-967e-6378a9c3b467.gif
comments: true
---
# Mnemonic key bindings navigation

View File

@ -2,6 +2,7 @@
title: Newsletter #1 - A New Hope
categories: newsletter
excerpt: "A new hope: turn vim/neovim to be an IDE for most languages"
comments: true
---
# [newsletter](https://spacevim.org/development#newsletter) > A New Hope

View File

@ -3,6 +3,7 @@ title: SpaceVim release v0.3.0
categories: changelog
excerpt: "Here you can check what has been done so far."
type: NewsArticle
comments: true
---
# [Changelogs](https://spacevim.org/development#changelog) > SpaceVim release v0.3.0

View File

@ -3,6 +3,7 @@ title: SpaceVim release v0.3.1
categories: changelog
excerpt: "Here you can check what has been done so far."
type: NewsArticle
comments: true
---
# [Changelogs](https://spacevim.org/development#changelog) > SpaceVim release v0.3.1

View File

@ -3,6 +3,7 @@ title: SpaceVim release v0.4.0
categories: changelog
excerpt: "Here you can check what has been done so far."
type: NewsArticle
comments: true
---
# [Changelogs](https://spacevim.org/development#changelog) > SpaceVim release v0.4.0

View File

@ -3,6 +3,7 @@ title: "Asynchronous plugin manager"
categories: feature
excerpt: ""
image: https://user-images.githubusercontent.com/13142418/34907332-903ae968-f842-11e7-8ac9-07fcc9940a53.gif
comments: true
---

View File

@ -2,6 +2,7 @@
title: "VIM 中 ctrl 相关的组合键的使用"
categories: tutorials_cn
excerpt: "枚举 Vim 内置的 Ctrl 组合键功能,以及终端下的一些区别"
comments: true
---
# Vim 中 ctrl 组合键的使用

View File

@ -3,6 +3,7 @@ title: SpaceVim release v0.5.0
categories: changelog
excerpt: "Many new features come out with v0.5.0"
type: NewsArticle
comments: true
---
# [Changelogs](https://spacevim.org/development#changelog) > SpaceVim release v0.5.0

View File

@ -3,6 +3,7 @@ title: "Help description for key bindings"
categories: feature
excerpt: "Key bindings are defined with help description, this feature is for getting Help description and jump to the position where the key bindings is defined."
image: https://user-images.githubusercontent.com/13142418/34907415-c2cf7e88-f843-11e7-92d3-ef0f9b1b72ae.gif
comments: true
---
# Mnemonic key bindings navigation

View File

@ -2,6 +2,7 @@
title: "An async code runner in SpaceVim"
categories: tutorials
excerpt: "A better way for running code with in vim, more info about the command status, will not move cursor from code buffer."
comments: true
---
# [Blogs](https://spacevim.org/community#blogs) > An async code runner in SpaceVim

View File

@ -4,6 +4,7 @@ categories: changelog
excerpt: "Many new features come out with v0.6.0"
type: NewsArticle
image: https://user-images.githubusercontent.com/13142418/33793078-3446cb6e-dc76-11e7-9998-376a355557a4.png
comments: true
---
# [Changelogs](https://spacevim.org/development#changelog) > SpaceVim release v0.6.0

View File

@ -3,6 +3,7 @@ title: "Newsletter #2 - Never lost, Never give up"
categories: newsletter
excerpt: "We know exactly what is the purpose of SpaceVim, and we keep trying to get it, never get lost, never give up..."
image: https://user-images.githubusercontent.com/13142418/34612367-18fdf2d6-f1ef-11e7-885e-5e82613c1444.png
comments: true
---
# [newsletter](https://spacevim.org/development#newsletter) > Never lost, Never give up