xolox / vim-easytags

Automated tag file generation and syntax highlighting of tags in Vim
http://peterodding.com/code/vim/easytags/
1.01k stars 109 forks source link

Linking directories #22

Closed punassuming closed 10 years ago

punassuming commented 12 years ago

Heres an idea for cross platform linking of files:

Get a dictionary of lists for each directory synced across platforms. Easytags checks the presence of each directory in the list and then substitutes the path in the tags file for each other item in the list.

For example:

You have a list like [''~/testing","D:\My Project Test","~/.vim/testing/testfiles"]

Depending on which directory is available (iterate through all and check, if more than 1, raise exception), replace all paths in your tags file with the present directory, maybe run an UpdateTags! afterwards to get rid of duplicates, but this shouldn't be an issue after the first conversion.

Let me know what you think, I have been doing this manually for a while and it works, especially if you have directories synced with git or with dropbox

punassuming commented 12 years ago

Here is the script in question in case you are interested:

import os
from string import replace
from glob import glob

dir_match = { 
        'dotfiles': ['/home/walesi/documents/dotfiles','F:/Documents/settings/dotfiles'],
        'python': ['/home/walesi/documents/dev/python','F:/Documents/dev/python'],
        'projects': ['F:/Documents/projects','/home/walesi/documents/projects'],
        'iecr': ['F:/Documents/collaboration/2011-IER','/home/walesi/documents/2011-IER'],
        'javascript': ['F:/Documents/settings/dotfiles/.js','/home/walesi/documents/dotfiles/.js','/home/walesi/.js'] }

tags_dir = replace(os.environ["HOME"]+os.sep+'.vim\\tags\\*','\\', os.sep)

tags = glob(tags_dir)

dir_exist = {}
dir_notexist = {}

# Determine existing directories
for key in dir_match.keys():
    # only one match
    dir_notexist[key] = []
    for directory in dir_match[key]:
        if os.path.isdir(directory) and not os.path.islink(directory):
            dir_exist[key] = directory
        else:
            dir_notexist[key].append(directory)

# Change the tagsfiles
for tagfile in tags:
    with open(tagfile, 'r') as f:
        read_data = f.read()
    new_read_data = read_data
    for key in dir_notexist.keys():
        for noexist in dir_notexist[key]:
            # print noexist + ' => ' + dir_exist[key]
            new_read_data = replace(new_read_data,noexist,dir_exist[key])
    if read_data != new_read_data:
        print tagfile + " changed"
        with open(tagfile,'w') as f:
            f.write(new_read_data)
xolox commented 10 years ago

Thanks for the suggestion and code sample but I won't add this to vim-easytags. I actually have all of my code repositories synced using Dropbox but I use tags files local to each machine which works fine. Rewriting tags files to match different computers sounds like more trouble than it's worth to me. Of course you're perfectly free to keep using the script you posted; by all means do! But I won't include it in vim-easytags itself because I don't think a lot of users will find this useful.