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: Fri, 15 Apr 2011 11:59:06 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <877hav4fj9.fsf@lifelogs.com> References: <87mxo9mvxm.fsf@lifelogs.com> <87bp4la59u.fsf@lifelogs.com> <87fwtx5n3c.fsf@lifelogs.com> <87sjtk73tb.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1306267441 10008 80.91.229.12 (24 May 2011 20:04:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 24 May 2011 20:04:01 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 24 22:03:57 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QOxpZ-0002nL-0C for geh-help-gnu-emacs@m.gmane.org; Tue, 24 May 2011 22:03:53 +0200 Original-Received: from localhost ([::1]:41440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOxpY-0000XA-FJ for geh-help-gnu-emacs@m.gmane.org; Tue, 24 May 2011 16:03:52 -0400 Original-Path: usenet.stanford.edu!news-transit.tcx.org.uk!news.albasani.net!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 139 Original-X-Trace: news.albasani.net +SLNbffKRxru6wLYCfhZRyjggs8kLiwbsW4kYEoTK95geRfyN78ncpodiBFjyK1+FiF35V0E9vuFFJz9ZtAogh9OFr6vAY3QSLosYEAfGdngK2ITY4VTnX/6PCklTy79 Original-NNTP-Posting-Date: Fri, 15 Apr 2011 16:59:06 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="glzaemvB7/MP7o6ojxxwNcVo13D/z9pieeJAM7bmbxHKTQnUXZhbIiq/DK2PFFVbtMoJ2g98/Cyl3wRPVx+AJMkquwtJCW8gTuR31nujV6o8wKmjbHDkKPR8+g63Pr1V"; mail-complaints-to="abuse@albasani.net" User-Agent: Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux) 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:8Jh3Qb6IHInhUhfzqopuHbhK6nE= sha1:edkDFMoozjVMaV1CtrtJPIK/1I4= Original-Xref: usenet.stanford.edu gnu.emacs.help:186685 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:81026 Archived-At: --=-=-= Content-Type: text/plain On Fri, 15 Apr 2011 12:29:53 -0300 Stefan Monnier wrote: >> mouse to look at the date as a tooltip. I didn't like how it looked >> with the `display' property: you would hit backspace from a string of 8 >> digits to 7, and the display property would remain the previously >> computed date. SM> You have to explicit remove the `display' property before refreshing SM> with font-lock. My sample code did not bother to do it because it was SM> just a proof of concept. SM> A naive way to do that is to add `display' to SM> font-lock-extra-managed-props, tho this will also remove `display' SM> properties added by other packages for other purposes. SM> So a better way is to add not just a `display' property but also another SM> property that is specific to your package, so that you can recognize SM> which `display' properties are yours, and then in font-lock-keywords you SM> can add a pseudo-keyword which will look for those display properties SM> and remove them. I think the more careful method is a real pain (I couldn't figure it out in a few hours of digging through the painful details), so I'd rather override `display' naively. I would have rather superimposed the date somehow, like make the line height larger... I was tempted to use SVG to render it just how I want, but then it won't work without SVG support and graphics. If you want, tell me how to patch my code, attached here, to do it the smart way. It doesn't seem like a big deal but if you do... As I said I want to put it in the GNU ELPA so if the bar is higher for that acceptance, I'll work on it some more. Ted --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=epoch-view.el Content-Transfer-Encoding: quoted-printable ;;; epoch-view.el --- minor mode to visualize epoch timestamps ;; Copyright (C) 2010 ;; Free Software Foundation, Inc. ;; Author: Ted Zlatanov ;; Keywords: data, timestamp, epoch, unix ;; Version: 0.1 ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; Use like any other minor mode. You'll see tooltips with dates ;; instead of Unix epoch times. This mode turns on font-lock and ;; leaves it on forever. You may or may not like that. ;;; code: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; User Variables: (defcustom epoch-view-time-format "%F %T" "Format for time view. Same as `format-time-string'." :type '(choice :tag "Time format" (string :tag "Choose your own `format-time-string' format") (const :tag "YYYY-MM-DD HH:MM:SS" "%F %T")) :group 'epoch-view) (defvar epoch-view-font-lock-keywords '(("\\<[0-9]\\{8,11\\}\\>" (0 (epoch-view-render)))) "Font-lock keywords of epoch timestamps.") (defun epoch-view-render () "Render a epoch match." (let ((text (match-string-no-properties 0))) `(face font-lock-warning-face display ,(epoch-view--render text)))) (defun epoch-view--render-time (text) "Render the time portion of an epoch match from TEXT." (format-time-string epoch-view-time-format (seconds-to-time (car (read-from-string (concat text ".0")))))) (defun epoch-view--render (text) "Render a epoch match from a number in TEXT, ending with TEXT." (format "[%s] %s" (epoch-view--render-time text) text)) (defun epoch-view-turn-on () "Turn on epoch-view-mode." (let ((props (make-local-variable 'font-lock-extra-managed-props))) (add-to-list props 'display)) (font-lock-add-keywords nil epoch-view-font-lock-keywords)) (defun epoch-view-turn-off () "Turn off epoch-view-mode." (font-lock-remove-keywords nil `(,@epoch-view-font-lock-keywords))) ;;;###autoload (define-minor-mode epoch-view-mode "Visualize epoch (Unix) timestamps." :lighter " EV" (progn (if epoch-view-mode (epoch-view-turn-on) (epoch-view-turn-off)) ;; Turn on font lock (font-lock-mode 1))) (provide 'epoch-view) (run-hooks 'epoch-view-load-hook) ;;; epoch-view.el ends here --=-=-=--