On sob gru 30 2006, Mikolaj Machowski wrote:
> Do you mean create tags files for every code file, and change tags
> file when switching between different code files?
> But how to combine all of these actions to a hotkey?
> If ctags can provide an update option, the problem can be solved very
> easily. But it seems ctags doesn't provide this option any longer.

No. It should looks like this:

1. Map common key to action. For language like C++ ";" (semicolon) is
   good choice (eg. for Python it should be <CR>).
2. inoremap it to function which will insert ; and perform some
   function.
3. This function should:
   
   a) get contents of file (:help getline())
   b) write it to temporary file (:help writefile, :help tempname; wide
      workaround but we don't want to write current file, it could break
      some things)
   c) execute ctags on that file (:help system(), man ctags - you can
      get tags directly into variable (note: this is string)::
      
          :let a = system('ctags -f - '.file)

      Good thing would be to remove header of tags file (lines beginning
      with '!').
   
   Now we have file with updated definitions of tags for current file.
   Rest depends on how do you organize your tags files. Lets assume you
   have one big tags file for whole project.

   d) find tags file (:help 'tags' and check how omnicomplete functions
      are finding tags files)
   e) read this file (:help readfile())
   f) delete lines containing definitions from current file (:help :for,
      :help remove())
   g) connect your new tags and global tags
   h) overwrite old tags file.

   Note: much faster, noticeable on big files, would be reading of tags
   file into buffer and just g//d proper lines and add tags at the end
   - but I hate buffer management in scripts, YMMV.

Sounds complicated but Vim should be able to perform all actions with
reasonable speed. The most expensive is f) .

You should carefully consider when this function should be performed.
I would vote for ; and BufLeave and BufWritePre autocommands.

m.

Reply via email to