Skip to content

Commit

Permalink
Improve file type detection (respect 'g:notes_suffix', issue #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Dec 11, 2011
1 parent 056bbc3 commit 4be5e0b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
9 changes: 6 additions & 3 deletions autoload/xolox/notes.vim
@@ -1,12 +1,12 @@
" Vim auto-load script " Vim auto-load script
" Author: Peter Odding <peter@peterodding.com> " Author: Peter Odding <peter@peterodding.com>
" Last Change: December 10, 2011 " Last Change: December 11, 2011
" URL: http://peterodding.com/code/vim/notes/ " URL: http://peterodding.com/code/vim/notes/


" Note: This file is encoded in UTF-8 including a byte order mark so " Note: This file is encoded in UTF-8 including a byte order mark so
" that Vim loads the script using the right encoding transparently. " 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') let s:scriptdir = expand('<sfile>:p:h')


function! xolox#notes#init() " {{{1 function! xolox#notes#init() " {{{1
Expand Down Expand Up @@ -541,7 +541,7 @@ function! xolox#notes#swaphack() " {{{2
endif endif
endfunction 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 " Generate a normalized automatic command pattern. First we resolve the path
" to the directory with notes (eliminating any symbolic links) so that the " to the directory with notes (eliminating any symbolic links) so that the
" automatic command also applies to symbolic links pointing to notes (Vim " automatic command also applies to symbolic links pointing to notes (Vim
Expand All @@ -556,6 +556,9 @@ function! xolox#notes#autocmd_pattern(directory) " {{{2
endif endif
" Escape the directory but not the trailing "*". " Escape the directory but not the trailing "*".
let pattern = fnameescape(directory) . '/*' 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. " On Windows the pattern won't match if it contains repeating slashes.
return substitute(pattern, '/\+', '/', 'g') return substitute(pattern, '/\+', '/', 'g')
endfunction endfunction
Expand Down
13 changes: 8 additions & 5 deletions ftdetect/notes.vim
@@ -1,16 +1,19 @@
" Vim file type detection script " Vim file type detection script
" Author: Peter Odding <peter@peterodding.com> " Author: Peter Odding <peter@peterodding.com>
" Last Change: November 26, 2011 " Last Change: December 11, 2011
" URL: http://peterodding.com/code/vim/notes " URL: http://peterodding.com/code/vim/notes


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


" Define the automatic commands used to recognize notes. " Define the automatic commands used to recognize notes.
for s:directory in [g:notes_directory, g:notes_shadowdir]
execute 'autocmd BufNewFile,BufRead' execute 'autocmd BufNewFile,BufRead'
\ xolox#notes#autocmd_pattern(s:directory) \ 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' \ 'if empty(&buftype) | setlocal filetype=notes | endif'
endfor


" vim: ts=2 sw=2 et " vim: ts=2 sw=2 et
6 changes: 3 additions & 3 deletions plugin/notes.vim
@@ -1,6 +1,6 @@
" Vim plug-in " Vim plug-in
" Author: Peter Odding <peter@peterodding.com> " Author: Peter Odding <peter@peterodding.com>
" Last Change: November 28, 2011 " Last Change: December 11, 2011
" URL: http://peterodding.com/code/vim/notes/ " URL: http://peterodding.com/code/vim/notes/


" Support for automatic update using the GLVS plug-in. " Support for automatic update using the GLVS plug-in.
Expand Down Expand Up @@ -41,8 +41,8 @@ augroup PluginNotes
" to notes (which is IMHO better than always showing the E325 prompt). " to notes (which is IMHO better than always showing the E325 prompt).
au BufReadCmd note:* nested call xolox#notes#shortcut() au BufReadCmd note:* nested call xolox#notes#shortcut()
" Automatic commands to read/write notes (used for automatic renaming). " 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 BufReadCmd' xolox#notes#autocmd_pattern(g:notes_shadowdir, 0) 'call xolox#notes#edit_shadow()'
exe 'au BufWriteCmd' xolox#notes#autocmd_pattern(g:notes_directory) 'call xolox#notes#save()' exe 'au BufWriteCmd' xolox#notes#autocmd_pattern(g:notes_directory, 1) 'call xolox#notes#save()'
augroup END augroup END


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

0 comments on commit 4be5e0b

Please sign in to comment.