From: Ian Main Date: Tue, 30 Sep 2014 21:08:51 +0000 (+1700) Subject: [PATCH] Make patch saving in vim a little better. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=66759c9de40aba88969320f2b5e51230dd38153c;p=notmuch-archives.git [PATCH] Make patch saving in vim a little better. --- diff --git a/ee/0a27c1e09adaeb6005d63068c0b884fcd1300e b/ee/0a27c1e09adaeb6005d63068c0b884fcd1300e new file mode 100644 index 000000000..048926905 --- /dev/null +++ b/ee/0a27c1e09adaeb6005d63068c0b884fcd1300e @@ -0,0 +1,93 @@ +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 3860D431FBC + for ; Tue, 30 Sep 2014 14:09:07 -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 NgVhOElQvE4R for ; + Tue, 30 Sep 2014 14:09:01 -0700 (PDT) +Received: from cmta17.telus.net (cmta17.telus.net [209.171.16.90]) + by olra.theworths.org (Postfix) with ESMTP id 8340A431FB6 + for ; Tue, 30 Sep 2014 14:09:01 -0700 (PDT) +Received: from ovo.mains.priv ([207.102.88.62]) by cmta17.telus.net with TELUS + id xZ8z1o00D1LiWEf01Z8zdN; Tue, 30 Sep 2014 15:09:01 -0600 +X-Authority-Analysis: v=2.0 cv=ea3jic4H c=1 sm=2 + a=EcQDfIwDZEqJA1f7rVUV8Q==:17 a=S-IsBHyFrF4A:10 a=tsa3CZZnAAAA:8 + a=UU_U-eNNhth3WP-8HIIA:9 a=EcQDfIwDZEqJA1f7rVUV8Q==:117 +X-Telus-Outbound-IP: 207.102.88.62 +From: Ian Main +To: notmuch@notmuchmail.org +Subject: [PATCH] Make patch saving in vim a little better. +Date: Tue, 30 Sep 2014 14:08:51 -0700 +Message-Id: <1412111331-18823-1-git-send-email-imain@stemwinder.org> +X-Mailer: git-send-email 1.9.3 +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: Tue, 30 Sep 2014 21:09:07 -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 +--- + vim/notmuch.vim | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/vim/notmuch.vim b/vim/notmuch.vim +index b33c6c6..d80f22f 100644 +--- a/vim/notmuch.vim ++++ b/vim/notmuch.vim +@@ -182,12 +182,18 @@ 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] ++ t.messages.each do |m| ++ next if not m['subject'] =~ /\[PATCH.*\]/ ++ next if m['subject'] =~ /^Re:/ ++ file = "#{m['subject']}-%04d.patch" % [n += 1] ++ # Sanitize for the filesystem ++ file.gsub!(/[^0-9A-Za-z.\-]/, '_') ++ # Remove leading underscores. ++ file.gsub!(/^_+/, '') ++ vim_puts "Saving patch to #{file}" + system "notmuch show --format=mbox id:#{m.message_id} > #{file}" + end +- vim_puts "Saved #{n} patches" ++ vim_puts "Saved #{n} patch(es)" + EOF + endfunction + +-- +1.9.3 +