My dotfiles. Period.

buffer.vim 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. "=============================================================================
  2. " $Id: buffer.vim 520 2012-03-19 18:09:15Z luc.hermitte $
  3. " File: autoload/lh/buffer.vim {{{1
  4. " Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
  5. " <URL:http://code.google.com/p/lh-vim/>
  6. " Licence: GPLv3
  7. " Version: 3.0.0
  8. " Created: 23rd Jan 2007
  9. " Last Update: $Date: 2012-03-19 19:09:15 +0100 (Mon, 19 Mar 2012) $
  10. "------------------------------------------------------------------------
  11. " Description:
  12. " Defines functions that help finding windows and handling buffers.
  13. "
  14. "------------------------------------------------------------------------
  15. " Installation:
  16. " Drop it into {rtp}/autoload/lh/
  17. " Vim 7+ required.
  18. " History:
  19. " v1.0.0 First Version
  20. " (*) Functions moved from searchInRuntimeTime
  21. " v2.2.0
  22. " (*) new function: lh#buffer#list()
  23. " v3.0.0 GPLv3
  24. " TODO:
  25. " }}}1
  26. "=============================================================================
  27. "=============================================================================
  28. let s:cpo_save=&cpo
  29. set cpo&vim
  30. " ## Functions {{{1
  31. "------------------------------------------------------------------------
  32. " # Debug {{{2
  33. function! lh#buffer#verbose(level)
  34. let s:verbose = a:level
  35. endfunction
  36. function! s:Verbose(expr)
  37. if exists('s:verbose') && s:verbose
  38. echomsg a:expr
  39. endif
  40. endfunction
  41. function! lh#buffer#debug(expr)
  42. return eval(a:expr)
  43. endfunction
  44. "------------------------------------------------------------------------
  45. " # Public {{{2
  46. " Function: lh#buffer#find({filename}) {{{3
  47. " If {filename} is opened in a window, jump to this window, otherwise return -1
  48. " Moved from searchInRuntimeTime.vim
  49. function! lh#buffer#find(filename)
  50. let b = bufwinnr(a:filename)
  51. if b == -1 | return b | endif
  52. exe b.'wincmd w'
  53. return b
  54. endfunction
  55. function! lh#buffer#Find(filename)
  56. return lh#buffer#find(a:filename)
  57. endfunction
  58. " Function: lh#buffer#jump({filename},{cmd}) {{{3
  59. function! lh#buffer#jump(filename, cmd)
  60. if lh#buffer#find(a:filename) != -1 | return | endif
  61. exe a:cmd . ' ' . a:filename
  62. endfunction
  63. function! lh#buffer#Jump(filename, cmd)
  64. return lh#buffer#jump(a:filename, a:cmd)
  65. endfunction
  66. " Function: lh#buffer#scratch({bname},{where}) {{{3
  67. function! lh#buffer#scratch(bname, where)
  68. try
  69. silent exe a:where.' sp '.a:bname
  70. catch /.*/
  71. throw "Can't open a buffer named '".a:bname."'!"
  72. endtry
  73. setlocal bt=nofile bh=wipe nobl noswf ro
  74. endfunction
  75. function! lh#buffer#Scratch(bname, where)
  76. return lh#buffer#scratch(a:bname, a:where)
  77. endfunction
  78. " Function: lh#buffer#list() {{{3
  79. function! lh#buffer#list()
  80. let all = range(0, bufnr('$'))
  81. " let res = lh#list#transform_if(all, [], 'v:1_', 'buflisted')
  82. let res = lh#list#copy_if(all, [], 'buflisted')
  83. return res
  84. endfunction
  85. " Ex: Names of the buffers listed
  86. " -> echo lh#list#transform(lh#buffer#list(), [], "bufname")
  87. " Ex: wipeout empty buffers listed
  88. " -> echo 'bw'.join(lh#list#copy_if(range(0, bufnr('$')), [], 'buflisted(v:1_) && empty(bufname(v:1_))'), ' ')
  89. "=============================================================================
  90. let &cpo=s:cpo_save
  91. "=============================================================================
  92. " vim600: set fdm=marker: