aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Odding <peter@peterodding.com>2010-07-20 12:47:39 +0200
committerPeter Odding <peter@peterodding.com>2010-07-20 12:47:39 +0200
commit3b934f6e0d0d4a44875024713dd0aeefdcdd206b (patch)
tree9b7105b794c1feacc38e7cb406d254f35698c22f
parentff64be5fe506a9a15dce28bac5b5585d4430f4a6 (diff)
downloadvim-easytags-3b934f6e0d0d4a44875024713dd0aeefdcdd206b.tar.gz
Another bug fix for the broken :set tags= command
Previously* I fixed a bug where easytags.vim failed to register the global tags file created by the plug-in with Vim, because even though the &tags option was set by the plug-in, Vim would refuse to acknowledge the new tags file, i.e. tagfiles() == []. The fix then was to change :let &tags= to :set tags= which apparently has a different implementation from :let &tags=?! I assumed this fix would be valid for both Windows and UNIX, but apparently this still doesn't work on Windows! There we actually have to use feedkeys() to convince Vim to change the &tags option... What a hack! :-( BTW I also fixed an embarrassing typo in the initialization code. * Bug fix for strange "E433: No tags file" problem: http://github.com/xolox/vim-easytags/commit/4fef0c17749e687d670b2e9e4e429022ec4c1055
-rw-r--r--TODO.md2
-rw-r--r--autoload.vim10
-rw-r--r--easytags.vim51
3 files changed, 41 insertions, 22 deletions
diff --git a/TODO.md b/TODO.md
index 798a258..4bc7b19 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,5 +1,7 @@
# Long term plans
+ * Automatically index C headers when /usr/include/$name.h exists?
+
* Integration with my unreleased project plug-in so that when you edit any
file in a project, all related files are automatically scanned for tags?
diff --git a/autoload.vim b/autoload.vim
index 847c0d2..8d3462b 100644
--- a/autoload.vim
+++ b/autoload.vim
@@ -1,6 +1,6 @@
" Vim script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: July 18, 2010
+" Last Change: July 20, 2010
" URL: http://peterodding.com/code/vim/easytags/
let s:script = expand('<sfile>:p:~')
@@ -78,7 +78,7 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{2
let listing = system(join(command))
if v:shell_error
let msg = "Failed to update tags file %s: %s!"
- throw printf(msg, fnamemodify(tagsfile, ':~'), strtrans(v:exception))
+ throw printf(msg, fnamemodify(tagsfile, ':~'), strtrans(listing))
endif
call easytags#add_tagged_file(filename)
let msg = "%s: Updated tags for %s in %s."
@@ -151,8 +151,8 @@ function! easytags#supported_filetypes() " {{{2
endif
let s:supported_filetypes = split(listing, '\n')
call map(s:supported_filetypes, 'easytags#to_vim_ft(v:val)')
- let msg = "%s: Retrieved supported languages in %s."
- call xolox#timer#stop(msg, s:script, start)
+ let msg = "%s: Retrieved %i supported languages in %s."
+ call xolox#timer#stop(msg, s:script, len(s:supported_filetypes), start)
endif
return s:supported_filetypes
endfunction
@@ -283,6 +283,8 @@ function! s:cache_tagged_files() " {{{2
endfunction
function! s:set_tagged_files(entries) " {{{2
+ " TODO use taglist() instead of readfile() so that all tag files are
+ " automatically used :-)
let s:tagged_files = {}
for entry in a:entries
let filename = matchstr(entry, '^[^\t]\+\t\zs[^\t]\+')
diff --git a/easytags.vim b/easytags.vim
index e340802..8d1eb94 100644
--- a/easytags.vim
+++ b/easytags.vim
@@ -1,10 +1,10 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: July 12, 2010
+" Last Change: July 20, 2010
" URL: http://peterodding.com/code/vim/easytags/
" Requires: Exuberant Ctags (http://ctags.sf.net)
" License: MIT
-" Version: 1.9.6
+" Version: 1.9.7
" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3114 1 :AutoInstall: easytags.zip
@@ -14,7 +14,7 @@ if &cp || exists('g:loaded_easytags')
finish
endif
-" Configuration defaults. {{{1
+" Configuration defaults and initialization. {{{1
if !exists('g:easytags_file')
if has('win32') || has('win64')
@@ -48,7 +48,7 @@ function! s:InitEasyTags(version)
endif
" On Ubuntu Linux, Exuberant Ctags is installed as `ctags'. On Debian Linux,
" Exuberant Ctags is installed as `exuberant-ctags'. On Free-BSD, Exuberant
- " Ctags is installed as `exctags'. Finally there is `ctags.exe' on Windows.
+ " Ctags is installed as `exctags'.
for name in ['ctags', 'exuberant-ctags', 'esctags']
if s:CheckCtags(name, a:version)
let g:easytags_cmd = name
@@ -82,7 +82,7 @@ if !s:InitEasyTags(55)
if !exists('g:easytags_ctags_version') || empty(g:easytags_ctags_version)
let msg = "easytags.vim: Plug-in not loaded because Exuberant Ctags isn't installed!"
if executable('apt-get')
- let msg ,= " On Ubuntu & Debian you can install Exuberant Ctags by"
+ let msg .= " On Ubuntu & Debian you can install Exuberant Ctags by"
let msg .= " installing the package named `exuberant-ctags':"
let msg .= " sudo apt-get install exuberant-ctags"
else
@@ -97,20 +97,34 @@ if !s:InitEasyTags(55)
finish
endif
-" Let Vim know about the global tags file created by this plug-in.
-
-" Parse the &tags option and get a list of all configured tags files including
-" non-existing files (this is why we can't just call the tagfiles() function).
-let s:tagfiles = xolox#option#split_tags(&tags)
-let s:expanded = map(copy(s:tagfiles), 'resolve(expand(v:val))')
-
-" Add the tags file to the &tags option when the user hasn't done so already.
-if index(s:expanded, resolve(expand(g:easytags_file))) == -1
- let s:value = substitute(expand(g:easytags_file), '[\\, ]', '\\\0', 'g')
- execute 'set tags=' . s:value . ',' . &tags
-endif
+function! s:RegisterTagsFile()
+ " Parse the &tags option and get a list of all tags files *including
+ " non-existing files* (this is why we can't just call tagfiles()).
+ let tagfiles = xolox#option#split_tags(&tags)
+ let expanded = map(copy(tagfiles), 'resolve(expand(v:val))')
+ " Add the filename to the &tags option when the user hasn't done so already.
+ if index(expanded, resolve(expand(g:easytags_file))) == -1
+ " This is a real mess because of bugs in Vim?! :let &tags = '...' doesn't
+ " work on UNIX and Windows, :set tags=... doesn't work on Windows. What I
+ " mean with "doesn't work" is that tagfiles() == [] after the :let/:set
+ " command even though the tags file exists! One easy way to confirm that
+ " this is a bug in Vim is to type :set tags= then press <Tab> followed by
+ " <CR>. Now you entered the exact same value that the code below also did
+ " but suddenly Vim sees the tags file and tagfiles() != [] :-S
+ call insert(tagfiles, g:easytags_file)
+ let value = xolox#option#join_tags(tagfiles)
+ let cmd = ':set tags=' . escape(value, '\ ')
+ if has('win32') || has('win64')
+ " TODO How to clear the expression from Vim's status line?
+ call feedkeys(":" . cmd . "|let &ro=&ro\<CR>", 'n')
+ else
+ execute cmd
+ endif
+ endif
+endfunction
-unlet! s:tagfiles s:expanded s:value
+" Let Vim know about the global tags file created by this plug-in.
+call s:RegisterTagsFile()
" The :UpdateTags and :HighlightTags commands. {{{1
@@ -122,6 +136,7 @@ command! -bar HighlightTags call easytags#highlight_cmd()
augroup PluginEasyTags
autocmd!
if g:easytags_always_enabled
+ " TODO Also on FocusGained because tags files might be updated externally?
autocmd BufReadPost,BufWritePost * call easytags#autoload()
endif
if g:easytags_on_cursorhold