vimwiki-backup / vimwiki

Automatically exported from code.google.com/p/vimwiki
1 stars 1 forks source link

feature request: add/update "Last Change" time stamp for every vimwiki file. #342

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Add a "Last Change" time stamp at top or bottom of viwmiki file is useful to 
tell you how old this file is.

I hope vimwiki can support a function to do this automatically. when create a 
new vimwiki file, add this "Last Change" line to vimwiki file. And when file is 
changed, update this "Last Change" time stamp.
Better setting this in an option.

I find some scripts which do this in attach.
You can reference them.

Original issue reported on code.google.com by numbch...@gmail.com on 10 Jun 2012 at 11:47

Attachments:

GoogleCodeExporter commented 8 years ago
Why can't you set up it with an autocommand?
I for myself did it...

Original comment by habamax on 10 Jun 2012 at 7:57

GoogleCodeExporter commented 8 years ago
Even though I found those scripts, but I do not know which one is better 
(through read the source code), and how to do with autocommand. I want to do 
with autocommand before I post issue here. But I found I can not put those 
script into vimrc function. then call function behind autocmd. That's why I ask 
for feature.

So, if you have done this with autocmd, can you let me reference your vimrc 
about how to do this ?

Original comment by numbch...@gmail.com on 11 Jun 2012 at 12:35

GoogleCodeExporter commented 8 years ago
add those into your .vimrc:

" Check no more than 30 lines from start for 'Last Change:' and update it with
" the current datetime.
function! LastChangeUpdate() "{{{
  for linenr in range(1, min([30, line('$')]))
    let line = getline(linenr)
    if line =~ 'Last Change:'
      let line = substitute(line, 'Last Change:.*$',
                  \ 'Last Change: '.strftime("%Y-%m-%d %H:%M"), '')
      call setline(linenr, line)
      break
    endif
  endfor
endfunction "}}}
au BufWritePre *.wiki call LastChangeUpdate()

Original comment by habamax on 12 Jun 2012 at 9:29

GoogleCodeExporter commented 8 years ago
works good. Thanks for this.

Original comment by numbch...@gmail.com on 12 Jun 2012 at 1:42

GoogleCodeExporter commented 8 years ago
I think this will be useful for me, but what I find disorienting, is when I 
type 'u' for undo after writing the file.  Since changing the timestamp is that 
last edit, it jumps to the top of the file.  

Is there any way to change this?

Original comment by stu.andrews on 15 Jun 2012 at 3:42

GoogleCodeExporter commented 8 years ago
I don't know the right way to bypass vim's undo system here. 
The only thing that comes up is to change date using readfile/writefile.

Another way, which is to use undojoin in the beginning of the function:

" Check no more than 30 lines from start for 'Last Change:' and update it with
" the current datetime.
function! LastChangeUpdate() "{{{
  undojoin
  for linenr in range(1, min([30, line('$')]))
    let line = getline(linenr)
    if line =~ 'Last Change:'
      let line = substitute(line, 'Last Change:.*$',
                  \ 'Last Change: '.strftime("%Y-%m-%d %H:%M"), '')
      call setline(linenr, line)
      break
    endif
  endfor
endfunction "}}}
au BufWritePre *.wiki call LastChangeUpdate()

It looks like it works, but I have not tested it much

Original comment by habamax on 15 Jun 2012 at 7:15