Discussion:Vim pour le projet GL

De Ensiwiki
Révision de 26 janvier 2009 à 16:46 par Len (discussion | contributions)

(diff) ← Version précédente | Voir la version courante (diff) | Version suivante → (diff)
Aller à : navigation, rechercher

J'ai fait un petit script pour avoir un VIM tout configuré pour faire de l'ADA pour le projet GL. Je comptais le fournir au début du projet GL, mais faute de moyen corrects pour le tester, je me suis abstenu. Ce qui est fait, en gros :

  • Télécharger et installer VIM 7.2 (actuellement c'est la vieille version 6 sur ensibm)
  • Télécharger ctags, le patcher pour le support de l'ADA et l'installer.
  • Ajouter les bonnes lignes, si besoin, dans le .bashrc.
  • Télécharger les plugins VIM essentiels :
    • Adabundle (coloration ADA avancée, etc.)
    • MinibufExpl (pour voir graphiquement les fichiers ouverts)
    • TagsParser (mise à jour automatique des tags d'un fichier et apperçu des prototypes des fonctions dans un cadre de VIM)
  • Ajout des données dans le .vimrc
    • Configuration d'AdaBundle
    • Ajout d'un raccourci (CTRL+F1) pour générer les tags d'un projet. Après un simple CTRL+Clic sur une fonction mène à sa définition.
    • Configuration du TagsParser
    • Configuration du makeprg pour que VIM lance "make" lors de la commande :mak et pas adamake.

A noter qu'actuellement on doit indiquer le chemin sous la forme ~/Chemin/Vers/Projet (avec le ~). C'est le plugin TagParser qui s'attend à l'avoir sous cette forme et je sais pas comment on passe d'un chemin absolu "/home/ensi2a/toto/" à un "~/chemin" en shell, à moins de faire du parsing moche.

N'oubliez pas de faire un source ~/.bashrc après l'exécution du script.


#!/bin/sh
INSTALL_DIR=${HOME}/sys
VIM_DIR=${INSTALL_DIR}
CTAGS_DIR=${INSTALL_DIR}
TEMP_DIR=/tmp/vim_temp${USER}

mkdir ${TEMP_DIR} 
cd ${TEMP_DIR}

#DL the last version of VIM and install
echo -e "\033[32m*************************************************"
echo "***** Downloading VIM ***************************"
echo -e "*************************************************\033[00m"
if [ "`vim --version | head -n 1 | cut -c -21`" != "VIM - Vi IMproved 7.2" ]; then
    wget ftp://ftp.vim.org/pub/vim/unix/vim-7.2.tar.bz2;
    tar -xjvf vim-7.2.tar.bz2;
    cd vim72;
    ./configure --prefix=${VIM_DIR} && make -j4 && make install;
    cd ..;
    VIM_DIR=${VIM_DIR}/bin
else
    TEMP=`which vim`
    VIM_DIR=`dirname ${TEMP}`
    echo "VIM is already installed in ${VIM_DIR}"
fi

#DL the last version of Ctags, patch and install
echo -e "\033[32m"
echo "*************************************************"
echo "***** Downloading CTAGS *************************"
echo -e "*************************************************\033[00m"
if [ "`ctags --version | head -n1`" = "Exuberant Ctags @@VERSION@@, Copyright (C) 1996-2004 Darren Hiebert" ]; then
    wget http://igate.ensimag.fr/ctags-5.7.tar.gz
    wget http://igate.ensimag.fr/ctags-ada-mode-4.3.11.tar.bz2
    tar -xzvf ctags-5.7.tar.gz
    tar -xjvf ctags-ada-mode-4.3.11.tar.bz2
    cd ctags-ada-mode-4.3.11
    cp ada.c ../ctags-5.7
    cp add_ada.vim ../ctags-5.7
    cd ../ctags-5.7
    ./configure --prefix=${CTAGS_DIR}
    vim add_ada.vim -c ":so %" -c ":q"
    make -j4
    make install
    cd ..
    CTAGS_DIR=${CTAGS_DIR}/bin
else
    TEMP=`which ctags`
    CTAGS_DIR=`dirname ${TEMP}`
    echo "CTAGS is already installed in ${CTAGS_DIR}"
fi

#Modify .bashrc
echo -e "\033[32m"
echo "*************************************************"
echo "***** Modifying .bashrc *************************"
echo -e "*************************************************\033[00m"
case :$PATH: in *${VIM_DIR}*) echo "VIM already in PATH";; *) 
echo "Adding VIM PATH into .bashrc"
echo -e "PATH=${VIM_DIR}:${PATH}\nexport PATH" >> ${HOME}/.bashrc
PATH=${VIM_DIR}:${PATH}
esac
case :$PATH: in *${CTAGS_DIR}*) echo "CTAGS already in PATH";; *) 
echo "Adding CTAGS PATH into .bashrc"
echo -e "PATH=${CTAGS_DIR}:${PATH}\nexport PATH" >> ${HOME}/.bashrc
PATH=${CTAGS_DIR}:${PATH}
esac
export PATH
source ${HOME}/.bashrc


#Get Vim Spell files (needed by the following .vimrc)
echo -e "\033[32m"
echo "*************************************************"
echo "***** Downloading spell files *******************"
echo -e "*************************************************\033[00m"
if [ ! -e "${HOME}/.vim/spell/fr.latin1.sug" ]; then
    wget http://igate.ensimag.fr/spell.tgz
    tar -xzvf spell.tgz
    mkdir ${HOME}/.vim
    mkdir ${HOME}/.vim/spell/
    mv .vim/spell/fr.* ${HOME}/.vim/spell/
else
    echo "Spell files already installed"
fi

#DL AdaBundle
echo -e "\033[32m"
echo "*************************************************"
echo "***** Downloading Ada Bundle ********************"
echo -e "*************************************************\033[00m"
if [ ! -e "${HOME}/.vim/autoload/ada.vim" ]; then
    #We use a temp vimrc, to be sure vim can do a :so %...
    wget http://igate.ensimag.fr/vimrc_temp 
    wget "http://www.vim.org/scripts/download_script.php?src_id=8904" -O Adabundle.vba 
    ${VIM_DIR}/vim Adabundle.vba -u vimrc_temp -c ":so %" -c "<Space>" -c ":q" 
   
    echo "**** PATCHING ***"
    # This version of ada.vim correctly creates tags
    wget http://igate.ensimag.fr/ada.vim
    mv ada.vim ${HOME}/.vim/autoload/
    # This version of adacomplete.vim correctly parses tags
    wget http://igate.ensimag.fr/adacomplete.vim
    mv adacomplete.vim ${HOME}/.vim/autoload/
else
    echo "Adabundle already downloaded make sure you have the patched version"
fi

echo -e "\033[32m"
echo "*************************************************"
echo "***** Downloading MinibufExpl *******************"
echo -e "*************************************************\033[00m"
if [ ! -e "${HOME}/.vim/plugin/minibufexpl.vim" ]; then
wget "http://www.vim.org/scripts/download_script.php?src_id=3640" -O minibufexpl.vim
mkdir ${HOME}/.vim/plugin/
mv minibufexpl.vim ${HOME}/.vim/plugin
else
    echo "MinibufExpl already downloaded"
fi


echo -e "\033[32m"
echo "*************************************************"
echo "***** Downloading TagsParser ********************"
echo -e "*************************************************\033[00m"
if [ ! -e "${HOME}/.vim/plugin/TagsParser.vim" ]; then
    wget http://www.vim.org/scripts/download_script.php?src_id=6835 -O TagsParser.tgz
    mv TagsParser.tgz ${HOME}/.vim/
    cd ${HOME}/.vim
    tar -xzvf TagsParser.tgz
    cd ${TEMP_DIR}
else
    echo "TagParser already installed"
fi


echo -e "\033[32m"
echo "*************************************************"
echo "***** Project DIR ? *****************************"
echo -e "*************************************************\033[00m"
echo "Please specify your project directory. This will be used to generate tags for auto-completion."
echo -e "\033[31mPlease write it as ~/PATH/TO/YOUR/PROJECT/GL"
echo -e "- The ~ represents your home directory"
echo -e "- DON'T put a / at the end of the path !\033[00m"
echo -e "Directory ? (~/Projet_GL for example)"
read PROJET_GL_DIR 
PROJET_GL_DIR2=`echo "${PROJET_GL_DIR}" | sed "s:~:${HOME}:"`
echo ${PROJET_GL_DIR2}
if [ ! -d ${PROJET_GL_DIR2} ]; then
    echo "Directory ${PROJET_GL_DIR2} does not exist."
    echo "Please re-run the script and select the right directory."
    exit 1;
fi

echo -e "\033[32m"
echo "*************************************************"
echo "***** Tags generation ***************************"
echo -e "*************************************************\033[00m"
cd ${PROJET_GL_DIR2}
echo "ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ ."
ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ .
cd ${TEMP_DIR}

#Get a complete .vimrc for the project
echo -e "\033[32m"
echo "*************************************************"
echo "***** Modifying .vimrc **************************"
echo -e "*************************************************\033[00m"
if [ ! -e "${HOME}/.vimrc" ]; then
    wget http://igate.ensimag.fr/vimrc -O .vimrc
    mv .vimrc ${HOME}/.vimrc 
    echo "set tags=${PROJET_GL_DIR2}/tags" >> ${HOME}/.vimrc
    echo "let g:TagsParserTagsPath=\"${PROJET_GL_DIR}**\"" >> ${HOME}/.vimrc
    echo "nmap <C-F1> :!ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ ${PROJET_GL_DIR2} && mv tags ${PROJET_GL_DIR2}/tags <CR><CR>" >> ${HOME}/.vimrc
    echo "imap <C-F1> :!ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ ${PROJET_GL_DIR2} && mv tags ${PROJET_GL_DIR2}/tags <CR><CR>" >> ${HOME}/.vimrc
else
    echo -e "\033[31mYou already have a .vimrc file !\033[00m"
    echo "What should we do ?"
    echo "[O]verride : will replace your .vimrc"
    echo "[A]ppend : will add extra ada informations in your vimrc."
    echo "[S]how : show which lines will be added to your .vimrc."
    echo "[C]ontinue : do nothing"
    read -n 1 variable
    variable=`echo "${variable}" | sed 's/.*/\U&/'`
    case ${variable} in
     O) echo "verriding..."
        wget http://igate.ensimag.fr/vimrc -O .vimrc
        mv .vimrc ${HOME}/.vimrc 
        echo "set tags=${PROJET_GL_DIR2}/tags" >> ${HOME}/.vimrc
        echo "let g:TagsParserTagsPath=\"${PROJET_GL_DIR}**\"" >> ${HOME}/.vimrc
        echo "nmap <C-F1> :!ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ ${PROJET_GL_DIR2} && mv tags ${PROJET_GL_DIR2}/tags <CR><CR>" >> ${HOME}/.vimrc
        echo "imap <C-F1> :!ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ ${PROJET_GL_DIR2} && mv tags ${PROJET_GL_DIR2}/tags <CR><CR>" >> ${HOME}/.vimrc
        ;;
     A) echo "ppend"
        echo "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" >> ${HOME}/.vimrc
        echo "\" Adabundle" >> ${HOME}/.vimrc
        echo "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" >> ${HOME}/.vimrc
        echo "let g:ada_standard_types = 1" >> ${HOME}/.vimrc
        echo "let g:ada_line_errors = 1" >> ${HOME}/.vimrc
        echo "set makeprg=make" >> ${HOME}/.vimrc
        echo "if !exists(\"g:gnat\")" >> ${HOME}/.vimrc
        echo "  let g:gnat = gnat#New ()" >> ${HOME}/.vimrc
        echo "endif" >> ${HOME}/.vimrc
        echo "let g:gnat.Make_Command=\"'make'\"" >> ${HOME}/.vimrc

        echo "" >> ${HOME}/.vimrc
        echo "" >> ${HOME}/.vimrc
        echo "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" >> ${HOME}/.vimrc
        echo "\" TagsParser                \"" >> ${HOME}/.vimrc
        echo "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" >> ${HOME}/.vimrc
        echo "let g:TagsParserTagsProgram = \"ctags\"" >> ${HOME}/.vimrc

        echo "" >> ${HOME}/.vimrc
        echo "let g:TagsParserLastPositionJump = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserCurrentFileCWD = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserFoldColumnDisabled = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserWindowSize = 25 \"Not more in 1024*768 or >> ${HOME}/.vimrc the cursor disappears !" >> ${HOME}/.vimrc
        echo "let g:TagsParserAutoOpenClose = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserSingleClick = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserHighlightCurrentTag = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserSortType = \"line\"" >> ${HOME}/.vimrc

        echo "" >> ${HOME}/.vimrc
        echo "let g:TagsParserCtagsOptions_ada = \"--ada-kinds=+PTUVRKOEay\"" >> ${HOME}/.vimrc
        echo "let g:TagsParserCtagsOptions_c = \"--c-kinds=+lpx\"" >> ${HOME}/.vimrc
        echo "let g:TagsParserCtagsOptions_cpp = \"--c-kinds=+lpx\"" >> ${HOME}/.vimrc

        echo "" >> ${HOME}/.vimrc
        echo "let g:TagsParserCtrlTabUsage = 'tabs'" >> ${HOME}/.vimrc
        echo "let g:TagsParserCtagsOptionsTypeList = [ \"ada\", \"c\" ]" >> ${HOME}/.vimrc

        echo "" >> ${HOME}/.vimrc
        echo "\"force the prototypes to be folded for c/cpp files" >> ${HOME}/.vimrc
        echo "let g:TagsParserFoldHeading_c_p = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserFoldHeading_cpp_p = 1" >> ${HOME}/.vimrc

        echo "" >> ${HOME}/.vimrc
        echo "\"force non-informative specifications to be folded for ada files" >> ${HOME}/.vimrc
        echo "let g:TagsParserFoldHeading_ada_R = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserFoldHeading_ada_E = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserFoldHeading_ada_T = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserFoldHeading_ada_U = 1" >> ${HOME}/.vimrc
        echo "let g:TagsParserFoldHeading_ada_V = 1" >> ${HOME}/.vimrc

        echo "" >> ${HOME}/.vimrc
        echo "" >> ${HOME}/.vimrc
        echo "\" Tags"  >> ${HOME}/.vimrc
        echo "set tags=${PROJET_GL_DIR2}/tags" >> ${HOME}/.vimrc
        echo "let g:TagsParserTagsPath=\"${PROJET_GL_DIR}**\"" >> ${HOME}/.vimrc
        echo "nmap <C-F1> :!ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ ${PROJET_GL_DIR2} && mv tags ${PROJET_GL_DIR2}/tags <CR><CR>" >> ${HOME}/.vimrc
        echo "imap <C-F1> :!ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ ${PROJET_GL_DIR2} && mv tags ${PROJET_GL_DIR2}/tags <CR><CR>" >> ${HOME}/.vimrc
        ;;
     S) echo "how"

        echo -e "\033[32m*************************************************"
        echo -e "*************************************************\033[00m"

        echo "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\""
        echo "\" Adabundle"
        echo "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\""
        echo "let g:ada_standard_types = 1"
        echo "let g:ada_line_errors = 1"
        echo "set makeprg=make"
        echo "if !exists(\"g:gnat\")"
        echo "  let g:gnat = gnat#New ()"
        echo "endif"
        echo "let g:gnat.Make_Command=\"'make'\""


        echo "" 
        echo "" 
        echo "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\""
        echo "\" TagsParser                \""
        echo "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\""
        echo "let g:TagsParserTagsProgram = \"ctags\""

        echo "" 
        echo "let g:TagsParserLastPositionJump = 1"
        echo "let g:TagsParserCurrentFileCWD = 1"
        echo "let g:TagsParserFoldColumnDisabled = 1"
        echo "let g:TagsParserWindowSize = 25 \"Not more in 1024*768 or the cursor disappears !"
        echo "let g:TagsParserAutoOpenClose = 1"
        echo "let g:TagsParserSingleClick = 1"
        echo "let g:TagsParserHighlightCurrentTag = 1"
        echo "let g:TagsParserSortType = \"line\""

        echo "" 
        echo "let g:TagsParserCtagsOptions_ada = \"--ada-kinds=+PTUVRKOEay\""
        echo "let g:TagsParserCtagsOptions_c = \"--c-kinds=+lpx\""
        echo "let g:TagsParserCtagsOptions_cpp = \"--c-kinds=+lpx\""

        echo "" 
        echo "let g:TagsParserCtrlTabUsage = 'tabs'"
        echo "let g:TagsParserCtagsOptionsTypeList = [ \"ada\", \"c\" ]"

        echo "" 
        echo "\"force the prototypes to be folded for c/cpp files"
        echo "let g:TagsParserFoldHeading_c_p = 1"
        echo "let g:TagsParserFoldHeading_cpp_p = 1"

        echo "" 
        echo "\"force non-informative specifications to be folded for ada files"
        echo "let g:TagsParserFoldHeading_ada_R = 1"
        echo "let g:TagsParserFoldHeading_ada_E = 1"
        echo "let g:TagsParserFoldHeading_ada_T = 1"
        echo "let g:TagsParserFoldHeading_ada_U = 1"
        echo "let g:TagsParserFoldHeading_ada_V = 1"


        echo "" 
        echo "" 
        echo "\" Tags"
        echo "set tags=${PROJET_GL_DIR2}/tags"
        echo "let g:TagsParserTagsPath=\"${PROJET_GL_DIR}**\"" 
        echo "nmap <C-F1> :!ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ ${PROJET_GL_DIR2} && mv tags ${PROJET_GL_DIR2}/tags <CR><CR>"
        echo "imap <C-F1> :!ctags --sort=yes --ada-kinds=+PTUVRKOEay -R /usr/local/GL/ ${PROJET_GL_DIR2} && mv tags ${PROJET_GL_DIR2}/tags <CR><CR>"

        echo -e "\033[32m*************************************************"
        echo -e "*************************************************\033[00m"
        ;;
     C) echo "ontinue"
        ;;
     *) echo ""
        echo "${variable} is not in O A S C..."
    esac
fi


echo -e "\033[32m"
echo "*************************************************"
echo "***** Success ! *********************************"
echo -e "*************************************************\033[00m"
echo "Don't forget to do a source ~/.bashrc to end the installation !"

rm -rf ${TEMP_DIR}


Si un shell guru veur transformer ce code bidouille en beau code, no problemo. J'ai fait ça vite fait et je suis conscient que c'est pas très propre.

A noter que j'ai pas pu tester la chose de font en comble. Si un 2A a encore ses sources GL et un peu de temps libre, il serait bien de tester le script avant de l'intégrer à la page principale. --Lepersb 26 janvier 2009 à 16:18 (UTC)

À mon avis, déjà remplacer les dizaines d'echo successifs par un

cat <<EOF
...
EOF

serait pas mal à mon avis, mais à mon avis, stocker les templates des fichiers à reproduire (.vimrc tout ça) dans des fichiers séparés et genre lancer m4(1) dessus, ce serait tout aussi bien. --Len 26 janvier 2009 à 16:46 (UTC)