Skip to content

Commit

Permalink
rg replaces ag
Browse files Browse the repository at this point in the history
  • Loading branch information
cheme committed Apr 5, 2017
1 parent 9bb24d3 commit 293cd91
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 27 deletions.
86 changes: 61 additions & 25 deletions .config/nvim/autoload/plug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
" " Any valid git URL is allowed
" Plug 'https://github.com/junegunn/vim-github-dashboard.git'
"
" " Group dependencies, vim-snippets depends on ultisnips
" " Multiple Plug commands can be written in a single line using | separators
" Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
"
" " On-demand loading
Expand All @@ -40,7 +40,7 @@
" " Unmanaged plugin (manually installed and updated)
" Plug '~/my-prototype-plugin'
"
" " Add plugins to &runtimepath
" " Initialize plugin system
" call plug#end()
"
" Then reload .vimrc and :PlugInstall to install plugins.
Expand All @@ -61,7 +61,7 @@
" More information: https://github.com/junegunn/vim-plug
"
"
" Copyright (c) 2016 Junegunn Choi
" Copyright (c) 2017 Junegunn Choi
"
" MIT License
"
Expand Down Expand Up @@ -225,6 +225,7 @@ function! plug#end()
endif
call add(s:triggers[name].map, cmd)
elseif cmd =~# '^[A-Z]'
let cmd = substitute(cmd, '!*$', '', '')
if exists(':'.cmd) != 2
call s:assoc(lod.cmd, cmd, name)
endif
Expand Down Expand Up @@ -425,7 +426,10 @@ function! s:dobufread(names)
let path = s:rtp(g:plugs[name]).'/**'
for dir in ['ftdetect', 'ftplugin']
if len(finddir(dir, path))
return s:doautocmd('BufRead')
if exists('#BufRead')
doautocmd BufRead
endif
return
endif
endfor
endfor
Expand Down Expand Up @@ -617,10 +621,10 @@ function! s:syntax()
syn match plugTag /(tag: [^)]\+)/
syn match plugInstall /\(^+ \)\@<=[^:]*/
syn match plugUpdate /\(^* \)\@<=[^:]*/
syn match plugCommit /^ \X*[0-9a-f]\{7} .*/ contains=plugRelDate,plugEdge,plugTag
syn match plugCommit /^ \X*[0-9a-f]\{7,9} .*/ contains=plugRelDate,plugEdge,plugTag
syn match plugEdge /^ \X\+$/
syn match plugEdge /^ \X*/ contained nextgroup=plugSha
syn match plugSha /[0-9a-f]\{7}/ contained
syn match plugSha /[0-9a-f]\{7,9}/ contained
syn match plugRelDate /([^)]*)$/ contained
syn match plugNotLoaded /(not loaded)$/
syn match plugError /^x.*/
Expand Down Expand Up @@ -750,7 +754,7 @@ function! s:prepare(...)
for k in ['<cr>', 'L', 'o', 'X', 'd', 'dd']
execute 'silent! unmap <buffer>' k
endfor
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline modifiable
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline modifiable nospell
setf vim-plug
if exists('g:syntax_on')
call s:syntax()
Expand Down Expand Up @@ -816,6 +820,10 @@ function! s:do(pull, force, todo)
let type = type(spec.do)
if type == s:TYPE.string
if spec.do[0] == ':'
if !get(s:loaded, name, 0)
let s:loaded[name] = 1
call s:reorg_rtp()
endif
call s:load_plugin(spec)
try
execute spec.do[1:]
Expand Down Expand Up @@ -860,7 +868,7 @@ function! s:checkout(spec)
let output = s:system('git rev-parse HEAD', a:spec.dir)
if !v:shell_error && !s:hash_match(sha, s:lines(output)[0])
let output = s:system(
\ 'git fetch --depth 999999 && git checkout '.s:esc(sha), a:spec.dir)
\ 'git fetch --depth 999999 && git checkout '.s:esc(sha).' --', a:spec.dir)
endif
return output
endfunction
Expand Down Expand Up @@ -918,7 +926,8 @@ function! s:check_ruby()
endfunction

function! s:update_impl(pull, force, args) abort
let args = copy(a:args)
let sync = index(a:args, '--sync') >= 0 || has('vim_starting')
let args = filter(copy(a:args), 'v:val != "--sync"')
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
\ remove(args, -1) : get(g:, 'plug_threads', 16)

Expand Down Expand Up @@ -954,7 +963,7 @@ function! s:update_impl(pull, force, args) abort

let use_job = s:nvim || s:vim8
let python = (has('python') || has('python3')) && !use_job
let ruby = has('ruby') && !use_job && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && s:check_ruby()
let ruby = has('ruby') && !use_job && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && threads > 1 && s:check_ruby()

let s:update = {
\ 'start': reltime(),
Expand All @@ -977,6 +986,10 @@ function! s:update_impl(pull, force, args) abort
let s:clone_opt = get(g:, 'plug_shallow', 1) ?
\ '--depth 1' . (s:git_version_requirement(1, 7, 10) ? ' --no-single-branch' : '') : ''

if has('win32unix')
let s:clone_opt .= ' -c core.eol=lf -c core.autocrlf=input'
endif

" Python version requirement (>= 2.7)
if python && !has('python3') && !ruby && !use_job && s:update.threads > 1
redir => pyv
Expand Down Expand Up @@ -1019,7 +1032,7 @@ function! s:update_impl(pull, force, args) abort
endtry
else
call s:update_vim()
while use_job && has('vim_starting')
while use_job && sync
sleep 100m
if s:update.fin
break
Expand Down Expand Up @@ -1058,11 +1071,11 @@ function! s:update_finish()
endif
endif
call s:log4(name, 'Checking out '.tag)
let out = s:system('git checkout -q '.s:esc(tag).' 2>&1', spec.dir)
let out = s:system('git checkout -q '.s:esc(tag).' -- 2>&1', spec.dir)
else
let branch = s:esc(get(spec, 'branch', 'master'))
call s:log4(name, 'Merging origin/'.branch)
let out = s:system('git checkout -q '.branch.' 2>&1'
let out = s:system('git checkout -q '.branch.' -- 2>&1'
\. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only origin/'.branch.' 2>&1')), spec.dir)
endif
if !v:shell_error && filereadable(spec.dir.'/.gitmodules') &&
Expand Down Expand Up @@ -1152,7 +1165,7 @@ function! s:job_cb(fn, job, ch, data)
call call(a:fn, [a:job, a:data])
endfunction

function! s:nvim_cb(job_id, data, event) abort
function! s:nvim_cb(job_id, data, event) dict abort
return a:event == 'stdout' ?
\ s:job_cb('s:job_out_cb', self, 0, join(a:data, "\n")) :
\ s:job_cb('s:job_exit_cb', self, 0, a:data)
Expand Down Expand Up @@ -1180,7 +1193,7 @@ function! s:spawn(name, cmd, opts)
\ 'Invalid arguments (or job table is full)']
endif
elseif s:vim8
let jid = job_start(argv, {
let jid = job_start(s:is_win ? join(argv, ' ') : argv, {
\ 'out_cb': function('s:job_cb', ['s:job_out_cb', job]),
\ 'exit_cb': function('s:job_cb', ['s:job_exit_cb', job]),
\ 'out_mode': 'raw'
Expand Down Expand Up @@ -1763,6 +1776,7 @@ function! s:update_ruby()
tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1
nthr = VIM::evaluate('s:update.threads').to_i
maxy = VIM::evaluate('winheight(".")').to_i
vim7 = VIM::evaluate('v:version').to_i <= 703 && RUBY_PLATFORM =~ /darwin/
cd = iswin ? 'cd /d' : 'cd'
tot = VIM::evaluate('len(s:update.todo)') || 0
bar = ''
Expand Down Expand Up @@ -1852,11 +1866,17 @@ function! s:update_ruby()
main = Thread.current
threads = []
watcher = Thread.new {
require 'io/console' # >= Ruby 1.9
nil until IO.console.getch == 3.chr
if vim7
while VIM::evaluate('getchar(1)')
sleep 0.1
end
else
require 'io/console' # >= Ruby 1.9
nil until IO.console.getch == 3.chr
end
mtx.synchronize do
running = false
threads.each { |t| t.raise Interrupt }
threads.each { |t| t.raise Interrupt } unless vim7
end
threads.each { |t| t.join rescue nil }
main.kill
Expand Down Expand Up @@ -2012,10 +2032,21 @@ function! s:git_validate(spec, check_branch)
\ branch, a:spec.branch)
endif
if empty(err)
let commits = len(s:lines(s:system(printf('git rev-list origin/%s..HEAD', a:spec.branch), a:spec.dir)))
if !v:shell_error && commits
let err = join([printf('Diverged from origin/%s by %d commit(s).', a:spec.branch, commits),
\ 'Reinstall after PlugClean.'], "\n")
let [ahead, behind] = split(s:lastline(s:system(printf(
\ 'git rev-list --count --left-right HEAD...origin/%s',
\ a:spec.branch), a:spec.dir)), '\t')
if !v:shell_error && ahead
if behind
" Only mention PlugClean if diverged, otherwise it's likely to be
" pushable (and probably not that messed up).
let err = printf(
\ "Diverged from origin/%s (%d commit(s) ahead and %d commit(s) behind!\n"
\ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', a:spec.branch, ahead, behind)
else
let err = printf("Ahead of origin/%s by %d commit(s).\n"
\ .'Cannot update until local changes are pushed.',
\ a:spec.branch, ahead)
endif
endif
endif
endif
Expand Down Expand Up @@ -2258,7 +2289,7 @@ function! s:preview_commit()
let b:plug_preview = !s:is_preview_window_open()
endif

let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-f]\{7}')
let sha = matchstr(getline('.'), '^ \X*\zs[0-9a-f]\{7,9}')
if empty(sha)
return
endif
Expand All @@ -2276,7 +2307,12 @@ function! s:preview_commit()
wincmd P
endif
setlocal previewwindow filetype=git buftype=nofile nobuflisted modifiable
execute 'silent %!cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha
try
let [sh, shrd] = s:chsh(1)
execute 'silent %!cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha
finally
let [&shell, &shellredir] = [sh, shrd]
endtry
setlocal nomodifiable
nnoremap <silent> <buffer> q :q<cr>
wincmd p
Expand Down Expand Up @@ -2358,7 +2394,7 @@ function! s:revert()
return
endif

call s:system('git reset --hard HEAD@{1} && git checkout '.s:esc(g:plugs[name].branch), g:plugs[name].dir)
call s:system('git reset --hard HEAD@{1} && git checkout '.s:esc(g:plugs[name].branch).' --', g:plugs[name].dir)
setlocal modifiable
normal! "_dap
setlocal nomodifiable
Expand Down
5 changes: 3 additions & 2 deletions .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,9 @@ let NERDTreeMapCWD="gd"
let NERDTreeMapOpenVSplit="gs"

"silversearche custo
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor\ --column
if executable('rg')
set grepprg=rg\ --no-heading\ --color\ never\ --column
" set grepprg=ag\ --nogroup\ --nocolor\ --column
let g:ctrlp_use_caching = 0
nnoremap K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR>
" command -nargs=+ -complete=file -bar Ag silent! grep! <args>|cwindow|redraw!
Expand Down

0 comments on commit 293cd91

Please sign in to comment.