help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: efficiently viewing Unix timestamps as dates


From: Stefan Monnier
Subject: Re: efficiently viewing Unix timestamps as dates
Date: Thu, 16 Dec 2010 17:23:34 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

> but the actual format string should be up to the user.  Really, my
> question is "how do I find numbers that look like 1292527019, run a
> function on them, and then show the results of that function overlaid on
> top of the number without actually changing it in the buffer?"

The first part is rather tricky: "2" looks an awful lot like a Unix
timestamp ...wait... it *is* a Unix timestamp!
But assuming you know something about those time stamps, you can try
something like:

  (add-hook 'foo-mode-hook
            (lambda ()
              (font-lock-add-keywords nil
                '(("^[0-9]+"
                   (0 `(face nil display
                        ,(format-time-string "%F %T"
                           (seconds-to-time
                            (car (read-from-string
                                  (concat "1292527019" ".0"))))))))))))

where "^[0-9]+" is the regexp that matches your timestamps (in this
case I chose to assume they're always at the beginning of a line).


        Stefan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]