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 1C908431FAF for ; Mon, 20 Oct 2014 12:44:49 -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 KyqRn0GJW4s3 for ; Mon, 20 Oct 2014 12:44:45 -0700 (PDT) Received: from cmta12.telus.net (cmta12.telus.net [209.171.16.85]) by olra.theworths.org (Postfix) with ESMTP id 37805431FAE for ; Mon, 20 Oct 2014 12:44:45 -0700 (PDT) Received: from ovo.mains.priv ([207.102.88.62]) by cmta12.telus.net with TELUS id 5Xkk1p0031LiWEf01XkkLt; Mon, 20 Oct 2014 13:44:44 -0600 X-Authority-Analysis: v=2.0 cv=f5eW8pOM c=1 sm=2 a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8 a=Lslhd1wAqYGKFm1UiiAA:9 a=EcQDfIwDZEqJA1f7rVUV8Q==:117 X-Telus-Outbound-IP: 207.102.88.62 From: Ian Main To: notmuch@notmuchmail.org Subject: [PATCH v2] VIM: Make patch saving in vim a little better. Date: Mon, 20 Oct 2014 12:44:34 -0700 Message-Id: <1413834274-5388-1-git-send-email-imain@stemwinder.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1412111331-18823-1-git-send-email-imain@stemwinder.org> References: <1412111331-18823-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: Mon, 20 Oct 2014 19:44:49 -0000 It seems like there was some bitrot on the previous version of this which made it not work correctly. This fixes the bitrot and also updates how it works. - Sometimes [PATCH.*] isn't at the beginning of the message (often on lists I'm on). - It now goes through all the messages in the thread. for some reason the toplevel messages didn't usually contain all the patches in my testing. - Check for 'Re:' at the beginning and skip if it's there. - Save patches to filesystem-safe filename containing the subject (unfortunately we use system()...) Ian --- We now prompt for directory name to save to. Also save in the format closer to git with numbers first. vim/notmuch.vim | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/vim/notmuch.vim b/vim/notmuch.vim index 331e930..8c46bb0 100644 --- a/vim/notmuch.vim +++ b/vim/notmuch.vim @@ -178,16 +178,32 @@ EOF endfunction function! s:show_save_patches() + let dir = input('Save to directory: ', getcwd(), 'dir') ruby << EOF - q = $curbuf.query($cur_thread) - t = q.search_threads.first - n = 0 - t.toplevel_messages.first.replies.each do |m| - next if not m['subject'] =~ /^\[PATCH.*\]/ - file = "%04d.patch" % [n += 1] - system "notmuch show --format=mbox id:#{m.message_id} > #{file}" - end - vim_puts "Saved #{n} patches" + dir = VIM::evaluate('dir') + if File.exists?(dir) + q = $curbuf.query($cur_thread) + t = q.search_threads.first + n = 0 + m = get_message + t.messages.each do |m| + next if not m['subject'] =~ /\[PATCH.*\]/ + next if m['subject'] =~ /^Re:/ + subject = m['subject'] + # Sanitize for the filesystem + subject.gsub!(/[^0-9A-Za-z.\-]/, '_') + # Remove leading underscores. + subject.gsub!(/^_+/, '') + # git style numbered patchset format. + file = "#{dir}/%04d-#{subject}.patch" % [n += 1] + vim_puts "Saving patch to #{file}" + system "notmuch show --format=mbox id:#{m.message_id} > #{file}" + end + vim_puts "Saved #{n} patch(es)" + else + VIM::command('redraw') + vim_puts "ERROR: Invalid directory: #{dir}" + end EOF endfunction -- 1.9.3