Skip to content

Fix issue #421 #462

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix issue #421 #462

wants to merge 2 commits into from

Conversation

shyun3
Copy link

@shyun3 shyun3 commented Jul 23, 2018

On Windows, universal-ctags escapes backslashes in filenames with another backslash. For example, a filename in a tags file may appear as C:\\tmp\\test.cpp whereas Exuberant Ctags would write the filename as C:\tmp\test.cpp. This would cause bufnr() function calls for those filenames to fail.

My solution is to replace the double backslashes with single forward slashes before passing the filenames to bufnr.

@mattn
Copy link
Member

mattn commented Sep 13, 2018

I don't still understand why this fix #421. please explain.

@shyun3
Copy link
Author

shyun3 commented Sep 16, 2018

For this example, I have a test file named test.cpp located in D:\tmp. Its contents are as follows:

int x;

Running Exuberant Ctags 5.8 on this file with the appropriate options, as defined in buffertag.vim, yields the following (omitting the header):

x	D:\tmp\test.cpp	/^int x;$/;"	variable	line:1

Running Universal Ctags on this file (I used the 2018-07-18 release) yields:

x	D:\\tmp\\test.cpp	/^int x;$/;"	variable	line:1

Note the double backslashes in the file name.

These lines are parsed in the s:parseline() function of buffertag.vim. Of particular note in this function is line 208:

let [bufnr, bufname] = [bufnr('^'.vals[2].'$'), fnamemodify(vals[2], ':p:t')]

where vals[2] is the matched filename.

Note the call to bufnr(). Running bufnr('^'.vals[2].'$') for our Exuberant Ctags example would be equivalent to bufnr('^'.'D:\tmp\test.cpp'.'$'). This will result in a valid buffer number, such as 13.

For the Universal Ctags case, the equivalent call would be bufnr('^'.'D:\\tmp\\test.cpp'.'$') and this will always result in the error value -1. This is due to the double backslashes in the filename. The failing bufnr() call breaks the entire buffer tag functionality.

As I mentioned before, my solution is to replace double backslashes with single forward slashes. So for our example, the Universal Ctags filename would be modified to D:/tmp/test.cpp which will result in a successful bufnr() call.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants