Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 00 / e500d5e3b84de6fae564db17509cf860ad2175
1 Return-Path: <imain@stemwinder.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 1B6C2431FDE\r
6         for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:49:08 -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 hFtmViP8QxOC for <notmuch@notmuchmail.org>;\r
16         Thu, 23 Oct 2014 21:49:04 -0700 (PDT)\r
17 Received: from cmta4.telus.net (cmta4.telus.net [209.171.16.77])\r
18         by olra.theworths.org (Postfix) with ESMTP id B67E7431FDD\r
19         for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:49:04 -0700 (PDT)\r
20 Received: from ovo.mains.priv ([207.102.88.62]) by cmta4.telus.net with TELUS\r
21         id 6sp31p00K1LiWEf01sp3Yp; Thu, 23 Oct 2014 22:49:04 -0600\r
22 X-Authority-Analysis: v=2.0 cv=CvthhAED c=1 sm=2\r
23         a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=4Nb5gDjYcHRG9ZgcxzkA:9\r
24         a=EcQDfIwDZEqJA1f7rVUV8Q==:117\r
25 X-Telus-Outbound-IP: 207.102.88.62\r
26 From: Ian Main <imain@stemwinder.org>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH v2] VIM: Fix header management and fold threads\r
29 Date: Thu, 23 Oct 2014 21:49:00 -0700\r
30 Message-Id: <1414126140-3299-1-git-send-email-imain@stemwinder.org>\r
31 X-Mailer: git-send-email 1.9.3\r
32 In-Reply-To: <1414123503-31766-1-git-send-email-imain@stemwinder.org>\r
33 References: <1414123503-31766-1-git-send-email-imain@stemwinder.org>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.13\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38         <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Fri, 24 Oct 2014 04:49:08 -0000\r
47 \r
48 Yes, it's here, the patch you've all been waiting for!  Well, maybe:\r
49 \r
50 - Add a variable to control which headers are displayed normally.\r
51 - Any header that is not displayed normally will be listed in a folded\r
52   area in the message so you can access it at will (can be turned off).\r
53 - Add the (optional) ability to list threads using vim folding so that\r
54   you can see at a glance the whole thread, which messages are new etc.\r
55 \r
56     Ian\r
57 ---\r
58 \r
59 Fix a thinko where I was using the local variable name instead of the\r
60 global.\r
61 \r
62  vim/notmuch.vim | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-------\r
63  1 file changed, 54 insertions(+), 7 deletions(-)\r
64 \r
65 diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
66 index cad9517..21cfcae 100644\r
67 --- a/vim/notmuch.vim\r
68 +++ b/vim/notmuch.vim\r
69 @@ -54,12 +54,22 @@ let s:notmuch_folders_default = [\r
70         \ [ 'unread', 'tag:unread' ],\r
71         \ ]\r
72  \r
73 +let s:notmuch_show_headers_default = [\r
74 +       \ 'Subject',\r
75 +       \ 'To',\r
76 +       \ 'Cc',\r
77 +       \ 'Date',\r
78 +       \ 'Message-ID',\r
79 +       \ ]\r
80 +\r
81  let s:notmuch_date_format_default = '%d.%m.%y'\r
82  let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S'\r
83  let s:notmuch_reader_default = 'mutt -f %s'\r
84  let s:notmuch_sendmail_default = 'sendmail'\r
85  let s:notmuch_folders_count_threads_default = 0\r
86  let s:notmuch_compose_start_insert_default = 1\r
87 +let s:notmuch_show_folded_full_headers_default = 1\r
88 +let s:notmuch_show_folded_threads_default = 1\r
89  \r
90  function! s:new_file_buffer(type, fname)\r
91         exec printf('edit %s', a:fname)\r
92 @@ -311,6 +321,9 @@ function! s:show(thread_id)\r
93         call s:new_buffer('show')\r
94         setlocal modifiable\r
95  ruby << EOF\r
96 +       show_full_headers = VIM::evaluate('g:notmuch_show_folded_full_headers')\r
97 +       show_threads_folded = VIM::evaluate('g:notmuch_show_folded_threads')\r
98 +\r
99         thread_id = VIM::evaluate('a:thread_id')\r
100         $cur_thread = thread_id\r
101         $messages.clear\r
102 @@ -326,11 +339,22 @@ ruby << EOF\r
103                         date_fmt = VIM::evaluate('g:notmuch_datetime_format')\r
104                         date = Time.at(msg.date).strftime(date_fmt)\r
105                         nm_m.start = b.count\r
106 -                       b << "%s %s (%s)" % [msg['from'], date, msg.tags]\r
107 -                       b << "Subject: %s" % [msg['subject']]\r
108 -                       b << "To: %s" % msg['to']\r
109 -                       b << "Cc: %s" % msg['cc']\r
110 -                       b << "Date: %s" % msg['date']\r
111 +                       b << "From: %s %s (%s)" % [msg['from'], date, msg.tags]\r
112 +                       showheaders = VIM::evaluate('g:notmuch_show_headers')\r
113 +                       showheaders.each do |h|\r
114 +                               b << "%s: %s" % [h, m.header[h]]\r
115 +                       end\r
116 +                       if show_full_headers\r
117 +                               # Now show the rest in a folded area.\r
118 +                               nm_m.full_header_start = b.count\r
119 +                               m.header.fields.each do |k|\r
120 +                                       # Only show the ones we haven't already printed out.\r
121 +                                       if not showheaders.include?(k.name)\r
122 +                                           b << '%s: %s' % [k.name, k.to_s]\r
123 +                                       end\r
124 +                               end\r
125 +                               nm_m.full_header_end = b.count\r
126 +                       end\r
127                         nm_m.body_start = b.count\r
128                         b << "--- %s ---" % part.mime_type\r
129                         part.convert.each_line do |l|\r
130 @@ -343,11 +367,19 @@ ruby << EOF\r
131         end\r
132         $messages.each_with_index do |msg, i|\r
133                 VIM::command("syntax region nmShowMsg#{i}Desc start='\\%%%il' end='\\%%%il' contains=@nmShowMsgDesc" % [msg.start, msg.start + 1])\r
134 -               VIM::command("syntax region nmShowMsg#{i}Head start='\\%%%il' end='\\%%%il' contains=@nmShowMsgHead" % [msg.start + 1, msg.body_start])\r
135 +               VIM::command("syntax region nmShowMsg#{i}Head start='\\%%%il' end='\\%%%il' contains=@nmShowMsgHead" % [msg.start + 1, msg.full_header_start])\r
136                 VIM::command("syntax region nmShowMsg#{i}Body start='\\%%%il' end='\\%%%dl' contains=@nmShowMsgBody" % [msg.body_start, msg.end])\r
137 +               if show_full_headers\r
138 +                       VIM::command("syntax region nmFold#{i}Headers start='\\%%%il' end='\\%%%il' fold transparent contains=@nmShowMsgHead" % [msg.full_header_start, msg.full_header_end])\r
139 +               end\r
140 +               # Only fold the whole message if there are multiple emails in this thread.\r
141 +               if $messages.count > 1 and show_threads_folded\r
142 +                       VIM::command("syntax region nmShowMsgFold#{i} start='\\%%%il' end='\\%%%il' fold transparent contains=ALL" % [msg.start, msg.end])\r
143 +               end\r
144         end\r
145  EOF\r
146         setlocal nomodifiable\r
147 +       setlocal foldmethod=syntax\r
148         call s:set_map(g:notmuch_show_maps)\r
149  endfunction\r
150  \r
151 @@ -460,6 +492,19 @@ function! s:set_defaults()\r
152                         let g:notmuch_folders = s:notmuch_folders_default\r
153                 endif\r
154         endif\r
155 +\r
156 +       if !exists('g:notmuch_show_headers')\r
157 +               let g:notmuch_show_headers = s:notmuch_show_headers_default\r
158 +       endif\r
159 +\r
160 +       if !exists('g:notmuch_show_folded_threads')\r
161 +               let g:notmuch_show_folded_threads = s:notmuch_show_folded_threads_default\r
162 +       endif\r
163 +\r
164 +       if !exists('g:notmuch_show_folded_full_headers')\r
165 +               let g:notmuch_show_folded_full_headers = s:notmuch_show_folded_full_headers_default\r
166 +       endif\r
167 +\r
168  endfunction\r
169  \r
170  function! s:NotMuch(...)\r
171 @@ -723,7 +768,7 @@ ruby << EOF\r
172         end\r
173  \r
174         class Message\r
175 -               attr_accessor :start, :body_start, :end\r
176 +               attr_accessor :start, :body_start, :end, :full_header_start, :full_header_end\r
177                 attr_reader :message_id, :filename, :mail\r
178  \r
179                 def initialize(msg, mail)\r
180 @@ -732,6 +777,8 @@ ruby << EOF\r
181                         @mail = mail\r
182                         @start = 0\r
183                         @end = 0\r
184 +                       @full_header_start = 0\r
185 +                       @full_header_end = 0\r
186                         mail.import_headers(msg) if not $mail_installed\r
187                 end\r
188  \r
189 -- \r
190 1.9.3\r
191 \r