Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 73 / a40ee50d679e14de9a9e8e7ac50554b42016d0
1 Return-Path: <awg@lagos.xvx.ca>\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 B4001431FD6\r
6         for <notmuch@notmuchmail.org>; Tue, 13 Mar 2012 21:30:26 -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: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 nz0ppL9DV+bM for <notmuch@notmuchmail.org>;\r
16         Tue, 13 Mar 2012 21:30:24 -0700 (PDT)\r
17 Received: from idcmail-mo2no.shaw.ca (idcmail-mo2no.shaw.ca [64.59.134.9])\r
18         by olra.theworths.org (Postfix) with ESMTP id A0BE5431FD7\r
19         for <notmuch@notmuchmail.org>; Tue, 13 Mar 2012 21:30:22 -0700 (PDT)\r
20 Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd6ml3no-ssvc.prod.shaw.ca)\r
21         ([10.0.144.222])\r
22         by pd7mo1no-svcs.prod.shaw.ca with ESMTP; 13 Mar 2012 22:30:21 -0600\r
23 X-Cloudmark-SP-Filtered: true\r
24 X-Cloudmark-SP-Result: v=1.1 cv=gFGh1ScE7ROJHT2jhivHYaSHya8441O0LZB7wkhlVyo=\r
25         c=1 sm=1\r
26         a=aj0SqZEsnloA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
27         a=IRZdaMhHRr9h3ODv8asA:9 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
28 Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
29         by pd6ml3no-dmz.prod.shaw.ca with ESMTP; 13 Mar 2012 22:30:21 -0600\r
30 Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
31         id 0273380002C3; Tue, 13 Mar 2012 22:30:20 -0600 (MDT)\r
32 From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
33 To: notmuch@notmuchmail.org\r
34 Subject: [PATCH v7.1 08/11] emacs: Factor out useful functions into\r
35  notmuch-lib\r
36 Date: Tue, 13 Mar 2012 22:30:13 -0600\r
37 Message-Id: <1331699416-30775-9-git-send-email-awg+notmuch@xvx.ca>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To: <1331699416-30775-1-git-send-email-awg+notmuch@xvx.ca>\r
40 References: <1331525142-30539-1-git-send-email-awg+notmuch@xvx.ca>\r
41         <1331699416-30775-1-git-send-email-awg+notmuch@xvx.ca>\r
42 X-BeenThere: notmuch@notmuchmail.org\r
43 X-Mailman-Version: 2.1.13\r
44 Precedence: list\r
45 List-Id: "Use and development of the notmuch mail system."\r
46         <notmuch.notmuchmail.org>\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
50 List-Post: <mailto:notmuch@notmuchmail.org>\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
54 X-List-Received-Date: Wed, 14 Mar 2012 04:30:27 -0000\r
55 \r
56 Move a few functions related to handling multipart/alternative parts\r
57 into notmuch-lib.el, so they can be used by future reply code.\r
58 ---\r
59  emacs/notmuch-lib.el  |   33 +++++++++++++++++++++++++++++++++\r
60  emacs/notmuch-show.el |   24 ++----------------------\r
61  2 files changed, 35 insertions(+), 22 deletions(-)\r
62 \r
63 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
64 index d315f76..7e3f110 100644\r
65 --- a/emacs/notmuch-lib.el\r
66 +++ b/emacs/notmuch-lib.el\r
67 @@ -21,6 +21,8 @@\r
68  \r
69  ;; This is an part of an emacs-based interface to the notmuch mail system.\r
70  \r
71 +(eval-when-compile (require 'cl))\r
72 +\r
73  (defvar notmuch-command "notmuch"\r
74    "Command to run the notmuch binary.")\r
75  \r
76 @@ -173,6 +175,37 @@ the user hasn't set this variable with the old or new value."\r
77    (list 'when (< emacs-major-version 23)\r
78         form))\r
79  \r
80 +(defun notmuch-split-content-type (content-type)\r
81 +  "Split content/type into 'content' and 'type'"\r
82 +  (split-string content-type "/"))\r
83 +\r
84 +(defun notmuch-match-content-type (t1 t2)\r
85 +  "Return t if t1 and t2 are matching content types, taking wildcards into account"\r
86 +  (let ((st1 (notmuch-split-content-type t1))\r
87 +       (st2 (notmuch-split-content-type t2)))\r
88 +    (if (or (string= (cadr st1) "*")\r
89 +           (string= (cadr st2) "*"))\r
90 +       (string= (car st1) (car st2))\r
91 +      (string= t1 t2))))\r
92 +\r
93 +(defvar notmuch-multipart/alternative-discouraged\r
94 +  '(\r
95 +    ;; Avoid HTML parts.\r
96 +    "text/html"\r
97 +    ;; multipart/related usually contain a text/html part and some associated graphics.\r
98 +    "multipart/related"\r
99 +    ))\r
100 +\r
101 +(defun notmuch-multipart/alternative-choose (types)\r
102 +  "Return a list of preferred types from the given list of types"\r
103 +  ;; Based on `mm-preferred-alternative-precedence'.\r
104 +  (let ((seq types))\r
105 +    (dolist (pref (reverse notmuch-multipart/alternative-discouraged))\r
106 +      (dolist (elem (copy-sequence seq))\r
107 +       (when (string-match pref elem)\r
108 +         (setq seq (nconc (delete elem seq) (list elem))))))\r
109 +    seq))\r
110 +\r
111  ;; Compatibility functions for versions of emacs before emacs 23.\r
112  ;;\r
113  ;; Both functions here were copied from emacs 23 with the following copyright:\r
114 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
115 index 4a60631..ed938bf 100644\r
116 --- a/emacs/notmuch-show.el\r
117 +++ b/emacs/notmuch-show.el\r
118 @@ -542,30 +542,13 @@ current buffer, if possible."\r
119             (mm-display-part handle)\r
120             t))))))\r
121  \r
122 -(defvar notmuch-show-multipart/alternative-discouraged\r
123 -  '(\r
124 -    ;; Avoid HTML parts.\r
125 -    "text/html"\r
126 -    ;; multipart/related usually contain a text/html part and some associated graphics.\r
127 -    "multipart/related"\r
128 -    ))\r
129 -\r
130  (defun notmuch-show-multipart/*-to-list (part)\r
131    (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
132           (plist-get part :content)))\r
133  \r
134 -(defun notmuch-show-multipart/alternative-choose (types)\r
135 -  ;; Based on `mm-preferred-alternative-precedence'.\r
136 -  (let ((seq types))\r
137 -    (dolist (pref (reverse notmuch-show-multipart/alternative-discouraged))\r
138 -      (dolist (elem (copy-sequence seq))\r
139 -       (when (string-match pref elem)\r
140 -         (setq seq (nconc (delete elem seq) (list elem))))))\r
141 -    seq))\r
142 -\r
143  (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)\r
144    (notmuch-show-insert-part-header nth declared-type content-type nil)\r
145 -  (let ((chosen-type (car (notmuch-show-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
146 +  (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
147         (inner-parts (plist-get part :content))\r
148         (start (point)))\r
149      ;; This inserts all parts of the chosen type rather than just one,\r
150 @@ -808,9 +791,6 @@ current buffer, if possible."\r
151  \r
152  ;; Functions for determining how to handle MIME parts.\r
153  \r
154 -(defun notmuch-show-split-content-type (content-type)\r
155 -  (split-string content-type "/"))\r
156 -\r
157  (defun notmuch-show-handlers-for (content-type)\r
158    "Return a list of content handlers for a part of type CONTENT-TYPE."\r
159    (let (result)\r
160 @@ -821,7 +801,7 @@ current buffer, if possible."\r
161           (list (intern (concat "notmuch-show-insert-part-*/*"))\r
162                 (intern (concat\r
163                          "notmuch-show-insert-part-"\r
164 -                        (car (notmuch-show-split-content-type content-type))\r
165 +                        (car (notmuch-split-content-type content-type))\r
166                          "/*"))\r
167                 (intern (concat "notmuch-show-insert-part-" content-type))))\r
168      result))\r
169 -- \r
170 1.7.5.4\r
171 \r