[PATCH] VIM: Fix header management and fold threads
authorIan Main <imain@stemwinder.org>
Fri, 24 Oct 2014 04:05:03 +0000 (21:05 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:05:33 +0000 (10:05 -0800)
88/75f2197c5bcfdcd0e42b1a23070a8abd917568 [new file with mode: 0644]

diff --git a/88/75f2197c5bcfdcd0e42b1a23070a8abd917568 b/88/75f2197c5bcfdcd0e42b1a23070a8abd917568
new file mode 100644 (file)
index 0000000..715abff
--- /dev/null
@@ -0,0 +1,185 @@
+Return-Path: <imain@stemwinder.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 7159B431FD8\r
+       for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:05:13 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id Dz2FDUh+Chqm for <notmuch@notmuchmail.org>;\r
+       Thu, 23 Oct 2014 21:05:08 -0700 (PDT)\r
+Received: from cmta13.telus.net (cmta13.telus.net [209.171.16.86])\r
+       by olra.theworths.org (Postfix) with ESMTP id CBEBD431FBD\r
+       for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 21:05:07 -0700 (PDT)\r
+Received: from ovo.mains.priv ([207.102.88.62]) by cmta13.telus.net with TELUS\r
+       id 6s551p00J1LiWEf01s567M; Thu, 23 Oct 2014 22:05:06 -0600\r
+X-Authority-Analysis: v=2.0 cv=OrmRPVDt c=1 sm=2\r
+       a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=tsa3CZZnAAAA:8 a=3htRWu4FMa_oRVYOwfYA:9\r
+       a=EcQDfIwDZEqJA1f7rVUV8Q==:117\r
+X-Telus-Outbound-IP: 207.102.88.62\r
+From: Ian Main <imain@stemwinder.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] VIM: Fix header management and fold threads\r
+Date: Thu, 23 Oct 2014 21:05:03 -0700\r
+Message-Id: <1414123503-31766-1-git-send-email-imain@stemwinder.org>\r
+X-Mailer: git-send-email 1.9.3\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 24 Oct 2014 04:05:13 -0000\r
+\r
+Yes, it's here, the patch you've all been waiting for!  Well, maybe:\r
+\r
+- Add a variable to control which headers are displayed normally.\r
+- Any header that is not displayed normally will be listed in a folded\r
+  area in the message so you can access it at will (can be turned off).\r
+- Add the (optional) ability to list threads using vim folding so that\r
+  you can see at a glance the whole thread, which messages are new etc.\r
+\r
+    Ian\r
+---\r
+ vim/notmuch.vim | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++-------\r
+ 1 file changed, 54 insertions(+), 7 deletions(-)\r
+\r
+diff --git a/vim/notmuch.vim b/vim/notmuch.vim\r
+index cad9517..affd1e2 100644\r
+--- a/vim/notmuch.vim\r
++++ b/vim/notmuch.vim\r
+@@ -54,12 +54,22 @@ let s:notmuch_folders_default = [\r
+       \ [ 'unread', 'tag:unread' ],\r
+       \ ]\r
\r
++let s:notmuch_show_headers_default = [\r
++      \ 'Subject',\r
++      \ 'To',\r
++      \ 'Cc',\r
++      \ 'Date',\r
++      \ 'Message-ID',\r
++      \ ]\r
++\r
+ let s:notmuch_date_format_default = '%d.%m.%y'\r
+ let s:notmuch_datetime_format_default = '%d.%m.%y %H:%M:%S'\r
+ let s:notmuch_reader_default = 'mutt -f %s'\r
+ let s:notmuch_sendmail_default = 'sendmail'\r
+ let s:notmuch_folders_count_threads_default = 0\r
+ let s:notmuch_compose_start_insert_default = 1\r
++let s:notmuch_show_folded_full_headers_default = 1\r
++let s:notmuch_show_folded_threads_default = 1\r
\r
+ function! s:new_file_buffer(type, fname)\r
+       exec printf('edit %s', a:fname)\r
+@@ -311,6 +321,9 @@ function! s:show(thread_id)\r
+       call s:new_buffer('show')\r
+       setlocal modifiable\r
+ ruby << EOF\r
++      show_full_headers = VIM::evaluate('g:notmuch_show_folded_full_headers')\r
++      show_threads_folded = VIM::evaluate('g:notmuch_show_folded_threads_default')\r
++\r
+       thread_id = VIM::evaluate('a:thread_id')\r
+       $cur_thread = thread_id\r
+       $messages.clear\r
+@@ -326,11 +339,22 @@ ruby << EOF\r
+                       date_fmt = VIM::evaluate('g:notmuch_datetime_format')\r
+                       date = Time.at(msg.date).strftime(date_fmt)\r
+                       nm_m.start = b.count\r
+-                      b << "%s %s (%s)" % [msg['from'], date, msg.tags]\r
+-                      b << "Subject: %s" % [msg['subject']]\r
+-                      b << "To: %s" % msg['to']\r
+-                      b << "Cc: %s" % msg['cc']\r
+-                      b << "Date: %s" % msg['date']\r
++                      b << "From: %s %s (%s)" % [msg['from'], date, msg.tags]\r
++                      showheaders = VIM::evaluate('g:notmuch_show_headers')\r
++                      showheaders.each do |h|\r
++                              b << "%s: %s" % [h, m.header[h]]\r
++                      end\r
++                      if show_full_headers\r
++                              # Now show the rest in a folded area.\r
++                              nm_m.full_header_start = b.count\r
++                              m.header.fields.each do |k|\r
++                                      # Only show the ones we haven't already printed out.\r
++                                      if not showheaders.include?(k.name)\r
++                                          b << '%s: %s' % [k.name, k.to_s]\r
++                                      end\r
++                              end\r
++                              nm_m.full_header_end = b.count\r
++                      end\r
+                       nm_m.body_start = b.count\r
+                       b << "--- %s ---" % part.mime_type\r
+                       part.convert.each_line do |l|\r
+@@ -343,11 +367,19 @@ ruby << EOF\r
+       end\r
+       $messages.each_with_index do |msg, i|\r
+               VIM::command("syntax region nmShowMsg#{i}Desc start='\\%%%il' end='\\%%%il' contains=@nmShowMsgDesc" % [msg.start, msg.start + 1])\r
+-              VIM::command("syntax region nmShowMsg#{i}Head start='\\%%%il' end='\\%%%il' contains=@nmShowMsgHead" % [msg.start + 1, msg.body_start])\r
++              VIM::command("syntax region nmShowMsg#{i}Head start='\\%%%il' end='\\%%%il' contains=@nmShowMsgHead" % [msg.start + 1, msg.full_header_start])\r
+               VIM::command("syntax region nmShowMsg#{i}Body start='\\%%%il' end='\\%%%dl' contains=@nmShowMsgBody" % [msg.body_start, msg.end])\r
++              if show_full_headers\r
++                      VIM::command("syntax region nmFold#{i}Headers start='\\%%%il' end='\\%%%il' fold transparent contains=@nmShowMsgHead" % [msg.full_header_start, msg.full_header_end])\r
++              end\r
++              # Only fold the whole message if there are multiple emails in this thread.\r
++              if $messages.count > 1 and show_threads_folded\r
++                      VIM::command("syntax region nmShowMsgFold#{i} start='\\%%%il' end='\\%%%il' fold transparent contains=ALL" % [msg.start, msg.end])\r
++              end\r
+       end\r
+ EOF\r
+       setlocal nomodifiable\r
++      setlocal foldmethod=syntax\r
+       call s:set_map(g:notmuch_show_maps)\r
+ endfunction\r
\r
+@@ -460,6 +492,19 @@ function! s:set_defaults()\r
+                       let g:notmuch_folders = s:notmuch_folders_default\r
+               endif\r
+       endif\r
++\r
++      if !exists('g:notmuch_show_headers')\r
++              let g:notmuch_show_headers = s:notmuch_show_headers_default\r
++      endif\r
++\r
++      if !exists('g:notmuch_show_folded_threads')\r
++              let g:notmuch_show_folded_threads = s:notmuch_show_folded_threads_default\r
++      endif\r
++\r
++      if !exists('g:notmuch_show_folded_full_headers')\r
++              let g:notmuch_show_folded_full_headers = s:notmuch_show_folded_full_headers_default\r
++      endif\r
++\r
+ endfunction\r
\r
+ function! s:NotMuch(...)\r
+@@ -723,7 +768,7 @@ ruby << EOF\r
+       end\r
\r
+       class Message\r
+-              attr_accessor :start, :body_start, :end\r
++              attr_accessor :start, :body_start, :end, :full_header_start, :full_header_end\r
+               attr_reader :message_id, :filename, :mail\r
\r
+               def initialize(msg, mail)\r
+@@ -732,6 +777,8 @@ ruby << EOF\r
+                       @mail = mail\r
+                       @start = 0\r
+                       @end = 0\r
++                      @full_header_start = 0\r
++                      @full_header_end = 0\r
+                       mail.import_headers(msg) if not $mail_installed\r
+               end\r
\r
+-- \r
+1.9.3\r
+\r