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