I have automated the procedure described in #1347302: Tags files are too big. (Comments #1 and #4). Now, I can generate new tags files without looking up all the options I need to use, and YOU can create a tags file customized to your Drupal installation, including all installed modules.

This is my first attempt at a drush command. Suggestions for style, conformance, efficiency, etc. are welcome.

To use, save the attached file as drush/vimrc.drush.inc inside your vimrc folder and run the commanddrush --include=./drush tags --ctags=/usr/local/bin/ctags --tag-file=d6.tags /tmp/drupal-6.22
(substituting appropriate paths for your system). You need to have Exuberant Ctags installed; the GNU ctags is not good enough. For details, read the error message you will get if it is not installed.

The tags file can be used for navigating your code and for omni-completion. Try using --tag-file=/absolute/path/to/drupal/tags (so you will get a tags file in your Drupal root directory) and then:set tags=/absolute/path/to/drupal/tagsto use this tags file. See our documentation for using tags in code navigation and automatic completion.

Tested on Mac OS X. Should work on Linux. Probably needs some work on Windows (see #1 below).

If you use Drupal 6.22, then you should get a file identical to drupal6.tags, distributed as part of this project, if you use the version attached to this issue summary. The version attached to #2 will produce smaller tags files, since it removes many bogus tags. It also adds options --include-test=[yes|no] and --include-js=[yes|no] (default yes). You can set them to "no" to get even smaller tags files.

Members fund testing for the Drupal project. Drupal Association Learn more


benjifisher’s picture

I tried this on Windows. When I installed Git, it included a bash shell, which shows up in my Windows menu as "Git Bash," so I used that. Luckily, I seem to have installed ctags already.

There is one glitch: I get the message Cannot write the tags file. It turns out that, if the file does not exist, then the lines

  $path = file_exists($tag_file) ? $tag_file : dirname($tag_file);
  if (!is_writable($path)) {

in the validate function decide that the directory is not writable. The work-around is$ touch test.tags

benjifisher’s picture

4.2 KB

This version removes a bunch of bogus tags. For example, a line like

  // This function is awesome!

generates an unwanted tag for the function "is". I also added options to include tags for .test and .js files; setting the options to "no" cuts down on the number of tags generated.

benjifisher’s picture

4.28 KB

Slight improvement: if you specify the path with a trailing slash (e.g., /tmp/drupal-6.22/) then the previous versions would give paths like $DRUPAL_ROOTmodules instead of $DRUPAL_ROOT/modules. Something about str_replace($path, ...).

benjifisher’s picture

4.64 KB

Committed: 12f8cae.

Since I just committed #1145580-28: Add installer?, the directory structure has been rearranged and there is already a vimrc.drush.inc file, so this patch adds to it. I made some further changes since the last version:

  1. The --include-js and --include-test options default to "no".
  2. If --include-test=no, then D8-style test directories are excluded. (Since D8 is a moving target, this may need updates in the future.)
  3. Simpler and more reliable validation that the tags file is writable.
  4. Exclude files under .git/.
  5. Minor documentation changes.

I intend to continue including tags for javascript and test files in the tags files I include in this project.

Thanks to #1145580-28: Add installer?, you can invoke this command without specifying an include directory:$ drush help vimrc-tag-gen

benjifisher’s picture

Status: Needs review » Fixed

Change the status.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Added more instructions. Described second version.