Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Improve file type detection (respect 'g:notes_suffix', issue #16)

  • Loading branch information...
commit 4be5e0b294e046cd03fb6ccf75feb92ee019a8ea 1 parent 056bbc3
@xolox authored
View
9 autoload/xolox/notes.vim
@@ -1,12 +1,12 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: December 10, 2011
+" Last Change: December 11, 2011
" URL: http://peterodding.com/code/vim/notes/
" Note: This file is encoded in UTF-8 including a byte order mark so
" that Vim loads the script using the right encoding transparently.
-let g:xolox#notes#version = '0.16.14'
+let g:xolox#notes#version = '0.16.15'
let s:scriptdir = expand('<sfile>:p:h')
function! xolox#notes#init() " {{{1
@@ -541,7 +541,7 @@ function! xolox#notes#swaphack() " {{{2
endif
endfunction
-function! xolox#notes#autocmd_pattern(directory) " {{{2
+function! xolox#notes#autocmd_pattern(directory, use_extension) " {{{2
" Generate a normalized automatic command pattern. First we resolve the path
" to the directory with notes (eliminating any symbolic links) so that the
" automatic command also applies to symbolic links pointing to notes (Vim
@@ -556,6 +556,9 @@ function! xolox#notes#autocmd_pattern(directory) " {{{2
endif
" Escape the directory but not the trailing "*".
let pattern = fnameescape(directory) . '/*'
+ if a:use_extension && !empty(g:notes_suffix)
+ let pattern .= g:notes_suffix
+ endif
" On Windows the pattern won't match if it contains repeating slashes.
return substitute(pattern, '/\+', '/', 'g')
endfunction
View
13 ftdetect/notes.vim
@@ -1,16 +1,19 @@
" Vim file type detection script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: November 26, 2011
+" Last Change: December 11, 2011
" URL: http://peterodding.com/code/vim/notes
" Initialize the configuration defaults.
call xolox#notes#init()
" Define the automatic commands used to recognize notes.
-for s:directory in [g:notes_directory, g:notes_shadowdir]
- execute 'autocmd BufNewFile,BufRead'
- \ xolox#notes#autocmd_pattern(s:directory)
+
+execute 'autocmd BufNewFile,BufRead'
+ \ xolox#notes#autocmd_pattern(g:notes_directory, 1)
+ \ 'if empty(&buftype) | setlocal filetype=notes | endif'
+
+execute 'autocmd BufNewFile,BufRead'
+ \ xolox#notes#autocmd_pattern(g:notes_shadowdir, 0)
\ 'if empty(&buftype) | setlocal filetype=notes | endif'
-endfor
" vim: ts=2 sw=2 et
View
6 plugin/notes.vim
@@ -1,6 +1,6 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: November 28, 2011
+" Last Change: December 11, 2011
" URL: http://peterodding.com/code/vim/notes/
" Support for automatic update using the GLVS plug-in.
@@ -41,8 +41,8 @@ augroup PluginNotes
" to notes (which is IMHO better than always showing the E325 prompt).
au BufReadCmd note:* nested call xolox#notes#shortcut()
" Automatic commands to read/write notes (used for automatic renaming).
- exe 'au BufReadCmd' xolox#notes#autocmd_pattern(g:notes_shadowdir) 'call xolox#notes#edit_shadow()'
- exe 'au BufWriteCmd' xolox#notes#autocmd_pattern(g:notes_directory) 'call xolox#notes#save()'
+ exe 'au BufReadCmd' xolox#notes#autocmd_pattern(g:notes_shadowdir, 0) 'call xolox#notes#edit_shadow()'
+ exe 'au BufWriteCmd' xolox#notes#autocmd_pattern(g:notes_directory, 1) 'call xolox#notes#save()'
augroup END
" Make sure the plug-in is only loaded once.
Please sign in to comment.
Something went wrong with that request. Please try again.