]> code.delx.au - gnu-emacs-elpa/commitdiff
Add epoch-view.el.
authorTed Zlatanov <tzz@lifelogs.com>
Tue, 26 Apr 2011 02:46:23 +0000 (21:46 -0500)
committerTed Zlatanov <tzz@lifelogs.com>
Tue, 26 Apr 2011 02:46:23 +0000 (21:46 -0500)
* packages/epoch-view-0.0.1.el: New package.

ChangeLog
packages/elpa.rss
packages/epoch-view-0.0.1.el [new file with mode: 0644]

index 758ba04e3ae86e48506d98fb0744b60d9518737b..04d021c0bdcad5353b4b8c2da784c5d089a846d5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-04-26  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * packages/epoch-view-0.0.1.el: New package.
+
 2011-04-20  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * packages/all-1.0.el: Change version.  Address byte-compiler warnings.
index 68706c1d947e994a54caf729a2ea7a895a864f78..5c75ed33c505de235f520387a6524f4606cf2c9f 100644 (file)
@@ -5,6 +5,12 @@
     <language>en</language>
     <description>News for the Emacs Lisp Package Archive</description>
 <item>
+<title>epoch-view version 0.0.1</title>
+<link>http://elpa.gnu.org/packages/news.html</link>
+<description>View Unix epoch timestamps as dates</description>
+<pubDate>Mon, 25 April 2011 20:10:00 -0500</pubDate>
+</item>
+<item>
 <title>load-dir version 0.0.2</title>
 <link>http://elpa.gnu.org/packages/news.html</link>
 <description>Modularize your .emacs: autoload Lisp snippets</description>
diff --git a/packages/epoch-view-0.0.1.el b/packages/epoch-view-0.0.1.el
new file mode 100644 (file)
index 0000000..46ed67c
--- /dev/null
@@ -0,0 +1,99 @@
+;;; epoch-view.el --- minor mode to visualize epoch timestamps
+
+;; Copyright (C) 2010
+;;   Free Software Foundation, Inc.
+
+;; Author: Ted Zlatanov <tzz@lifelogs.com>
+;; Keywords: data, timestamp, epoch, unix
+;; Version: 0.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 <http://www.gnu.org/licenses/>.
+
+;;; 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.
+
+;; TODO: instead of letting font-lock-mode manage the `display'
+;; property, manage it ourselves so when multiple modes specify
+;; `display' it won't get wiped out when this mode doesn't need it
+;; anymore.
+
+;;; Code:
+
+\f
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;; 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 " EpochVw"
+  (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