Skip to content

Commit

Permalink
Optionally append suffix to note filenames (thanks to Christopher Pep…
Browse files Browse the repository at this point in the history
…lin)
  • Loading branch information
xolox committed Jun 14, 2011
1 parent d532ede commit 96a16ed
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -26,12 +26,20 @@ Unzip the most recent [ZIP archive] [download] file inside your Vim profile dire

## Options

Note that if the plug-in works after following the installation instructions above, you probably don't need to change any of the options below. They're available for people who like to customize their directory layout.
All options have reasonable defaults so if the plug-in works after installation you don't need to change any options. They're available for people who like to customize their directory layout. These options can be configured in your [vimrc] [vimrc] by including a line like this:

let g:notes_directory = '~/Documents/Notes'

### The `g:notes_directory` option

All your notes are stored together in one directory. This option defines the path of this directory.

### The `g:notes_suffix` option

The suffix to add to generated filenames. The plug-in generates filenames for your notes based on the title (first line) of each note and by default these filenames don't include an extension like `.txt`. You can use this option to make the plug-in automatically append an extension without having to embed the extension in the note's title, e.g.:

:let g:notes_suffix = '.txt'

### The `g:notes_shadowdir` option

The notes plug-in comes with some default notes containing documentation about the plug-in. This option defines the path of the directory containing these notes.
Expand Down Expand Up @@ -130,6 +138,7 @@ This software is licensed under the [MIT license] [mit].
[gf]: http://vimdoc.sourceforge.net/htmldoc/editing.html#gf
[slate]: http://code.google.com/p/vim/source/browse/runtime/colors/slate.vim
[download]: http://peterodding.com/code/vim/downloads/notes.zip
[vimrc]: http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc
[edit]: http://vimdoc.sourceforge.net/htmldoc/editing.html#:edit
[split]: http://vimdoc.sourceforge.net/htmldoc/windows.html#:split
[tabedit]: http://vimdoc.sourceforge.net/htmldoc/tabpage.html#:tabedit
Expand Down
14 changes: 11 additions & 3 deletions autoload/xolox/notes.vim
@@ -1,6 +1,6 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: June 11, 2011
" Last Change: June 14, 2011
" URL: http://peterodding.com/code/vim/notes/

" Note: This file is encoded in UTF-8 including a byte order mark so
Expand Down Expand Up @@ -539,14 +539,22 @@ endfunction

function! xolox#notes#fname_to_title(filename) " {{{3
" Convert absolute note {filename} to title.
return xolox#misc#path#decode(fnamemodify(a:filename, ':t'))
let fname = a:filename
" Strip suffix?
if fname[-len(g:notes_suffix):] == g:notes_suffix
let fname = fname[0:-len(g:notes_suffix)-1]
endif
" Strip directory path.
let fname = fnamemodify(fname, ':t')
" Decode special characters.
return xolox#misc#path#decode(fname)
endfunction

function! xolox#notes#title_to_fname(title) " {{{3
" Convert note {title} to absolute filename.
let filename = xolox#misc#path#encode(a:title)
if filename != ''
let pathname = xolox#misc#path#merge(g:notes_directory, filename)
let pathname = xolox#misc#path#merge(g:notes_directory, filename . g:notes_suffix)
return xolox#misc#path#absolute(pathname)
endif
return ''
Expand Down
20 changes: 17 additions & 3 deletions doc/notes.txt
Expand Up @@ -68,16 +68,30 @@ continue from there (and how to use the plug-in in general).
*notes-options*
Options ~

Note that if the plug-in works after following the installation instructions
above, you probably don't need to change any of the options below. They're
available for people who like to customize their directory layout.
All options have reasonable defaults so if the plug-in works after
installation you don't need to change any options. They're available for
people who like to customize their directory layout. These options can be
configured in your |vimrc| by including a line like this:
>
let g:notes_directory = '~/Documents/Notes'
-------------------------------------------------------------------------------
The *g:notes_directory* option

All your notes are stored together in one directory. This option defines the
path of this directory.

-------------------------------------------------------------------------------
The *g:notes_suffix* option

The suffix to add to generated filenames. The plug-in generates filenames for
your notes based on the title (first line) of each note and by default these
filenames don't include an extension like '.txt'. You can use this option to
make the plug-in automatically append an extension without having to embed the
extension in the note's title, e.g.:
>
:let g:notes_suffix = '.txt'
-------------------------------------------------------------------------------
The *g:notes_shadowdir* option

Expand Down
7 changes: 6 additions & 1 deletion plugin/notes.vim
Expand Up @@ -3,7 +3,7 @@
" Last Change: June 14, 2011
" URL: http://peterodding.com/code/vim/notes/
" License: MIT
" Version: 0.9
" Version: 0.9.1

" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3375 1 :AutoInstall: notes.zip
Expand Down Expand Up @@ -36,6 +36,11 @@ if !exists('g:notes_indexscript')
let g:notes_indexscript = s:plugindir . '/scanner.py'
endif

" Define the default suffix for note filenames.
if !exists('g:notes_suffix')
let g:notes_suffix = ''
endif

" User commands to create, delete and search notes.
command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete Note call xolox#notes#edit(<q-bang>, <q-args>)
command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(<q-bang>)
Expand Down

0 comments on commit 96a16ed

Please sign in to comment.