2 " Author: Peter Odding <peter@peterodding.com>
3 " Last Change: September 4, 2011
4 " URL: http://peterodding.com/code/vim/notes/
6 " Support for automatic update using the GLVS plug-in.
7 " GetLatestVimScripts: 3375 1 :AutoInstall: notes.zip
9 " Don't source the plug-in when it's already been loaded or &compatible is set.
10 if &cp || exists('g:loaded_notes')
14 " Make sure the default paths below are compatible with Pathogen.
15 let s:plugindir = expand('<sfile>:p:h') . '/../misc/notes'
17 " Define the default location where the user's notes are saved?
18 if !exists('g:notes_directory')
19 let g:notes_directory = s:plugindir . '/user'
22 " Define the default location of the shadow directory with predefined notes?
23 if !exists('g:notes_shadowdir')
24 let g:notes_shadowdir = s:plugindir . '/shadow'
27 " Define the default location for the full text index.
28 if !exists('g:notes_indexfile')
29 let g:notes_indexfile = s:plugindir . '/index.sqlite3'
32 " Define the default location for the keyword scanner script.
33 if !exists('g:notes_indexscript')
34 let g:notes_indexscript = s:plugindir . '/scanner.py'
37 " Define the default suffix for note filenames.
38 if !exists('g:notes_suffix')
39 let g:notes_suffix = ''
42 " Define the default location for the tag name index (used for completion).
43 if !exists('g:notes_tagsindex')
44 let g:notes_tagsindex = s:plugindir . '/tags.txt'
47 " User commands to create, delete and search notes.
48 command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete Note call xolox#notes#edit(<q-bang>, <q-args>)
49 command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(<q-bang>)
50 command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete DeleteNote call xolox#notes#delete(<q-bang>, <q-args>)
51 command! -bang -nargs=? SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
52 command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
53 command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent(<q-bang>, <q-args>)
54 command! -bar -count=1 ShowTaggedNotes call xolox#notes#tags#show_tags(<count>)
55 command! -bar IndexTaggedNotes call xolox#notes#tags#create_index()
57 " Automatic commands to enable the :edit note:… shortcut and load the notes file type.
59 function! s:DAC(events, directory, command)
60 " Define automatic command for {events} in {directory} with {command}.
61 " Resolve the path to the directory with notes so that the automatic command
62 " also applies to symbolic links pointing to notes (Vim matches filename
63 " patterns in automatic commands after resolving filenames).
64 let directory = xolox#misc#path#absolute(a:directory)
65 " On Windows we have to replace backslashes with forward slashes.
66 if xolox#misc#os#is_win()
67 let directory = substitute(directory, '\\', '/', 'g')
69 let pattern = fnameescape(directory) . '/*'
70 " On Windows the pattern won't match if it contains repeating slashes.
71 let pattern = substitute(pattern, '/\+', '/', 'g')
72 execute 'autocmd' a:events pattern a:command
77 " NB: "nested" is used here so that SwapExists automatic commands apply
78 " to notes (which is IMHO better than always showing the E325 prompt).
79 au BufReadCmd note:* nested call xolox#notes#shortcut()
80 call s:DAC('BufReadCmd', g:notes_shadowdir, 'call xolox#notes#edit_shadow()')
81 call s:DAC('BufWriteCmd', g:notes_directory, 'call xolox#notes#save()')
82 au SwapExists * call xolox#notes#swaphack()
83 au WinEnter * if &ft == 'notes' | call xolox#notes#highlight_names(0) | endif
84 au BufReadPost * if &ft == 'notes' | unlet! b:notes_names_last_highlighted | endif
85 au BufUnload * if &ft == 'notes' | call xolox#notes#unload_from_cache() | endif
88 augroup filetypedetect
89 call s:DAC('BufNewFile,BufRead', g:notes_directory, 'if &bt == "" | setl ft=notes | endif')
90 call s:DAC('BufNewFile,BufRead', g:notes_shadowdir, 'if &bt == "" | setl ft=notes | endif')
95 " Make sure the plug-in is only loaded once.
96 let g:loaded_notes = 1