Skip to content

Commit 1021528

Browse files
committed
Minor bug fix: Always save tags index when file doesn't exist
1 parent b38f0ee commit 1021528

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

autoload/xolox/notes.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
" Note: This file is encoded in UTF-8 including a byte order mark so
77
" that Vim loads the script using the right encoding transparently.
88

9-
let g:xolox#notes#version = '0.11.1'
9+
let g:xolox#notes#version = '0.11.2'
1010

1111
function! xolox#notes#shortcut() " {{{1
1212
" The "note:" pseudo protocol is just a shortcut for the :Note command.

autoload/xolox/notes/tags.vim

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ function! xolox#notes#tags#create_index() " {{{1
4545
let filenames = xolox#notes#get_fnames(0)
4646
let s:currently_tagged_notes = {}
4747
for idx in range(len(filenames))
48-
let title = xolox#notes#fname_to_title(filenames[idx])
49-
call xolox#misc#msg#info("notes.vim %s: Scanning note %i/%i: %s", g:xolox#notes#version, idx + 1, len(filenames), title)
50-
call xolox#notes#tags#scan_note(title, join(readfile(filenames[idx]), "\n"))
48+
if filereadable(filenames[idx])
49+
let title = xolox#notes#fname_to_title(filenames[idx])
50+
call xolox#misc#msg#info("notes.vim %s: Scanning note %i/%i: %s", g:xolox#notes#version, idx + 1, len(filenames), title)
51+
call xolox#notes#tags#scan_note(title, join(readfile(filenames[idx]), "\n"))
52+
endif
5153
endfor
5254
if xolox#notes#tags#save_index()
5355
let s:previously_tagged_notes = deepcopy(s:currently_tagged_notes)
@@ -58,17 +60,23 @@ function! xolox#notes#tags#create_index() " {{{1
5860
endfunction
5961

6062
function! xolox#notes#tags#save_index() " {{{1
61-
if s:currently_tagged_notes == s:previously_tagged_notes
63+
let indexfile = expand(g:notes_tagsindex)
64+
let existingfile = filereadable(indexfile)
65+
let nothingchanged = (s:currently_tagged_notes == s:previously_tagged_notes)
66+
if existingfile && nothingchanged
67+
call xolox#misc#msg#debug("notes.vim %s: Index not dirty so not saved.", g:xolox#notes#version)
6268
return 1 " Nothing to be done
6369
else
6470
let lines = []
6571
for [tagname, filenames] in items(s:currently_tagged_notes)
6672
call add(lines, join([tagname] + filenames, "\t"))
6773
endfor
68-
let indexfile = expand(g:notes_tagsindex)
6974
let status = writefile(lines, indexfile) == 0
7075
if status
76+
call xolox#misc#msg#debug("notes.vim %s: Index saved to %s.", g:xolox#notes#version, g:notes_tagsindex)
7177
let s:last_disk_sync = getftime(indexfile)
78+
else
79+
call xolox#misc#msg#debug("notes.vim %s: Failed to save index to %s.", g:xolox#notes#version, g:notes_tagsindex)
7280
endif
7381
return status
7482
endif

0 commit comments

Comments
 (0)