This should work.

  1. Use Exuberant ctags to generate a tags file for the Drupal codebase. Options to be determined, but something like
    $ /usr/local/bin/ctags -R /path/to/drupal
    should do it.
  2. Edit the tags file, replacing /path/to/drupal with something like $DDIR (for Drupal directory).
  3. Add the tags file to our repository.
  4. In plugin/drupal.vim, via an autocommand and a function, do :let $DDIR='/path/to/drupal'.
  5. In ftplugin/drupal.vim, do :set tags+=<sfile>/tags.

Who needs api.drupal.org? Just position the cursor on drupal_set_message and type <C-]> to view the source!

Comments

benjifisher’s picture

I am not sure where to document this, so I will add it here for now.

$ ctags -R -f drupal6.tags  --extra=+f --langmap=php:+.module.install.inc.profile.theme.engine.test /tmp/drupal-6.22
$ ctags -R -f drupal7.tags  --extra=+f --langmap=php:+.module.install.inc.profile.theme.engine.test /tmp/drupal-7.9

I decided to use $DRUPAL_ROOT for the environment variable, to mimic define('DRUPAL_ROOT', getcwd()); in index.php.

I have done steps 4 and 5 (slightly modified) and will post a patch to #1328290: Add suppport for javascript and other file types. after some more testing. So far, it works like a charm.

In addition to tag searches, it should be possible to use the tags file for omnicompletion via the PHP completion script included with the vim distro. This may take some work: so far, it only looks for tags in the current buffer, not every file listed in the 'tags' option.

benjifisher’s picture

Status: Active » Fixed

I just added the two tags files to the project. They are not very useful without the patch I am about to post to #1328290: Add suppport for javascript and other file types., but they are large enough that I could not post them as a patch on that issue. Look there for further usage suggestions.

Exuberant ctags is very ... exuberant. In other words, it includes tags for a bunch of questionable "variables," "functions," etc. Later, I may decide to remove some lines from the tags files.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

benjifisher’s picture

Version: » 7.x-1.x-dev
Assigned: Unassigned » benjifisher
Category: task » bug
Status: Closed (fixed) » Needs review
StatusFileSize
new2.34 MB
new807.89 KB

I am reopening this issue because the tags files are too big. Blame it on Exuberant ctags. (See #2 above.)

Obviously, a smaller tags file means smaller downloads and faster tag searches, but the real problem with the big tags files is that they make it harder to find what you want. For example, suppose you want to find the definition of url(). If you try

:stag url

in a D7 module, you will find the line

$url = url($batch['url'], $batch['url_options']);

in includes/batch.inc. If you RTFM about tag searches, you can try

:tselect

and find that there are 63 different tags for url, of which #4 is the definition of the function.

My solution is to recreate the tags files, adding the option --php-kinds=-v to ctags. This tells ctags not to create tags for variables. (It will still create tags for constants.)

I have been thinking of doing this for a while. I am very reluctant to throw away information, but I have come to the conclusion that this information is just getting in the way.

Please let me know what you think.

benjifisher’s picture

Title: Generate a tags file for the Drupal code base. » Tags files are too big.

I am changing the title.

psynaptic’s picture

Status: Needs review » Reviewed & tested by the community

Works great! I tested by applying both patches and running :tag t which took me to the function definition for t().

benjifisher’s picture

Status: Reviewed & tested by the community » Fixed

Committed: http://drupalcode.org/project/vimrc.git/commit/118e377

I have not added any documentation, but I think that comments #1 and #4 above need a more permanent home.

psynaptic’s picture

Another tip I only discovered recently is that if you're in the same file as the definition you can use gd to go to the definition. This works for class methods.

benjifisher’s picture

Perhaps we can add a page to the docs with some tips. Even without any customization, vim has more features than any one person can use.

I think we can do some clever things with the 'define' and 'include' options. That will be another issue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.