Skip to content

Commit 273aa01

Browse files
committed
Improved filename <-> title synchronization (bug fix* + better dialog)
* Whenever creating a new note the plug-in would complain that the filename and title didn't match :-/... Sorry about that, it was annoying for me as well :-). Anyway should be fixed now, let's hope I didn't break anything else in the process.
1 parent 9985806 commit 273aa01

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

autoload/xolox/notes.vim

Lines changed: 12 additions & 7 deletions
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.12.1'
9+
let g:xolox#notes#version = '0.12.2'
1010

1111
function! xolox#notes#shortcut() " {{{1
1212
" The "note:" pseudo protocol is just a shortcut for the :Note command.
@@ -34,8 +34,7 @@ function! xolox#notes#edit(bang, title) abort " {{{1
3434
endif
3535
" At this point we're dealing with a new note.
3636
let fname = xolox#notes#title_to_fname(title)
37-
execute 'edit' . a:bang fnameescape(fname)
38-
setlocal filetype=notes
37+
noautocmd execute 'edit' . a:bang fnameescape(fname)
3938
if line('$') == 1 && getline(1) == ''
4039
let fname = xolox#misc#path#merge(g:notes_shadowdir, 'New note')
4140
execute 'silent read' fnameescape(fname)
@@ -48,25 +47,31 @@ function! xolox#notes#edit(bang, title) abort " {{{1
4847
if title != 'New note'
4948
call setline(1, title)
5049
endif
50+
setlocal filetype=notes
5151
doautocmd BufReadPost
5252
call xolox#misc#timer#stop('notes.vim %s: Started new note in %s.', g:xolox#notes#version, starttime)
5353
endfunction
5454

5555
function! xolox#notes#check_sync_title() " {{{1
5656
if g:notes_title_sync != 'no' && xolox#notes#buffer_is_note()
5757
" Check if the note's title and filename are out of sync.
58+
let title = getline(1)
5859
let name_on_disk = xolox#misc#path#absolute(expand('%:p'))
59-
let name_from_title = xolox#notes#title_to_fname(getline(1))
60+
let name_from_title = xolox#notes#title_to_fname(title)
6061
if !xolox#misc#path#equals(name_on_disk, name_from_title)
62+
call xolox#misc#msg#debug("notes.vim %s: Filename (%s) doesn't match note title (%s)", g:xolox#notes#version, name_on_disk, name_from_title)
6163
let action = g:notes_title_sync
6264
if action == 'prompt'
6365
" Prompt the user what to do (if anything). First we perform a redraw
6466
" to make sure the note's content is visible (without this the Vim
6567
" window would be blank in my tests).
6668
redraw
67-
let message = "The note's title and filename do not correspond. What do you want to do?"
68-
let options = "Change &title\nRename &file\nDo &nothing"
69-
let choice = confirm(message, options, 3, 'Question')
69+
let message = "The note's title and filename do not correspond. What do you want to do?\n\n"
70+
let message .= "Current filename: " . name_on_disk . "\n"
71+
let message .= "Corresponding title: " . xolox#notes#fname_to_title(name_on_disk) . "\n\n"
72+
let message .= "Current title: " . title . "\n"
73+
let message .= "Corresponding filename: " . xolox#notes#title_to_fname(title)
74+
let choice = confirm(message, "Change &title\nRename &file\nDo &nothing", 3, 'Question')
7075
if choice == 1
7176
let action = 'change_title'
7277
elseif choice == 2

0 commit comments

Comments
 (0)