" autoload/characterize.vim
" Maintainer: Tim Pope <http://tpo.pe/>
+unlet! s:digraphs
+
if exists("g:autoloaded_characterize") || &cp
finish
endif
scriptencoding utf-8
function! characterize#digraphs(...) abort
- redir => out
- silent digraphs
- redir END
- redraw
- let digraphs = {}
- for line in split(out, '\n')
- for entry in split(line, " \\d\\+\\zs\\s\\+")
- let nr = matchstr(entry, '\d\+$')
- if nr ==# '10' && len(digraphs) <= 1
- let nr = 0
- endif
- if !has_key(digraphs, nr)
- let digraphs[nr] = []
- endif
- let digraphs[nr] += [matchstr(entry, '^..')]
+ if !exists('s:digraphs')
+ redir => out
+ silent digraphs
+ redir END
+ redraw
+ let s:digraphs = {}
+ for line in split(out, '\n')
+ for entry in split(line, " \\d\\+\\zs\\s*")
+ let nr = matchstr(entry, '\d\+$')
+ if nr ==# '10' && len(s:digraphs) <= 1
+ let nr = 0
+ endif
+ if !has_key(s:digraphs, nr)
+ let s:digraphs[nr] = []
+ endif
+ let s:digraphs[nr] += [matchstr(entry, '^..')]
+ endfor
endfor
- endfor
- return a:0 ? get(digraphs, a:1, []) : digraphs
+ endif
+ return a:0 ? get(s:digraphs, a:1, []) : s:digraphs
endfunction
function! characterize#html_entity(nr) abort
if empty(a:char)
return 'NUL'
endif
- let nr = a:char ==# "\n" ? 0 : char2nr(a:char)
- let char = nr < 32 ? '^'.nr2char(64 + nr) : a:char
- let out = '<' . char . '> ' . nr
- if nr < 256
- let out .= printf(', \%03o', nr)
- endif
- let out .= printf(', U+%04X', nr)
- let out .= ' '.characterize#description(nr, '<unknown>')
- for digraph in characterize#digraphs(nr)
- let out .= ", \<C-K>".digraph
- endfor
- for emoji in characterize#emojis(nr)
- let out .= ', '.emoji
- endfor
- let entity = characterize#html_entity(nr)
- if !empty(entity)
- let out .= ', '.entity
- endif
- return out
+ let charseq = a:char
+ let outs = []
+ while !empty(charseq)
+ let nr = charseq ==# "\n" ? 0 : char2nr(charseq)
+ let char = nr < 32 ? '^'.nr2char(64 + nr) : nr2char(nr)
+ let charseq = strpart(charseq, nr ? len(nr2char(nr)) : 1)
+ let out = '<' . (empty(outs) ? '' : ' ') . char . '> ' . nr
+ if nr < 256
+ let out .= printf(', \%03o', nr)
+ endif
+ let out .= printf(', U+%04X', nr)
+ let out .= ' '.characterize#description(nr, '<unknown>')
+ for digraph in characterize#digraphs(nr)
+ let out .= ", \<C-K>".digraph
+ endfor
+ for emoji in characterize#emojis(nr)
+ let out .= ', '.emoji
+ endfor
+ let entity = characterize#html_entity(nr)
+ if !empty(entity)
+ let out .= ', '.entity
+ endif
+ call add(outs, out)
+ endwhile
+ return join(outs, ' ')
endfunction
-nmap <silent><script> ga :<C-U>echo <SID>info(matchstr(getline('.')[col('.')-1:-1],'.'))<CR>
+nnoremap <silent><script> <Plug>(characterize) :<C-U>echo <SID>info(matchstr(getline('.')[col('.')-1:-1],'.'))<CR>
+if !hasmapto('<Plug>(characterize)', 'n')
+ nmap ga <Plug>(characterize)
+endif
" vim:set sw=2 et: