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