Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 81 / 9b7eef451685cf4486508e7ae101a79b1179e6
1 Return-Path: <dme@dme.org>\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 6794B431FC1\r
6         for <notmuch@notmuchmail.org>; Thu, 29 Apr 2010 03:33:21 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=ham\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 99iVZeFFCXRt for <notmuch@notmuchmail.org>;\r
16         Thu, 29 Apr 2010 03:33:20 -0700 (PDT)\r
17 Received: from mail-ww0-f53.google.com (mail-ww0-f53.google.com\r
18  [74.125.82.53])        by olra.theworths.org (Postfix) with ESMTP id EC7734196F0       for\r
19  <notmuch@notmuchmail.org>; Thu, 29 Apr 2010 03:33:19 -0700 (PDT)\r
20 Received: by wwe15 with SMTP id 15so603711wwe.26\r
21         for <notmuch@notmuchmail.org>; Thu, 29 Apr 2010 03:33:19 -0700 (PDT)\r
22 Received: by 10.216.93.2 with SMTP id k2mr4509734wef.56.1272537198082;\r
23         Thu, 29 Apr 2010 03:33:18 -0700 (PDT)\r
24 Received: from ut.hh.sledj.net (gmp-ea-fw-1b.sun.com [192.18.8.1])\r
25         by mx.google.com with ESMTPS id t2sm1264584wbc.8.2010.04.29.03.33.16\r
26         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
27         Thu, 29 Apr 2010 03:33:17 -0700 (PDT)\r
28 Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
29         id E3D8D59411F; Thu, 29 Apr 2010 11:33:37 +0100 (BST)\r
30 From: David Edmondson <dme@dme.org>\r
31 To: notmuch@notmuchmail.org\r
32 Subject: [PATCH] emacs: Avoid runtime use of `cl'.\r
33 Date: Thu, 29 Apr 2010 11:33:36 +0100\r
34 Message-Id: <1272537216-2635-1-git-send-email-dme@dme.org>\r
35 X-Mailer: git-send-email 1.7.0\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.13\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Thu, 29 Apr 2010 10:33:21 -0000\r
49 \r
50 The GNU Emacs Lisp Reference Manual section D.1 says:\r
51 \r
52 > *  Please don't require the cl package of Common Lisp extensions at\r
53 >    run time. Use of this package is optional, and it is not part of\r
54 >    the standard Emacs namespace. If your package loads cl at run time,\r
55 >    that could cause name clashes for users who don't use that package.\r
56 >\r
57 >    However, there is no problem with using the cl package at compile\r
58 >    time, with (eval-when-compile (require 'cl)). That's sufficient for\r
59 >    using the macros in the cl package, because the compiler expands\r
60 >    them before generating the byte-code.\r
61 \r
62 Follow this advice, requiring the following changes where `cl' was\r
63 used at runtime:\r
64 \r
65 - replace `rassoc-if' in `notmuch-search-buffer-title' with the `loop'\r
66   macro and inline code. At the same time find the longest prefix\r
67   which matches the query rather than simply the last,\r
68 - replace `union', `intersection' and `set-difference' in\r
69   `notmuch-show-add-tag' and `notmuch-show-remove-tag' with local code\r
70   to calculate the result of adding and removing a list of tags from\r
71   another list of tags.\r
72 ---\r
73 \r
74 This change requires some careful review, particularly for the code\r
75 which manipulates sets of tags.\r
76 \r
77  emacs/notmuch-hello.el |    2 +-\r
78  emacs/notmuch-show.el  |   54 +++++++++++++++++++++++++++++++++++------------\r
79  emacs/notmuch.el       |   16 +++++++++----\r
80  3 files changed, 52 insertions(+), 20 deletions(-)\r
81 \r
82 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
83 index acf40bc..538785f 100644\r
84 --- a/emacs/notmuch-hello.el\r
85 +++ b/emacs/notmuch-hello.el\r
86 @@ -19,9 +19,9 @@\r
87  ;;\r
88  ;; Authors: David Edmondson <dme@dme.org>\r
89  \r
90 +(eval-when-compile (require 'cl))\r
91  (require 'widget)\r
92  (require 'wid-edit) ; For `widget-forward'.\r
93 -(require 'cl)\r
94  \r
95  (require 'notmuch-lib)\r
96  (require 'notmuch-mua)\r
97 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
98 index 4b1baf3..ff1a7a7 100644\r
99 --- a/emacs/notmuch-show.el\r
100 +++ b/emacs/notmuch-show.el\r
101 @@ -21,7 +21,7 @@\r
102  ;; Authors: Carl Worth <cworth@cworth.org>\r
103  ;;          David Edmondson <dme@dme.org>\r
104  \r
105 -(require 'cl)\r
106 +(eval-when-compile (require 'cl))\r
107  (require 'mm-view)\r
108  (require 'message)\r
109  (require 'mm-decode)\r
110 @@ -908,29 +908,55 @@ to stdout or stderr will appear in the *Messages* buffer."\r
111          (list command " < "\r
112                (shell-quote-argument (notmuch-show-get-filename)))))\r
113  \r
114 +(defun notmuch-show-add-tags-worker (current-tags add-tags)\r
115 +  "Add to `current-tags' with any tags from `add-tags' not\r
116 +currently present and return the result."\r
117 +  (let ((result-tags (copy-seq current-tags)))\r
118 +    (mapc (lambda (add-tag)\r
119 +           (unless (member add-tag current-tags)\r
120 +             (setq result-tags (push add-tag result-tags))))\r
121 +           add-tags)\r
122 +    (sort result-tags 'string<)))\r
123 +\r
124 +(defun notmuch-show-del-tags-worker (current-tags del-tags)\r
125 +  "Remove any tags in `del-tags' from `current-tags' and return\r
126 +the result."\r
127 +  (let ((result-tags (copy-seq current-tags)))\r
128 +    (mapc (lambda (del-tag)\r
129 +           (setq result-tags (delete del-tag result-tags)))\r
130 +         del-tags)\r
131 +    result-tags))\r
132 +\r
133  (defun notmuch-show-add-tag (&rest toadd)\r
134    "Add a tag to the current message."\r
135    (interactive\r
136     (list (notmuch-select-tag-with-completion "Tag to add: ")))\r
137 -  (apply 'notmuch-call-notmuch-process\r
138 -        (append (cons "tag"\r
139 -                      (mapcar (lambda (s) (concat "+" s)) toadd))\r
140 -                (cons (notmuch-show-get-message-id) nil)))\r
141 -  (notmuch-show-set-tags (sort (union toadd (notmuch-show-get-tags) :test 'string=) 'string<)))\r
142 +\r
143 +  (let* ((current-tags (notmuch-show-get-tags))\r
144 +        (new-tags (notmuch-show-add-tags-worker current-tags toadd)))\r
145 +\r
146 +    (unless (equal current-tags new-tags)\r
147 +      (apply 'notmuch-call-notmuch-process\r
148 +            (append (cons "tag"\r
149 +                          (mapcar (lambda (s) (concat "+" s)) toadd))\r
150 +                    (cons (notmuch-show-get-message-id) nil)))\r
151 +      (notmuch-show-set-tags new-tags))))\r
152  \r
153  (defun notmuch-show-remove-tag (&rest toremove)\r
154    "Remove a tag from the current message."\r
155    (interactive\r
156     (list (notmuch-select-tag-with-completion\r
157           "Tag to remove: " (notmuch-show-get-message-id))))\r
158 -  (let ((tags (notmuch-show-get-tags)))\r
159 -    (if (intersection tags toremove :test 'string=)\r
160 -       (progn\r
161 -         (apply 'notmuch-call-notmuch-process\r
162 -                (append (cons "tag"\r
163 -                              (mapcar (lambda (s) (concat "-" s)) toremove))\r
164 -                        (cons (notmuch-show-get-message-id) nil)))\r
165 -         (notmuch-show-set-tags (sort (set-difference tags toremove :test 'string=) 'string<))))))\r
166 +\r
167 +  (let* ((current-tags (notmuch-show-get-tags))\r
168 +        (new-tags (notmuch-show-del-tags-worker current-tags toremove)))\r
169 +\r
170 +    (unless (equal current-tags new-tags)\r
171 +      (apply 'notmuch-call-notmuch-process\r
172 +            (append (cons "tag"\r
173 +                          (mapcar (lambda (s) (concat "-" s)) toremove))\r
174 +                    (cons (notmuch-show-get-message-id) nil)))\r
175 +      (notmuch-show-set-tags new-tags))))\r
176  \r
177  (defun notmuch-show-toggle-headers ()\r
178    "Toggle the visibility of the current message headers."\r
179 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
180 index 7c9c028..c2fefe5 100644\r
181 --- a/emacs/notmuch.el\r
182 +++ b/emacs/notmuch.el\r
183 @@ -47,7 +47,7 @@\r
184  ; kudos: Notmuch list <notmuch@notmuchmail.org> (subscription is not\r
185  ; required, but is available from http://notmuchmail.org).\r
186  \r
187 -(require 'cl)\r
188 +(eval-when-compile (require 'cl))\r
189  (require 'mm-view)\r
190  (require 'message)\r
191  \r
192 @@ -712,10 +712,16 @@ characters as well as `_.+-'.\r
193  \r
194  (defun notmuch-search-buffer-title (query)\r
195    "Returns the title for a buffer with notmuch search results."\r
196 -  (let* ((saved-search (rassoc-if (lambda (key)\r
197 -                                   (string-match (concat "^" (regexp-quote key))\r
198 -                                                 query))\r
199 -                                 (reverse (notmuch-saved-searches))))\r
200 +  (let* ((saved-search\r
201 +         (let (longest\r
202 +               (longest-length 0))\r
203 +           (loop for tuple in notmuch-saved-searches\r
204 +                 if (let ((quoted-query (regexp-quote (cdr tuple))))\r
205 +                      (and (string-match (concat "^" quoted-query) query)\r
206 +                           (> (length (match-string 0 query))\r
207 +                              longest-length)))\r
208 +                 do (setq longest tuple))\r
209 +           longest))\r
210          (saved-search-name (car saved-search))\r
211          (saved-search-query (cdr saved-search)))\r
212      (cond ((and saved-search (equal saved-search-query query))\r
213 -- \r
214 1.7.0\r
215 \r