Skip to content

Commit

Permalink
ability to customize window colors
Browse files Browse the repository at this point in the history
  • Loading branch information
pechorin committed Mar 9, 2020
1 parent 11c0fc9 commit 330b535
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 72 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,33 +120,34 @@ let g:any_jump_search_prefered_engine = 'rg'
" - 'filename_last'
let g:any_jump_results_ui_style = 'filename_first'
" Any-jump window size & position options
let g:any_jump_window_width_ratio = 0.6
let g:any_jump_window_height_ratio = 0.6
let g:any_jump_window_top_offset = 4
" Customize any-jump colors types
let g:any_jump_colors = {
\"plain_text": "Comment",
\"preview": "Comment",
\"preview_keyword": "Operator",
\"heading_text": "Function",
\"heading_keyword": "Identifier",
\"group_text": "Comment",
\"group_name": "Function",
\"more_button": "Operator",
\"more_explain": "Comment",
\"result_line_number": "Comment",
\"result_text": "Statement",
\"result_path": "String",
\"help": "Comment"
\}
" Disable default any-jump keybindings (default: 0)
let g:any_jump_disable_default_keybindings = 1
" Remove comments line from search results (default: 1)
let g:any_jump_remove_comments_from_results = 1
" Cursor keyword selection mode
"
" on line:
"
" "MyNamespace::MyClass"
" ^
"
" then cursor is on MyClass word
"
" 'word' - will match 'MyClass'
" 'full' - will match 'MyNamespace::MyClass'
" DEPRECATED:
let g:any_jump_keyword_match_cursor_mode', 'word'
" Add ignore files
call g:AnyJumpAddIgnoredFile('*.tmp')
call g:AnyJumpAddIgnoredFile('*.temp')
Expand Down
62 changes: 32 additions & 30 deletions autoload/internal_buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -398,23 +398,23 @@ fu! s:InternalBuffer.GrepResultToItems(gr, current_idx, layer) dict abort

if g:any_jump_list_numbers
let prefix_text = a:current_idx + 1
let prefix = self.CreateItem("link", prefix_text, "Comment", options)
let prefix = self.CreateItem("link", prefix_text, g:AnyJumpGetColor('result_line_number'), options)

call add(items, prefix)
endif

if g:any_jump_results_ui_style == 'filename_first'
let path_text = '' . gr.path . ":" . gr.line_number
let matched_text = self.CreateItem("link", gr.text, "Statement", original_link_options)
let file_path = self.CreateItem("link", path_text, "String", options)
let matched_text = self.CreateItem("link", gr.text, g:AnyJumpGetColor('result_text'), original_link_options)
let file_path = self.CreateItem("link", path_text, g:AnyJumpGetColor('result_path'), options)

call add(items, matched_text)
call add(items, file_path)

elseif g:any_jump_results_ui_style == 'filename_last'
let path_text = gr.path . ":" . gr.line_number
let matched_text = self.CreateItem("link", "" . gr.text, "Statement", original_link_options)
let file_path = self.CreateItem("link", path_text, "String", options)
let matched_text = self.CreateItem("link", "" . gr.text, g:AnyJumpGetColor('result_text'), original_link_options)
let file_path = self.CreateItem("link", path_text, g:AnyJumpGetColor('result_path'), options)

call add(items, file_path)
call add(items, matched_text)
Expand All @@ -434,11 +434,11 @@ fu! s:InternalBuffer.GrepResultToGroupedItems(gr, current_idx, layer) dict abort
\"layer": a:layer, "original_link": v:true }

let prefix_text = gr.line_number
let prefix = self.CreateItem("link", prefix_text, "Comment", options)
let prefix = self.CreateItem("link", prefix_text, g:AnyJumpGetColor('result_line_number'), options)

call add(items, prefix)

let matched_text = self.CreateItem("link", gr.text, "Statement", original_link_options)
let matched_text = self.CreateItem("link", gr.text, g:AnyJumpGetColor('result_text'), original_link_options)

call add(items, matched_text)

Expand All @@ -464,9 +464,9 @@ fu! s:InternalBuffer.RenderUiUsagesList(grep_results, start_ln) dict abort
endif

call self.AddLineAt([
\self.CreateItem("text", ">", "Function", {'layer': 'usages'}),
\self.CreateItem("text", self.keyword, "Identifier", {'layer': 'usages'}),
\self.CreateItem("text", len(self.usages_grep_results) . " references", "Function", {'layer': 'usages'}),
\self.CreateItem("text", ">", g:AnyJumpGetColor('heading_text'), {'layer': 'usages'}),
\self.CreateItem("text", self.keyword, g:AnyJumpGetColor('heading_keyword'), {'layer': 'usages'}),
\self.CreateItem("text", len(self.usages_grep_results) . " references", g:AnyJumpGetColor('heading_text'), {'layer': 'usages'}),
\], start_ln)


Expand Down Expand Up @@ -499,8 +499,8 @@ fu! s:InternalBuffer.RenderUiUsagesList(grep_results, start_ln) dict abort
\"group_header": v:true,
\}

let prefix = self.CreateItem("link", ">", "Comment", opts)
let group_name = self.CreateItem("link", path, "Function", opts)
let prefix = self.CreateItem("link", ">", g:AnyJumpGetColor('group_text'), opts)
let group_name = self.CreateItem("link", path, g:AnyJumpGetColor('group_name'), opts)
let line = [ prefix, group_name ]

call self.AddLineAt(line, start_ln)
Expand Down Expand Up @@ -537,8 +537,8 @@ fu! s:InternalBuffer.RenderUiUsagesList(grep_results, start_ln) dict abort
let start_ln += 1

call self.AddLineAt([
\self.CreateItem("more_button", '[ ' . hidden_count . ' more ]', "Operator", {"layer": "usages"}),
\self.CreateItem("more_button", '— [a] load more results [A] load all', "Comment", {"layer": "usages"}),
\self.CreateItem("more_button", '[ ' . hidden_count . ' more ]', g:AnyJumpGetColor('more_button'), {"layer": "usages"}),
\self.CreateItem("more_button", '— [a] load more results [A] load all', g:AnyJumpGetColor('more_explain'), {"layer": "usages"}),
\], start_ln)
let start_ln += 1
endif
Expand All @@ -555,9 +555,9 @@ fu! s:InternalBuffer.RenderUi() dict abort
call self.AddLine([ self.CreateItem("text", "", "Comment") ])

call self.AddLine([
\self.CreateItem("text", ">", "Function"),
\self.CreateItem("text", self.keyword, "Identifier"),
\self.CreateItem("text", len(self.definitions_grep_results) . " definitions", "Function"),
\self.CreateItem("text", ">", g:AnyJumpGetColor('heading_text')),
\self.CreateItem("text", self.keyword, g:AnyJumpGetColor('heading_keyword')),
\self.CreateItem("text", len(self.definitions_grep_results) . " definitions", g:AnyJumpGetColor('heading_text')),
\])

call self.AddLine([ self.CreateItem("text", "", "Comment") ])
Expand Down Expand Up @@ -603,8 +603,8 @@ fu! s:InternalBuffer.RenderUi() dict abort
\"group_header": v:true,
\}

let prefix = self.CreateItem("link", ">", "Comment", opts)
let group_name = self.CreateItem("link", path, "Function", opts)
let prefix = self.CreateItem("link", ">", g:AnyJumpGetColor('group_text'), opts)
let group_name = self.CreateItem("link", path, g:AnyJumpGetColor('group_name'), opts)
let line = [ prefix, group_name ]

call self.AddLine(line)
Expand Down Expand Up @@ -633,16 +633,16 @@ fu! s:InternalBuffer.RenderUi() dict abort
let idx += 1
endfor
else
call self.AddLine([ self.CreateItem("text", "No definitions results", "Comment") ])
call self.AddLine([ self.CreateItem("text", "No definitions results", g:AnyJumpGetColor('plain_text')) ])
endif

call self.AddLine([ self.CreateItem("text", "", "Comment") ])
endif

if hidden_count > 0
call self.AddLine([
\self.CreateItem("more_button", '[ + ' . hidden_count . ' more ]', "Operator"),
\self.CreateItem("more_button", '— [a] load more results [A] load all', "Comment"),
\self.CreateItem("more_button", '[ + ' . hidden_count . ' more ]', g:AnyJumpGetColor('more_button')),
\self.CreateItem("more_button", '— [a] load more results [A] load all', g:AnyJumpGetColor('more_explain')),
\])
call self.AddLine([ self.CreateItem("text", "", "Comment") ])
endif
Expand All @@ -651,15 +651,17 @@ fu! s:InternalBuffer.RenderUi() dict abort
call self.RenderUiUsagesList(self.usages_grep_results, self.len() + 1)
endif

call self.AddLine([ self.CreateItem("help_link", "> Help", "Function") ])
call self.AddLine([ self.CreateItem("help_link", "> Help", g:AnyJumpGetColor('heading_text')) ])

call self.AddLine([ self.CreateItem("help_text", "", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", "[o] open [t] open in tab [s] open in split [v] open in vsplit", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", "[p/tab] preview file [b] scroll to first result", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", "[a] load more results [A] load all results", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", "[r] show references [T] group by file", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", "[L] toggle search [esc/q] exit", "Comment") ])
call self.AddLine([ self.CreateItem("help_text", " results ui style", "Comment") ])
let color = g:AnyJumpGetColor('help_color')

call self.AddLine([ self.CreateItem("help_text", "", color) ])
call self.AddLine([ self.CreateItem("help_text", "[o] open [t] open in tab [s] open in split [v] open in vsplit", color) ])
call self.AddLine([ self.CreateItem("help_text", "[p/tab] preview file [b] scroll to first result", color) ])
call self.AddLine([ self.CreateItem("help_text", "[a] load more results [A] load all results", color) ])
call self.AddLine([ self.CreateItem("help_text", "[r] show references [T] group by file", color) ])
call self.AddLine([ self.CreateItem("help_text", "[L] toggle search [esc/q] exit", color) ])
call self.AddLine([ self.CreateItem("help_text", " results ui style", color) ])
endfu

fu! s:InternalBuffer.RemoveGarbagedLines() dict abort
Expand Down
35 changes: 18 additions & 17 deletions doc/any-jump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,38 +91,39 @@ let g:any_jump_max_search_results = 7
" Prefered search engine: rg or ag
let g:any_jump_search_prefered_engine = 'rg'


" Search results list styles:
" Default search results list styles:
" - 'filename_first'
" - 'filename_last'
let g:any_jump_results_ui_style = 'filename_first'


" Any-jump window size & position options
let g:any_jump_window_width_ratio = 0.6
let g:any_jump_window_height_ratio = 0.6
let g:any_jump_window_top_offset = 4

" Customize window colors types
let g:any_jump_colors = {
\"plain_text": "Comment",
\"preview": "Comment",
\"preview_keyword": "Operator",
\"heading_text": "Function",
\"heading_keyword": "Identifier",
\"group_text": "Comment",
\"group_name": "Function",
\"more_button": "Operator",
\"more_explain": "Comment",
\"result_line_number": "Comment",
\"result_text": "Statement",
\"result_path": "String",
\"help": "Comment"
\}

" Disable default any-jump keybindings (default: 0)
let g:any_jump_disable_default_keybindings = 1

" Remove comments line from search results (default: 1)
let g:any_jump_remove_comments_from_results = 1

" Cursor keyword selection mode
"
" on line:
"
" "MyNamespace::MyClass"
" ^
"
" then cursor is on MyClass word
"
" 'word' - will match 'MyClass'
" 'full' - will match 'MyNamespace::MyClass'

let g:any_jump_keyword_match_cursor_mode', 'word'

" Add ignore files
call g:AnyJumpAddIgnoredFile('*.tmp')
call g:AnyJumpAddIgnoredFile('*.temp')
Expand Down
50 changes: 41 additions & 9 deletions plugin/any-jump.vim
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,45 @@ call s:set_plugin_global_option('any_jump_disable_vcs_ignore', v:false)
" Public customization methods
" ----------------------------------------------

let g:any_jump_ignored_files = []
call s:set_plugin_global_option('any_jump_ignored_files', ['*.tmp', '*.temp'])

fu! g:AnyJumpAddIgnoredFile(mask) abort
call add(g:any_jump_ignored_files, a:mask)
if index(g:any_jump_ignored_files, a:mask) == -1
call add(g:any_jump_ignored_files, a:mask)
endif
endfu

call s:set_plugin_global_option('any_jump_colors', {
\"plain_text": "Comment",
\"preview": 'Comment',
\"preview_keyword": "Operator",
\"heading_text": "Function",
\"heading_keyword": "Identifier",
\"group_text": "Comment",
\"group_name": "Function",
\"more_button": "Operator",
\"more_explain": "Comment",
\"result_line_number": "Comment",
\"result_text": "Statement",
\"result_path": "String",
\"help": "Comment"
\})

fu! g:AnyJumpSetColors(colors) abort
if type(a:colors) == v:t_dict
let g:any_jump_colors = a:colors
else
echoe "invalid color map"
endif
endfu

fu! g:AnyJumpGetColor(name) abort
if has_key(g:any_jump_colors, a:name)
return g:any_jump_colors[a:name]
else
echo "any-jump color not found: " . a:name
return 'Comment'
endif
endfu

" ----------------------------------------------
Expand Down Expand Up @@ -658,22 +693,22 @@ fu! g:AnyJumpHandlePreview() abort
if first_kw_pos == 0
let cur_kw = ui.CreateItem("preview_text",
\ cur_text[first_kw_pos : first_kw_pos + len(ui.keyword) - 1],
\ "Operator",
\ g:AnyJumpGetColor("preview_keyword"),
\ { "link": action_item, "no_padding": v:true })

call add(items, cur_kw)
let cur_text = cur_text[first_kw_pos + len(ui.keyword) : -1]

elseif first_kw_pos == -1
let tail = cur_text
let item = ui.CreateItem("preview_text", tail, "Comment", { "link": action_item, "no_padding": v:true })
let item = ui.CreateItem("preview_text", tail, g:AnyJumpGetColor('preview'), { "link": action_item, "no_padding": v:true })

call add(items, item)
let cur_text = ''

else
let head = cur_text[0 : first_kw_pos - 1]
let head_item = ui.CreateItem("preview_text", head, "Comment", { "link": action_item, "no_padding": v:true })
let head_item = ui.CreateItem("preview_text", head, g:AnyJumpGetColor('preview'), { "link": action_item, "no_padding": v:true })

call add(items, head_item)

Expand All @@ -690,7 +725,7 @@ fu! g:AnyJumpHandlePreview() abort
let first_kw_pos = match(cur_text, '\<' . ui.keyword . '\>')
endwhile
else
let items = [ ui.CreateItem("preview_text", line, "Comment", { "link": action_item } ) ]
let items = [ ui.CreateItem("preview_text", line, g:AnyJumpGetColor('preview'), { "link": action_item } ) ]
endif

call ui.AddLineAt(items, render_ln + 1)
Expand Down Expand Up @@ -780,6 +815,3 @@ if g:any_jump_disable_default_keybindings == v:false
nnoremap <leader>ab :AnyJumpBack<CR>
nnoremap <leader>al :AnyJumpLastResults<CR>
end

call g:AnyJumpAddIgnoredFile('*.tmp')
call g:AnyJumpAddIgnoredFile('*.temp')

0 comments on commit 330b535

Please sign in to comment.