Skip to content

Commit

Permalink
almost reach to v0.61
Browse files Browse the repository at this point in the history
  • Loading branch information
lymslive committed Jun 2, 2018
1 parent 1f3ba47 commit 2f51fa2
Show file tree
Hide file tree
Showing 18 changed files with 1,345 additions and 61 deletions.
3 changes: 2 additions & 1 deletion autoload/class/notebar.vim
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function! s:class.RefreshBar() dict abort "{{{

setlocal modifiable
:1,$delet
call append(line('$'), l:lsContent)
" call append(0, l:lsContent)
call setline(1, l:lsContent)
if &filetype !=# 'notebar'
setlocal filetype=notebar
setlocal buftype=nofile
Expand Down
60 changes: 19 additions & 41 deletions autoload/class/notebuff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
" Author: lymslive
" Description: current buffer as note file
" Create: 2017-02-17
" Modify: 2017-08-04
" Modify: 2018-06-01

"LOAD:
if exists('s:load') && !exists('g:DEBUG')
Expand All @@ -14,15 +14,7 @@ let s:class = class#note#old()
let s:class._name_ = 'class#notebuff'
let s:class._version_ = 1

" buffer number of the note, 0 is current buffer
" let s:class.bufnr = 0

" marked saved tag
let s:class.tagsave = {}
" mark saved cache
let s:class.chesave = v:false
let s:class.forcesave = ''
let s:class.perlsave = v:false
let s:class.saved = v:false

function! class#notebuff#class() abort "{{{
return s:class
Expand All @@ -43,9 +35,6 @@ function! class#notebuff#ctor(this, ...) abort "{{{
else
call l:Suctor(a:this, l:pFileName)
endif
let a:this.tagsave = {}
let a:this.chesave = v:false
let a:this.forcesave = ''
endfunction "}}}

" ISOBJECT:
Expand All @@ -58,30 +47,34 @@ function! s:class.GetHeadLine(iMaxLine) dict abort "{{{
return getline(1, a:iMaxLine)
endfunction "}}}

" MarkSaved:
function! s:class.MarkSaved(...) dict abort "{{{
let l:saved = get(a:000, 0, v:true)
let self.saved = l:saved
endfunction "}}}

" SaveNote: auto save cache and tag file
" > a:1 force save
function! s:class.SaveNote(...) dict abort "{{{
if a:0 > 0 && !empty(a:1)
let self.tagsave = {}
let self.chesave = v:false
let self.forcesave = a:1
let self.saved = v:false
endif

if self.saved
return 0
endif

let l:iErr = 0
let l:iErr += self.PushMru()

if g:vnote#perlx#enable
if !self.perlsave || !empty(self.forcesave)
call vnote#perlx#OnSave(self.GetNoteName())
let self.perlsave = v:true
endif
let l:iErr += vnote#perlx#OnSave(self.GetNoteName())
else
let l:iErr += self.UpdateCache()
let l:iErr += self.UpdateTagFile()
endif

let self.forcesave = ''

let self.saved = v:true
return l:iErr
endfunction "}}}

Expand All @@ -94,21 +87,14 @@ endfunction "}}}

" UpdateCache:
function! s:class.UpdateCache() dict abort "{{{
if self.chesave && empty(self.forcesave)
return 0
endif

" may have zero time bug
" use :NoteSave y
if !self.IsTodayNote() && self.forcesave !~? '^y'
if !self.IsTodayNote() " && self.forcesave !~? '^y'
return 0
endif

let l:sNoteEntry = self.GetNoteEntry()
let l:iErr = self.notebook.SaveCache(l:sNoteEntry)
if 0 == l:iErr
let self.chesave = v:true
endif
return l:iErr
endfunction "}}}

Expand Down Expand Up @@ -171,18 +157,14 @@ endfunction "}}}
" UpdateOneTag:
function! s:class.UpdateOneTag(sTag) dict abort "{{{
let l:sTag = tolower(a:sTag)
if has_key(self.tagsave, l:sTag)
return 0
endif

" note entry of current note
let l:sNoteEntry = self.GetNoteEntry()
let l:jNoteTag = class#notetag#new(l:sTag)

let l:iRet = l:jNoteTag.UpdateEntry(l:sNoteEntry, self.forcesave)
let l:iRet = l:jNoteTag.UpdateEntry(l:sNoteEntry, 1)
if l:iRet == 0
:DLOG 'update tag file: ' . l:sTag
let self.tagsave[l:sTag] = v:true
else
:DLOG 'fail to update tag file: ' . l:sTag
endif
Expand All @@ -198,16 +180,12 @@ function! s:class.RemoveUpdateTag(sTag) dict abort "{{{

let l:jNoteTag = class#notetag#new(l:sTag)
let l:iRet = l:jNoteTag.RemoveEntry(l:sNoteName)
if l:iRet == 0 && has_key(self.tagsave, l:sTag)
remove(self.tagsave, l:sTag)
endif

return l:iRet
endfunction "}}}

" AddTag:
function! s:class.AddTag(...) dict abort "{{{
let l:list = module#less#list#import()
let l:list = class#less#list#export()
let l:lsTag = l:list.Flat(a:000)
for l:sTag in l:lsTag
call self._AddTag(l:sTag)
Expand Down Expand Up @@ -238,7 +216,7 @@ endfunction "}}}

" RemoveTag:
function! s:class.RemoveTag(...) dict abort "{{{
let l:list = module#less#list#import()
let l:list = class#less#list#export()
let l:lsTag = l:list.Flat(a:000)
for l:sTag in l:lsTag
call self._RemoveTag(l:sTag)
Expand Down
29 changes: 29 additions & 0 deletions autoload/note.vim
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ function! note#DetectTag(bol) abort "{{{
endfunction "}}}

" OnSaveNote: triggle by some write event
" when cursor on the first 2 lines, force save as consider it just
" has modified title or tags
function! note#OnSaveNote(...) abort "{{{
let l:jNoteBuff = s:GetNoteObject()
if empty(l:jNoteBuff)
return 0
endif

let l:sForce = get(a:000, 0, '')
if empty(l:sForce)
if line('.') <= 2
let l:sForce = 1
endif
endif

return l:jNoteBuff.SaveNote(l:sForce)
endfunction "}}}
" OnBufRead:
Expand All @@ -142,6 +150,7 @@ function! note#OnBufRead() abort "{{{
if empty(l:jNoteBuff)
return 0
endif
call l:jNoteBuff.MarkSaved()
return l:jNoteBuff.PushMru()
endfunction "}}}

Expand Down Expand Up @@ -187,6 +196,26 @@ function! note#hNoteMark(...) abort "{{{
endif
endfunction "}}}

" NoteNew: create new note with the same tag set as current one
function! note#hNoteNew(...) abort "{{{
if a:0 == 0
if !exists('b:jNoteBuff') || b:jNoteBuff.saved != v:true
:ELOG 'you should save current note first'
return -1
endif
let l:tagLine = getline(2)
let l:sNoteName = b:jNoteBuff.GetNoteName()
if l:sNoteName =~# '-$'
call notebook#hNoteNew('-')
else
call notebook#hNoteNew()
endif
call setline(2, l:tagLine)
else
call call(function('notebook#hNoteNew'), a:000)
endif
endfunction "}}}

" GetContext: get the first word of current line
function! note#GetContext() abort "{{{
let l:sLine = getline('.')
Expand Down
11 changes: 7 additions & 4 deletions autoload/notebook.vim
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ function! notebook#hNoteNew(...) "{{{
if !empty(l:lsTag)
call map(l:lsTag, 'printf("`%s`", v:val)')
let l:sTagLine .= ' ' . join(l:lsTag, ' ')
else
" add a `untag` tag if none provided
let l:sTagLine .= '`untag`'
endif

if !empty(l:sTagLine)
Expand Down Expand Up @@ -143,16 +146,16 @@ function! notebook#hNoteEdit(...) "{{{
endfunction "}}}

" NoteIndex: build cache index for notebook
" when perlx enabled, '-u' option will update to today, or by default
" when perlx enabled, default update to today, '-c' option
" rebuild all notebook
" when perlx not enabled, use old viml process,
" accept '-t' to rebuild tag as well
function! notebook#hNoteIndex(...) abort "{{{
if g:vnote#perlx#enable
if match(a:000, '-u') != -1
call vnote#perlx#OnUpdate()
else
if match(a:000, '-c') != -1
call vnote#perlx#OnBuild()
else
call vnote#perlx#OnUpdate()
endif
return
endif
Expand Down
5 changes: 5 additions & 0 deletions autoload/vnote/perlx.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ function! vnote#perlx#OnSave(sNoteID) abort "{{{
\'in_top': 1, 'in_bot': 2
\}
let l:job = job_start(l:aCmd, l:opt)
let l:status = job_status(l:job)
if l:status ==? 'fail'
return -1
endif
return 0
endfunction "}}}

" cbError:
Expand Down
Loading

0 comments on commit 2f51fa2

Please sign in to comment.