aboutsummaryrefslogtreecommitdiffhomepage
path: root/vim
diff options
context:
space:
mode:
authorGravatar Felipe Contreras <felipe.contreras@gmail.com>2013-10-14 01:57:28 -0500
committerGravatar Felipe Contreras <felipe.contreras@gmail.com>2013-11-20 07:23:29 -0600
commitde74431cfeb24ca72f6dfa4df93130ba49c59219 (patch)
tree2f5bed153ce822af45ecb3b68554a9b0ffc542ec /vim
parent2ec69fd39e4b1132032b700ec678d3dfa082c74a (diff)
vim: refactor open_reply()
In preparation for composing new messages. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Diffstat (limited to 'vim')
-rw-r--r--vim/notmuch.vim92
1 files changed, 49 insertions, 43 deletions
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()