Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. " File: D2190.vim
  2. " Created: 2017 Jun 30
  3. " Last Change: 2018 May 15
  4. " Version: 0.5
  5. " Author: Andy Wokula <anwoku@yahoo.de>
  6. " License: Vim License, see :h license
  7. " Dependencies: (by :PutDepend)
  8. " CallOverloaded()
  9.  
  10. " HasPatchExpr({vimver}, {patchnr})
  11. " HasPatchExpr({major}, {minor}, {patchnr})
  12. " HasPatchExpr({patchlevel})
  13. "
  14. " return an expression (string) that can be used (literally in a script)
  15. " to check the running Vim against a certain patch level.
  16. "
  17. " Depending on the represented patch value, this for example returns
  18. " has("patch-7.4.237")
  19. " or
  20. " v:version > 704 || v:version == 704 && has("patch236")
  21. " (the patch numbers are different by intention).
  22. "
  23. " The first variant is easier to read, but only understood since
  24. " Vim 7.4.237 (older Vims always return 0). The second variant works
  25. " everywhere and will be used for versions up to Vim 7.4.236.
  26. "
  27. " Arguments can be given in several ways:
  28. " {vimver} (number) v:version, eg 704 for Vim 7.4
  29. " {patchnr} (number) 0 or greater
  30. " or
  31. " {major} (number) major version, eg 7
  32. " {minor} (number) minor version, eg 4
  33. " {patchnr} (number) 0 or greater
  34. " or
  35. " {patchlevel} (string) '7.4.237' or 'v7-4-237' or 'patch-7.4.237'
  36. "
  37. " A general check can use the newer notation for a newer patch, but must
  38. " use the older notation for an older patch.
  39. "
  40.  
  41. " History:
  42. " 2019 Jun 14 Note: v:versionlong (added with 8.1.1526) cannot be used for
  43. " version checking
  44. " 2018 Jul 28 BF: HasPatchExpr('701', '040') => '... has("patch36")'
  45. " 2018 May 15 not sure why Empty() was used
  46. " 2017 Nov 05 BF: HasPatchExpr('7.1.040') => '... has("patch36")'
  47. " 2017 Nov 03 use CallOverloaded()
  48. " 2017 Jul 17 BF: checked argument against version of running Vim (stupid)
  49.  
  50. func! HasPatchExpr(arg, ...) "{{{
  51. return CallOverloaded(s:f, [a:arg] + a:000, {})
  52. endfunc "}}}
  53.  
  54.  
  55. let s:f = {}
  56.  
  57. func! s:f.XX(vimver, patchnr) "{{{
  58. return s:HasPatchExpr(str2nr(a:vimver), str2nr(a:patchnr))
  59. endfunc "}}}
  60.  
  61. func! s:f.XXX(major, minor, patchnr) "{{{
  62. return s:HasPatchExpr(str2nr(a:major) * 100 + str2nr(a:minor), str2nr(a:patchnr))
  63. endfunc "}}}
  64.  
  65. func! s:f.S(str) "{{{
  66. " from HasPatch()
  67. let ml = matchlist(a:str, '\(\d\+\)\D\(\d\+\)\D\(\d\+\)')
  68. if !empty(ml)
  69. let [major, minor, patchnr] = ml[1:3]
  70. return s:HasPatchExpr(str2nr(major) * 100 + str2nr(minor), str2nr(patchnr))
  71. else
  72. echoerr printf('HasPatchExpr(): invalid argument "%s"', a:str)
  73. return ''
  74. endif
  75. endfunc "}}}
  76.  
  77. func! s:f._(...) "{{{
  78. echoerr 'HasPatchExpr(): unrecognized arguments'
  79. return ''
  80. endfunc "}}}
  81.  
  82.  
  83. func! s:HasPatchExpr(vimver, patchnr) "{{{
  84. if a:patchnr >= 1
  85. if a:vimver > 704 || a:vimver == 704 && a:patchnr >= 237
  86. return printf('has("patch-%d.%d.%d")', a:vimver/100, a:vimver%100, a:patchnr)
  87. else
  88. return printf('v:version > %d || v:version == %d && has("patch%d")', a:vimver, a:vimver, a:patchnr)
  89. endif
  90. else
  91. return printf('v:version >= %d', a:vimver)
  92. endif
  93. endfunc "}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement