[PATCH] emacs: implement notmuch-search-color-line with dolist.
[notmuch-archives.git] / b8 / 2fd8cae072f584bcb43449cdba52839a512cb7
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 9F4F9431FC2\r
6         for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 11:03:25 -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.699\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001]\r
13         autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id P8MI7zUCVgVs for <notmuch@notmuchmail.org>;\r
17         Thu, 30 Oct 2014 11:03:20 -0700 (PDT)\r
18 Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com\r
19         [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id AEE4E431FCB\r
22         for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 11:03:20 -0700 (PDT)\r
23 Received: by mail-wi0-f169.google.com with SMTP id n3so1855209wiv.4\r
24         for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 11:03:18 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=1e100.net; s=20130820;\r
27         h=x-gm-message-state:user-agent:from:to:subject:date:message-id;\r
28         bh=i3+w0Q4I4jLdsg9c5Zz7H7VaP//JDuMmenU7xX9fFzA=;\r
29         b=Lk1+oAudFEpwyKwuRfC8sAvxkKI8gyX2DRHXSK8zDZ9Ceey3KxSURAe6RYhZRHsASV\r
30         RF46u1uyV3bqnvZREu99qGcaVH58G8wYqbEcJ0C5SJtxmuNqAq/FQ3/3AFi1tVpSQwJw\r
31         +JGjT2r5+k28Zh/H2H2IJ1Y/O8padxDvc+yPokgYkHMunmwmjZ9qurSWs3fTh4OlcOL5\r
32         rSVrn6/+Mq2mzE8wgVDFTYH0zk7gXeRPuck6k17NTq6dcc4xOdIDu+Ek6oa+gCI6ooqh\r
33         RqGAY8VTA6/u5Cuw+BO8K7QYobI18XPT26M5G5Zxgfk2Nx+AwN30CGApQ/rlvC9qHiju\r
34         Yonw==\r
35 X-Gm-Message-State:\r
36  ALoCoQma+A9kFWeDtjhFO+L4QRF0ECDTEl9kT4A24ExkgvfROJEPXfxEJreYmyGYx5f3rG7AJgnZ\r
37 X-Received: by 10.181.8.98 with SMTP id dj2mr21658488wid.70.1414692198209;\r
38         Thu, 30 Oct 2014 11:03:18 -0700 (PDT)\r
39 Received: from disaster-area.hh.sledj.net\r
40         ([2a01:348:1a2:1:ea39:35ff:fe2c:a227])\r
41         by mx.google.com with ESMTPSA id s10sm3991183wix.14.2014.10.30.11.03.17\r
42         for <notmuch@notmuchmail.org>\r
43         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
44         Thu, 30 Oct 2014 11:03:17 -0700 (PDT)\r
45 Received: from localhost (30000@localhost [local]);\r
46         by localhost (OpenSMTPD) with ESMTPA id fa989dfb;\r
47         for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 18:03:16 +0000 (UTC)\r
48 User-Agent: OpenSMTPD enqueuer (Demoostik)\r
49 From: David Edmondson <dme@dme.org>\r
50 To: notmuch@notmuchmail.org\r
51 Subject: [PATCH v1] emacs: Improved header display.\r
52 Date: Thu, 30 Oct 2014 18:03:16 +0000\r
53 Message-Id: <1414692196-12550-1-git-send-email-dme@dme.org>\r
54 X-Mailer: git-send-email 2.1.1\r
55 X-BeenThere: notmuch@notmuchmail.org\r
56 X-Mailman-Version: 2.1.13\r
57 Precedence: list\r
58 List-Id: "Use and development of the notmuch mail system."\r
59         <notmuch.notmuchmail.org>\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
63 List-Post: <mailto:notmuch@notmuchmail.org>\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
67 X-List-Received-Date: Thu, 30 Oct 2014 18:03:25 -0000\r
68 \r
69 Truncate the displayed headers to the window width. Show an ellipsis\r
70 if the displayed header is truncated. Add a binding 'T' to toggle the\r
71 truncation of headers. Add the not-displayed section of the header as\r
72 a tooltip to the displayed section.\r
73 ---\r
74  emacs/notmuch-show.el | 54 ++++++++++++++++++++++++++++++++++++++++++++++++---\r
75  1 file changed, 51 insertions(+), 3 deletions(-)\r
76 \r
77 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
78 index a997482..523cef5 100644\r
79 --- a/emacs/notmuch-show.el\r
80 +++ b/emacs/notmuch-show.el\r
81 @@ -443,9 +443,56 @@ message at DEPTH in the current thread."\r
82             ")\n")\r
83      (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face)))\r
84  \r
85 +(defun notmuch-truncate-nicely (addresses target-length)\r
86 +  ;; If it fits, everything is easy.\r
87 +  (if (< (length addresses) target-length)\r
88 +      (cons addresses nil)\r
89 +    (let* ((visible-length (- target-length (length "...")))\r
90 +          (visible (substring addresses 0 visible-length))\r
91 +          (invisible (substring addresses visible-length)))\r
92 +      ;; Try to terminate the visible string at a good break point.\r
93 +      (when (string-match "\\(.+\\),\\([^,]*\\)" visible)\r
94 +       ;; Order is important (second clause is destructive on\r
95 +       ;; `visible'.\r
96 +       (setq invisible (concat (match-string 2 visible) invisible)\r
97 +             visible (match-string 1 visible)))\r
98 +      ;; `invisible' can end up with a leading space or\r
99 +      ;; comma-space, because the list of addresses is\r
100 +      ;; seperated with ", ", but we split on ",".\r
101 +      (setq invisible (replace-regexp-in-string "^[, ]*\\(.*\\)$" "\\1" invisible))\r
102 +      (cons visible invisible))))\r
103 +\r
104 +(defun notmuch-show-toggle-header-truncation ()\r
105 +  (interactive)\r
106 +  (let ((invisibility-spec-member (cons 'notmuch-show-mode t)))\r
107 +    (if (member invisibility-spec-member buffer-invisibility-spec)\r
108 +       (remove-from-invisibility-spec invisibility-spec-member)\r
109 +      (add-to-invisibility-spec invisibility-spec-member)))\r
110 +  ;; Required to have the change in visibility take effect.\r
111 +  (force-window-update))\r
112 +\r
113  (defun notmuch-show-insert-header (header header-value)\r
114    "Insert a single header."\r
115 -  (insert header ": " (notmuch-sanitize header-value) "\n"))\r
116 +  (let* ((header-value (notmuch-sanitize header-value))\r
117 +        (header-colon (concat header ": "))\r
118 +        (available-width (- (window-width) (length header-colon)))\r
119 +        (v-i (notmuch-truncate-nicely header-value available-width)))\r
120 +\r
121 +    (insert header-colon)\r
122 +    (let ((visible (car v-i))\r
123 +         (invisible (cdr v-i)))\r
124 +      (when invisible\r
125 +       (setq visible (propertize visible 'help-echo (concat "..." invisible))))\r
126 +      (insert visible)\r
127 +      (when invisible\r
128 +       (insert ", ")\r
129 +       (let ((start (point))\r
130 +             overlay)\r
131 +         (insert invisible)\r
132 +         (setq overlay (make-overlay start (point)))\r
133 +         (overlay-put overlay 'invisible 'notmuch-show-mode)\r
134 +         (overlay-put overlay 'isearch-open-invisible #'delete-overlay))))\r
135 +    (insert "\n")))\r
136  \r
137  (defun notmuch-show-insert-headers (headers)\r
138    "Insert the headers of the current message."\r
139 @@ -1328,6 +1375,7 @@ reset based on the original query."\r
140      (define-key map "$" 'notmuch-show-toggle-process-crypto)\r
141      (define-key map "<" 'notmuch-show-toggle-thread-indentation)\r
142      (define-key map "t" 'toggle-truncate-lines)\r
143 +    (define-key map "T" 'notmuch-show-toggle-header-truncation)\r
144      (define-key map "." 'notmuch-show-part-map)\r
145      map)\r
146    "Keymap for \"notmuch show\" buffers.")\r
147 @@ -1367,8 +1415,8 @@ All currently available key bindings:\r
148    (use-local-map notmuch-show-mode-map)\r
149    (setq major-mode 'notmuch-show-mode\r
150         mode-name "notmuch-show")\r
151 -  (setq buffer-read-only t\r
152 -       truncate-lines t))\r
153 +  (add-to-invisibility-spec (cons 'notmuch-show-mode t))\r
154 +  (setq buffer-read-only t))\r
155  \r
156  (defun notmuch-tree-from-show-current-query ()\r
157    "Call notmuch tree with the current query"\r
158 -- \r
159 2.1.1\r
160 \r