[PATCH] emacs: add support for stashing formatted timestamp

Subject: [PATCH] emacs: add support for stashing formatted timestamp

Date: Tue, 10 Jan 2017 20:15:25 +0200

To: notmuch@notmuchmail.org

Cc:

From: Jani Nikula


notmuch-show-stash-date stashes the Date: header of the message
verbatim. While that is useful, sometimes more control of the output
is desirable.

Add support for stashing the message timestamp (as parsed by gmime at
the lib level from the Date: header) according to a user customizable
format. The user can use this to stash the message date in the
preferred format, or perhaps as a date: range query, for example
"date:@%s.." to find all messages since the current message.
---
 emacs/notmuch-show.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 364004b82040..694b6de54104 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -182,6 +182,14 @@ each attachment handler is logged in buffers with names beginning
 \" *notmuch-part*\". This option requires emacs version at least
 24.3 to work.")
 
+(defcustom notmuch-show-stash-timestamp-format "%s"
+  "Format string for `notmuch-show-stash-timestamp'.
+
+This is the FORMAT-STRING passed to `format-time-string' for
+stashing the current message's timestamp."
+  :type 'string
+  :group 'notmuch-show)
+
 (defcustom notmuch-show-stash-mlarchive-link-alist
   '(("Gmane" . "http://mid.gmane.org/")
     ("MARC" . "https://marc.info/?i=")
@@ -1403,6 +1411,7 @@ reset based on the original query."
   (let ((map (make-sparse-keymap)))
     (define-key map "c" 'notmuch-show-stash-cc)
     (define-key map "d" 'notmuch-show-stash-date)
+    (define-key map "D" 'notmuch-show-stash-timestamp)
     (define-key map "F" 'notmuch-show-stash-filename)
     (define-key map "f" 'notmuch-show-stash-from)
     (define-key map "i" 'notmuch-show-stash-message-id)
@@ -1666,6 +1675,9 @@ current thread."
 (defun notmuch-show-get-date ()
   (notmuch-show-get-header :Date))
 
+(defun notmuch-show-get-timestamp ()
+  (notmuch-show-get-prop :timestamp))
+
 (defun notmuch-show-get-from ()
   (notmuch-show-get-header :From))
 
@@ -2236,6 +2248,13 @@ thread from search."
   (interactive)
   (notmuch-common-do-stash (notmuch-show-get-date)))
 
+(defun notmuch-show-stash-timestamp ()
+  "Copy timestamp of current message to kill-ring, formatted according to `notmuch-show-stash-timestamp-format'."
+  (interactive)
+  (notmuch-common-do-stash
+   (format-time-string notmuch-show-stash-timestamp-format
+		       (seconds-to-time (notmuch-show-get-timestamp)))))
+
 (defun notmuch-show-stash-filename ()
   "Copy filename of current message to kill-ring."
   (interactive)
-- 
2.11.0


Thread: