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, 14 Apr 2011 19:31:44 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87sjtk73tb.fsf@lifelogs.com> References: <87mxo9mvxm.fsf@lifelogs.com> <87bp4la59u.fsf@lifelogs.com> <87fwtx5n3c.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1306268767 19021 80.91.229.12 (24 May 2011 20:26:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 24 May 2011 20:26:07 +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:26:02 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 1QOyB0-0000LT-9G for geh-help-gnu-emacs@m.gmane.org; Tue, 24 May 2011 22:26:02 +0200 Original-Received: from localhost ([::1]:48176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOxrV-0004k7-1Q for geh-help-gnu-emacs@m.gmane.org; Tue, 24 May 2011 16:05:53 -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: 126 Original-X-Trace: news.albasani.net jDXoypxdFEOmG16xyZUxBHzNFFy8xtR9OmOqWl7788HclxE37Q29r9TLo8D5dEu9nqWVHVqfFJ80hrqRKA3UwQ== Original-NNTP-Posting-Date: Fri, 15 Apr 2011 00:31:45 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="BGP4vIEmnrkBGS+BO0Dp3wlKfHa8FAGv88gevH9xWCVttmHPE5MFxkXpdAdmc2gfjPDMjrcLx71fdlrzDRSUJD7ZEdrAG1e8KPOsh+raR7aWi6VzH4wkIluWSl6JpDvz"; 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:YHkIKFLclihQwN48YRQfqOGJPM0= sha1:aG0gsd4lgQO9Ypn4zM8rGn0E28I= Original-Xref: usenet.stanford.edu gnu.emacs.help:186678 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:81150 Archived-At: --=-=-= Content-Type: text/plain On Thu, 16 Dec 2010 21:35:10 -0500 Stefan Monnier wrote: >> 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? SM> Use `define-minor-mode' rather than `add-hook'. Attached is my attempt to view numbers matching "\\<[0-9]\\{8,11\\}\\>" as dates. It works all right, but not perfectly. I looked at rainbow-mode.el for some of the setup and did some on my own. It uses the `help-echo' text property, which means you have to use the 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. If someone could explain how to display the calculated date in some other way besides `help-echo', or how to use the margins or something else to show the `help-echo' string, I'd really appreciate it. Once this is ready I'll put it up on the GNU ELPA or wherever... It's really useful for me but others may not find it so useful. Thanks 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. ;;; 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." `(face font-lock-warning-face epoch-view-data ,(match-string-no-properties 0) help-echo epoch-view--render)) (defun epoch-view--render (win buf pos) "Render a epoch match from a number." (format-time-string epoch-view-time-format (seconds-to-time (car (read-from-string (concat (get-text-property pos 'epoch-view-data b= uf) ".0")))))) (defun epoch-view-turn-on () "Turn on epoch-view-mode." (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 --=-=-=--