From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.help Subject: Re: efficiently viewing Unix timestamps as dates Date: Thu, 16 Dec 2010 17:12:23 -0600 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87fwtx5n3c.fsf@lifelogs.com> References: <87mxo9mvxm.fsf@lifelogs.com> <87bp4la59u.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1292542856 12455 80.91.229.12 (16 Dec 2010 23:40:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 16 Dec 2010 23:40:56 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 17 00:40:51 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PTNRK-0006UE-Lt for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Dec 2010 00:40:50 +0100 Original-Received: from localhost ([127.0.0.1]:51328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PTNRK-00083X-6j for geh-help-gnu-emacs@m.gmane.org; Thu, 16 Dec 2010 18:40:50 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!newsfeed.freenet.ag!news.albasani.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 56 Original-X-Trace: news.albasani.net WKH/7wIMUOssw3e4zDmpNw8bSRolqDYxlj8RZHnBuwxRapb1ZOfa2AyJFT8c3KLoK8Ob5pzFQ4l92+ZWydmv1Q== Original-NNTP-Posting-Date: Thu, 16 Dec 2010 23:12:25 +0000 (UTC) X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Cancel-Lock: sha1:xD+Zo9To9+my17cLsDM1StIPXFY= sha1:ktOGyvsaqRXHR7Flhpvc/GrzAV8= User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) Injection-Info: news.albasani.net; logging-data="Kq0A8ktpjVhy3t4FKEWHI+Fg6lgPzN3rRAdEXw62lrM6I1F4iLYg6KT4JRy+Qiz9YgRhmgaT5woh7NXiNevhjLPlVwvVDCYkr8q6uxnji2+GHqSR7Ny2V1ALj76SAZcb"; mail-complaints-to="abuse@albasani.net" Original-Xref: usenet.stanford.edu gnu.emacs.help:183359 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:77611 Archived-At: On Thu, 16 Dec 2010 17:23:34 -0500 Stefan Monnier wrote: >> 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?" SM> The first part is rather tricky: "2" looks an awful lot like a Unix SM> timestamp ...wait... it *is* a Unix timestamp! SM> But assuming you know something about those time stamps, you can try SM> something like: SM> (add-hook 'foo-mode-hook SM> (lambda () SM> (font-lock-add-keywords nil SM> '(("^[0-9]+" SM> (0 `(face nil display SM> ,(format-time-string "%F %T" SM> (seconds-to-time SM> (car (read-from-string SM> (concat "1292527019" ".0")))))))))))) SM> where "^[0-9]+" is the regexp that matches your timestamps (in this SM> case I chose to assume they're always at the beginning of a line). I see a small bug in the last line, but I think it's fixable :) On Thu, 16 Dec 2010 13:34:51 -0800 PJ Weisberg wrote: PW> Argh. I don't actually know how to do the visual-only thing, but that PW> problem is complicated by the fact that the string "December 16, 2010" PW> (for example) contains TWO Unix timestamps, both in the early morning PW> hours of January 1, 1970. It's not so bad (I only bothered for dates after 2001 or 0-padded at the beginning): (add-hook 'foo-mode-hook (lambda () (font-lock-add-keywords nil '(("[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" (0 `(face nil display ,(format-time-string "%F %T" (seconds-to-time (car (read-from-string (concat (match-string 0) ".0")))))))))))) I'd rather make this a minor mode than a hook, so I can easily turn it on in a buffer. Is that easy or hard to do? Any specific example I can look at? Ted