" 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
On Fri, 2 Jul 2010, Romeyke, Andreas wrote:
> Hello,
>
> Is it possible to map the keys "asdf hjkl" in insert-mode to be
> registered if the key is released and not pressed? Is it possible to
> collect all pressed keys until one of them will be released?
>
> Example:
> user presses and holds key "a" and key "f", if key "a" is released, the
> mapped string will be "af ".
>
> Example:
> user presses "a", releases "a" and presses "f" and releases "f", the
> mapped string will be "a f"
>
> Is there an easy way to ignore order of key presses, so if the user
> presses and holds key "a" and key "f" the mapped string will be "af "
> and if user presses first "f" and then "a" the mapped sting will be "a f
> " too?
>
> Still exists there a vim-plugin to generate computer-braille?
>
Try the attached first attempt at a plugin[1]. To install, put it in
your ~/.vim/plugins/ directory as Braille.vim Then to set up the
abbreviations:
:call BrailleAbbrev()
It's currently set up to use asdf hjkl to correspond to dots 1237 4568
There are commented-out variations near the top of the file that use:
1qaz 2wsx (on a U.S. keyboard, possibly easier for sighted typists)
1237 4568 (enter dots by their number)
To type a blank Braille pattern, type dot 1 twice ('aa' unless you
switch to another variation).
Because it uses 'iabbrev', it leaves spaces between each character.
Unfortunately, because of the way iabbrev works, it's not practical to
remove that space (because then a preceding Braille character prevents it
from recognizing the next pattern).
Patterns that contain fewer than 6 dots set can be typed in any order.
With 6-8 dots set, there are too many combinations to work quickly.
If it works well for you, let me know, and maybe I'll have time (or make
time) to package it properly.
--
Best,
Ben
[1] also at http://benizi.com/vim/Braille.vim
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment