From de74431cfeb24ca72f6dfa4df93130ba49c59219 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Mon, 14 Oct 2013 01:57:28 -0500 Subject: vim: refactor open_reply() In preparation for composing new messages. Signed-off-by: Felipe Contreras --- vim/notmuch.vim | 92 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 43 deletions(-) (limited to 'vim') diff --git a/vim/notmuch.vim b/vim/notmuch.vim index 9a45300f..8383fd65 100644 --- a/vim/notmuch.vim +++ b/vim/notmuch.vim @@ -504,12 +504,37 @@ ruby << EOF return "<#{random_tag}@#{Socket.gethostname}.notmuch>" end - def open_reply(orig) + def open_compose_helper(lines, cur) help_lines = [ 'Notmuch-Help: Type in your message here; to help you use these bindings:', 'Notmuch-Help: ,s - send the message (Notmuch-Help lines will be removed)', 'Notmuch-Help: ,q - abort the message', ] + + dir = File.expand_path('~/.notmuch/compose') + FileUtils.mkdir_p(dir) + Tempfile.open(['nm-', '.mail'], dir) do |f| + f.puts(help_lines) + f.puts + f.puts(lines) + + sig_file = File.expand_path('~/.signature') + if File.exists?(sig_file) + f.puts("-- ") + f.write(File.read(sig_file)) + end + + f.flush + + cur += help_lines.size + 1 + + VIM::command("let s:reply_from='%s'" % $email_address) + VIM::command("call s:new_file_buffer('compose', '#{f.path}')") + VIM::command("call cursor(#{cur}, 0)") + end + end + + def open_reply(orig) reply = orig.reply do |m| # fix headers if not m[:reply_to] @@ -522,54 +547,35 @@ ruby << EOF m.content_transfer_encoding = '7bit' end - dir = File.expand_path('~/.notmuch/compose') - FileUtils.mkdir_p(dir) - Tempfile.open(['nm-', '.mail'], dir) do |f| - lines = [] - - lines += help_lines - lines << '' - - body_lines = [] - if $mail_installed - addr = Mail::Address.new(orig[:from].value) - name = addr.name - name = addr.local + "@" if name.nil? && !addr.local.nil? - else - name = orig[:from] - end - name = "somebody" if name.nil? - - body_lines << "%s wrote:" % name - part = orig.find_first_text - part.convert.each_line do |l| - body_lines << "> %s" % l.chomp - end - body_lines << "" - body_lines << "" - body_lines << "" - - reply.body = body_lines.join("\n") + lines = [] - lines += reply.to_s.lines.map { |e| e.chomp } - lines << "" + body_lines = [] + if $mail_installed + addr = Mail::Address.new(orig[:from].value) + name = addr.name + name = addr.local + "@" if name.nil? && !addr.local.nil? + else + name = orig[:from] + end + name = "somebody" if name.nil? - old_count = lines.count - 1 + body_lines << "%s wrote:" % name + part = orig.find_first_text + part.convert.each_line do |l| + body_lines << "> %s" % l.chomp + end + body_lines << "" + body_lines << "" + body_lines << "" - f.puts(lines) + reply.body = body_lines.join("\n") - sig_file = File.expand_path('~/.signature') - if File.exists?(sig_file) - f.puts("-- ") - f.write(File.read(sig_file)) - end + lines += reply.to_s.lines.map { |e| e.chomp } + lines << "" - f.flush + cur = lines.count - 1 - VIM::command("let s:reply_from='%s'" % $email_address) - VIM::command("call s:new_file_buffer('compose', '#{f.path}')") - VIM::command("call cursor(#{old_count}, 0)") - end + open_compose_helper(lines, cur) end def folders_render() -- cgit v1.2.3