Feature: Add command VimwikiColorize (Issue #990)

Only colorize the current line to start
This commit is contained in:
mtourneb
2020-09-03 23:43:56 -04:00
parent dbbadc8035
commit a7f34cd8cf
6 changed files with 128 additions and 3 deletions
+43
View File
@@ -2902,6 +2902,49 @@ function! vimwiki#base#linkify() abort
endfunction 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 " Load syntax-specific Wiki functionality
for s:syn in s:vimwiki_get_known_syntaxes() for s:syn in s:vimwiki_get_known_syntaxes()
+24
View File
@@ -451,6 +451,13 @@ endfunction
" Get default wikilocal values " Get default wikilocal values
" Please: keep alphabetical sort " Please: keep alphabetical sort
function! s:get_default_wikilocal() abort 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 { return {
\ 'auto_diary_index': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, \ 'auto_diary_index': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'auto_export': {'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}, \ 'auto_toc': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'automatic_nested_syntaxes': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, \ 'automatic_nested_syntaxes': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'base_url': {'type': type(''), 'default': '', 'min_length': 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'}, \ 'commentstring': {'type': type(''), 'default': '%%%s'},
\ 'css_name': {'type': type(''), 'default': 'style.css', 'min_length': 1}, \ 'css_name': {'type': type(''), 'default': 'style.css', 'min_length': 1},
\ 'custom_wiki2html': {'type': type(''), 'default': ''}, \ 'custom_wiki2html': {'type': type(''), 'default': ''},
+30
View File
@@ -957,6 +957,15 @@ Vimwiki file.
are specified, outputs all tags. To make this command work properly, make are specified, outputs all tags. To make this command work properly, make
sure the tags have been built (see |vimwiki-build-tags|). 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* 5. Wiki syntax *vimwiki-syntax*
@@ -2818,6 +2827,25 @@ Value Description~
Default: 0 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* 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. https://github.com/vimwiki-backup/vimwiki/issues.
New:~ New:~
* Issue #990: Feature request: highlight multiline selection
Add :VimwikiColorize with only support to clorize the current line
* PR #919: Fix duplicate helptag * PR #919: Fix duplicate helptag
* Feature: PR #988: Command VimwikiVar to list, get and set variables * Feature: PR #988: Command VimwikiVar to list, get and set variables
* Feature: #837 extract web page <title> from URL under cursor and create * Feature: #837 extract web page <title> from URL under cursor and create
+2 -1
View File
@@ -371,6 +371,8 @@ command! -buffer -nargs=* -complete=custom,vimwiki#tags#complete_tags
command! -buffer VimwikiPasteUrl call vimwiki#html#PasteUrl(expand('%:p')) command! -buffer VimwikiPasteUrl call vimwiki#html#PasteUrl(expand('%:p'))
command! -buffer VimwikiCatUrl call vimwiki#html#CatUrl(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 " Keybindings
@@ -716,7 +718,6 @@ if str2nr(vimwiki#vars#get_global('key_mappings').headers)
call vimwiki#u#map_key('n', '[=', '<Plug>VimwikiGoToPrevSiblingHeader') call vimwiki#u#map_key('n', '[=', '<Plug>VimwikiGoToPrevSiblingHeader')
endif endif
if vimwiki#vars#get_wikilocal('auto_export') if vimwiki#vars#get_wikilocal('auto_export')
" Automatically generate HTML on page write. " Automatically generate HTML on page write.
augroup vimwiki augroup vimwiki
+29
View File
@@ -295,6 +295,35 @@ if vimwiki#vars#get_global('valid_html_tags') !=? ''
call vimwiki#u#hi_typeface(html_typeface) call vimwiki#u#hi_typeface(html_typeface)
endif 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 " Comment: home made
execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('comment_regex'). execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('comment_regex').
\ '/ contains=@Spell,VimwikiTodo' \ '/ contains=@Spell,VimwikiTodo'
-2
View File
@@ -201,7 +201,6 @@ getVers() {
} }
vader_filter() { vader_filter() {
echo 'Tin vader filter called'
# Filter Vader Stdout # Filter Vader Stdout
local err=0 local err=0
# Keep indentation # Keep indentation
@@ -223,7 +222,6 @@ vader_filter() {
if [ "$success" -lt "$total" ]; then if [ "$success" -lt "$total" ]; then
err=1 err=1
fi fi
echo "Tin got success $success and total $total"
echo "$REPLY" echo "$REPLY"
elif [[ "$verbose" != 0 ]]; then elif [[ "$verbose" != 0 ]]; then
# just print everything # just print everything