Loading ...
Sorry, an error occurred while loading the content.

Re: Tags best-practices for multiple projects?

Expand Messages
  • Tony Mechelynck
    ... make tags generates tags for the Vim project (which, on my machine, has its files at ~/.build/vim/vim71/ and below). You could have a similar target in
    Message 1 of 7 , Sep 30, 2007
    • 0 Attachment
      Mikael Jansson wrote:
      > Hey Tony!
      > >
      >> 2) all tagfiles collected together: it might be easier to handle if each
      >> tagfile is in the top directory for the corresponding project. This assumes
      >> that each project has its own directory structure, separate from every other
      >> project's. If you wish, you may add softlinks (if supported by your OS and
      >> filesystem) from ~/.tags/project1 to (e.g.) ~/.build/project1/tags (Reminder:
      >> every tagfile SHOULD be named "tags" if in Vim format, or "TAGS" if in Emacs
      >> format.)
      > >
      >> 3) auto-generated: see the "tags" target in src/Makefile in the Vim source for
      >> an example.
      > >
      > Not quite sure I understand what you mean by "automatic", here -- I
      > looked in the Makefile but couldn't find much useful that relates to
      > multiple-project tags. Then, I'm not very familiar with tags. I'd
      > appreciate some hand-holding in this matter.

      "make tags" generates tags for the Vim project (which, on my machine, has its
      files at ~/.build/vim/vim71/ and below). You could have a similar target in
      the makefiles for your other projects. If you want the tagfile regenerated in
      some project whenever you invoke "make" without arguments, then you could have
      a dependency for "tags" (or for some equivalent phony target) in the default
      target (such as "all") defined in the makefile for that project. Or else run
      "make tags" manually after running "make" or instead of it.

      >
      >> 4) with (2) above, ":cd <projectdir>" ought to be enough to have Vim find the
      >> correct tagfile.
      >>
      > I'd need for vim to scan for the tags file in parent directories
      > successively until it reaches the root of my project directory and the
      > tags file. Would that be doable?

      yes, it's a matter of having the correct value in the 'tags' option. See
      ":help file-searching" and scroll down to "2) Upward search".

      Example:
      set tags=tags,./tags;

      meaning: search for "tags" in the current directory, and upward starting at
      the directory of the current file. To limit the upward search, add a
      "stop-directory" after the semicolon.

      >
      > Moreover, I'd probably need the tags from >1 project (but still separate
      > tags files!) -- can I make vim merge the inputted definitions and/or
      > read >1 tags file? Or do I have to do it manually by defining all
      > directories when creating the tags file, i.e. w/ ctags?
      >
      > - Mikael

      Hm, why would you need the tagfiles from several projects at the same time?
      Wouldn't you want to limit the search to the project you're currently working on?

      From ":help tags-option" I seem to understand that all tagfiles in all dirs
      specified (including upward dirs if specified) are searched until a matching
      tag is found. What "matching" means in this context depends on the
      'ignorecase' setting. You could e.g. use

      set tags+=/usr/include/tags

      if you have generated a tagfile there for your common include files.

      To edit files from different projects in split-windows in a single Vim, then
      (if the default option of searching from the current file's dir doesn't suit
      you), remember that this option is |global-local| : you can use ":setlocal" to
      set a different value for one buffer.


      Best regards,
      Tony.
      --
      Age, n.:
      That period of life in which we compound for the vices that we
      still cherish by reviling those that we no longer have the enterprise
      to commit.
      -- Ambrose Bierce

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Charles E Campbell Jr
      ... Well, for the second point, I use in my .vimrc: Project Vimrc And Tags: {{{1 if has( unix ) source any local .vimrc let origcurdir = getcwd() let
      Message 2 of 7 , Oct 2, 2007
      • 0 Attachment
        Mikael Jansson wrote:

        >I'm working on a bunch of different projects, and I want to have tags
        >files for them. My assumptions are the following:
        >
        >* I should have one tags file per project
        >* I want to have them collected in one place (e.g. ~/.tags)
        >
        >What I'd like is:
        >
        >* To have the tags file (more-or-less) auto-generated and placed
        > in the proper location.
        >* Not having to think about which tags file I need to load up
        > for a specific project.
        >
        >
        Well, for the second point, I use in my .vimrc:

        " Project Vimrc And Tags: {{{1
        if has("unix")
        " source any local .vimrc
        let origcurdir = getcwd()
        let curdir = origcurdir
        while curdir != expand("$HOME")
        if filereadable(".vimrc")
        so .vimrc
        break
        endif
        cd ..
        let curdir= getcwd()
        endwhile

        " set up tags
        exe "cd ".origcurdir
        let curdir = origcurdir
        while curdir != expand("$HOME")
        if filereadable("tags")
        if &tags !~ '\(^\|,\)'.curdir.'\(,\|$\)'
        exe "set tags^=".curdir."/tags"
        endif
        break
        endif
        cd ..
        let curdir= getcwd()
        endwhile

        let curdir= origcurdir
        exe "cd ".origcurdir
        endif

        What this code does is, starting at the current directory and going up,
        look for a "local" .vimrc and a "local" tags file. The first such
        .vimrc file is sourced and the first such tags file is prepended to the
        tags setting. So if one has projects where there's a single top
        directory, place a .vimrc and tags file there.

        Regards,
        Chip Campbell


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      Your message has been successfully submitted and would be delivered to recipients shortly.