Gentoo Archives: gentoo-dev

From: Anna Vyalkova <cyber+gentoo@×××××.in>
To: gentoo-dev@l.g.o
Cc: vim@g.o
Subject: [gentoo-dev] [PATCH v5 5/9] vim-plugin.eclass: document VIM_PLUGIN_VIM_VERSION
Date: Mon, 11 Apr 2022 12:35:09
Message-Id: 20220411123306.24750-6-cyber+gentoo@sysrq.in
In Reply to: [gentoo-dev] [PATCH v5 0/9] Vim eclasses by Anna Vyalkova
1 Signed-off-by: Anna Vyalkova <cyber+gentoo@×××××.in>
2 ---
3 eclass/vim-plugin.eclass | 3 +++
4 1 file changed, 3 insertions(+)
5
6 diff --git a/eclass/vim-plugin.eclass b/eclass/vim-plugin.eclass
7 index a7b5f258b0..a521c3673c 100644
8 --- a/eclass/vim-plugin.eclass
9 +++ b/eclass/vim-plugin.eclass
10 @@ -1,225 +1,228 @@
11 # Copyright 1999-2022 Gentoo Authors
12 # Distributed under the terms of the GNU General Public License v2
13
14 # @ECLASS: vim-plugin.eclass
15 # @MAINTAINER:
16 # vim@g.o
17 # @SUPPORTED_EAPIS: 6 7 8
18 # @BLURB: used for installing vim plugins
19 # @DESCRIPTION:
20 # This eclass simplifies installation of app-vim plugins into
21 # /usr/share/vim/vimfiles. This is a version-independent directory
22 # which is read automatically by vim. The only exception is
23 # documentation, for which we make a special case via vim-doc.eclass.
24
25 case ${EAPI} in
26 6|7) ;;
27 8) _DEFINE_VIM_PLUGIN_SRC_PREPARE=true ;;
28 *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
29 esac
30
31 if [[ ! ${_VIM_PLUGIN_ECLASS} ]]; then
32
33 inherit vim-doc
34
35 fi
36
37 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
38
39 # src_prepare is only exported in EAPI >= 8
40 case ${EAPI:-0} in
41 6|7) ;;
42 8) EXPORT_FUNCTIONS src_prepare ;;
43 esac
44
45 if [[ ! ${_VIM_PLUGIN_ECLASS} ]]; then
46 +# @ECLASS_VARIABLE: VIM_PLUGIN_VIM_VERSION
47 +# @DESCRIPTION:
48 +# Minimum Vim version the plugin supports.
49 VIM_PLUGIN_VIM_VERSION="${VIM_PLUGIN_VIM_VERSION:-7.3}"
50
51 DEPEND="|| ( >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION}
52 >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} )"
53 RDEPEND="${DEPEND}"
54 if [[ ${PV} != 9999* ]] ; then
55 SRC_URI="mirror://gentoo/${P}.tar.bz2
56 https://dev.gentoo.org/~radhermit/vim/${P}.tar.bz2"
57 fi
58 SLOT="0"
59
60 if ${_DEFINE_VIM_PLUGIN_SRC_PREPARE}; then
61 # @FUNCTION: vim-plugin_src_prepare
62 # @USAGE:
63 # @DESCRIPTION:
64 # Moves "after/syntax" plugins to directories to avoid file collisions with
65 # other packages.
66 # Note that this function is only defined and exported in EAPIs >= 8.
67 vim-plugin_src_prepare() {
68 default_src_prepare
69
70 # return if there's nothing to do
71 [[ -d after/syntax ]] || return
72
73 pushd after/syntax >/dev/null || die
74 for file in *.vim; do
75 [[ -f "${file}" ]] || continue
76 mkdir "${file%.vim}" || die
77 mv "${file}" "${file%.vim}/${PN}.vim" || die
78 done
79 popd >/dev/null || die
80 }
81 fi
82
83 # @ECLASS_VARIABLE: _VIM_PLUGIN_ALLOWED_DIRS
84 # @INTERNAL
85 # @DESCRIPTION:
86 # Vanilla Vim dirs.
87 # See /usr/share/vim/vim* for reference.
88 _VIM_PLUGIN_ALLOWED_DIRS=(
89 after autoload colors compiler doc ftdetect ftplugin indent keymap
90 macros plugin spell syntax
91 )
92
93 # @FUNCTION: vim-plugin_src_install
94 # @USAGE: [<dir>...]
95 # @DESCRIPTION:
96 # Overrides the default src_install phase. In order, this function:
97 # * installs help and documentation files.
98 # * installs all files recognized by default Vim installation and directories
99 # passed to this function as arguments in "${ED}"/usr/share/vim/vimfiles.
100 #
101 # Example use:
102 # @CODE
103 # src_install() {
104 # vim-plugin_src_install syntax_checkers
105 # }
106 # @CODE
107 vim-plugin_src_install() {
108 # Install non-vim-help-docs
109 einstalldocs
110
111 # Install remainder of plugin
112 insinto /usr/share/vim/vimfiles/
113 local d
114 case ${EAPI:-0} in
115 6|7)
116 for d in *; do
117 [[ -d "${d}" ]] || continue
118 doins -r "${d}"
119 done ;;
120 *)
121 for d in "${_VIM_PLUGIN_ALLOWED_DIRS[@]}" "${@}"; do
122 [[ -d "${d}" ]] || continue
123 doins -r "${d}"
124 done ;;
125 esac
126 }
127
128 # @FUNCTION: vim-plugin_pkg_postinst
129 # @USAGE:
130 # @DESCRIPTION:
131 # Overrides the pkg_postinst phase for this eclass.
132 # The following functions are called:
133 # * update_vim_helptags
134 # * update_vim_afterscripts
135 # * display_vim_plugin_help
136 vim-plugin_pkg_postinst() {
137 update_vim_helptags # from vim-doc
138 update_vim_afterscripts # see below
139 display_vim_plugin_help # see below
140 }
141
142 # @FUNCTION: vim-plugin_pkg_postrm
143 # @DESCRIPTION:
144 # Overrides the pkg_postrm phase for this eclass.
145 # This function calls the update_vim_helptags and update_vim_afterscripts
146 # functions and eventually removes a bunch of empty directories.
147 vim-plugin_pkg_postrm() {
148 update_vim_helptags # from vim-doc
149 update_vim_afterscripts # see below
150
151 # Remove empty dirs; this allows
152 # /usr/share/vim to be removed if vim-core is unmerged
153 find "${EPREFIX}/usr/share/vim/vimfiles" -depth -type d -exec rmdir {} \; 2>/dev/null || \
154 die "rmdir failed"
155 }
156
157 # @FUNCTION: update_vim_afterscripts
158 # @USAGE:
159 # @DESCRIPTION:
160 # Creates scripts in /usr/share/vim/vimfiles/after/*
161 # comprised of the snippets in /usr/share/vim/vimfiles/after/*/*.d
162 update_vim_afterscripts() {
163 local d f afterdir="${EROOT}"/usr/share/vim/vimfiles/after
164
165 # Nothing to do if the dir isn't there
166 [[ -d "${afterdir}" ]] || return 0
167
168 einfo "Updating scripts in ${afterdir}"
169 find "${afterdir}" -type d -name \*.vim.d | while read d; do
170 echo '" Generated by update_vim_afterscripts' > "${d%.d}" || die
171 find "${d}" -name \*.vim -type f -maxdepth 1 -print0 | sort -z | \
172 xargs -0 cat >> "${d%.d}" || die "update_vim_afterscripts failed"
173 done
174
175 einfo "Removing dead scripts in ${afterdir}"
176 find "${afterdir}" -type f -name \*.vim | \
177 while read f; do
178 [[ "$(head -n 1 ${f})" == '" Generated by update_vim_afterscripts' ]] \
179 || continue
180 # This is a generated file, but might be abandoned. Check
181 # if there's no corresponding .d directory, or if the
182 # file's effectively empty
183 if [[ ! -d "${f}.d" || -z "$(grep -v '^"' "${f}")" ]]; then
184 rm "${f}" || die
185 fi
186 done
187 }
188
189 # @FUNCTION: display_vim_plugin_help
190 # @USAGE:
191 # @DESCRIPTION:
192 # Displays a message with the plugin's help file if one is available. Uses the
193 # VIM_PLUGIN_HELPFILES env var. If multiple help files are available, they
194 # should be separated by spaces. If no help files are available, but the env
195 # var VIM_PLUGIN_HELPTEXT is set, that is displayed instead. Finally, if we
196 # have nothing else, this functions displays a link to VIM_PLUGIN_HELPURI. An
197 # extra message regarding enabling filetype plugins is displayed if
198 # VIM_PLUGIN_MESSAGES includes the word "filetype".
199 display_vim_plugin_help() {
200 local h
201
202 if [[ -z ${REPLACING_VERSIONS} ]]; then
203 if [[ -n ${VIM_PLUGIN_HELPFILES} ]]; then
204 elog " "
205 elog "This plugin provides documentation via vim's help system. To"
206 elog "view it, use:"
207 for h in ${VIM_PLUGIN_HELPFILES}; do
208 elog " :help ${h}"
209 done
210 elog " "
211
212 elif [[ -n ${VIM_PLUGIN_HELPTEXT} ]]; then
213 elog " "
214 while read h ; do
215 elog "$h"
216 done <<<"${VIM_PLUGIN_HELPTEXT}"
217 elog " "
218
219 elif [[ -n ${VIM_PLUGIN_HELPURI} ]]; then
220 elog " "
221 elog "Documentation for this plugin is available online at:"
222 elog " ${VIM_PLUGIN_HELPURI}"
223 elog " "
224 fi
225
226 if has filetype ${VIM_PLUGIN_MESSAGES}; then
227 elog "This plugin makes use of filetype settings. To enable these,"
228 elog "add lines like:"
229 elog " filetype plugin on"
230 elog " filetype indent on"
231 elog "to your ~/.vimrc file."
232 elog " "
233 fi
234 fi
235 }
236
237 _VIM_PLUGIN_ECLASS=1
238 fi
239 --
240 2.35.1