Skip to content

Commit

Permalink
Merge branch 'v1.0'
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
	plugin/ack.vim
  • Loading branch information
kassio committed Apr 16, 2014
2 parents ad919da + 4cee6b3 commit 08be6a8
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 162 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,19 @@ check out the docs for the Perl script 'ack', for obvious reasons:
### Gotchas

Some characters have special meaning, and need to be escaped your search
pattern. For instance, '#'. You have to escape it like this `:Ack '\\\#define
foo'` to search for '#define foo'. (From blueyed in issue #5.)
pattern. For instance, '#'. You have to escape it like this :Ack '\\\#define
foo' to search for #define foo. (From blueyed in issue #5.)

## RoadMap
## Changelog

Goals for 1.0:
### 1.0

* Improve documentation, list all options and shortcuts
* Remove support to ack 1.x
* Start to use a Changelog
* Use `autoload` directory to define functions, instead of `plugin`.
* Add option to auto fold the results(`g:ack_autofold_results`)
* Improve documentation, list all options and shortcuts
* Improve highlight option to work when passes directories or use quotes.
* Add g:ack_mapping
* Add g:ack_default_options
* Add a help toggle `?`(like NERDTree)
* Add option to open all files from result list
143 changes: 143 additions & 0 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
function! ack#Ack(cmd, args)
redraw
echo "Searching ..."

" If no pattern is provided, search for the word under the cursor
if empty(a:args)
let l:grepargs = expand("<cword>")
else
let l:grepargs = a:args . join(a:000, ' ')
end
let l:ackprg_run = g:ackprg

" Format, used to manage column jump
if a:cmd =~# '-g$'
let g:ackformat="%f"
let l:ackprg_run = substitute(l:ackprg_run, '-H\|--column', '', 'g')
else
let g:ackformat="%f:%l:%c:%m,%f:%l:%m"
endif

let grepprg_bak = &grepprg
let grepformat_bak = &grepformat
let &grepprg=l:ackprg_run
let &grepformat=g:ackformat

try
" NOTE: we escape special chars, but not everything using shellescape to
" allow for passing arguments etc
silent execute a:cmd . " " . escape(l:grepargs, '|#%')
finally
let &grepprg=grepprg_bak
let &grepformat=grepformat_bak
endtry

if a:cmd =~# '^l'
let s:handler = g:ack_lhandler
let s:apply_mappings = g:ack_apply_lmappings
let s:close_cmd = ':lclose<CR>'
else
let s:handler = g:ack_qhandler
let s:apply_mappings = g:ack_apply_qmappings
let s:close_cmd = ':cclose<CR>'
endif

call ack#show_results()
call <SID>highlight(l:grepargs)

redraw!
endfunction

function! ack#show_results()
execute s:handler
call <SID>apply_maps()
endfunction

function! s:apply_maps()
let g:ack_mappings.q = s:close_cmd

execute "nnoremap <buffer> <silent> ? :call ack#quick_help()<CR>"

if s:apply_mappings && &ft == "qf"
if g:ack_autoclose
for key_map in items(g:ack_mappings)
execute printf("nnoremap <buffer> <silent> %s %s", get(key_map, 0), get(key_map, 1) . s:close_cmd)
endfor
execute "nnoremap <buffer> <silent> <CR> <CR>" . s:close_cmd
else
for key_map in items(g:ack_mappings)
execute printf("nnoremap <buffer> <silent> %s %s", get(key_map, 0), get(key_map, 1))
endfor
endif

if exists("g:ackpreview") " if auto preview in on, remap j and k keys
execute "nnoremap <buffer> <silent> j j<CR><C-W><C-W>"
execute "nnoremap <buffer> <silent> k k<CR><C-W><C-W>"
endif
endif
endfunction

function! ack#quick_help()
execute "edit " . globpath(&rtp, "doc/ack_quick_help.txt")

silent normal gg
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal noswapfile
setlocal nobuflisted
setlocal nomodifiable
setlocal filetype=help
setlocal nonumber
setlocal norelativenumber
setlocal nowrap
setlocal foldlevel=20
setlocal foldmethod=diff
nnoremap <buffer> <silent> ? :q!<CR>:call ack#show_results()<CR>
endfunction

function! s:highlight(args)
if !g:ackhighlight
return
endif

let @/ = matchstr(a:args, "\\v\\w+\>|['\"]\\zs[^\"]+\\ze['\"]")
setlocal hlsearch
call feedkeys(":let v:hlsearch=1 \| echo \<CR>", "n")
endfunction

function! ack#AckFromSearch(cmd, args)
let search = getreg('/')
" translate vim regular expression to perl regular expression.
let search = substitute(search, '\(\\<\|\\>\)', '\\b', 'g')
call ack#Ack(a:cmd, '"' . search . '" ' . a:args)
endfunction

function! s:GetDocLocations()
let dp = ''
for p in split(&rtp, ',')
let p = p . '/doc/'
if isdirectory(p)
let dp = p . '*.txt ' . dp
endif
endfor

return dp
endfunction

function! ack#AckHelp(cmd, args)
let args = a:args . ' ' . s:GetDocLocations()
call ack#Ack(a:cmd, args)
endfunction

function! ack#AckWindow(cmd, args)
let files = tabpagebuflist()
" remove duplicated filenames (files appearing in more than one window)
let files = filter(copy(sort(files)), 'index(files,v:val,v:key+1)==-1')
call map(files, "bufname(v:val)")
" remove unnamed buffers as quickfix (empty strings before shellescape)
call filter(files, 'v:val != ""')
" expand to full path (avoid problems with cd/lcd in au QuickFixCmdPre)
let files = map(files, "shellescape(fnamemodify(v:val, ':p'))")
let args = a:args . ' ' . join(files)
call ack#Ack(a:cmd, args)
endfunction
106 changes: 99 additions & 7 deletions doc/ack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,92 @@ CONFIGURATION *ack-configuration*

*g:ackprg*
g:ackprg
Default for ubuntu: "ack-grep -H --nocolor --nogroup --column"
Default for other systems: "ack -H --nocolor --nogroup --column"
Default for ubuntu: "ack-grep"
Default for other systems: "ack"

Use this option to specify the ack command and its options

Example:
>
let g:ackprg = "other-bin-ack"
<

g:ack_default_options*
g:ack_default_options
Default: " -s -H --nocolor --nogroup --column"

Use this option to specify the options used by ack

Example:
>
let g:ackprg =
\ "ack -H --nocolor --nogroup --column --smart-case --follow"
\ " -s -H --nocolor --nogroup --column --smart-case --follow"
<

*g:ack_apply_qmappings*
g:ack_apply_qmappings
Default: 1

This option enable mappings on quickview window.

*g:ack_apply_lmappings*
g:ack_apply_lmappings
Default: 1

This option enable mappings on Location list window.

*g:ack_mappings*
g:ack_mappings
Default: {
\ "t": "<C-W><CR><C-W>T",
\ "T": "<C-W><CR><C-W>TgT<C-W>j",
\ "o": "<CR>",
\ "O": "<CR><C-W><C-W>:ccl<CR>",
\ "go": "<CR><C-W>j",
\ "h": "<C-W><CR><C-W>K",
\ "H": "<C-W><CR><C-W>K<C-W>b",
\ "v": "<C-W><CR><C-W>H<C-W>b<C-W>J<C-W>t",
\ "gv": "<C-W><CR><C-W>H<C-W>b<C-W>J" }

This option list all maps create on quickfix/Location list window.

Example, if you want to open the result in the middle of the screen:
>
let g:ack_mappings = { "o": "<CR>zz" }
<

*g:ack_qhandler*
g:ack_qhandler
Default: "botright copen"

Command to open the quickview window.

If you want to open a quickview window with 30 lines you can do:
>
let g:ack_qhandler = "botright copen 30"
<

*g:ack_lhandler*
g:ack_lhandler
Default: "botright lopen"

Command to open the Location list window.

If you want to open a Location list window with 30 lines you can do:
>
let g:ack_lhandler = "botright lopen 30"
<

*g:ackhighlight*

g:ackhighlight
Default: 0

Use this option to highlight the searched term.

Example:
>
let g:ackhighlight = 1
<

*g:ack_autoclose*
Expand All @@ -99,16 +176,31 @@ Example:
let g:ack_autoclose = 1
<

*g:ackhighlight*
*g:ack_autofold_results*

g:ackhighlight
g:ack_autofold_results
Default: 0

Use this option to highlight the searched term
Use this option to fold the results in quickfix by file name. Only the current
fold will be open by default and while you press 'j' and 'k' to move between the
results if you hit other fold the last one will be closed and the current will
be open.

Example:
>
let g:ackhighlight
let g:ack_autofold_results = 1
<

*g:ackpreview*

g:ackpreview
Default: 0

Use this option to automagically open the file with 'j' or 'k'.

Example:
>
let g:ackpreview = 1
<

*g:ackpreview*
Expand Down
14 changes: 14 additions & 0 deletions doc/ack_quick_help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
==== ack.vim quick help ===============

*?:* Show this help
*t:* Open in a new tab
*T:* Open in a new tab silently
*o:* Open
*O:* Open and close result window
*go:* Preview
*h:* Horizontal open
*H:* Horizontal open silently
*v:* Vertical open
*gv:* Vertical open silently

========================================
9 changes: 9 additions & 0 deletions ftplugin/qf.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if g:ack_autofold_results
setlocal foldlevel=0
setlocal foldmethod=expr
setlocal foldexpr=matchstr(getline(v:lnum),'^[^\|]\\+')==#matchstr(getline(v:lnum+1),'^[^\|]\\+')?1:'<1'
setlocal foldenable
setlocal foldclose=all
setlocal foldopen=all
nnoremap <buffer> j jzz
endif
Loading

0 comments on commit 08be6a8

Please sign in to comment.