Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / d9 / 90a7ae8216f1d116592c2b1d9db8964925696d
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 9DD616DE009A\r
6  for <notmuch@notmuchmail.org>; Fri, 29 Jan 2016 09:27:10 -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.356\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.356 tagged_above=-999 required=5 tests=[AWL=0.423, \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 F4u0oaFlaE61 for <notmuch@notmuchmail.org>;\r
18  Fri, 29 Jan 2016 09:27:09 -0800 (PST)\r
19 Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com\r
20  [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id A14826DE0AF8 for\r
21  <notmuch@notmuchmail.org>; Fri, 29 Jan 2016 09:27:08 -0800 (PST)\r
22 Received: by mail-wm0-f65.google.com with SMTP id 128so8903908wmz.3\r
23  for <notmuch@notmuchmail.org>; Fri, 29 Jan 2016 09:27:08 -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=0X/jsVseyH/oTnptr3Ki0Za91lOU+HnuENP3Pi1dtjs=;\r
28  b=z8FEbvrBxXvJOA73bwx19H5PGvVmPcvkvJTkTthLKQYPUTIY+FanS9m25m0HvCLQdx\r
29  9gGKgSoXLy1wP9nFUl8vWJXB61A2pC3aB5wNve+19CwoGO39SYKClnqiJJDPGF+PpouE\r
30  KAluBt1x6HshPJ8ya5NRl+BXFuDKySAHoQZSFzFDq6MzxGCsfUCjRvvctmods6z7+byt\r
31  VSxnqIbcwqFfWpXC9h/8tV8k750HwEk5fFvn9UK61qcOqI+DljM/OSmx1hAnG1K/beUx\r
32  oymh3R4mSUDzrfRjMIcRNB1awldXkkb/chCXWQeidy0LZkVhhWQpPHb7gAXXqq9zCUVU\r
33  Bxmg==\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=0X/jsVseyH/oTnptr3Ki0Za91lOU+HnuENP3Pi1dtjs=;\r
39  b=OxJZ0gKOqYVrbCmLS1ZYjCs01Xo278FGE3TGJ7OMT5YMOKEhMeX1m75nF38FqZRrnh\r
40  AWvu0PIJB1Qw7aDp/RDNTqaGNQ4cNBQDyAyD4cBzRzEBmXGgspsiurkxNrzn3DgUYqk3\r
41  7Uk8dJCX2w9F+euWQ4BqpCwhVnvzvvwb1SenKD0QKB0g8PJPwNtskLSJdZiWEc5PvxeT\r
42  p/puKUMA6z4ZOsysVEe0AneFfDytxd2oZWz8RhayfTG6cHPL8euhPlTTIosRPTf4T93l\r
43  UPiUGdUxPS/HBfkCwS+ORdT0klpYzULF73KraC5mMVNRHIf4sbjHgzgQgaD/7cQ2Z4X/\r
44  0S2g==\r
45 X-Gm-Message-State:\r
46  AG10YOS/WYd08EXI645gtOlGGIRCNsGTA1Iz3ncH9Fz5fTeyxBJWXmOlGitwNDAFIaNRUg==\r
47 X-Received: by 10.28.131.70 with SMTP id f67mr10682226wmd.66.1454088427238;\r
48  Fri, 29 Jan 2016 09:27:07 -0800 (PST)\r
49 Received: from disaster-area.hh.sledj.net\r
50  ([2a01:348:1a2:1:ea39:35ff:fe2c:a227])\r
51  by smtp.gmail.com with ESMTPSA id e9sm16533897wja.25.2016.01.29.09.27.05\r
52  for <notmuch@notmuchmail.org>\r
53  (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
54  Fri, 29 Jan 2016 09:27:05 -0800 (PST)\r
55 Received: from localhost (disaster-area.hh.sledj.net [local])\r
56  by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 66f89116\r
57  for <notmuch@notmuchmail.org>; Fri, 29 Jan 2016 17:27:02 +0000 (UTC)\r
58 From: David Edmondson <dme@dme.org>\r
59 To: notmuch@notmuchmail.org\r
60 Subject: [PATCH v2] emacs: Allow part preferences to depend on message\r
61  content.\r
62 Date: Fri, 29 Jan 2016 17:27:01 +0000\r
63 Message-Id: <1454088421-6081-2-git-send-email-dme@dme.org>\r
64 X-Mailer: git-send-email 2.6.3\r
65 In-Reply-To: <1454088421-6081-1-git-send-email-dme@dme.org>\r
66 References: <1454088421-6081-1-git-send-email-dme@dme.org>\r
67 X-BeenThere: notmuch@notmuchmail.org\r
68 X-Mailman-Version: 2.1.20\r
69 Precedence: list\r
70 List-Id: "Use and development of the notmuch mail system."\r
71  <notmuch.notmuchmail.org>\r
72 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
73  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
74 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
75 List-Post: <mailto:notmuch@notmuchmail.org>\r
76 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
77 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
78  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
79 X-List-Received-Date: Fri, 29 Jan 2016 17:27:10 -0000\r
80 \r
81 Currently the preference for which sub-part of a multipart/alternative\r
82 part is shown is global. Allow to the user to override the settings on a\r
83 per-message basis by providing the ability to call a function that has\r
84 access to the message to return the discouraged type list.\r
85 \r
86 The original approach is retained as the default.\r
87 ---\r
88  emacs/notmuch-lib.el  | 20 ++++++++++++++++----\r
89  emacs/notmuch-mua.el  |  2 +-\r
90  emacs/notmuch-show.el |  2 +-\r
91  3 files changed, 18 insertions(+), 6 deletions(-)\r
92 \r
93 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
94 index 89c01a5..6b815c2 100644\r
95 --- a/emacs/notmuch-lib.el\r
96 +++ b/emacs/notmuch-lib.el\r
97 @@ -520,11 +520,23 @@ This replaces spaces, percents, and double quotes in STR with\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 +(defun notmuch-multipart/alternative-determine-discouraged (msg)\r
104 +  "Return the discouraged alternatives for the specified message."\r
105 +  ;; If a function, return the result of calling it.\r
106 +  (if (functionp notmuch-multipart/alternative-discouraged)\r
107 +      (funcall notmuch-multipart/alternative-discouraged msg)\r
108 +    ;; Otherwise simply return the value of the variable, which is\r
109 +    ;; assumed to be a list of discouraged alternatives. This is the\r
110 +    ;; default behaviour.\r
111 +    notmuch-multipart/alternative-discouraged))\r
112 +\r
113 +(defun notmuch-multipart/alternative-choose (msg types)\r
114 +  "Return a list of preferred types from the given list of types\r
115 +for this message, if present."\r
116    ;; Based on `mm-preferred-alternative-precedence'.\r
117 -  (let ((seq types))\r
118 -    (dolist (pref (reverse notmuch-multipart/alternative-discouraged))\r
119 +  (let ((discouraged (notmuch-multipart/alternative-determine-discouraged msg))\r
120 +       (seq types))\r
121 +    (dolist (pref (reverse discouraged))\r
122        (dolist (elem (copy-sequence seq))\r
123         (when (string-match pref elem)\r
124           (setq seq (nconc (delete elem seq) (list elem))))))\r
125 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
126 index 5462f54..8244258 100644\r
127 --- a/emacs/notmuch-mua.el\r
128 +++ b/emacs/notmuch-mua.el\r
129 @@ -147,7 +147,7 @@ Note that these functions use `mail-citation-hook' if that is non-nil."\r
130         if (notmuch-match-content-type (plist-get part :content-type) "multipart/alternative")\r
131           collect (let* ((subparts (plist-get part :content))\r
132                         (types (mapcar (lambda (part) (plist-get part :content-type)) subparts))\r
133 -                       (chosen-type (car (notmuch-multipart/alternative-choose types))))\r
134 +                       (chosen-type (car (notmuch-multipart/alternative-choose nil types))))\r
135                    (loop for part in (reverse subparts)\r
136                          if (notmuch-match-content-type (plist-get part :content-type) chosen-type)\r
137                          return part))\r
138 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
139 index 3345878..2ec30a8 100644\r
140 --- a/emacs/notmuch-show.el\r
141 +++ b/emacs/notmuch-show.el\r
142 @@ -612,7 +612,7 @@ will return nil if the CID is unknown or cannot be retrieved."\r
143           (plist-get part :content)))\r
144  \r
145  (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)\r
146 -  (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
147 +  (let ((chosen-type (car (notmuch-multipart/alternative-choose msg (notmuch-show-multipart/*-to-list part))))\r
148         (inner-parts (plist-get part :content))\r
149         (start (point)))\r
150      ;; This inserts all parts of the chosen type rather than just one,\r
151 -- \r
152 2.6.3\r
153 \r