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