Feature: Add command VimwikiColorize (Issue #990)
Only colorize the current line to start
This commit is contained in:
@@ -2902,6 +2902,49 @@ function! vimwiki#base#linkify() abort
|
||||
endfunction
|
||||
|
||||
|
||||
function! vimwiki#base#complete_colorize(ArgLead, CmdLine, CursorPos) abort
|
||||
" We can safely ignore args if we use -custom=complete option, Vim engine
|
||||
" will do the job of filtering
|
||||
let colorlist = keys(vimwiki#vars#get_wikilocal('color_dic'))
|
||||
return join(colorlist, "\n")
|
||||
endfunction
|
||||
|
||||
function! vimwiki#base#colorize(...) abort
|
||||
" TODO Must be coherent with color_tag_template
|
||||
" -- Just removeing spaces, \/ -> /, replacing COLORFG will do it
|
||||
let key = a:0 ? a:1 : 'default'
|
||||
let color_dic = vimwiki#vars#get_wikilocal('color_dic')
|
||||
|
||||
" Guard: color key nust exist
|
||||
if !has_key(color_dic, key)
|
||||
call vimwiki#u#error('color_dic variable has no key ''' . key . '''')
|
||||
return
|
||||
endif
|
||||
|
||||
" Get content
|
||||
let content = getline('.')
|
||||
" TODO save position for visual selection: see u#get_selection
|
||||
|
||||
" Surround
|
||||
" -- pre
|
||||
let [fg, bg] = color_dic[key]
|
||||
let pre = '<span style="'
|
||||
if fg !=# ''
|
||||
let pre .= 'color:' . fg . ';'
|
||||
endif
|
||||
if bg !=# ''
|
||||
let pre .= 'background:' . bg . ';'
|
||||
endif
|
||||
let pre .= '">'
|
||||
" -- post
|
||||
let post = '</span>'
|
||||
" -- concat
|
||||
let content = pre . content . post
|
||||
|
||||
" Set buffer content
|
||||
call setline('.', content)
|
||||
endfunction
|
||||
|
||||
" -------------------------------------------------------------------------
|
||||
" Load syntax-specific Wiki functionality
|
||||
for s:syn in s:vimwiki_get_known_syntaxes()
|
||||
|
||||
@@ -451,6 +451,13 @@ endfunction
|
||||
" Get default wikilocal values
|
||||
" Please: keep alphabetical sort
|
||||
function! s:get_default_wikilocal() abort
|
||||
" Build color_tag_template regular expression
|
||||
" Must be coherent with VimwikiColorize
|
||||
let fg = 'color\s*:\s*__COLORFG__\s*;\s*'
|
||||
let bg = 'background\s*:\s*__COLORBG__\s*;\s*'
|
||||
let color_tag_rx = '<span \s*style\s*=\s*"\s*\('
|
||||
\ . fg . bg . '\|' . fg . '\|' . bg
|
||||
\ . '\)"\s*>__CONTENT__<\/span>'
|
||||
return {
|
||||
\ 'auto_diary_index': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
||||
\ 'auto_export': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
||||
@@ -460,6 +467,23 @@ function! s:get_default_wikilocal() abort
|
||||
\ 'auto_toc': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
|
||||
\ 'automatic_nested_syntaxes': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
|
||||
\ 'base_url': {'type': type(''), 'default': '', 'min_length': 1},
|
||||
\ 'color_dic': {'type': type({}), 'default': {
|
||||
\ 'default': ['', '#d79921'],
|
||||
\ 'red': ['#cc241d', ''],
|
||||
\ 'bred': ['', '#cc241d'],
|
||||
\ 'green': ['#98971a', ''],
|
||||
\ 'bgreen': ['', '#98971a'],
|
||||
\ 'yellow': ['#d79921', ''],
|
||||
\ 'byellow': ['', '#d79921'],
|
||||
\ 'blue': ['#458588', ''],
|
||||
\ 'bblue': ['', '#458588'],
|
||||
\ 'purple': ['#b16286', ''],
|
||||
\ 'bpurple': ['', '#b16286'],
|
||||
\ 'orange': ['#d65d0e', ''],
|
||||
\ 'borange': ['', '#d65d0e'],
|
||||
\ 'gray': ['#a89984', ''],
|
||||
\ 'bgray': ['', '#a89984']}},
|
||||
\ 'color_tag_template': {'type': type({}), 'default': color_tag_rx},
|
||||
\ 'commentstring': {'type': type(''), 'default': '%%%s'},
|
||||
\ 'css_name': {'type': type(''), 'default': 'style.css', 'min_length': 1},
|
||||
\ 'custom_wiki2html': {'type': type(''), 'default': ''},
|
||||
|
||||
@@ -957,6 +957,15 @@ Vimwiki file.
|
||||
are specified, outputs all tags. To make this command work properly, make
|
||||
sure the tags have been built (see |vimwiki-build-tags|).
|
||||
|
||||
*:VimwikiColorize* red
|
||||
Colorize current line with the color given in argument. The possible
|
||||
colors are configured by |vimwiki-option-color_dic| and the format of the
|
||||
surrounding color tags by |vimwiki-option-color_tag_template|
|
||||
TODO
|
||||
Currently only the current line is colorized, a support for the selection
|
||||
will come. Maybe some mapping and color completion in popup (See
|
||||
changelog
|
||||
|
||||
|
||||
==============================================================================
|
||||
5. Wiki syntax *vimwiki-syntax*
|
||||
@@ -2818,6 +2827,25 @@ Value Description~
|
||||
|
||||
Default: 0
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*vimwiki-option-color_dic*
|
||||
|
||||
Dictionary containing the possible html colors for |:VimwikiColorize| the
|
||||
keys are the color names used as argument, the values are a list [foreground,
|
||||
backgroud] of the color. For example:
|
||||
|
||||
{'red': ['#cc241d', ''], 'bred': ['', '#cc241d']}
|
||||
|
||||
Provides two colors to |:VimwikiColorize|: 'red' => red foreground and 'bred'
|
||||
=> red background.
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*vimwiki-option-color_tag_template*
|
||||
|
||||
Not supposed to be edited already: a regex with __COLORFG__, __COLORBG__ and
|
||||
__CONTENT__ placeholders to surround the content with a tag to define its
|
||||
color. (See autoload/vimwiki/vars.vim)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
12.4 Syntax Options *vimwiki-syntax-options*
|
||||
@@ -3812,6 +3840,8 @@ http://code.google.com/p/vimwiki/issues/list. They may be accessible from
|
||||
https://github.com/vimwiki-backup/vimwiki/issues.
|
||||
|
||||
New:~
|
||||
* Issue #990: Feature request: highlight multiline selection
|
||||
Add :VimwikiColorize with only support to clorize the current line
|
||||
* PR #919: Fix duplicate helptag
|
||||
* Feature: PR #988: Command VimwikiVar to list, get and set variables
|
||||
* Feature: #837 extract web page <title> from URL under cursor and create
|
||||
|
||||
@@ -371,6 +371,8 @@ command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags
|
||||
command! -buffer VimwikiPasteUrl call vimwiki#html#PasteUrl(expand('%:p'))
|
||||
command! -buffer VimwikiCatUrl call vimwiki#html#CatUrl(expand('%:p'))
|
||||
|
||||
command! -buffer -nargs=* -complete=custom,vimwiki#base#complete_colorize
|
||||
\ VimwikiColorize call vimwiki#base#colorize(<f-args>)
|
||||
|
||||
" ------------------------------------------------
|
||||
" Keybindings
|
||||
@@ -716,7 +718,6 @@ if str2nr(vimwiki#vars#get_global('key_mappings').headers)
|
||||
call vimwiki#u#map_key('n', '[=', '<Plug>VimwikiGoToPrevSiblingHeader')
|
||||
endif
|
||||
|
||||
|
||||
if vimwiki#vars#get_wikilocal('auto_export')
|
||||
" Automatically generate HTML on page write.
|
||||
augroup vimwiki
|
||||
|
||||
@@ -295,6 +295,35 @@ if vimwiki#vars#get_global('valid_html_tags') !=? ''
|
||||
call vimwiki#u#hi_typeface(html_typeface)
|
||||
endif
|
||||
|
||||
" Html Color: <span style="color:#FF0000";>Red paragraph</span>
|
||||
" -- See: h color_dic
|
||||
let color_dic = vimwiki#vars#get_wikilocal('color_dic')
|
||||
let color_tag = vimwiki#vars#get_wikilocal('color_tag_template')
|
||||
for [color_key, color_value] in items(color_dic)
|
||||
let [fg, bg] = color_value
|
||||
let delimiter = color_tag
|
||||
let delimiter = substitute(delimiter, '__COLORFG__', fg, 'g')
|
||||
let delimiter = substitute(delimiter, '__COLORBG__', bg, 'g')
|
||||
" The user input has been already checked
|
||||
let [pre_region, post_region] = split(delimiter, '__CONTENT__')
|
||||
let cmd = 'syntax region Vimwiki' . color_key . ' matchgroup=VimwikiDelimiterColor'
|
||||
\ . ' start=/' . pre_region . '/'
|
||||
\ . ' end=/' . post_region . '/'
|
||||
\ . ' ' . b:vimwiki_syntax_concealends
|
||||
execute cmd
|
||||
|
||||
" Build hightlight command
|
||||
let cmd = 'hi Vimwiki' . color_key
|
||||
if fg !=# ''
|
||||
let cmd .= ' guifg=' . fg
|
||||
endif
|
||||
if bg !=# ''
|
||||
let cmd .= ' guibg=' . bg
|
||||
endif
|
||||
execute cmd
|
||||
endfor
|
||||
|
||||
|
||||
" Comment: home made
|
||||
execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('comment_regex').
|
||||
\ '/ contains=@Spell,VimwikiTodo'
|
||||
|
||||
@@ -201,7 +201,6 @@ getVers() {
|
||||
}
|
||||
|
||||
vader_filter() {
|
||||
echo 'Tin vader filter called'
|
||||
# Filter Vader Stdout
|
||||
local err=0
|
||||
# Keep indentation
|
||||
@@ -223,7 +222,6 @@ vader_filter() {
|
||||
if [ "$success" -lt "$total" ]; then
|
||||
err=1
|
||||
fi
|
||||
echo "Tin got success $success and total $total"
|
||||
echo "$REPLY"
|
||||
elif [[ "$verbose" != 0 ]]; then
|
||||
# just print everything
|
||||
|
||||
Reference in New Issue
Block a user