Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 4e / 2f264682420e5df4392184301fa3d9ec7f3e13
1 Return-Path: <jrollins@finestructure.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 4259B41A558\r
6         for <notmuch@notmuchmail.org>; Sun, 19 Dec 2010 19:54:47 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id OJZ-zuwRPG28 for <notmuch@notmuchmail.org>;\r
16         Sun, 19 Dec 2010 19:54:46 -0800 (PST)\r
17 Received: from serrano.cc.columbia.edu (serrano.cc.columbia.edu [128.59.29.6])\r
18         by olra.theworths.org (Postfix) with ESMTP id 76971431FB5\r
19         for <notmuch@notmuchmail.org>; Sun, 19 Dec 2010 19:54:46 -0800 (PST)\r
20 Received: from servo.finestructure.net (cpe-74-66-82-137.nyc.res.rr.com\r
21         [74.66.82.137])\r
22         (user=jgr2110 author=jrollins@finestructure.net mech=PLAIN bits=0)\r
23         by serrano.cc.columbia.edu (8.14.4/8.14.3) with ESMTP id oBK3siom009683\r
24         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT)\r
25         for <notmuch@notmuchmail.org>; Sun, 19 Dec 2010 22:54:45 -0500 (EST)\r
26 Received: from jrollins by servo.finestructure.net with local (Exim 4.72)\r
27         (envelope-from <jrollins@finestructure.net>)\r
28         id 1PUWpg-00066I-9C; Sun, 19 Dec 2010 22:54:44 -0500\r
29 From: Jameson Rollins <jrollins@finestructure.net>\r
30 To: Notmuch Mail <notmuch@notmuchmail.org>\r
31 Subject: [PATCH 1/2] emacs function to perform a search with a look back time\r
32         restriction\r
33 Date: Sun, 19 Dec 2010 22:54:39 -0500\r
34 Message-Id: <1292817280-20999-2-git-send-email-jrollins@finestructure.net>\r
35 X-Mailer: git-send-email 1.7.2.3\r
36 In-Reply-To: <1292817280-20999-1-git-send-email-jrollins@finestructure.net>\r
37 References: <1292817280-20999-1-git-send-email-jrollins@finestructure.net>\r
38 X-No-Spam-Score: Local\r
39 X-Scanned-By: MIMEDefang 2.68 on 128.59.29.6\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Mon, 20 Dec 2010 03:54:47 -0000\r
53 \r
54 This function allows for restricting the date range of a search, back\r
55 from the current time.  The look-back time range is given at a second\r
56 prompt.  An example time range is '4d' to indicate four days or '12y'\r
57 to indicate twelve years.\r
58 \r
59 On slow machines this can speed up the search considerably.  I believe\r
60 this handles the most common usage where one wishes to perform a\r
61 search for a message that is known to have been received recently.\r
62 \r
63 One might imagine extending this function to be able to handle date\r
64 ranges, such as "11/2004-2/2005", or it becoming obsolete if more\r
65 flexible date specs are folded into notmuch search directly.\r
66 ---\r
67  emacs/notmuch.el |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
68  1 files changed, 62 insertions(+), 0 deletions(-)\r
69 \r
70 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
71 index 3d82f0d..763d517 100644\r
72 --- a/emacs/notmuch.el\r
73 +++ b/emacs/notmuch.el\r
74 @@ -948,6 +948,68 @@ current search results AND that are tagged with the given tag."\r
75     (list (notmuch-select-tag-with-completion "Filter by tag: ")))\r
76    (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))\r
77  \r
78 +(defun notmuch-search-convert-time-spec (spec)\r
79 +  "Internal function to convert an abbreviated time spec into seconds."\r
80 +  (if (string= spec "")\r
81 +      0\r
82 +    (let ((factor (replace-regexp-in-string "[Mhdwmy]$" "" spec))\r
83 +         (unit (replace-regexp-in-string "^[0123456789]*" "" spec))\r
84 +         seconds)\r
85 +      (if (string= factor "")\r
86 +         (setq factor 1)\r
87 +       (setq factor (string-to-number factor)))\r
88 +      (if (string= unit "")\r
89 +         (setq seconds 1)\r
90 +       (cond ((string= unit "M")\r
91 +              (setq seconds 60))\r
92 +             ((string= unit "h")\r
93 +              (setq seconds 3600))\r
94 +             ((string= unit "d")\r
95 +              (setq seconds 86400))\r
96 +             ((string= unit "w")\r
97 +              (setq seconds 604800))\r
98 +             ((string= unit "m")\r
99 +              (setq seconds 2678400))\r
100 +             ((string= unit "y")\r
101 +              (setq seconds 31536000))\r
102 +             (t\r
103 +              (setq seconds nil))))\r
104 +      (if (null seconds)\r
105 +         nil\r
106 +       (* factor seconds)))))\r
107 +\r
108 +(defun notmuch-search-date-restrict (query time-spec)\r
109 +  "Run \"notmuch search\" but with a look-back time restriction.\r
110 +\r
111 +This first argument is the query string.\r
112 +The second argument is a look-back time spec of the form 'XY',\r
113 +where X is an integer and Y is one of:\r
114 +  'M'  minute\r
115 +  'h'  hour\r
116 +  'd'  day\r
117 +  'w'  week\r
118 +  'm'  month\r
119 +  'y'  year\r
120 +For instance, a time spec of '3w' would return only search\r
121 +results from within the last three weeks.\r
122 +A time spec of nil returns the full search results.\r
123 +\r
124 +For more information see the \"notmuch-search\"."\r
125 +  (interactive "sNotmuch search: \nslook back?: ")\r
126 +  (let ((look-back (notmuch-search-convert-time-spec time-spec)))\r
127 +    (cond ((null look-back)\r
128 +          (message "unknown time spec"))\r
129 +         ((= look-back 0)\r
130 +          (notmuch-search query))\r
131 +         (t\r
132 +          (let* ((now (current-time))\r
133 +                 (start (time-subtract now (seconds-to-time look-back))))\r
134 +            (notmuch-search (concat\r
135 +                             query " "\r
136 +                             (format-time-string "%s" start)\r
137 +                             ".."\r
138 +                             (format-time-string "%s" now))))))))\r
139 +\r
140  ;;;###autoload\r
141  (defun notmuch ()\r
142    "Run notmuch and display saved searches, known tags, etc."\r
143 -- \r
144 1.7.2.3\r
145 \r