| 1 | function _autopair_insert_same --argument-names key |
| 2 | set --local buffer (commandline) |
| 3 | set --local index (commandline --cursor) |
| 4 | set --local next (string sub --start=(math $index + 1) --length=1 -- "$buffer") |
| 5 | |
| 6 | if test (math (count (string match --all --regex -- "$key" "$buffer")) % 2) = 0 |
| 7 | test $key = $next && commandline --cursor (math $index + 1) && return |
| 8 | |
| 9 | commandline --insert -- $key |
| 10 | |
| 11 | if test $index -lt 1 || |
| 12 | contains -- (string sub --start=$index --length=1 -- "$buffer") "" " " $autopair_left && |
| 13 | contains -- $next "" " " $autopair_right |
| 14 | commandline --insert -- $key |
| 15 | commandline --cursor (math $index + 1) |
| 16 | end |
| 17 | else |
| 18 | commandline --insert -- $key |
| 19 | end |
| 20 | end |