motion.vim 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. " Python-mode motion functions
  2. fun! pymode#motion#move(pattern, flags, ...) "{{{
  3. let cnt = v:count1 - 1
  4. let [line, column] = searchpos(a:pattern, a:flags . 'sW')
  5. let indent = indent(line)
  6. while cnt && line
  7. let [line, column] = searchpos(a:pattern, a:flags . 'W')
  8. if indent(line) == indent
  9. let cnt = cnt - 1
  10. endif
  11. endwhile
  12. return [line, column]
  13. endfunction "}}}
  14. fun! pymode#motion#vmove(pattern, flags) range "{{{
  15. call cursor(a:lastline, 0)
  16. let end = pymode#motion#move(a:pattern, a:flags)
  17. call cursor(a:firstline, 0)
  18. normal! v
  19. call cursor(end)
  20. endfunction "}}}
  21. fun! pymode#motion#pos_le(pos1, pos2) "{{{
  22. return ((a:pos1[0] < a:pos2[0]) || (a:pos1[0] == a:pos2[0] && a:pos1[1] <= a:pos2[1]))
  23. endfunction "}}}
  24. fun! pymode#motion#select(pattern, inner) "{{{
  25. let cnt = v:count1 - 1
  26. let orig = getpos('.')[1:2]
  27. let snum = pymode#BlockStart(orig[0], a:pattern)
  28. if getline(snum) !~ a:pattern
  29. return 0
  30. endif
  31. let enum = pymode#BlockEnd(snum, indent(snum))
  32. while cnt
  33. let lnum = search(a:pattern, 'nW')
  34. if lnum
  35. let enum = pymode#BlockEnd(lnum, indent(lnum))
  36. call cursor(enum, 1)
  37. endif
  38. let cnt = cnt - 1
  39. endwhile
  40. if pymode#motion#pos_le([snum, 0], orig) && pymode#motion#pos_le(orig, [enum, 1])
  41. if a:inner
  42. let snum = snum + 1
  43. let enum = prevnonblank(enum)
  44. endif
  45. call cursor(snum, 1)
  46. normal! v
  47. call cursor(enum, len(getline(enum)))
  48. endif
  49. endfunction "}}}
  50. " vim: fdm=marker:fdl=0