Skip to content

Commit 94e10b3

Browse files
committed
Enable naming new notes with :NewNote arguments
:NewNote doesn't warn about existing notes with the same name because one of my next commits will rename :NewNote to :Note and make it open existing notes instead of creating a new buffer with the same name (to avoid confusion / accidental overwriting of notes).
1 parent 16f4600 commit 94e10b3

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

autoload.vim

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: December 25, 2010
3+
" Last Change: December 28, 2010
44
" URL: http://peterodding.com/code/vim/notes/
55

66
" Note: This file is encoded in UTF-8 including a byte order mark so
77
" that Vim loads the script using the right encoding transparently.
88

99
let s:script = expand('<sfile>:p:~')
1010

11-
function! xolox#notes#new(bang) " {{{1
11+
function! xolox#notes#new(bang, name) " {{{1
1212
" Create a new note using the :NewNote command.
1313
if !s:is_empty_buffer()
1414
execute 'enew' . a:bang
1515
endif
1616
setlocal filetype=notes
1717
execute 'silent read' fnameescape(xolox#path#merge(g:notes_shadowdir, 'New note'))
1818
1delete
19-
setlocal nomodified
19+
if a:name =~ '\S'
20+
call setline(1, xolox#trim(a:name))
21+
else
22+
setlocal nomodified
23+
endif
2024
doautocmd BufReadPost
2125
endfunction
2226

@@ -59,7 +63,7 @@ function! xolox#notes#shortcut() " {{{1
5963
let filename = ''
6064
let arguments = xolox#trim(matchstr(expand('<afile>'), 'note:\zs.*'))
6165
if arguments == ''
62-
call xolox#notes#new(bang)
66+
call xolox#notes#new(bang, '')
6367
return
6468
endif
6569
for [fname, title] in items(xolox#notes#get_fnames_and_titles())

notes.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Last Change: December 28, 2010
44
" URL: http://peterodding.com/code/vim/notes/
55
" License: MIT
6-
" Version: 0.7.20
6+
" Version: 0.7.21
77

88
" Support for automatic update using the GLVS plug-in.
99
" GetLatestVimScripts: 3375 1 :AutoInstall: session.zip
@@ -37,7 +37,7 @@ if !exists('g:notes_indexscript')
3737
endif
3838

3939
" User commands to create, delete and search notes.
40-
command! -bar -bang NewNote call xolox#notes#new(<q-bang>)
40+
command! -bar -bang -nargs=? NewNote call xolox#notes#new(<q-bang>, <q-args>)
4141
command! -bar -bang DeleteNote call xolox#notes#delete(<q-bang>)
4242
command! -bar -bang -nargs=1 SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
4343
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)

0 commit comments

Comments
 (0)