jceb / vim-orgmode

Text outlining and task management for Vim based on Emacs' Org-Mode
http://www.vim.org/scripts/script.php?script_id=3642
Other
3.1k stars 266 forks source link

Replace non-ASCII chars with their numeric value in highlight group names #347

Closed pardelapawel closed 4 years ago

pardelapawel commented 4 years ago

tl;dr

replaces any char matching \W to "u" . char2nr(_matched_char_) when calling highlight which allows for decorated unicode todo keywords


When defining a face for todo keyword, the highlight command is used internally with the new keyword as a part of the new name.

For example, when we want 'TODO' to be yellow we might define

let g:org_todo_keyword_faces = [['TODO', ':foreground yellow']]

For the above command vim-orgmode calls

highlight org_todo_keyword_face_TODO term=standout ctermfg=0 ctermbg=6 guifg=Blue guibg=Yellow  ctermfg=yellow guifg=yellow

If we were to define a new keyword that contains non-ASCII characters, vim-orgmode would try to use this non-ASCII word as a part of the highlight group name.

With these keywords and faces:

let g:org_todo_keywords = [['TODO', '할것', '|', 'πŸ‘'], ['|', 'CANCELED', '🦊']]
let g:org_todo_keyword_faces = [
    \['TODO', [':foreground yellow']],
    \['할것', [':foreground green', 'background yellow']],
    \['πŸ‘', [':background LightCyan']],
    \['CANCELED', [':foreground red', ':background black', ':weight bold', ':slant italic', ':decoration underline']],
    \['🦊', [':foreground red', ':background black', ':weight bold', ':slant italic', ':decoration underline']]
\]

vim reports this error 3 times:

Error detected while processing function <SNR>29_ReadTodoKeywords[4]..<SNR>29_ReadTodoKeywords[20]..OrgExtendHighlightingGroup:

Internally vim-orgmode tried to run

highlight org_todo_keyword_face_TODO term=standout ctermfg=0 ctermbg=6 guifg=Blue guibg=Yellow  ctermfg=yellow guifg=yellow
highlight org_todo_keyword_face_할것 term=standout ctermfg=0 ctermbg=6 guifg=Blue guibg=Yellow  ctermfg=green guifg=green ctermfg=green guifg=green
highlight org_todo_keyword_face_πŸ‘ term=standout ctermfg=2 gui=bold guifg=Green ctermbg=LightCyan guibg=LightCyan
highlight org_todo_keyword_face_CANCELED term=standout ctermfg=2 gui=bold guifg=Green ctermfg=red guifg=red ctermbg=black guibg=black term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline
highlight org_todo_keyword_face_🦊 term=standout ctermfg=2 gui=bold guifg=Green ctermfg=red guifg=red ctermbg=black guibg=black term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline

What this commit introduces is a conversion from all \W to their "u" . char2nr() representation.

When this patch is applied the above highlight commands will change to:

highlight org_todo_keyword_face_TODO term=standout ctermfg=0 ctermbg=6 guifg=Blue guibg=Yellow  ctermfg=yellow guifg=yellow
highlight org_todo_keyword_face_u54624u44163 term=standout ctermfg=0 ctermbg=6 guifg=Blue guibg=Yellow  ctermfg=green guifg=green ctermfg=green guifg=green
highlight org_todo_keyword_face_u128017 term=standout ctermfg=2 gui=bold guifg=Green  ctermbg=LightCyan guibg=LightCyan
highlight org_todo_keyword_face_CANCELED term=standout ctermfg=2 gui=bold guifg=Green  ctermfg=red guifg=red ctermbg=black guibg=black term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline
highlight org_todo_keyword_face_u129418 term=standout ctermfg=2 gui=bold guifg=Green  ctermfg=red guifg=red ctermbg=black guibg=black term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline

and errors will disappear

codecov-io commented 4 years ago

Codecov Report

Merging #347 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #347   +/-   ##
=======================================
  Coverage   84.38%   84.38%           
=======================================
  Files          49       49           
  Lines        6794     6794           
=======================================
  Hits         5733     5733           
  Misses       1061     1061

Continue to review full report at Codecov.

Legend - Click here to learn more Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data Powered by Codecov. Last update c6cd668...3ad2f0a. Read the comment docs.

XVilka commented 4 years ago

In theory that should not be a problem in the ideal Vim, but indeed a good fix right now.