From 97f07b6e8b4504cb77867f5072259b944e49c92b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 14 Jul 2018 17:48:58 +1200 Subject: First version --- README.md | 16 ++++++++++ VERSION | 1 + autoload/digraph_search.vim | 75 +++++++++++++++++++++++++++++++++++++++++++++ doc/digraph_search.txt | 34 ++++++++++++++++++++ plugin/digraph_search.vim | 19 ++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 README.md create mode 100644 VERSION create mode 100644 autoload/digraph_search.vim create mode 100644 doc/digraph_search.txt create mode 100644 plugin/digraph_search.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..e690c91 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +digraph\_search.vim +=================== + +This plugin provides an insert mode mapping target to search for digraphs by +searching for a substring of the character's official name, per `:help +digraph-table` and `:help digraph-table-multibyte`. This is for situations +where you might be able to remember part of the official name for a character, +but you can't remember the digraph pieces. + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 diff --git a/autoload/digraph_search.vim b/autoload/digraph_search.vim new file mode 100644 index 0000000..172b17c --- /dev/null +++ b/autoload/digraph_search.vim @@ -0,0 +1,75 @@ +" Search for digraphs +function! digraph_search#Search() abort + + " Get the search string + let l:search = input('Digraph search: ') + if !strlen(l:search) + return + endif + + " Look for the uppercased search in the table + let l:results = [] + for l:digraph in digraph_search#Digraphs() + if stridx(l:digraph['name'], toupper(l:search)) != -1 + call add(l:results, l:digraph) + endif + endfor + + " Print results, or if there weren't any, say so + redraw + echo 'Digraphs matching '.toupper(l:search).':' + if len(l:results) + for l:result in l:results + echo l:result['char'] + \.' '.l:result['keys'] + \.' '.l:result['name'] + endfor + else + echo 'None!' + endif + +endfunction + +" Get private memoized list of digraph dictionary objects +function! digraph_search#Digraphs() abort + + " We haven't been called yet; get the digraph list + if !exists('s:digraphs') + let s:digraphs = [] + let l:table = 0 + for l:line in readfile($VIMRUNTIME.'/doc/digraph.txt') + + " Flag whether we're in one of the digraph tables; look for the heading + let l:table = l:table && strlen(l:line) + \ || l:line =~# '\C\*digraph-table\%(-mbyte\)\=\*$' + " Skip to next line if not in a table + if !l:table + continue + endif + + " Check whether this row matches a parseable digraph row + let l:match = matchlist(l:line, + \ '^\(\S\)\+\s\+' + \ . '\(\S\S\)\s\+' + \ . '\%(0x\)\=\x\+\s\+' + \ . '\d\+\s\+' + \ . '\(.\+\)' + \ ) + " Skip to next line if not a table row match + if !len(l:match) + continue + endif + + " Add to the digraphs list; key is digraph, value is full name + call add(s:digraphs, { + \ 'char': l:match[1], + \ 'keys': l:match[2], + \ 'name': l:match[3], + \ }) + endfor + endif + + " Return the list, whether newly-generated or from the first call + return s:digraphs + +endfunction diff --git a/doc/digraph_search.txt b/doc/digraph_search.txt new file mode 100644 index 0000000..da25b2c --- /dev/null +++ b/doc/digraph_search.txt @@ -0,0 +1,34 @@ +*digraph_search.txt* For Vim version 7.0 Last change: 2018 July 14 + +DESCRIPTION *digraph_search* + +This plugin provides an insert mode mapping target to search for |digraphs| by +searching for a substring of the character's official name, per +|digraph-table| and |digraph-table-multibyte|. This is for situations where +you might be able to remember part of the official name for a character, but +you can't remember the digraph pieces. + +REQUIREMENTS *digraph_search-requirements* + +This plugin only loads if 'compatible' is not set. It requires the |+digraphs| +feature, of course. + +MAPPINGS *digraph_search-mappings* + + *(DigraphSearch)* +The single insert mode mapping target is |(DigraphSearch)|. There is no +default key mapping; you should define one yourself in your |vimrc|. For +example: +> + imap (DigraphSearch) +< +AUTHOR *digraph_search-author* + +Written and maintained by Tom Ryder . + +LICENSE *digraph_search-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: + diff --git a/plugin/digraph_search.vim b/plugin/digraph_search.vim new file mode 100644 index 0000000..44a1307 --- /dev/null +++ b/plugin/digraph_search.vim @@ -0,0 +1,19 @@ +" +" digraph_search.vim: Insert mode mappings to find a digraph by searching for +" its name in the contents of :help digraph-table. +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if exists('g:loaded_digraph_search') || &compatible + finish +endif +if v:version < 700 + finish +endif +let g:loaded_digraph_search = 1 + +" Set up mapping +inoremap + \ (DigraphSearch) + \ :call digraph_search#Search() -- cgit v1.2.3