From 53e835f51020c44d5864725b0bbc9fe65b07c2ef Mon Sep 17 00:00:00 2001 From: Sai Kalidindi Date: Wed, 14 Oct 2015 00:31:45 -0700 Subject: [PATCH 1/5] remove redundant apply_mappings check --- autoload/ag.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ag.vim b/autoload/ag.vim index 6703396b..a0ce7d8c 100644 --- a/autoload/ag.vim +++ b/autoload/ag.vim @@ -165,7 +165,7 @@ function! ag#Ag(cmd, args) " J Slam the quickfix/location list window against the bottom edge " :exe printf(":normal %d\c-w>_", b:height) Restore the quickfix/location list window's height from before we opened the match - if g:ag_mapping_message && l:apply_mappings + if g:ag_mapping_message echom "ag.vim keys: q=quit /e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same" endif endif From 43a31980db3de75e60469fbdfad1716e3ac80efb Mon Sep 17 00:00:00 2001 From: Sai Kalidindi Date: Wed, 14 Oct 2015 00:34:53 -0700 Subject: [PATCH 2/5] abstract matches-window key mapping to helper fn The helper `ag#AgSetDefaultMappings` takes one argument, `matches_window_prefix`, which is determined by whether the matches window is a location list or quickfix window. Custom keymaps can now be given by setting the `g:ag_lmapping_func` and `g:ag_qmapping_func` options. --- autoload/ag.vim | 54 ++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/autoload/ag.vim b/autoload/ag.vim index a0ce7d8c..b4b88219 100644 --- a/autoload/ag.vim +++ b/autoload/ag.vim @@ -43,6 +43,14 @@ if !exists("g:ag_lhandler") let g:ag_lhandler="botright lopen" endif +if !exists("g:ag_qmapping_func") + let g:ag_qmapping_func="call ag#AgSetDefaultMappings('c')" " we're using the quickfix window +endif + +if !exists("g:ag_lmapping_func") + let g:ag_lmapping_func="call ag#AgSetDefaultMappings('l')" " we're using the location list +endif + if !exists("g:ag_mapping_message") let g:ag_mapping_message=1 endif @@ -51,6 +59,28 @@ if !exists("g:ag_working_path_mode") let g:ag_working_path_mode = 'c' endif +function! ag#AgSetDefaultMappings(matches_window_prefix) + nnoremap h K + nnoremap H Kb + nnoremap o + nnoremap t T + nnoremap T TgT + nnoremap v HbJt + + exe 'nnoremap e :' . a:matches_window_prefix .'close' + exe 'nnoremap go :' . a:matches_window_prefix . 'open' + exe 'nnoremap q :' . a:matches_window_prefix . 'close' + + exe 'nnoremap gv :let b:height=winheight(0)H:' . a:matches_window_prefix . 'openJ:exe printf(":normal %d\c-w>_", b:height)' + " Interpretation: + " :let b:height=winheight(0) Get the height of the quickfix/location list window + " Open the current item in a new split + " H Slam the newly opened window against the left edge + " :copen -or- :lopen Open either the quickfix window or the location list (whichever we were using) + " J Slam the quickfix/location list window against the bottom edge + " :exe printf(":normal %d\c-w>_", b:height) Restore the quickfix/location list window's height from before we opened the match +endfunction + function! ag#AgBuffer(cmd, args) let l:bufs = filter(range(1, bufnr('$')), 'buflisted(v:val)') let l:files = [] @@ -128,11 +158,11 @@ function! ag#Ag(cmd, args) if a:cmd =~# '^l' && l:match_count exe g:ag_lhandler let l:apply_mappings = g:ag_apply_lmappings - let l:matches_window_prefix = 'l' " we're using the location list + let l:ag_mapping_func = g:ag_lmapping_func elseif l:match_count exe g:ag_qhandler let l:apply_mappings = g:ag_apply_qmappings - let l:matches_window_prefix = 'c' " we're using the quickfix window + let l:ag_mapping_func = g:ag_qmapping_func endif " If highlighting is on, highlight the search keyword. @@ -145,25 +175,7 @@ function! ag#Ag(cmd, args) if l:match_count if l:apply_mappings - nnoremap h K - nnoremap H Kb - nnoremap o - nnoremap t T - nnoremap T TgT - nnoremap v HbJt - - exe 'nnoremap e :' . l:matches_window_prefix .'close' - exe 'nnoremap go :' . l:matches_window_prefix . 'open' - exe 'nnoremap q :' . l:matches_window_prefix . 'close' - - exe 'nnoremap gv :let b:height=winheight(0)H:' . l:matches_window_prefix . 'openJ:exe printf(":normal %d\c-w>_", b:height)' - " Interpretation: - " :let b:height=winheight(0) Get the height of the quickfix/location list window - " Open the current item in a new split - " H Slam the newly opened window against the left edge - " :copen -or- :lopen Open either the quickfix window or the location list (whichever we were using) - " J Slam the quickfix/location list window against the bottom edge - " :exe printf(":normal %d\c-w>_", b:height) Restore the quickfix/location list window's height from before we opened the match + exe l:ag_mapping_func if g:ag_mapping_message echom "ag.vim keys: q=quit /e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same" From 086456eff05b9cdd1c07c19663d59aac329e8009 Mon Sep 17 00:00:00 2001 From: Sai Kalidindi Date: Wed, 14 Oct 2015 01:09:43 -0700 Subject: [PATCH 3/5] allow custom message text The option `g:ag_mapping_message_text` can now be used to display a custom message when the location list / quickfix window opens. --- autoload/ag.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autoload/ag.vim b/autoload/ag.vim index b4b88219..f20aca1a 100644 --- a/autoload/ag.vim +++ b/autoload/ag.vim @@ -55,6 +55,10 @@ if !exists("g:ag_mapping_message") let g:ag_mapping_message=1 endif +if !exists("g:ag_mapping_message_text") + let g:ag_mapping_message_text="ag.vim keys: q=quit /e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same" +endif + if !exists("g:ag_working_path_mode") let g:ag_working_path_mode = 'c' endif @@ -178,7 +182,7 @@ function! ag#Ag(cmd, args) exe l:ag_mapping_func if g:ag_mapping_message - echom "ag.vim keys: q=quit /e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same" + echom g:ag_mapping_message_text endif endif else From b5e9e0332ce66b335379342d297c31dccf476d6c Mon Sep 17 00:00:00 2001 From: Sai Kalidindi Date: Wed, 14 Oct 2015 12:41:27 -0700 Subject: [PATCH 4/5] update doc for custom mapping options --- doc/ag.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/ag.txt b/doc/ag.txt index e702c291..4f1f226e 100644 --- a/doc/ag.txt +++ b/doc/ag.txt @@ -138,6 +138,18 @@ window is opened, or what size it is. Example: > let g:ag_qhandler="copen 20" < + *g:ag_lmapping_func* +A custom command used to set key mappings for the location list. Default: +"call ag#AgSetDefaultMappings('l')". Example: > + let g:ag_qhandler="call AgSetMyCustomMappings()" +< + + + *g:ag_qmapping_func* +A custom command used to set key mappings for the quickfix window. Default: +"call ag#AgSetDefaultMappings('c')". Example: > + let g:ag_qhandler="call AgSetMyCustomMappings()" +< *g:ag_mapping_message* Whether or not to show the message explaining the extra mappings that are added to the results list this plugin populates. This message is not shown if @@ -147,7 +159,7 @@ the mappings are not applied (see |g:ag_apply_qmappings| and < ============================================================================== -MAPPINGS *ag-mappings* +DEFAULT MAPPINGS *ag-mappings* The following keyboard shortcuts are available in the quickfix window: From d0475d99c76a280b72fc198d0aed79a903793213 Mon Sep 17 00:00:00 2001 From: Sai Kalidindi Date: Wed, 14 Oct 2015 12:41:55 -0700 Subject: [PATCH 5/5] update doc for custom message text option --- doc/ag.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/ag.txt b/doc/ag.txt index 4f1f226e..fdea9fcd 100644 --- a/doc/ag.txt +++ b/doc/ag.txt @@ -154,10 +154,18 @@ A custom command used to set key mappings for the quickfix window. Default: Whether or not to show the message explaining the extra mappings that are added to the results list this plugin populates. This message is not shown if the mappings are not applied (see |g:ag_apply_qmappings| and -|g:ag_apply_lmappings| for more info. Default 1. Example: > +|g:ag_apply_lmappings| for more info). Default 1. Example: > let g:ag_mapping_message=0 < + *g:ag_mapping_message_text* +A custom message string to display when the results list window opens +(see |g:ag_mapping_message| and for more info). Default "ag.vim keys: q=quit +/e/t/h/v=enter/edit/tab/split/vsplit go/T/H/gv=preview versions of same". +Example: > + let g:ag_mapping_message="Press q to close results list" +< + ============================================================================== DEFAULT MAPPINGS *ag-mappings*