Hi all


In my vimrc the BufRead autocommands for some filetypes call this function.
Maybe some readers want to “copy & paste” or even enhance it
(the vim license applies):

function! s:UpdateTimestamp(RegexMatchingLine, TimestampFormat)
    "  File is left untouched, update of timestamp dropped, if closed without 
    "  other modifications.  By default, vim is “smart” and unsets &modified 
    "  afterwards, if BufRead event handlers modify content.
    "  For performance reasons, timestamps are updated on reading, not on 
    "  writing, thus may be older than filesystem mtime by up to 1 day.
    "  Considering only those content timestamps, which comply with the 
    "  condition
    "    0  ≤  ((filesystem timestamp mtime) - (content timestamp))  ≤  (1 day)
    "  should be a mostly sufficient (but NOT GUARANTEED) protection against 
    "  touching timestamps not intended to be updated.  Use at your own risk, 
    "  tracking by version management system recommended.
    "  Usage example:
    "  autocmd BufRead runtime/syntax/*.vim call 
<SID>UpdateTimestamp('\v^\s*Last Change:\s+20\d\d-[01]\d-[0-3]\d', "%F")
    "  -- Roland Eggner 2015-07-07
    if &readonly
        return
    endif
    let l:TimestampOld = strftime(a:TimestampFormat, 
getftime(expand("<afile>:p")))
    let l:TimestampOld1 = strftime(a:TimestampFormat, 
getftime(expand("<afile>:p")) - 86400)
    let l:TimestampNew = strftime(a:TimestampFormat)
    let l:LinenumberTimestamp = search(a:RegexMatchingLine . l:TimestampOld, 
"cnw")
    if l:LinenumberTimestamp == 0
        let l:TimestampOld = l:TimestampOld1
        let l:LinenumberTimestamp = search(a:RegexMatchingLine . 
l:TimestampOld, "cnw")
    endif
    if l:LinenumberTimestamp > 1
        call setline(l:LinenumberTimestamp, 
substitute(getline(l:LinenumberTimestamp), l:TimestampOld, l:TimestampNew, ""))
    endif
endfunction


I am not aware of any mention of an equivalent solution in this mailing list.  
I am too lazy to check, if an equivalent or even better vimScript solution 
already has been published elsewhere.  Sorry for the noise, if it has been.



-- 
Have fun,
Roland Eggner

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Attachment: pgpY9Jh6d4iIB.pgp
Description: PGP signature

Raspunde prin e-mail lui