1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: vim-plugin.eclass
7 # @BLURB: used for installing vim plugins
9 # This eclass simplifies installation of app-vim plugins into
10 # /usr/share/vim/vimfiles. This is a version-independent directory
11 # which is read automatically by vim. The only exception is
12 # documentation, for which we make a special case via vim-doc.eclass.
14 inherit estack vim-doc
15 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
17 VIM_PLUGIN_VIM_VERSION="${VIM_PLUGIN_VIM_VERSION:-7.3}"
19 DEPEND="|| ( >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION}
20 >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} )"
22 if [[ ${PV} != 9999* ]] ; then
23 SRC_URI="mirror://gentoo/${P}.tar.bz2
24 https://dev.gentoo.org/~radhermit/vim/${P}.tar.bz2"
28 # @FUNCTION: vim-plugin_src_install
30 # Overrides the default src_install phase. In order, this function:
31 # * fixes file permission across all files in ${S}.
32 # * installs help and documentation files.
33 # * installs all files in "${ED}"/usr/share/vim/vimfiles.
34 vim-plugin_src_install() {
35 has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
38 # When globbing, if nothing exists, the shell literally returns the glob
39 # pattern. So turn on nullglob and extglob options to avoid this.
40 eshopts_push -s extglob
41 eshopts_push -s nullglob
43 ebegin "Cleaning up unwanted files and directories"
44 # We're looking for dotfiles, dotdirectories and Makefiles here.
46 eval "local matches=(@(.[^.]|.??*|Makefile*))"
47 for obj in "${matches[@]}"; do
48 rm -rv "${obj}" || die "cannot remove ${obj}"
52 # Turn those options back off.
56 # Install non-vim-help-docs
57 cd "${S}" || die "couldn't cd in ${S}"
60 [[ -f "${f}" ]] || continue
61 if [[ "${f}" = *.html ]]; then
69 # Install remainder of plugin
70 cd "${WORKDIR}" || die "couldn't cd in ${WORKDIR}"
72 mv "${S}" "${ED}"/usr/share/vim/vimfiles || die \
73 "couldn't move ${S} to ${ED}/usr/share/vim/vimfiles"
76 fperms -R a+rX /usr/share/vim/vimfiles
79 # @FUNCTION: vim-plugin_pkg_postinst
81 # Overrides the pkg_postinst phase for this eclass.
82 # The following functions are called:
83 # * update_vim_helptags
84 # * update_vim_afterscripts
85 # * display_vim_plugin_help
86 vim-plugin_pkg_postinst() {
87 update_vim_helptags # from vim-doc
88 update_vim_afterscripts # see below
89 display_vim_plugin_help # see below
92 # @FUNCTION: vim-plugin_pkg_postrm
94 # Overrides the pkg_postrm phase for this eclass.
95 # This function calls the update_vim_helptags and update_vim_afterscripts
96 # functions and eventually removes a bunch of empty directories.
97 vim-plugin_pkg_postrm() {
98 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
99 update_vim_helptags # from vim-doc
100 update_vim_afterscripts # see below
102 # Remove empty dirs; this allows
103 # /usr/share/vim to be removed if vim-core is unmerged
104 find "${EPREFIX}/usr/share/vim/vimfiles" -depth -type d -exec rmdir {} \; 2>/dev/null || \
108 # @FUNCTION: update_vim_afterscripts
110 # Creates scripts in /usr/share/vim/vimfiles/after/*
111 # comprised of the snippets in /usr/share/vim/vimfiles/after/*/*.d
112 update_vim_afterscripts() {
113 has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
114 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
115 local d f afterdir="${EROOT}"/usr/share/vim/vimfiles/after
117 # Nothing to do if the dir isn't there
118 [ -d "${afterdir}" ] || return 0
120 einfo "Updating scripts in ${EPREFIX}/usr/share/vim/vimfiles/after"
121 find "${afterdir}" -type d -name \*.vim.d | while read d; do
122 echo '" Generated by update_vim_afterscripts' > "${d%.d}" || die
123 find "${d}" -name \*.vim -type f -maxdepth 1 -print0 | sort -z | \
124 xargs -0 cat >> "${d%.d}" || die "update_vim_afterscripts failed"
127 einfo "Removing dead scripts in ${EPREFIX}/usr/share/vim/vimfiles/after"
128 find "${afterdir}" -type f -name \*.vim | \
130 [[ "$(head -n 1 ${f})" == '" Generated by update_vim_afterscripts' ]] \
132 # This is a generated file, but might be abandoned. Check
133 # if there's no corresponding .d directory, or if the
134 # file's effectively empty
135 if [[ ! -d "${f}.d" || -z "$(grep -v '^"' "${f}")" ]]; then
141 # @FUNCTION: display_vim_plugin_help
143 # Displays a message with the plugin's help file if one is available. Uses the
144 # VIM_PLUGIN_HELPFILES env var. If multiple help files are available, they
145 # should be separated by spaces. If no help files are available, but the env
146 # var VIM_PLUGIN_HELPTEXT is set, that is displayed instead. Finally, if we
147 # have nothing else, this functions displays a link to VIM_PLUGIN_HELPURI. An
148 # extra message regarding enabling filetype plugins is displayed if
149 # VIM_PLUGIN_MESSAGES includes the word "filetype".
150 display_vim_plugin_help() {
153 if ! has_version ${CATEGORY}/${PN} ; then
154 if [[ -n "${VIM_PLUGIN_HELPFILES}" ]] ; then
156 elog "This plugin provides documentation via vim's help system. To"
158 for h in ${VIM_PLUGIN_HELPFILES} ; do
163 elif [[ -n "${VIM_PLUGIN_HELPTEXT}" ]] ; then
167 done <<<"${VIM_PLUGIN_HELPTEXT}"
170 elif [[ -n "${VIM_PLUGIN_HELPURI}" ]] ; then
172 elog "Documentation for this plugin is available online at:"
173 elog " ${VIM_PLUGIN_HELPURI}"
177 if has "filetype" "${VIM_PLUGIN_MESSAGES}" ; then
178 elog "This plugin makes use of filetype settings. To enable these,"
179 elog "add lines like:"
180 elog " filetype plugin on"
181 elog " filetype indent on"
182 elog "to your ~/.vimrc file."