1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # This eclass simplifies installation of app-vim plugins into
6 # /usr/share/vim/vimfiles. This is a version-independent directory
7 # which is read automatically by vim. The only exception is
8 # documentation, for which we make a special case via vim-doc.eclass
11 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
13 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} )"
18 if [[ ${PV} != 9999* ]] ; then
19 SRC_URI="mirror://gentoo/${P}.tar.bz2
20 https://dev.gentoo.org/~radhermit/vim/${P}.tar.bz2"
24 vim-plugin_src_install() {
25 has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
28 if use !prefix && [[ ${EUID} -eq 0 ]] ; then
29 ebegin "Fixing file permissions"
30 # Make sure perms are good
31 chmod -R a+rX "${S}" || die "chmod failed"
32 find "${S}" -user 'portage' -exec chown root '{}' \; || die "chown failed"
33 if use userland_BSD || [[ ${CHOST} == *-darwin* ]] ; then
34 find "${S}" -group 'portage' -exec chgrp wheel '{}' \; || die "chgrp failed"
36 find "${S}" -group 'portage' -exec chgrp root '{}' \; || die "chgrp failed"
41 # Remove unwanted files that may exist
42 rm -rf .[^.] .??* Makefile*
44 # Install non-vim-help-docs
47 [[ -f "${f}" ]] || continue
48 if [[ "${f}" = *.html ]]; then
56 # Install remainder of plugin
59 mv "${S}" "${ED}"/usr/share/vim/vimfiles
61 # Fix remaining bad permissions
62 chmod -R -x+X "${ED}"/usr/share/vim/vimfiles/ || die "chmod failed"
65 vim-plugin_pkg_postinst() {
66 update_vim_helptags # from vim-doc
67 update_vim_afterscripts # see below
68 display_vim_plugin_help # see below
71 vim-plugin_pkg_postrm() {
72 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
73 update_vim_helptags # from vim-doc
74 update_vim_afterscripts # see below
76 # Remove empty dirs; this allows
77 # /usr/share/vim to be removed if vim-core is unmerged
78 find "${EPREFIX}/usr/share/vim/vimfiles" -depth -type d -exec rmdir {} \; 2>/dev/null
81 # update_vim_afterscripts: create scripts in
82 # /usr/share/vim/vimfiles/after/* comprised of the snippets in
83 # /usr/share/vim/vimfiles/after/*/*.d
84 update_vim_afterscripts() {
85 has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
86 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
87 local d f afterdir="${EROOT}"/usr/share/vim/vimfiles/after
89 # Nothing to do if the dir isn't there
90 [ -d "${afterdir}" ] || return 0
92 einfo "Updating scripts in ${EPREFIX}/usr/share/vim/vimfiles/after"
93 find "${afterdir}" -type d -name \*.vim.d | \
95 echo '" Generated by update_vim_afterscripts' > "${d%.d}"
96 find "${d}" -name \*.vim -type f -maxdepth 1 -print0 | \
97 sort -z | xargs -0 cat >> "${d%.d}"
100 einfo "Removing dead scripts in ${EPREFIX}/usr/share/vim/vimfiles/after"
101 find "${afterdir}" -type f -name \*.vim | \
103 [[ "$(head -n 1 ${f})" == '" Generated by update_vim_afterscripts' ]] \
105 # This is a generated file, but might be abandoned. Check
106 # if there's no corresponding .d directory, or if the
107 # file's effectively empty
108 if [[ ! -d "${f}.d" || -z "$(grep -v '^"' "${f}")" ]]; then
114 # Display a message with the plugin's help file if one is available. Uses the
115 # VIM_PLUGIN_HELPFILES env var. If multiple help files are available, they
116 # should be separated by spaces. If no help files are available, but the env
117 # var VIM_PLUGIN_HELPTEXT is set, that is displayed instead. Finally, if we
118 # have nothing else, display a link to VIM_PLUGIN_HELPURI. An extra message
119 # regarding enabling filetype plugins is displayed if VIM_PLUGIN_MESSAGES
120 # includes the word "filetype".
121 display_vim_plugin_help() {
124 if ! has_version ${CATEGORY}/${PN} ; then
125 if [[ -n "${VIM_PLUGIN_HELPFILES}" ]] ; then
127 elog "This plugin provides documentation via vim's help system. To"
129 for h in ${VIM_PLUGIN_HELPFILES} ; do
134 elif [[ -n "${VIM_PLUGIN_HELPTEXT}" ]] ; then
138 done <<<"${VIM_PLUGIN_HELPTEXT}"
141 elif [[ -n "${VIM_PLUGIN_HELPURI}" ]] ; then
143 elog "Documentation for this plugin is available online at:"
144 elog " ${VIM_PLUGIN_HELPURI}"
148 if has "filetype" "${VIM_PLUGIN_MESSAGES}" ; then
149 elog "This plugin makes use of filetype settings. To enable these,"
150 elog "add lines like:"
151 elog " filetype plugin on"
152 elog " filetype indent on"
153 elog "to your ~/.vimrc file."