My dotfiles. Period.

float.vim 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. "=============================================================================
  2. " $Id: float.vim 520 2012-03-19 18:09:15Z luc.hermitte $
  3. " File: autoload/lh/float.vim {{{1
  4. " Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
  5. " <URL:http://code.google.com/p/lh-vim/>
  6. " License: GPLv3 with exceptions
  7. " <URL:http://code.google.com/p/lh-vim/wiki/License>
  8. " Version: 3.0.0
  9. " Created: 16th Nov 2010
  10. " Last Update: $Date: 2012-03-19 19:09:15 +0100 (Mon, 19 Mar 2012) $
  11. "------------------------------------------------------------------------
  12. " Description:
  13. " Defines functions related to |expr-float| numbers
  14. "
  15. "------------------------------------------------------------------------
  16. " Installation:
  17. " Drop this file into {rtp}/autoload/lh
  18. " Requires Vim7+
  19. " History:
  20. " v2.0.0: first version
  21. " v3.0.0: GPLv3
  22. " TODO:
  23. " }}}1
  24. "=============================================================================
  25. let s:cpo_save=&cpo
  26. set cpo&vim
  27. "------------------------------------------------------------------------
  28. " ## Misc Functions {{{1
  29. " # Version {{{2
  30. let s:k_version = 300
  31. function! lh#float#version()
  32. return s:k_version
  33. endfunction
  34. " # Debug {{{2
  35. let s:verbose = 0
  36. function! lh#float#verbose(...)
  37. if a:0 > 0 | let s:verbose = a:1 | endif
  38. return s:verbose
  39. endfunction
  40. function! s:Verbose(expr)
  41. if s:verbose
  42. echomsg a:expr
  43. endif
  44. endfunction
  45. function! lh#float#debug(expr)
  46. return eval(a:expr)
  47. endfunction
  48. "------------------------------------------------------------------------
  49. " ## Exported functions {{{1
  50. " # lh#float#min(list) {{{2
  51. function! lh#float#min(list)
  52. let am = lh#float#arg_min(a:list)
  53. return a:list[am]
  54. endfunction
  55. function! lh#float#arg_min(list)
  56. if empty(a:list) | return -1 | endif
  57. let m = type(a:list[0]) == type(0.0) ? a:list[0] : str2float(a:list[0])
  58. let p = 0
  59. let i = 1
  60. while i != len(a:list)
  61. let e = a:list[i]
  62. if type(e) != type(0.0) |
  63. let v = str2float(e)
  64. else
  65. let v = e
  66. endif
  67. if v < m
  68. let m = v
  69. let p = i
  70. endif
  71. let i += 1
  72. endwhile
  73. return p
  74. endfunction
  75. " # lh#float#max(list) {{{2
  76. function! lh#float#max(list)
  77. let am = lh#float#arg_max(a:list)
  78. return a:list[am]
  79. endfunction
  80. function! lh#float#arg_max(list)
  81. if empty(a:list) | return -1 | endif
  82. let m = type(a:list[0]) == type(0.0) ? a:list[0] : str2float(a:list[0])
  83. let p = 0
  84. let i = 1
  85. while i != len(a:list)
  86. let e = a:list[i]
  87. if type(e) != type(0.0) |
  88. let v = str2float(e)
  89. else
  90. let v = e
  91. endif
  92. if v > m
  93. let m = v
  94. let p = i
  95. endif
  96. let i += 1
  97. endwhile
  98. return p
  99. endfunction
  100. "------------------------------------------------------------------------
  101. " ## Internal functions {{{1
  102. "------------------------------------------------------------------------
  103. let &cpo=s:cpo_save
  104. "=============================================================================
  105. " vim600: set fdm=marker: