Skip to content

Commit 268e5cb

Browse files
committed
Add way to visualize library
1 parent bc7eddf commit 268e5cb

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

autoload/noteworthy.vim

Lines changed: 30 additions & 9 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,19 @@ 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 . '"'
48-
return
48+
else
49+
echo 'Current library is set to "' . g:noteworthy_current_library . '"'
50+
endif
51+
if a:visualize
52+
call s:Visualize(s:GetCurrentLibrary())
4953
endif
50-
call s:GetCurrentLibrary()
51-
echo 'Current library is set to "' . g:noteworthy_current_library . '"'
5254
endfunction
5355

54-
""
56+
""{{{
5557
" Get or set the extension to use for notes.
5658
function! noteworthy#Extension(...) abort
5759
if a:0
@@ -74,12 +76,31 @@ function! noteworthy#Delimiter(...) abort
7476
echo 'Current delimiter is set to "' .
7577
\ get(g:, 'noteworthy_delimiter', s:GetNoteDelimiter()) . '"'
7678
endfunction
77-
79+
"}}}
7880
" PRIVATE API
7981

82+
""
83+
" TODO Getting closer. The files just don't open when you hit they key.
84+
" Also, is Netrw just used for stuff like this? Should I not be trying to do
85+
" this manually?
86+
function! s:Visualize(library) abort
87+
execute 'silent vsplit __' . toupper(g:noteworthy_current_library) . '_LIBRARY__'
88+
setlocal buftype=nofile
89+
setlocal modifiable
90+
let l:files = split(noteworthy#Completion(), "\n")
91+
call append(0, l:files)
92+
nnoremap <buffer> o call noteworthy#Open(a:library)
93+
silent normal! gg
94+
setlocal nomodifiable
95+
endfunction
96+
97+
function! noteworthy#Open(library) abort
98+
echo 'edit' a:library . getline('.')
99+
endfunction
100+
80101
""
81102
" The current library in use.
82-
function! s:GetCurrentLibrary()
103+
function! s:GetCurrentLibrary() abort
83104
if !exists('g:noteworthy_libraries')
84105
call s:Error("'g:noteworthy_libraries' is not set!")
85106
return 0
@@ -153,7 +174,7 @@ function! s:GetFormattedTitle(title) abort
153174
return '# ' . substitute(a:title, '\<.', '\u&', 'g')
154175
endfunction
155176

156-
function s:Deprecated(from, to) abort
177+
function! s:Deprecated(from, to) abort
157178
call s:Warn(a:from . ' is deprecated. Use ' . a:to . 'instead.')
158179
endfunction
159180

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)