dev-util/qbs: version bump
[gentoo.git] / eclass / vim-doc.eclass
1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4 #
5 # This eclass is used by vim.eclass and vim-plugin.eclass to update
6 # the documentation tags.  This is necessary since vim doesn't look in
7 # /usr/share/vim/vimfiles/doc for documentation; it only uses the
8 # versioned directory, for example /usr/share/vim/vim62/doc
9 #
10 # We depend on vim being installed, which is satisfied by either the
11 # DEPEND in vim-plugin or by whatever version of vim is being
12 # installed by the eclass.
13
14
15 update_vim_helptags() {
16         has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
17         local vimfiles vim d s
18
19         # This is where vim plugins are installed
20         vimfiles="${EROOT}"/usr/share/vim/vimfiles
21
22         if [[ $PN != vim-core ]]; then
23                 # Find a suitable vim binary for updating tags :helptags
24                 vim=$(type -P vim 2>/dev/null)
25                 [[ -z "$vim" ]] && vim=$(type -P gvim 2>/dev/null)
26                 [[ -z "$vim" ]] && vim=$(type -P kvim 2>/dev/null)
27                 if [[ -z "$vim" ]]; then
28                         ewarn "No suitable vim binary to rebuild documentation tags"
29                 fi
30         fi
31
32         # Make vim not try to connect to X. See :help gui-x11-start
33         # in vim for how this evil trickery works.
34         if [[ -n "${vim}" ]] ; then
35                 ln -s "${vim}" "${T}/tagvim"
36                 vim="${T}/tagvim"
37         fi
38
39         # Install the documentation symlinks into the versioned vim
40         # directory and run :helptags
41         for d in "${EROOT%/}"/usr/share/vim/vim[0-9]*; do
42                 [[ -d "$d/doc" ]] || continue   # catch a failed glob
43
44                 # Remove links, and possibly remove stale dirs
45                 find $d/doc -name \*.txt -type l | while read s; do
46                         [[ $(readlink "$s") = $vimfiles/* ]] && rm -f "$s"
47                 done
48                 if [[ -f "$d/doc/tags" && $(find "$d" | wc -l | tr -d ' ') = 3 ]]; then
49                         # /usr/share/vim/vim61
50                         # /usr/share/vim/vim61/doc
51                         # /usr/share/vim/vim61/doc/tags
52                         einfo "Removing $d"
53                         rm -r "$d"
54                         continue
55                 fi
56
57                 # Re-create / install new links
58                 if [[ -d $vimfiles/doc ]]; then
59                         ln -s $vimfiles/doc/*.txt $d/doc 2>/dev/null
60                 fi
61
62                 # Update tags; need a vim binary for this
63                 if [[ -n "$vim" ]]; then
64                         einfo "Updating documentation tags in $d"
65                         DISPLAY= $vim -u NONE -U NONE -T xterm -X -n -f \
66                                 '+set nobackup nomore' \
67                                 "+helptags $d/doc" \
68                                 '+qa!' </dev/null &>/dev/null
69                 fi
70         done
71
72         [[ -n "${vim}" && -f "${vim}" ]] && rm "${vim}"
73 }