* [PATCH] Make patch saving in vim a little better.
@ 2014-09-30 21:08 Ian Main
2014-10-18 20:48 ` Franz Fellner
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ian Main @ 2014-09-30 21:08 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] Make patch saving in vim a little better.
2014-09-30 21:08 [PATCH] Make patch saving in vim a little better Ian Main
@ 2014-10-18 20:48 ` Franz Fellner
2014-10-19 9:39 ` Tomi Ollila
2014-10-20 19:44 ` [PATCH v2] VIM: " Ian Main
2 siblings, 0 replies; 4+ messages in thread
From: Franz Fellner @ 2014-10-18 20:48 UTC (permalink / raw)
To: Ian Main, Ian Main, notmuch
PATCH LGTM. Did not find any patch that couldn't be saved.
One issue: It saves the patches into $WORKDIR. It would be great if the target path could
be prompted (default again to ~/.notmuch/tmp?) so no random dirs get polluted.
But that isn't a regression to the previous behaviour -> no showstopper.
Franz
Ian Main wrote:
> 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
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Make patch saving in vim a little better.
2014-09-30 21:08 [PATCH] Make patch saving in vim a little better Ian Main
2014-10-18 20:48 ` Franz Fellner
@ 2014-10-19 9:39 ` Tomi Ollila
2014-10-20 19:44 ` [PATCH v2] VIM: " Ian Main
2 siblings, 0 replies; 4+ messages in thread
From: Tomi Ollila @ 2014-10-19 9:39 UTC (permalink / raw)
To: Ian Main, notmuch
On Wed, Oct 01 2014, Ian Main <imain@stemwinder.org> wrote:
> 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]
Is the subject here taken from first message in the thread or
is the subject changing in every message ? If the name is changing
(which I presume, cannot test), the list of files will look a bit
confusing. This could follow the git patch naming where the number is at
the beginning of filename.
> + # Sanitize for the filesystem
> + file.gsub!(/[^0-9A-Za-z.\-]/, '_')
> + # Remove leading underscores.
> + file.gsub!(/^_+/, '')
The naming could also follow git way, dashes (-) between words and
replacing multiple --:s with just one - (like gsub(/--+/, '-'))
-- but in this case there could something in the filename to distinguish
from git patches as these patches may be `git am` -incompatible.
> + 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
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] VIM: Make patch saving in vim a little better.
2014-09-30 21:08 [PATCH] Make patch saving in vim a little better Ian Main
2014-10-18 20:48 ` Franz Fellner
2014-10-19 9:39 ` Tomi Ollila
@ 2014-10-20 19:44 ` Ian Main
2 siblings, 0 replies; 4+ messages in thread
From: Ian Main @ 2014-10-20 19:44 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-10-20 19:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-30 21:08 [PATCH] Make patch saving in vim a little better Ian Main
2014-10-18 20:48 ` Franz Fellner
2014-10-19 9:39 ` Tomi Ollila
2014-10-20 19:44 ` [PATCH v2] VIM: " Ian Main
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).