sys-process/glances: revbump 3.1.4.1, add missing doc dep
[gentoo.git] / eclass / vim-plugin.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: vim-plugin.eclass
5 # @MAINTAINER:
6 # vim@gentoo.org
7 # @BLURB: used for installing vim plugins
8 # @DESCRIPTION:
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.
13
14 inherit estack vim-doc
15 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
16
17 VIM_PLUGIN_VIM_VERSION="${VIM_PLUGIN_VIM_VERSION:-7.3}"
18
19 DEPEND="|| ( >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION}
20         >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} )"
21 RDEPEND="${DEPEND}"
22 if [[ ${PV} != 9999* ]] ; then
23         SRC_URI="mirror://gentoo/${P}.tar.bz2
24                 https://dev.gentoo.org/~radhermit/vim/${P}.tar.bz2"
25 fi
26 SLOT="0"
27
28 # @FUNCTION: vim-plugin_src_install
29 # @DESCRIPTION:
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}"
36         local f
37
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
42
43         ebegin "Cleaning up unwanted files and directories"
44         # We're looking for dotfiles, dotdirectories and Makefiles here.
45         local obj
46         eval "local matches=(@(.[^.]|.??*|Makefile*))"
47         for obj in "${matches[@]}"; do
48                 rm -rv "${obj}" || die "cannot remove ${obj}"
49         done
50         eend $?
51
52         # Turn those options back off.
53         eshopts_pop
54         eshopts_pop
55
56         # Install non-vim-help-docs
57         cd "${S}" || die "couldn't cd in ${S}"
58         local f
59         for f in *; do
60                 [[ -f "${f}" ]] || continue
61                 if [[ "${f}" = *.html ]]; then
62                         dohtml "${f}"
63                 else
64                         dodoc "${f}"
65                 fi
66                 rm "${f}" || die
67         done
68
69         # Install remainder of plugin
70         cd "${WORKDIR}" || die "couldn't cd in ${WORKDIR}"
71         dodir /usr/share/vim
72         mv "${S}" "${ED}"/usr/share/vim/vimfiles || die \
73                 "couldn't move ${S} to ${ED}/usr/share/vim/vimfiles"
74
75         # Set permissions
76         fperms -R a+rX /usr/share/vim/vimfiles
77 }
78
79 # @FUNCTION: vim-plugin_pkg_postinst
80 # @DESCRIPTION:
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
90 }
91
92 # @FUNCTION: vim-plugin_pkg_postrm
93 # @DESCRIPTION:
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
101
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 || \
105                 die "rmdir failed"
106 }
107
108 # @FUNCTION: update_vim_afterscripts
109 # @DESCRIPTION:
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
116
117         # Nothing to do if the dir isn't there
118         [ -d "${afterdir}" ] || return 0
119
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"
125         done
126
127         einfo "Removing dead scripts in ${EPREFIX}/usr/share/vim/vimfiles/after"
128         find "${afterdir}" -type f -name \*.vim | \
129         while read f; do
130                 [[ "$(head -n 1 ${f})" == '" Generated by update_vim_afterscripts' ]] \
131                         || continue
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
136                         rm "${f}" || die
137                 fi
138         done
139 }
140
141 # @FUNCTION: display_vim_plugin_help
142 # @DESCRIPTION:
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() {
151         local h
152
153         if ! has_version ${CATEGORY}/${PN} ; then
154                 if [[ -n "${VIM_PLUGIN_HELPFILES}" ]] ; then
155                         elog " "
156                         elog "This plugin provides documentation via vim's help system. To"
157                         elog "view it, use:"
158                         for h in ${VIM_PLUGIN_HELPFILES} ; do
159                                 elog "    :help ${h}"
160                         done
161                         elog " "
162
163                 elif [[ -n "${VIM_PLUGIN_HELPTEXT}" ]] ; then
164                         elog " "
165                         while read h ; do
166                                 elog "$h"
167                         done <<<"${VIM_PLUGIN_HELPTEXT}"
168                         elog " "
169
170                 elif [[ -n "${VIM_PLUGIN_HELPURI}" ]] ; then
171                         elog " "
172                         elog "Documentation for this plugin is available online at:"
173                         elog "    ${VIM_PLUGIN_HELPURI}"
174                         elog " "
175                 fi
176
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."
183                         elog " "
184                 fi
185         fi
186 }