" hook_source {{{ function s:add_rules(shared, rules) abort call map(a:rules, { _, rule -> lexima#add_rule(a:shared->deepcopy()->extend(rule, 'error')) }) endfunction call s:add_rules( \ #{ char: '' }, \ [ \ #{ at: '\%#\s*\n\{,1}\s*)', leave: ')' }, \ #{ at: '\%#\s*\n\{,1}\s*]', leave: ']' }, \ #{ at: '\%#\s*\n\{,1}\s*}', leave: '}' }, \ #{ at: '\%#\s*\n\{,1}\s*"', leave: '"' }, \ #{ at: '\%#\s*\n\{,1}\s*''', leave: "'" }, \ #{ at: '\%#\s*\n\{,1}\s*`', leave: '`' }, \ ] \ ) call s:add_rules( \ #{ filetype: 'lua' }, \ [ \ #{ char: '', at: '\%#\s*\n{,1}\s*end', leave: 'end' }, \ #{ char: '', at: 'function\(\s[a-zA-Z0-9\.\_:]\+\)\{,1}(.*\%#)', leave: ')', input_after: 'end' }, \ #{ char: '', at: '\%#end', input_after: '' }, \ #{ char: '', at: 'if\s.*\sthen\%#', input_after: 'end' }, \ #{ char: '', at: '\%#end', input_after: '' }, \ ] \ ) call s:add_rules( \ #{ filetype: 'html' }, \ [ \ #{ char: '', at: '\%#', leave: '>' }, \ #{ char: '', at: '\%#<\w\+>', input_after: '' }, \ #{ char: '>', at: '<\(\w\+\)\%(\s\+\w\+=\".\+\"\)*\%#', input_after: '', with_submatch: 1 }, \ #{ char: '/', at: '<\(\w\+\)\(\s\+\w\+=\".\+\"\)*\%#', input: '>' }, \ #{ char: '=', at: '\w\+\%#', input: '="', input_after: '"' }, \ ] \ ) call s:add_rules( \ #{ filetype: ['cs', 'razor'] }, \ [ \ #{ char: '', at: 'get\%( => [^;]\+\)*\%#;', leave: ';' }, \ #{ char: '', at: '\%(set\|init\)\%( => .\+\)*\%#; }', leave: '}' }, \ #{ char: '', at: '<\%([a-zA-Z0-9_\.]\+?\{,1}\)\%(,\s*[a-zA-Z0-9_\.]\+?\{,1}\)*>*\%#>', leave: '>' }, \ #{ char: '', at: '\%(get\|set\|init\)\%#;', input: ' => ' }, \ #{ char: '', at: '\%(@if\|\s\+if\|^if\)\%#', input: '(', input_after: ')' }, \ #{ char: 'd', at: '#if \%#', input: 'DEBUG' }, \ #{ char: '', at: '^\s*#if\s\+.\+\%#', input_after: '#endif' }, \ #{ char: '', at: '@\{,1}\%(for\|while\|foreach\|switch\)\%#', input: '(', input_after: ')' }, \ #{ char: '', at: '<\%#>', delete: '>' }, \ #{ char: 'g', at: '{ \%# }', input: 'get', input_after: ';' }, \ #{ char: 's', at: '{ get\%( => [^;]\+\)*; \%# }', input: 'set', input_after: ';' }, \ #{ char: 'i', at: '{ get\%( => [^;]\+\)*; \%# }', input: 'init', input_after: ';' }, \ #{ char: '', at: 'DbSet<\([0-9a-zA-Z<>_]\+\)> \w\+\%#', input: ' => Set<\1>();', with_submatch: 1 }, \ #{ char: '<', at: '[a-zA-Z0-9_]\%#', input_after: '>' }, \ #{ char: ';', at: 'for\s*([^)]*\%#)', input: ';' }, \ #{ char: ';', at: '\%(get\|set\|init\)\%( => [^;]\+\)*\%#', input: ';' }, \ #{ char: ';', at: '\%#.\+$', input: ';' }, \ #{ char: '', at: '\.\w\+(\%([^)]\+,\s\)*\<\%(new\|out\)\@!\w\+\%#)', input: '=>' }, \ #{ char: '$', input: '$"', input_after: '"' }, \ #{ char: '', at: '\Console.WriteLine(', input_after: ')' }, \ ] \ ) call s:add_rules( \ #{ filetype: 'razor' }, \ [ \ #{ char: '*', at: '@\%#', input_after: '*@' }, \ #{ char: '', at: '@\*\%#\*@', input_after: '' }, \ #{ char: '', at: '@\*\s\%#\s\*@', input: '' }, \ #{ char: '', at: '@\*\%#\*@', input: '', delete: '*@' }, \ #{ char: '/', at: '<[^>]\+\%#', input: '/>' }, \ #{ char: '>', at: '<\(\w\+\)[^>]*\%#', with_submatch: 1, input: '>', input_after: '' }, \ #{ char: '', at: '\%#', input_after: '' }, \ #{ char: '', at: '\%#\n\{,1}\s*', leave: '>' } \ ] \ ) call s:add_rules( \ #{ filetype: 'vim' }, \ [ \ #{ char: '(', at: '\\\%#', input_after: '\)' }, \ #{ char: '(', at: '\\%\%#', input_after: '\)' }, \ #{ char: '', at: '\%#\\)', leave: '\\)' }, \ #{ char: '', at: '\\(\%#\\)', input: '', delete: '\\)' }, \ #{ char: '', at: '\\%(\%#\\)', input: '', delete: '\\)' }, \ ] \ ) call s:add_rules( \ #{ filetype: ['lisp', 'scheme'] }, \ [ \ #{ char: "'", input: "'" }, \ #{ char: '`', input: '`' }, \ ] \ ) call lexima#add_rule(#{ char: '(complete-function-symbol)', input: '(', input_after: ')' }) " input: >>, effect: `if (\%#)condition` -> `if (condition)` call lexima#add_rule(#{ char: '>', at: '(>\%#)', input: ')' }) " cmdline rules " `:g` -> `:vimgrep \%# %` call add(g:AlterCommands, #{ char: 'g', input: 'vimgrep', input_after: ' %' }) " ORIGINAL: " SOURCE: https://github.com/yuki-yano/lexima-alter-command.vim/blob/main/autoload/lexima_alter_command.vim " LICENSE: https://github.com/yuki-yano/lexima-alter-command.vim/blob/main/LICENSE for alterCmd in g:AlterCommands let space_rule = #{ mode: ':', at: '^\%(''<,''>\)\?' .. alterCmd.char, char: '' } let cr_rule = #{ mode: ':', at: '^\%(''<,''>\)\?' .. alterCmd.char, char: '' } if ! alterCmd->get('input')->empty() let space_rule.input = '' .. alterCmd.input .. '' let cr_rule.input = '' .. alterCmd.input .. '' endif if ! alterCmd->get('input_after')->empty() let space_rule.input_after = alterCmd.input_after let cr_rule.input_after = alterCmd.input_after endif call lexima#add_rule(space_rule) call lexima#add_rule(cr_rule) endfor " }}}