Commits

ZyX_I committed a56bced

@/mappings: Fixed map.unmap (it failed to catch exceptions from {l}un{type})
Fixed maparg version for older Vim
Made map-resource test work in old Vim

Comments (0)

Files changed (3)

plugin/frawor/mappings.vim

     " 2. Cannot differentiate between <CR> and <LT>CR>
     " 3. Cannot restore <silent> flag
     function s:F.savemap(lhs, mode, abbr)
-        let rhs=maparg(a:lhs, a:mode, a:abbr)
+        if a:mode is 0
+            let mode=' '
+        else
+            let mode=a:mode
+        endif
+        let type=((a:abbr)?('abbr'):('map'))
+        let modes=s:F.modrewrite(mode, type)
+        let rhs=maparg(a:lhs, mode, a:abbr)
+        if len(modes)>1
+            let om=0
+            for m in modes
+                if maparg(a:lhs, m, a:abbr) is# rhs
+                    if om is 0
+                        let om=m
+                    endif
+                else
+                    let mode=om
+                    break
+                endif
+            endfor
+        endif
         if empty(rhs)
             let rhs='<Nop>'
         endif
-        let cmd=(a:abbr ? 'abbr' : 'map')
+        let cmd=type
         redir => mapoutput
-        silent! execute a:mode.cmd subtitute(a:lhs, ' ', '<Space>', 'g')
+        silent! execute mode.cmd substitute(a:lhs, ' ', '<Space>', 'g')
         redir END
         let maplines=split(mapoutput, "\n")
         let noremap=0
                     \'noremap': noremap,
                     \   'expr': 0,
                     \ 'buffer': buffer,
-                    \   'mode': a:mode,
+                    \   'mode': mode,
                     \    'sid': 0,
-                    \   'type': ((a:abbr)?('abbr'):('map')),}
+                    \   'type': type,}
     endfunction
 endif
 "▶1 hsescape      :: String, sid[, a:1::Bool] → String
 "▶1 modrewrite    :: mode, type → [mode]
 function s:F.modrewrite(mode, type)
     if a:type is# 'abbr'
-        return split(substitute(a:mode, ' ', 'ci', ''), '.\@=')
+        return split(substitute(a:mode, ' ', 'ci', ''), '\v.@=')
     else
         return split(substitute(substitute(substitute(a:mode,
                     \' ', 'nxso', ''),
                     \'!', 'ic',   ''),
                     \'v', 'xs',   ''),
-                    \'.\@=')
+                    \'\v.@=')
     endif
 endfunction
 "▶1 map           :: mapdescr → + :map
                         \ '<special>'
                         \ ((a:mapdescr.buffer)?('<buffer>'):(''))
                         \ lhs
-        catch /\v^Vim\(un\w+\)\:E(24|31|329):/
+        catch /\v^Vim\(\l?un\w+\)\:E(24|31|329):/
             let r=0
         endtry
     endfor

test/map-resource.in

 :let &rtp.=",".escape($TESTDIR, ',\').'/rtp'
 :let g:testfile="plugin/".g:curtest.".vim"
-:source test.vim
+:source test-redir.vim

test/rtp/plugin/map-resource.vim

 execute frawor#Setup("0.0", {'plugin/frawor/mappings': '0.0'}, 1)
 nnoremap          a :call WriteFile('"'.v:register)<CR>
-nnoremap <expr>   b WriteFile('"'.v:register." b")
-    nmap <expr>   c '"aa'
+if v:version>703 || (v:version==703 && has('patch32'))
+    nnoremap <expr>   b WriteFile('"'.v:register." b")
+        nmap <expr>   c '"aa'
+else
+    nnoremap          b :call WriteFile('"'.v:register.' b')<CR>
+        nmap          c "aa
+endif
 nnoremap          d :call WriteFile("D")<CR>
 nnoremap <buffer> d :call WriteFile("d")<CR>
  noremap          e <C-\><C-n>:call WriteFile("e")<CR>
 execute "normal" keys."ve\<C-\>\<C-n>"
 
 let d={}
-for k in split(keys, '\zs')
+for k in split(keys, '\v.@=')
     let d[k]=s:_r.map.maparg(k, 0, 'n')
     call s:_r.map.unmap(d[k])
 endfor