vim-doc.eclass 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright 1999-2011 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. #
  4. # This eclass is used by vim.eclass and vim-plugin.eclass to update
  5. # the documentation tags. This is necessary since vim doesn't look in
  6. # /usr/share/vim/vimfiles/doc for documentation; it only uses the
  7. # versioned directory, for example /usr/share/vim/vim62/doc
  8. #
  9. # We depend on vim being installed, which is satisfied by either the
  10. # DEPEND in vim-plugin or by whatever version of vim is being
  11. # installed by the eclass.
  12. update_vim_helptags() {
  13. has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
  14. local vimfiles vim d s
  15. # This is where vim plugins are installed
  16. vimfiles="${EROOT}"/usr/share/vim/vimfiles
  17. if [[ $PN != vim-core ]]; then
  18. # Find a suitable vim binary for updating tags :helptags
  19. vim=$(type -P vim 2>/dev/null)
  20. [[ -z "$vim" ]] && vim=$(type -P gvim 2>/dev/null)
  21. [[ -z "$vim" ]] && vim=$(type -P kvim 2>/dev/null)
  22. if [[ -z "$vim" ]]; then
  23. ewarn "No suitable vim binary to rebuild documentation tags"
  24. fi
  25. fi
  26. # Make vim not try to connect to X. See :help gui-x11-start
  27. # in vim for how this evil trickery works.
  28. if [[ -n "${vim}" ]] ; then
  29. ln -s "${vim}" "${T}/tagvim"
  30. vim="${T}/tagvim"
  31. fi
  32. # Install the documentation symlinks into the versioned vim
  33. # directory and run :helptags
  34. for d in "${EROOT%/}"/usr/share/vim/vim[0-9]*; do
  35. [[ -d "$d/doc" ]] || continue # catch a failed glob
  36. # Remove links, and possibly remove stale dirs
  37. find $d/doc -name \*.txt -type l | while read s; do
  38. [[ $(readlink "$s") = $vimfiles/* ]] && rm -f "$s"
  39. done
  40. if [[ -f "$d/doc/tags" && $(find "$d" | wc -l | tr -d ' ') = 3 ]]; then
  41. # /usr/share/vim/vim61
  42. # /usr/share/vim/vim61/doc
  43. # /usr/share/vim/vim61/doc/tags
  44. einfo "Removing $d"
  45. rm -r "$d"
  46. continue
  47. fi
  48. # Re-create / install new links
  49. if [[ -d $vimfiles/doc ]]; then
  50. ln -s $vimfiles/doc/*.txt $d/doc 2>/dev/null
  51. fi
  52. # Update tags; need a vim binary for this
  53. if [[ -n "$vim" ]]; then
  54. einfo "Updating documentation tags in $d"
  55. DISPLAY= $vim -u NONE -U NONE -T xterm -X -n -f \
  56. '+set nobackup nomore' \
  57. "+helptags $d/doc" \
  58. '+qa!' </dev/null &>/dev/null
  59. fi
  60. done
  61. [[ -n "${vim}" && -f "${vim}" ]] && rm "${vim}"
  62. }