Skip to content

Commit 4be5e0b

Browse files
committed
Improve file type detection (respect 'g:notes_suffix', issue #16)
1 parent 056bbc3 commit 4be5e0b

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

autoload/xolox/notes.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: December 10, 2011
3+
" Last Change: December 11, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55

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.16.14'
9+
let g:xolox#notes#version = '0.16.15'
1010
let s:scriptdir = expand('<sfile>:p:h')
1111

1212
function! xolox#notes#init() " {{{1
@@ -541,7 +541,7 @@ function! xolox#notes#swaphack() " {{{2
541541
endif
542542
endfunction
543543

544-
function! xolox#notes#autocmd_pattern(directory) " {{{2
544+
function! xolox#notes#autocmd_pattern(directory, use_extension) " {{{2
545545
" Generate a normalized automatic command pattern. First we resolve the path
546546
" to the directory with notes (eliminating any symbolic links) so that the
547547
" automatic command also applies to symbolic links pointing to notes (Vim
@@ -556,6 +556,9 @@ function! xolox#notes#autocmd_pattern(directory) " {{{2
556556
endif
557557
" Escape the directory but not the trailing "*".
558558
let pattern = fnameescape(directory) . '/*'
559+
if a:use_extension && !empty(g:notes_suffix)
560+
let pattern .= g:notes_suffix
561+
endif
559562
" On Windows the pattern won't match if it contains repeating slashes.
560563
return substitute(pattern, '/\+', '/', 'g')
561564
endfunction

ftdetect/notes.vim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
" Vim file type detection script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: November 26, 2011
3+
" Last Change: December 11, 2011
44
" URL: http://peterodding.com/code/vim/notes
55

66
" Initialize the configuration defaults.
77
call xolox#notes#init()
88

99
" Define the automatic commands used to recognize notes.
10-
for s:directory in [g:notes_directory, g:notes_shadowdir]
11-
execute 'autocmd BufNewFile,BufRead'
12-
\ xolox#notes#autocmd_pattern(s:directory)
10+
11+
execute 'autocmd BufNewFile,BufRead'
12+
\ xolox#notes#autocmd_pattern(g:notes_directory, 1)
13+
\ 'if empty(&buftype) | setlocal filetype=notes | endif'
14+
15+
execute 'autocmd BufNewFile,BufRead'
16+
\ xolox#notes#autocmd_pattern(g:notes_shadowdir, 0)
1317
\ 'if empty(&buftype) | setlocal filetype=notes | endif'
14-
endfor
1518

1619
" vim: ts=2 sw=2 et

plugin/notes.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim plug-in
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: November 28, 2011
3+
" Last Change: December 11, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55

66
" Support for automatic update using the GLVS plug-in.
@@ -41,8 +41,8 @@ augroup PluginNotes
4141
" to notes (which is IMHO better than always showing the E325 prompt).
4242
au BufReadCmd note:* nested call xolox#notes#shortcut()
4343
" Automatic commands to read/write notes (used for automatic renaming).
44-
exe 'au BufReadCmd' xolox#notes#autocmd_pattern(g:notes_shadowdir) 'call xolox#notes#edit_shadow()'
45-
exe 'au BufWriteCmd' xolox#notes#autocmd_pattern(g:notes_directory) 'call xolox#notes#save()'
44+
exe 'au BufReadCmd' xolox#notes#autocmd_pattern(g:notes_shadowdir, 0) 'call xolox#notes#edit_shadow()'
45+
exe 'au BufWriteCmd' xolox#notes#autocmd_pattern(g:notes_directory, 1) 'call xolox#notes#save()'
4646
augroup END
4747

4848
" Make sure the plug-in is only loaded once.

0 commit comments

Comments
 (0)