vim-plugin.eclass 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: vim-plugin.eclass
  4. # @MAINTAINER:
  5. # vim@gentoo.org
  6. # @BLURB: used for installing vim plugins
  7. # @DESCRIPTION:
  8. # This eclass simplifies installation of app-vim plugins into
  9. # /usr/share/vim/vimfiles. This is a version-independent directory
  10. # which is read automatically by vim. The only exception is
  11. # documentation, for which we make a special case via vim-doc.eclass.
  12. inherit vim-doc
  13. EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
  14. VIM_PLUGIN_VIM_VERSION="${VIM_PLUGIN_VIM_VERSION:-7.3}"
  15. DEPEND="|| ( >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION}
  16. >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} )"
  17. RDEPEND="${DEPEND}"
  18. if [[ ${PV} != 9999* ]] ; then
  19. SRC_URI="mirror://gentoo/${P}.tar.bz2
  20. https://dev.gentoo.org/~radhermit/vim/${P}.tar.bz2"
  21. fi
  22. SLOT="0"
  23. vim-plugin_src_install() {
  24. has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
  25. local f
  26. if use !prefix && [[ ${EUID} -eq 0 ]] ; then
  27. ebegin "Fixing file permissions"
  28. # Make sure perms are good
  29. chmod -R a+rX "${S}" || die "chmod failed"
  30. find "${S}" -user 'portage' -exec chown root '{}' \; || die "chown failed"
  31. if use userland_BSD || [[ ${CHOST} == *-darwin* ]] ; then
  32. find "${S}" -group 'portage' -exec chgrp wheel '{}' \; || die "chgrp failed"
  33. else
  34. find "${S}" -group 'portage' -exec chgrp root '{}' \; || die "chgrp failed"
  35. fi
  36. eend $?
  37. fi
  38. # Remove unwanted files that may exist
  39. rm -rf .[^.] .??* Makefile*
  40. # Install non-vim-help-docs
  41. cd "${S}"
  42. for f in *; do
  43. [[ -f "${f}" ]] || continue
  44. if [[ "${f}" = *.html ]]; then
  45. dohtml "${f}"
  46. else
  47. dodoc "${f}"
  48. fi
  49. rm -f "${f}"
  50. done
  51. # Install remainder of plugin
  52. cd "${WORKDIR}"
  53. dodir /usr/share/vim
  54. mv "${S}" "${ED}"/usr/share/vim/vimfiles
  55. # Fix remaining bad permissions
  56. chmod -R -x+X "${ED}"/usr/share/vim/vimfiles/ || die "chmod failed"
  57. }
  58. vim-plugin_pkg_postinst() {
  59. update_vim_helptags # from vim-doc
  60. update_vim_afterscripts # see below
  61. display_vim_plugin_help # see below
  62. }
  63. vim-plugin_pkg_postrm() {
  64. has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
  65. update_vim_helptags # from vim-doc
  66. update_vim_afterscripts # see below
  67. # Remove empty dirs; this allows
  68. # /usr/share/vim to be removed if vim-core is unmerged
  69. find "${EPREFIX}/usr/share/vim/vimfiles" -depth -type d -exec rmdir {} \; 2>/dev/null
  70. }
  71. # update_vim_afterscripts: create scripts in
  72. # /usr/share/vim/vimfiles/after/* comprised of the snippets in
  73. # /usr/share/vim/vimfiles/after/*/*.d
  74. update_vim_afterscripts() {
  75. has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
  76. has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
  77. local d f afterdir="${EROOT}"/usr/share/vim/vimfiles/after
  78. # Nothing to do if the dir isn't there
  79. [ -d "${afterdir}" ] || return 0
  80. einfo "Updating scripts in ${EPREFIX}/usr/share/vim/vimfiles/after"
  81. find "${afterdir}" -type d -name \*.vim.d | \
  82. while read d; do
  83. echo '" Generated by update_vim_afterscripts' > "${d%.d}"
  84. find "${d}" -name \*.vim -type f -maxdepth 1 -print0 | \
  85. sort -z | xargs -0 cat >> "${d%.d}"
  86. done
  87. einfo "Removing dead scripts in ${EPREFIX}/usr/share/vim/vimfiles/after"
  88. find "${afterdir}" -type f -name \*.vim | \
  89. while read f; do
  90. [[ "$(head -n 1 ${f})" == '" Generated by update_vim_afterscripts' ]] \
  91. || continue
  92. # This is a generated file, but might be abandoned. Check
  93. # if there's no corresponding .d directory, or if the
  94. # file's effectively empty
  95. if [[ ! -d "${f}.d" || -z "$(grep -v '^"' "${f}")" ]]; then
  96. rm -f "${f}"
  97. fi
  98. done
  99. }
  100. # Display a message with the plugin's help file if one is available. Uses the
  101. # VIM_PLUGIN_HELPFILES env var. If multiple help files are available, they
  102. # should be separated by spaces. If no help files are available, but the env
  103. # var VIM_PLUGIN_HELPTEXT is set, that is displayed instead. Finally, if we
  104. # have nothing else, display a link to VIM_PLUGIN_HELPURI. An extra message
  105. # regarding enabling filetype plugins is displayed if VIM_PLUGIN_MESSAGES
  106. # includes the word "filetype".
  107. display_vim_plugin_help() {
  108. local h
  109. if ! has_version ${CATEGORY}/${PN} ; then
  110. if [[ -n "${VIM_PLUGIN_HELPFILES}" ]] ; then
  111. elog " "
  112. elog "This plugin provides documentation via vim's help system. To"
  113. elog "view it, use:"
  114. for h in ${VIM_PLUGIN_HELPFILES} ; do
  115. elog " :help ${h}"
  116. done
  117. elog " "
  118. elif [[ -n "${VIM_PLUGIN_HELPTEXT}" ]] ; then
  119. elog " "
  120. while read h ; do
  121. elog "$h"
  122. done <<<"${VIM_PLUGIN_HELPTEXT}"
  123. elog " "
  124. elif [[ -n "${VIM_PLUGIN_HELPURI}" ]] ; then
  125. elog " "
  126. elog "Documentation for this plugin is available online at:"
  127. elog " ${VIM_PLUGIN_HELPURI}"
  128. elog " "
  129. fi
  130. if has "filetype" "${VIM_PLUGIN_MESSAGES}" ; then
  131. elog "This plugin makes use of filetype settings. To enable these,"
  132. elog "add lines like:"
  133. elog " filetype plugin on"
  134. elog " filetype indent on"
  135. elog "to your ~/.vimrc file."
  136. elog " "
  137. fi
  138. fi
  139. }