x11-themes/gentoo10-backgrounds: Cleanup per bug #85210
[gentoo.git] / eclass / vim-plugin.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: vim-plugin.eclass
6 # @MAINTAINER:
7 # vim@gentoo.org
8 # @BLURB: used for installing vim plugins
9 # @DESCRIPTION:
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.
14
15 inherit vim-doc
16 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
17
18 VIM_PLUGIN_VIM_VERSION="${VIM_PLUGIN_VIM_VERSION:-7.3}"
19
20 DEPEND="|| ( >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION}
21         >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} )"
22 RDEPEND="${DEPEND}"
23 if [[ ${PV} != 9999* ]] ; then
24         SRC_URI="mirror://gentoo/${P}.tar.bz2
25                 https://dev.gentoo.org/~radhermit/vim/${P}.tar.bz2"
26 fi
27 SLOT="0"
28
29 vim-plugin_src_install() {
30         has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}"
31         local f
32
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"
40                 else
41                         find "${S}" -group 'portage' -exec chgrp root '{}' \; || die "chgrp failed"
42                 fi
43                 eend $?
44         fi
45
46         # Remove unwanted files that may exist
47         rm -rf .[^.] .??* Makefile*
48
49         # Install non-vim-help-docs
50         cd "${S}"
51         for f in *; do
52                 [[ -f "${f}" ]] || continue
53                 if [[ "${f}" = *.html ]]; then
54                         dohtml "${f}"
55                 else
56                         dodoc "${f}"
57                 fi
58                 rm -f "${f}"
59         done
60
61         # Install remainder of plugin
62         cd "${WORKDIR}"
63         dodir /usr/share/vim
64         mv "${S}" "${ED}"/usr/share/vim/vimfiles
65
66         # Fix remaining bad permissions
67         chmod -R -x+X "${ED}"/usr/share/vim/vimfiles/ || die "chmod failed"
68 }
69
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
74 }
75
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
80
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
84 }
85
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
93
94         # Nothing to do if the dir isn't there
95         [ -d "${afterdir}" ] || return 0
96
97         einfo "Updating scripts in ${EPREFIX}/usr/share/vim/vimfiles/after"
98         find "${afterdir}" -type d -name \*.vim.d | \
99         while read d; do
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}"
103         done
104
105         einfo "Removing dead scripts in ${EPREFIX}/usr/share/vim/vimfiles/after"
106         find "${afterdir}" -type f -name \*.vim | \
107         while read f; do
108                 [[ "$(head -n 1 ${f})" == '" Generated by update_vim_afterscripts' ]] \
109                         || continue
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
114                         rm -f "${f}"
115                 fi
116         done
117 }
118
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() {
127         local h
128
129         if ! has_version ${CATEGORY}/${PN} ; then
130                 if [[ -n "${VIM_PLUGIN_HELPFILES}" ]] ; then
131                         elog " "
132                         elog "This plugin provides documentation via vim's help system. To"
133                         elog "view it, use:"
134                         for h in ${VIM_PLUGIN_HELPFILES} ; do
135                                 elog "    :help ${h}"
136                         done
137                         elog " "
138
139                 elif [[ -n "${VIM_PLUGIN_HELPTEXT}" ]] ; then
140                         elog " "
141                         while read h ; do
142                                 elog "$h"
143                         done <<<"${VIM_PLUGIN_HELPTEXT}"
144                         elog " "
145
146                 elif [[ -n "${VIM_PLUGIN_HELPURI}" ]] ; then
147                         elog " "
148                         elog "Documentation for this plugin is available online at:"
149                         elog "    ${VIM_PLUGIN_HELPURI}"
150                         elog " "
151                 fi
152
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."
159                         elog " "
160                 fi
161         fi
162 }