From 96a16ed08305954621ee7197c60e42716ea68c1a Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Tue, 14 Jun 2011 02:05:09 +0200 Subject: [PATCH] Optionally append suffix to note filenames (thanks to Christopher Peplin) --- README.md | 11 ++++++++++- autoload/xolox/notes.vim | 14 +++++++++++--- doc/notes.txt | 20 +++++++++++++++++--- plugin/notes.vim | 7 ++++++- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 60d1e15..7550dbd 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/autoload/xolox/notes.vim b/autoload/xolox/notes.vim index ad33134..34695f8 100644 --- a/autoload/xolox/notes.vim +++ b/autoload/xolox/notes.vim @@ -1,6 +1,6 @@ " Vim auto-load script " Author: Peter Odding -" 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 @@ -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 '' diff --git a/doc/notes.txt b/doc/notes.txt index 667cdd0..6389697 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -68,9 +68,12 @@ 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 @@ -78,6 +81,17 @@ 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 diff --git a/plugin/notes.vim b/plugin/notes.vim index fde3231..2e8f4de 100644 --- a/plugin/notes.vim +++ b/plugin/notes.vim @@ -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 @@ -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(, ) command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection()