aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-14 17:48:58 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-14 17:48:58 +1200
commit97f07b6e8b4504cb77867f5072259b944e49c92b (patch)
tree28a7a8cf7fa232f73f4b8d949a55d69ac41dfdff
downloadvim-digraph-search-97f07b6e8b4504cb77867f5072259b944e49c92b.tar.gz
vim-digraph-search-97f07b6e8b4504cb77867f5072259b944e49c92b.zip
First versionv0.1.0
-rw-r--r--README.md16
-rw-r--r--VERSION1
-rw-r--r--autoload/digraph_search.vim75
-rw-r--r--doc/digraph_search.txt34
-rw-r--r--plugin/digraph_search.vim19
5 files changed, 145 insertions, 0 deletions
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*
+
+ *<Plug>(DigraphSearch)*
+The single insert mode mapping target is |<Plug>(DigraphSearch)|. There is no
+default key mapping; you should define one yourself in your |vimrc|. For
+example:
+>
+ imap <C-K><C-K> <Plug>(DigraphSearch)
+<
+AUTHOR *digraph_search-author*
+
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
+
+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 <tom@sanctum.geek.nz>
+" 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 <buffer>
+ \ <Plug>(DigraphSearch)
+ \ <C-O>:call digraph_search#Search()<CR>