Native Vim packages make everything a lot more simple, so let's use them. Implementation notes:
- VIM_PLUGIN_AUTOLOAD is unset by default as it's a safer choice. - 'update_vim_helptags' hook is replaced by calling helpztags(1) in 'vim-plugin_src_prepare'. - 'update_vim_afterscripts' hook is useless for the vast majority of packages, so it will not be reimplemented. - Vim package hierarchy is already protected against file collisions, so we don't need to do anything special in 'vim-plugin_src_prepare' anymore. - Debian's helpztags(1) utility is now a dependency used to create documentation tags (app-vim/helpztags needs to be keyworded for multiple arches before we can bump packages to EAPI 9). - I decided to write a one-line '_using_vim_pack' helper function instead of using a variable because function calls are less typo-prone. Closes: https://bugs.gentoo.org/768984 (obsolete) Signed-off-by: Anna (cybertailor) Vyalkova <[email protected]> --- eclass/vim-plugin.eclass | 174 ++++++++++++++++++++++++++++----------- 1 file changed, 125 insertions(+), 49 deletions(-) diff --git a/eclass/vim-plugin.eclass b/eclass/vim-plugin.eclass index b39408a38e6..fc25be9a764 100644 --- a/eclass/vim-plugin.eclass +++ b/eclass/vim-plugin.eclass @@ -5,33 +5,76 @@ # @MAINTAINER: # [email protected] # @SUPPORTED_EAPIS: 7 8 9 -# @BLURB: used for installing vim plugins +# @BLURB: install addons for Vim # @DESCRIPTION: -# This eclass simplifies installation of app-vim plugins into -# /usr/share/vim/vimfiles. This is a version-independent directory -# which is read automatically by vim. The only exception is -# documentation, for which we make a special case via vim-doc.eclass. +# This eclass simplifies installation of Vim plugins into a corresponding +# version-independent directory and generating the help tags file for any +# documentation. +# +# If EAPI 9 or later is used, plugins are installed into directories following +# Vim's native package hierarchy (see ":help packages"), while older EAPIs are +# using the legacy addon packaging. if [[ -z ${_VIM_PLUGIN_ECLASS} ]]; then _VIM_PLUGIN_ECLASS=1 case ${EAPI} in - 7|8|9) ;; + 7|8) inherit vim-doc ;; + 9) ;; *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; esac -inherit vim-doc - [[ ${EAPI} != 7 ]] && _DEFINE_VIM_PLUGIN_SRC_PREPARE=true +# @ECLASS_VARIABLE: VIM_PLUGIN_NAME +# @DESCRIPTION: +# The addon's name. +# +# Change if necessary to match the user's expectation when "packadd! <addon>" +# or "let g:loaded_<addon> = 1" are used. +# +# This variable only makes effect since EAPI 9. +: "${VIM_PLUGIN_NAME:=${PN}}" + +# @ECLASS_VARIABLE: VIM_PLUGIN_AUTOLOAD +# @DEFAULT_UNSET +# @DESCRIPTION: +# If set to a non-empty value, a plugin is immediately enabled for +# users when installed. +# Otherwise, users need to explicitly enable an addon by adding +# "packadd! <addon>" to their vimrc. +# +# According to ":help packages", filetype plugins should always be +# autoloaded, and it's recommended to not autoload color schemes. +# +# This variable only makes effect since EAPI 9. + +# @FUNCTION: _using_vim_pack +# @INTERNAL +# @DESCRIPTION: +# The exit status is 0 if the eclass uses the new Vim plugin packaging +# and 1 if the legacy packaging is used. +_using_vim_pack() { + [[ ${EAPI} != [78] ]] +} + # @ECLASS_VARIABLE: VIM_PLUGIN_VIM_VERSION +# @PRE_INHERIT # @DESCRIPTION: # Minimum Vim version the plugin supports. -: "${VIM_PLUGIN_VIM_VERSION:=7.3}" +if _using_vim_pack; then + # Native package support (i.e. ":packadd") is available since Vim 8.0 + : "${VIM_PLUGIN_VIM_VERSION:=8.0}" +else + : "${VIM_PLUGIN_VIM_VERSION:=7.3}" +fi DEPEND="|| ( >=app-editors/vim-${VIM_PLUGIN_VIM_VERSION} >=app-editors/gvim-${VIM_PLUGIN_VIM_VERSION} )" RDEPEND="${DEPEND}" +_using_vim_pack && + BDEPEND="app-vim/helpztags" + if [[ ${PV} != 9999* ]] ; then SRC_URI="mirror://gentoo/${P}.tar.bz2 https://dev.gentoo.org/~radhermit/vim/${P}.tar.bz2" @@ -40,34 +83,43 @@ SLOT="0" if [[ ${_DEFINE_VIM_PLUGIN_SRC_PREPARE} ]]; then # @FUNCTION: vim-plugin_src_prepare -# @USAGE: # @DESCRIPTION: -# Moves "after/syntax" plugins to directories to avoid file collisions with -# other packages. -# Note that this function is only defined and exported in EAPIs >= 8. +# Overrides the default src_prepare phase. +# +# For EAPI 8 this function moves "after/syntax" plugins to directories +# to avoid file collisions with other packages. +# +# For EAPI 9 and later this function instead creates documentation tags, +# replacing update_vim_helptags. vim-plugin_src_prepare() { debug-print-function ${FUNCNAME} "$@" default_src_prepare - # return if there's nothing to do - [[ -d after/syntax ]] || return + local file + if ! _using_vim_pack && [[ -d after/syntax ]]; then + pushd after/syntax >/dev/null || die + for file in *.vim; do + [[ -f "${file}" ]] || continue + mkdir "${file%.vim}" || die + mv "${file}" "${file%.vim}/${PN}.vim" || die + done + popd >/dev/null || die + fi - pushd after/syntax >/dev/null || die - for file in *.vim; do - [[ -f "${file}" ]] || continue - mkdir "${file%.vim}" || die - mv "${file}" "${file%.vim}/${PN}.vim" || die - done - popd >/dev/null || die + if _using_vim_pack && [[ -d doc ]]; then + einfo "Updating documentation tags" + helpztags doc || die + fi } fi # @ECLASS_VARIABLE: _VIM_PLUGIN_ALLOWED_DIRS # @INTERNAL # @DESCRIPTION: -# Vanilla Vim dirs. -# See /usr/share/vim/vim* for reference. +# List of directories recognized by Vim. +# +# See ":help runtimepath" for a reference. _VIM_PLUGIN_ALLOWED_DIRS=( after autoload colors compiler doc ftdetect ftplugin indent keymap macros plugin spell syntax @@ -76,12 +128,12 @@ _VIM_PLUGIN_ALLOWED_DIRS=( # @FUNCTION: vim-plugin_src_install # @USAGE: [<dir>...] # @DESCRIPTION: -# Overrides the default src_install phase. In order, this function: -# -# * installs help and documentation files. +# Overrides the default src_install phase. # -# * installs all files recognized by default Vim installation and directories -# passed to this function as arguments in "${ED}"/usr/share/vim/vimfiles. +# This function installs all plugin files that are recognized by +# default Vim installation (see ":help runtimepath" for an overview). +# If any additional directories are passed to this function as +# arguments, install them too. # # Example use: # @CODE @@ -92,50 +144,60 @@ _VIM_PLUGIN_ALLOWED_DIRS=( vim-plugin_src_install() { debug-print-function ${FUNCNAME} "$@" - # Install non-vim-help-docs einstalldocs - # Install remainder of plugin - insinto /usr/share/vim/vimfiles/ - local d + local dirs_to_install=() case ${EAPI} in - 7) - for d in *; do - [[ -d "${d}" ]] || continue - doins -r "${d}" - done ;; - *) - for d in "${_VIM_PLUGIN_ALLOWED_DIRS[@]}" "${@}"; do - [[ -d "${d}" ]] || continue - doins -r "${d}" - done ;; + 7) dirs_to_install=( * ) ;; + *) dirs_to_install=( "${_VIM_PLUGIN_ALLOWED_DIRS[@]}" "${@}" ) ;; esac + + local vim_pack_dir="/usr/share/vim/vimfiles/pack/dist-bundle" + if ! _using_vim_pack; then + insinto /usr/share/vim/vimfiles + elif [[ ${VIM_PLUGIN_AUTOLOAD} ]]; then + insinto "${vim_pack_dir}/start/${VIM_PLUGIN_NAME}" + else + insinto "${vim_pack_dir}/opt/${VIM_PLUGIN_NAME}" + fi + + local d + for d in "${dirs_to_install[@]}"; do + [[ -d "${d}" ]] || continue + doins -r "${d}" + done } # @FUNCTION: vim-plugin_pkg_postinst -# @USAGE: # @DESCRIPTION: # Overrides the pkg_postinst phase for this eclass. +# # The following functions are called: # -# * update_vim_helptags +# * update_vim_helptags (only in EAPI < 9) # -# * update_vim_afterscripts +# * update_vim_afterscripts (only in EAPI < 9) # # * display_vim_plugin_help vim-plugin_pkg_postinst() { debug-print-function ${FUNCNAME} "$@" - update_vim_helptags # from vim-doc - update_vim_afterscripts # see below + if ! _using_vim_pack; then + update_vim_helptags # from vim-doc + update_vim_afterscripts # see below + fi display_vim_plugin_help # see below } +if ! _using_vim_pack; then # @FUNCTION: vim-plugin_pkg_postrm # @DESCRIPTION: # Overrides the pkg_postrm phase for this eclass. +# # This function calls the update_vim_helptags and update_vim_afterscripts # functions and eventually removes a bunch of empty directories. +# +# This function is only defined and exported in EAPI < 9. vim-plugin_pkg_postrm() { debug-print-function ${FUNCNAME} "$@" @@ -147,12 +209,16 @@ vim-plugin_pkg_postrm() { find "${EPREFIX}/usr/share/vim/vimfiles" -depth -type d -exec rmdir {} \; 2>/dev/null || \ die "rmdir failed" } +fi +if ! _using_vim_pack; then # @FUNCTION: update_vim_afterscripts # @USAGE: # @DESCRIPTION: # Creates scripts in /usr/share/vim/vimfiles/after/* # comprised of the snippets in /usr/share/vim/vimfiles/after/*/*.d +# +# This function is only defined in EAPI < 9. update_vim_afterscripts() { debug-print-function ${FUNCNAME} "$@" @@ -181,6 +247,7 @@ update_vim_afterscripts() { fi done } +fi # @FUNCTION: display_vim_plugin_help # @USAGE: @@ -197,6 +264,12 @@ display_vim_plugin_help() { local h + if _using_vim_pack && [[ ! ${VIM_PLUGIN_AUTOLOAD} ]]; then + elog "This plugin will not be loaded automatically. To enable it," + elog "add the following line to your ~/.vimrc file:" + elog " packadd! ${VIM_PLUGIN_NAME}" + fi + if [[ -z ${REPLACING_VERSIONS} ]]; then if [[ -n ${VIM_PLUGIN_HELPFILES} ]]; then elog " " @@ -237,4 +310,7 @@ fi # src_prepare is only exported in EAPI >= 8 [[ ${_DEFINE_VIM_PLUGIN_SRC_PREPARE} ]] && EXPORT_FUNCTIONS src_prepare -EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm +# pkg_postrm is only exported in EAPI < 9 +_using_vim_pack || EXPORT_FUNCTIONS pkg_postrm + +EXPORT_FUNCTIONS src_install pkg_postinst -- 2.52.0
