Skip to content

Commit 96a16ed

Browse files
committed
Optionally append suffix to note filenames (thanks to Christopher Peplin)
1 parent d532ede commit 96a16ed

File tree

4 files changed

+44
-8
lines changed

4 files changed

+44
-8
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@ Unzip the most recent [ZIP archive] [download] file inside your Vim profile dire
2626

2727
## Options
2828

29-
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.
29+
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:
30+
31+
let g:notes_directory = '~/Documents/Notes'
3032

3133
### The `g:notes_directory` option
3234

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

37+
### The `g:notes_suffix` option
38+
39+
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.:
40+
41+
:let g:notes_suffix = '.txt'
42+
3543
### The `g:notes_shadowdir` option
3644

3745
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].
130138
[gf]: http://vimdoc.sourceforge.net/htmldoc/editing.html#gf
131139
[slate]: http://code.google.com/p/vim/source/browse/runtime/colors/slate.vim
132140
[download]: http://peterodding.com/code/vim/downloads/notes.zip
141+
[vimrc]: http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc
133142
[edit]: http://vimdoc.sourceforge.net/htmldoc/editing.html#:edit
134143
[split]: http://vimdoc.sourceforge.net/htmldoc/windows.html#:split
135144
[tabedit]: http://vimdoc.sourceforge.net/htmldoc/tabpage.html#:tabedit

autoload/xolox/notes.vim

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: June 11, 2011
3+
" Last Change: June 14, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55

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

540540
function! xolox#notes#fname_to_title(filename) " {{{3
541541
" Convert absolute note {filename} to title.
542-
return xolox#misc#path#decode(fnamemodify(a:filename, ':t'))
542+
let fname = a:filename
543+
" Strip suffix?
544+
if fname[-len(g:notes_suffix):] == g:notes_suffix
545+
let fname = fname[0:-len(g:notes_suffix)-1]
546+
endif
547+
" Strip directory path.
548+
let fname = fnamemodify(fname, ':t')
549+
" Decode special characters.
550+
return xolox#misc#path#decode(fname)
543551
endfunction
544552

545553
function! xolox#notes#title_to_fname(title) " {{{3
546554
" Convert note {title} to absolute filename.
547555
let filename = xolox#misc#path#encode(a:title)
548556
if filename != ''
549-
let pathname = xolox#misc#path#merge(g:notes_directory, filename)
557+
let pathname = xolox#misc#path#merge(g:notes_directory, filename . g:notes_suffix)
550558
return xolox#misc#path#absolute(pathname)
551559
endif
552560
return ''

doc/notes.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,30 @@ continue from there (and how to use the plug-in in general).
6868
*notes-options*
6969
Options ~
7070

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

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

84+
-------------------------------------------------------------------------------
85+
The *g:notes_suffix* option
86+
87+
The suffix to add to generated filenames. The plug-in generates filenames for
88+
your notes based on the title (first line) of each note and by default these
89+
filenames don't include an extension like '.txt'. You can use this option to
90+
make the plug-in automatically append an extension without having to embed the
91+
extension in the note's title, e.g.:
92+
>
93+
:let g:notes_suffix = '.txt'
94+
8195
-------------------------------------------------------------------------------
8296
The *g:notes_shadowdir* option
8397

plugin/notes.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Last Change: June 14, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55
" License: MIT
6-
" Version: 0.9
6+
" Version: 0.9.1
77

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

39+
" Define the default suffix for note filenames.
40+
if !exists('g:notes_suffix')
41+
let g:notes_suffix = ''
42+
endif
43+
3944
" User commands to create, delete and search notes.
4045
command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete Note call xolox#notes#edit(<q-bang>, <q-args>)
4146
command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(<q-bang>)

0 commit comments

Comments
 (0)