]> git.notmuchmail.org Git - notmuch/commitdiff
vim: refactor open_reply()
authorFelipe Contreras <felipe.contreras@gmail.com>
Mon, 14 Oct 2013 06:57:28 +0000 (01:57 -0500)
committerFelipe Contreras <felipe.contreras@gmail.com>
Wed, 20 Nov 2013 13:23:29 +0000 (07:23 -0600)
In preparation for composing new messages.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
vim/notmuch.vim

index 9a45300f2683e210cbd21bf0446585819d74492d..8383fd65a5448b3610fee105235720419d5f4464 100644 (file)
@@ -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()