Skip to content
This repository
Browse code

Proper handling of unnamed buffers

  • Loading branch information...
commit 24cd42357f25f0cf182c83b3b82a3b60e6e6e9f0 1 parent f313338
Peter Odding authored June 16, 2010

Showing 1 changed file with 20 additions and 10 deletions. Show diff stats Hide diff stats

  1. 30  autoload.vim
30  autoload.vim
@@ -11,9 +11,11 @@ function! easytags#autoload() " {{{2
11 11
   try
12 12
     " Update the entries for the current file in the global tags file?
13 13
     let pathname = s:resolve(expand('%:p'))
14  
-    let tags_outdated = getftime(pathname) > getftime(easytags#get_tagsfile())
15  
-    if tags_outdated || !easytags#file_has_tags(pathname)
16  
-      UpdateTags
  14
+    if pathname != ''
  15
+      let tags_outdated = getftime(pathname) > getftime(easytags#get_tagsfile())
  16
+      if tags_outdated || !easytags#file_has_tags(pathname)
  17
+        UpdateTags
  18
+      endif
17 19
     endif
18 20
     " Apply highlighting of tags in global tags file to current buffer?
19 21
     if &eventignore !~? '\<syntax\>'
@@ -39,19 +41,20 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{2
39 41
     let filename = s:resolve(expand('%:p'))
40 42
     let ft_supported = index(easytags#supported_filetypes(), &ft) >= 0
41 43
     let ft_ignored = g:easytags_ignored_filetypes != '' && &ft =~ g:easytags_ignored_filetypes
42  
-    if (filename != '' && ft_supported && !ft_ignored) || a:filter_invalid_tags
  44
+    let update_tags = (filename != '') && ft_supported && !ft_ignored
  45
+    if update_tags || a:filter_invalid_tags
43 46
       let start = xolox#timer#start()
44 47
       let tagsfile = easytags#get_tagsfile()
45 48
       let command = [g:easytags_cmd, '-f', shellescape(tagsfile), '--fields=+l']
46 49
       if filereadable(tagsfile)
47 50
         call add(command, '-a')
48  
-        let filter_file_tags = easytags#file_has_tags(filename)
  51
+        let filter_file_tags = update_tags && easytags#file_has_tags(filename)
49 52
         if a:filter_invalid_tags || filter_file_tags
50 53
           let [header, entries] = easytags#read_tagsfile(tagsfile)
51 54
           let num_entries = len(entries)
52 55
           call s:set_tagged_files(entries)
53 56
           let filters = []
54  
-          if ft_supported && !ft_ignored && filter_file_tags
  57
+          if filter_file_tags
55 58
             let filename_pattern = '\t' . xolox#escape#pattern(filename) . '\t'
56 59
             call add(filters, 'v:val !~ filename_pattern')
57 60
           endif
@@ -67,7 +70,7 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{2
67 70
           endif
68 71
         endif
69 72
       endif
70  
-      if ft_supported && !ft_ignored
  73
+      if update_tags
71 74
         call add(command, '--language-force=' . easytags#to_ctags_ft(&ft))
72 75
         call add(command, shellescape(filename))
73 76
         let listing = system(join(command))
@@ -76,9 +79,12 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{2
76 79
           throw printf(msg, fnamemodify(tagsfile, ':~'), strtrans(v:exception))
77 80
         endif
78 81
         call easytags#add_tagged_file(filename)
  82
+        let msg = "%s: Updated tags for %s in %s."
  83
+        call xolox#timer#stop(msg, s:script, expand('%:p:~'), start)
  84
+      else
  85
+        let msg = "%s: Filtered invalid tags in %s."
  86
+        call xolox#timer#stop(msg, s:script, start)
79 87
       endif
80  
-      let msg = "%s: Updated tags for %s in %s."
81  
-      call xolox#timer#stop(msg, s:script, expand('%:p:~'), start)
82 88
       return 1
83 89
     endif
84 90
     return 0
@@ -113,8 +119,12 @@ function! easytags#highlight_cmd() " {{{2
113 119
         endif
114 120
       endfor
115 121
       redraw
  122
+      let bufname = expand('%:p:~')
  123
+      if bufname == ''
  124
+        let bufname = 'unnamed buffer #' . bufnr('%')
  125
+      endif
116 126
       let msg = "%s: Highlighted tags in %s in %s."
117  
-      call xolox#timer#stop(msg, s:script, expand('%:p:~'), start)
  127
+      call xolox#timer#stop(msg, s:script, bufname, start)
118 128
     endif
119 129
   catch
120 130
     call xolox#warning("%s: %s (at %s)", s:script, v:exception, v:throwpoint)

0 notes on commit 24cd423

Please sign in to comment.
Something went wrong with that request. Please try again.