summaryrefslogtreecommitdiff
blob: 95a17900626d436c787f35a745e9cd668e99a8f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/vim-plugin.eclass,v 1.4 2003/10/31 02:48:08 agriffis Exp $
#
# 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

inherit vim-doc
ECLASS=vim-plugin
INHERITED="${INHERITED} ${ECLASS}"
EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm

IUSE=""
DEPEND="|| ( >=app-editors/vim-6.2 
	>=app-editors/gvim-6.2 
	>=app-editors/kvim-6.2 )"
RDEPEND="${DEPEND}"
SRC_URI="mirror://gentoo/${P}.tar.bz2"
SLOT="0"

vim-plugin_src_install() {
	local f

	# Make sure perms are good
	chmod -R a+rX ${S}

	# Install non-vim-help-docs
	cd ${S}
	for f in *; do
		[[ -f "${f}" ]] || continue
		if [[ "${f}" = *.html ]]; then
			dohtml "${f}"
		else
			dodoc "${f}"
		fi
		rm -f "${f}"
	done
	
	# Install remainder of plugin
	cd ${WORKDIR}
	dodir /usr/share/vim
	mv ${S} ${D}/usr/share/vim/vimfiles
}

vim-plugin_pkg_postinst() {
	update_vim_helptags		# from vim-doc
	update_vim_afterscripts	# see below
}

vim-plugin_pkg_postrm() {
	update_vim_helptags		# from vim-doc
	update_vim_afterscripts	# see below
	
	# Remove empty dirs; this allows
	# /usr/share/vim to be removed if vim-core is unmerged
	find /usr/share/vim/vimfiles -depth -type d -exec rmdir {} \; 2>/dev/null
}

# update_vim_afterscripts: create scripts in
# /usr/share/vim/vimfiles/after/* comprised of the snippets in
# /usr/share/vim/vimfiles/after/*/*.d
update_vim_afterscripts() {
	local d f afterdir=/usr/share/vim/vimfiles/after

	# Nothing to do if the dir isn't there
	[ -d ${afterdir} ] || return 0

	einfo "Updating scripts in /usr/share/vim/vimfiles/after"
	find ${afterdir} -type d -name \*.vim.d | \
	while read d; do
		echo '" Generated by update_vim_afterscripts' > "${d%.d}"
		find "${d}" -name \*.vim -type f -maxdepth 1 -print0 | \
		sort -z | xargs -0 cat >> "${d%.d}"
	done

	einfo "Removing dead scripts in /usr/share/vim/vimfiles/after"
	find ${afterdir} -type f -name \*.vim | \
	while read f; do
		[[ "$(head -n 1 ${f})" == '" Generated by update_vim_afterscripts' ]] \
			|| continue
		# This is a generated file, but might be abandoned.  Check
		# if there's no corresponding .d directory, or if the
		# file's effectively empty
		if [[ ! -d "${f}.d" || -z "$(grep -v '^"')" ]]; then
			rm -f "${f}"
		fi
	done
}