Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 5a / a1a790474dcb1857483ef183f45a1c57e7fb3c
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 arlo.cworth.org (Postfix) with ESMTP id 1CA616DE00DD\r
6  for <notmuch@notmuchmail.org>; Fri, 15 Jan 2016 05:35:06 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.471\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.471 tagged_above=-999 required=5 tests=[AWL=0.538, \r
12  DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7,\r
13  RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_NEUTRAL=0.652,\r
14  UNPARSEABLE_RELAY=0.001] autolearn=disabled\r
15 Received: from arlo.cworth.org ([127.0.0.1])\r
16  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
17  with ESMTP id 02VRpVpTmo2n for <notmuch@notmuchmail.org>;\r
18  Fri, 15 Jan 2016 05:35:04 -0800 (PST)\r
19 Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com\r
20  [74.125.82.66]) by arlo.cworth.org (Postfix) with ESMTPS id 0BDFA6DE1607 for\r
21  <notmuch@notmuchmail.org>; Fri, 15 Jan 2016 05:35:04 -0800 (PST)\r
22 Received: by mail-wm0-f66.google.com with SMTP id u188so2889276wmu.0\r
23  for <notmuch@notmuchmail.org>; Fri, 15 Jan 2016 05:35:03 -0800 (PST)\r
24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25  d=dme-org.20150623.gappssmtp.com; s=20150623;\r
26  h=from:to:subject:date:message-id:in-reply-to:references;\r
27  bh=rg9a1wZyTmC3l9iFL/5Mls/NcpgAG88Xg0d0XF9v3eY=;\r
28  b=JP3TCF9y5tsMw/yFhOWkiynbUA2xaQwtNSoGw8T8u1HB1NnuCBwpKLaceVTfpjpDl3\r
29  kxrnmH1F+dbbGkV4HaKCZeeynJOjKdgeyBZgMEQTuIbU4teU/thUNseJr3FgxpNtq5kc\r
30  mydkz0jljEwzFVG8aS/lkNpvAr0kH8RNVH4hGxUwl4MJRhsqGZ/8/EC6yBR0KzJVtLbz\r
31  8J0CarGB81w4aKY+KE/v9D0iA1LrtH9JGsckRX+l3lq6ie60SVTcWbw2JbqECDwnLZCp\r
32  6mYf6KhaZIahQ3KNg6MdwmmY90wlCd7LDRetLTuQbMvJNpcK3kVIg2pcbqnZhF6vx0/h\r
33  /weA==\r
34 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
35  d=1e100.net; s=20130820;\r
36  h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to\r
37  :references;\r
38  bh=rg9a1wZyTmC3l9iFL/5Mls/NcpgAG88Xg0d0XF9v3eY=;\r
39  b=YWgHxAfN6AF6W1pEpSWNTPFoyg6KOUybtBP9mXym4DVFKjCt4NrlvbfkER1cffR3b4\r
40  US4D7Vibp+vHlEH0JBJXxDJgNlNsIPv6EyhAfLl4XL11Bi3eXf41KOtK/Yfc/T9cQdex\r
41  FVoJokc2V+4fCjBH79+h6OkaMhYGMnYJ7cf9JHq5l7d5qvJmr/Vd/cd0eV8TftXgD39u\r
42  N4Ucpuam9Hes4IeM9S8DX7zjc/89CiEzUm/NRDxgZ+T5z5JWpBXPUl7QjMRjP3v0C7ah\r
43  /sfvu6RNy8VFELCDSMSW0F9DE1kd9ugEds1v1HZ+jct4WVuqKB5Za2PWr9HxyZhp9lbN\r
44  8FKA==\r
45 X-Gm-Message-State: ALoCoQmENMQUULb36dXpULT5t47eMSfoF5D7zpJ4NGr66raIdVC0JBGkX2u6+8JuDitPWQ/1xQ+brVtg69VwNwm9CLEEGYiUAQ==\r
46 X-Received: by 10.194.114.106 with SMTP id\r
47  jf10mr12021610wjb.149.1452864902738;  Fri, 15 Jan 2016 05:35:02 -0800 (PST)\r
48 Received: from disaster-area.hh.sledj.net\r
49  ([2a01:348:1a2:1:ea39:35ff:fe2c:a227])\r
50  by smtp.gmail.com with ESMTPSA id id1sm10648439wjb.19.2016.01.15.05.35.01\r
51  for <notmuch@notmuchmail.org>\r
52  (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
53  Fri, 15 Jan 2016 05:35:01 -0800 (PST)\r
54 Received: from localhost (disaster-area.hh.sledj.net [local])\r
55  by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id f596f93b\r
56  for <notmuch@notmuchmail.org>; Fri, 15 Jan 2016 13:34:58 +0000 (UTC)\r
57 From: David Edmondson <dme@dme.org>\r
58 To: notmuch@notmuchmail.org\r
59 Subject: [PATCH v1] emacs: Allow part preferences to depend on message\r
60  content.\r
61 Date: Fri, 15 Jan 2016 13:34:58 +0000\r
62 Message-Id: <1452864898-9719-2-git-send-email-dme@dme.org>\r
63 X-Mailer: git-send-email 2.6.3\r
64 In-Reply-To: <1452864898-9719-1-git-send-email-dme@dme.org>\r
65 References: <1452864898-9719-1-git-send-email-dme@dme.org>\r
66 X-BeenThere: notmuch@notmuchmail.org\r
67 X-Mailman-Version: 2.1.20\r
68 Precedence: list\r
69 List-Id: "Use and development of the notmuch mail system."\r
70  <notmuch.notmuchmail.org>\r
71 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
72  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
74 List-Post: <mailto:notmuch@notmuchmail.org>\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
76 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
77  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
78 X-List-Received-Date: Fri, 15 Jan 2016 13:35:06 -0000\r
79 \r
80 Currently the preference for which sub-part of a multipart/alternative\r
81 part is shown is global. Allow to the user to override the settings on a\r
82 per-message basis by providing two new options:\r
83 \r
84   - the ability to call a function that has access to the message to\r
85     return the discouraged type list,\r
86   - a simple evaluation environment to reduce the need for most users to\r
87     write their own function.\r
88 \r
89 The original approach is retained as the default.\r
90 ---\r
91  emacs/notmuch-lib.el  | 39 +++++++++++++++++++++++++++++++++++----\r
92  emacs/notmuch-mua.el  |  2 +-\r
93  emacs/notmuch-show.el |  2 +-\r
94  3 files changed, 37 insertions(+), 6 deletions(-)\r
95 \r
96 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
97 index 89c01a5..2b9d108 100644\r
98 --- a/emacs/notmuch-lib.el\r
99 +++ b/emacs/notmuch-lib.el\r
100 @@ -520,11 +520,42 @@ This replaces spaces, percents, and double quotes in STR with\r
101      "multipart/related"\r
102      ))\r
103  \r
104 -(defun notmuch-multipart/alternative-choose (types)\r
105 -  "Return a list of preferred types from the given list of types"\r
106 +(defun notmuch-multipart/alternative-determine-discouraged-1 (msg directive)\r
107 +  (let* ((headers (plist-get msg :headers))\r
108 +        ;; Headers that we make available:\r
109 +        (from (plist-get headers :From))\r
110 +        (subject (plist-get headers :Subject))\r
111 +        (to (plist-get headers :To))\r
112 +        (cc (plist-get headers :Cc)))\r
113 +\r
114 +    (eval directive)))\r
115 +\r
116 +(defun notmuch-multipart/alternative-determine-discouraged (msg)\r
117 +  "Return the discouraged alternatives for the specified message."\r
118 +  (cond\r
119 +   ;; If a function, return the result of calling it.\r
120 +   ((functionp notmuch-multipart/alternative-discouraged)\r
121 +    (funcall notmuch-multipart/alternative-discouraged msg))\r
122 +\r
123 +   ;; If the first element is a string, return the list. This matches\r
124 +   ;; with the default setting of\r
125 +   ;; `notmuch-multipart/alternative-discouraged'.\r
126 +   ((and (listp notmuch-multipart/alternative-discouraged)\r
127 +        (stringp (car notmuch-multipart/alternative-discouraged)))\r
128 +    notmuch-multipart/alternative-discouraged)\r
129 +\r
130 +   ;; New style pattern matcher.\r
131 +   (t\r
132 +    (notmuch-multipart/alternative-determine-discouraged-1\r
133 +     msg notmuch-multipart/alternative-discouraged))))\r
134 +\r
135 +(defun notmuch-multipart/alternative-choose (msg types)\r
136 +  "Return a list of preferred types from the given list of types\r
137 +for this message, if present."\r
138    ;; Based on `mm-preferred-alternative-precedence'.\r
139 -  (let ((seq types))\r
140 -    (dolist (pref (reverse notmuch-multipart/alternative-discouraged))\r
141 +  (let ((discouraged (notmuch-multipart/alternative-determine-discouraged msg))\r
142 +       (seq types))\r
143 +    (dolist (pref (reverse discouraged))\r
144        (dolist (elem (copy-sequence seq))\r
145         (when (string-match pref elem)\r
146           (setq seq (nconc (delete elem seq) (list elem))))))\r
147 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
148 index 5462f54..8244258 100644\r
149 --- a/emacs/notmuch-mua.el\r
150 +++ b/emacs/notmuch-mua.el\r
151 @@ -147,7 +147,7 @@ Note that these functions use `mail-citation-hook' if that is non-nil."\r
152         if (notmuch-match-content-type (plist-get part :content-type) "multipart/alternative")\r
153           collect (let* ((subparts (plist-get part :content))\r
154                         (types (mapcar (lambda (part) (plist-get part :content-type)) subparts))\r
155 -                       (chosen-type (car (notmuch-multipart/alternative-choose types))))\r
156 +                       (chosen-type (car (notmuch-multipart/alternative-choose nil types))))\r
157                    (loop for part in (reverse subparts)\r
158                          if (notmuch-match-content-type (plist-get part :content-type) chosen-type)\r
159                          return part))\r
160 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
161 index 3345878..2ec30a8 100644\r
162 --- a/emacs/notmuch-show.el\r
163 +++ b/emacs/notmuch-show.el\r
164 @@ -612,7 +612,7 @@ will return nil if the CID is unknown or cannot be retrieved."\r
165           (plist-get part :content)))\r
166  \r
167  (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)\r
168 -  (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
169 +  (let ((chosen-type (car (notmuch-multipart/alternative-choose msg (notmuch-show-multipart/*-to-list part))))\r
170         (inner-parts (plist-get part :content))\r
171         (start (point)))\r
172      ;; This inserts all parts of the chosen type rather than just one,\r
173 -- \r
174 2.6.3\r
175 \r