Skip to content

Commit 5f020ab

Browse files
committed
Add way to visualize library
1 parent bc7eddf commit 5f020ab

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

autoload/noteworthy.vim

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ endfunction
3030

3131
""
3232
" Completion for :Note.
33-
function! noteworthy#Completion(arg_lead, cmd_line, cursor_pos) abort
33+
function! noteworthy#Completion(...) abort
3434
let l:fext = get(g:, 'noteworthy_ambiguous', 0) ? '*' : s:GetNoteFileExt()
3535
let l:dir = s:GetCurrentLibrary()
3636
if !isdirectory(l:dir) | return '' | endif
@@ -41,17 +41,18 @@ endfunction
4141
""
4242
" Call for :NoteLibrary. Decides if we're getting or setting, and calls the
4343
" appropriate function.
44-
function! noteworthy#Library(...) abort
44+
function! noteworthy#Library(visualize, ...) abort
4545
if a:0
4646
call s:SetCurrentLibrary(a:1)
4747
echo 'Setting library to "' . a:1 . '"'
4848
return
4949
endif
50-
call s:GetCurrentLibrary()
50+
let l:lib = s:GetCurrentLibrary()
5151
echo 'Current library is set to "' . g:noteworthy_current_library . '"'
52+
if a:visualize | call s:Visualize(l:lib) | endif
5253
endfunction
5354

54-
""
55+
""{{{
5556
" Get or set the extension to use for notes.
5657
function! noteworthy#Extension(...) abort
5758
if a:0
@@ -74,12 +75,30 @@ function! noteworthy#Delimiter(...) abort
7475
echo 'Current delimiter is set to "' .
7576
\ get(g:, 'noteworthy_delimiter', s:GetNoteDelimiter()) . '"'
7677
endfunction
77-
78+
"}}}
7879
" PRIVATE API
7980

81+
""
82+
" TODO Getting closer. The files just don't open when you hit they key.
83+
" Also, is Netrw just used for stuff like this? Should I not be trying to do
84+
" this manually?
85+
function! s:Visualize(library) abort
86+
vsplit
87+
setlocal buftype=nofile
88+
setlocal modifiable
89+
let l:files = split(noteworthy#Completion(), "\n")
90+
call append(0, l:files)
91+
nnoremap <buffer> o call notheworthy#Open(a:library)
92+
setlocal nomodifiable
93+
endfunction
94+
95+
function! noteworthy#Open(library) abort
96+
echo 'edit' a:library . getline('.')
97+
endfunction
98+
8099
""
81100
" The current library in use.
82-
function! s:GetCurrentLibrary()
101+
function! s:GetCurrentLibrary() abort
83102
if !exists('g:noteworthy_libraries')
84103
call s:Error("'g:noteworthy_libraries' is not set!")
85104
return 0
@@ -153,7 +172,7 @@ function! s:GetFormattedTitle(title) abort
153172
return '# ' . substitute(a:title, '\<.', '\u&', 'g')
154173
endfunction
155174

156-
function s:Deprecated(from, to) abort
175+
function! s:Deprecated(from, to) abort
157176
call s:Warn(a:from . ' is deprecated. Use ' . a:to . 'instead.')
158177
endfunction
159178

plugin/noteworthy.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ command! -nargs=+ -complete=custom,noteworthy#Completion Tnote
2828
\ call noteworthy#Tnote(<f-args>)
2929

3030
""
31-
" :NoteLibrary [{directory}]
31+
" :NoteLibrary[!] [{directory}]
3232
" Show or change the current library.
33-
command! -nargs=? -complete=custom,noteworthy#LibraryCompletion NoteLibrary
34-
\ call noteworthy#Library(<f-args>)
33+
command! -bang -nargs=? -complete=custom,noteworthy#LibraryCompletion NoteLibrary
34+
\ call noteworthy#Library(<bang>0, <f-args>)
3535

3636
""
3737
" :NoteExtension {extension}

0 commit comments

Comments
 (0)