fun! s:BrailleInit() " set up the dot-to-key mappings: " Braille numeric order: " 14 " 25 " 36 " 78 " let s:dots = [ '1', '2', '3', '4', '5', '6', '7', '8' ] " Home row: " ah " sj " dk " fl let s:dots = [ 'a', 's', 'd', 'h', 'j', 'k', 'f', 'l' ] " graphical (on a US keyboard): " 12 " qw " as " zx "let s:dots = [ '1', 'q', 'a', '2', 'w', 's', 'z', 'x' ] let s:blank = s:dots[0].s:dots[0] let s:orderings = [] " numeric call add(s:orderings, [1,2,3,4, 5,6,7,8]) " top-to-bottom, left-to-right call add(s:orderings, [1,2,3,7, 4,5,6,8]) " left-to-right, top-to-bottom call add(s:orderings, [1,4, 2,5, 3,6, 7,8]) " if 6 or more dots are set, there are too many permutations if you want " to set all possible orders let s:too_many_to_set_all = 6 endfun fun! s:LSBBinary(input) let n = a:input let b = '' let i = 0 while i < 8 let b .= n % 2 let n -= n % 2 let n = n / 2 let i+=1 endwhile return b endfun fun! s:Permute(n) if !exists('l:permcache') let l:permcache = [ [], [[0]] ] endif if len(l:permcache) > a:n return l:permcache[a:n] else let newperms = [] for l in s:Permute(a:n-1) let i = 0 while i < len(l) + 1 let new = copy(l) call insert(new, a:n-1, i) call add(newperms, new) let i+=1 endwhile endfor let l:permcache[a:n] = newperms return newperms endif endfun " returns all permutations of string in keys fun! s:KeyOrderings(keys) let ret = [] let chars = split(a:keys,'\zs') for indexlist in s:Permute(len(chars)) let k = '' for i in indexlist let k .= chars[i] endfor call add(ret, k) endfor return ret endfun " Just make dots typeable in various orders: fun! s:SomeOrderings(keys) let ret = [] let set = {} for char in split(a:keys,'\zs') let set[char] = 1 endfor let setdots = [] let i = 0 while i < len(s:dots) call add(setdots,has_key(set,s:dots[i])?1:0) let i += 1 endwhile for ordering in s:orderings let newkeys = '' for ndot in ordering if setdots[ndot-1] let newkeys .= s:dots[ndot-1] endif endfor call add(ret,newkeys) endfor return ret endfun fun! BrailleAbbrev() call s:BrailleInit() let i = 0 while i < pow(2, len(s:dots)) if !i let keyslist = [ s:blank ] else let keys = '' let bin = s:LSBBinary(i) let j = 0 let setbits = 0 for bit in split(bin,'\zs') if str2nr(bit) == 1 let keys .= s:dots[j] let setbits += 1 endif let j += 1 endfor if setbits < s:too_many_to_set_all let keyslist = s:KeyOrderings(keys) else let keyslist = s:SomeOrderings(keys) endif endif for keys in keyslist let abb = ":iab ".keys." ".nr2char(0x2800+i) exe abb endfor let i+=1 endwhile endfun