Add support for additional Notmuch-* headers: special headers read (and
then removed) by vnm upon send. The plan is to use these special headers
for all sorts of fancy features: attachments, PGP, whatever, so that the
inputs to these features are editable from vim.

For the moment, this just factors the code a bit: the Notmuch-Help lines
are expanded to list allowed headers, and the number of headers to
ignore is now decided at runtime, instead of being hardcoded.

The biggest change is the addition of dynamic highlighting for these: at
the end of the compose helper we add syntax highlighting for all the
special headers we interpret. Since these are now generated dynamically,
we remove the highlighting code from the static syntax files.
---
 vim/notmuch.vim                | 24 ++++++++++++++++++++----
 vim/syntax/notmuch-compose.vim |  5 -----
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index ad8b7c8..bea30f8 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -87,13 +87,19 @@ endfunction
 function! s:compose_send()
        let b:compose_done = 1
        let fname = expand('%')
-       let lines = getline(5, '$')
 
 ruby << EOF
        # Generate proper mail to send
-       text = VIM::evaluate('lines').join("\n")
+       text = []
+       eval_nm_headers = true
+       VIM::evaluate('getline(0, \'$\')').each do |line|
+               unless eval_nm_headers and NotmuchHeaders.any? { |h| 
line.start_with?("Notmuch-#{h}: ") }
+                       text << line
+                       eval_nm_headers = false
+               end
+       end
        fname = VIM::evaluate('fname')
-       transport = Mail.new(text)
+       transport = Mail.new(text.join("\n"))
        transport.message_id = generate_message_id
        transport.charset = 'utf-8'
        File.write(fname, transport.to_s)
@@ -483,6 +489,8 @@ ruby << EOF
        $messages = []
        $mail_installed = defined?(Mail)
 
+       NotmuchHeaders = ["Help"]
+
        def get_config_item(item)
                result = ''
                IO.popen(['notmuch', 'config', 'get', item]) { |out|
@@ -491,6 +499,7 @@ ruby << EOF
                return result.rstrip
        end
 
+
        def get_config
                $db_name = get_config_item('database.path')
                $email_name = get_config_item('user.name')
@@ -547,8 +556,9 @@ ruby << EOF
        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:   ,s    - send the message',
                        'Notmuch-Help:   ,q    - abort the message',
+                       "Notmuch-Help: Magic Notmuch- headers (removed on 
send): #{NotmuchHeaders.join(", ")}.",
                        ]
 
                dir = File.expand_path('~/.notmuch/compose')
@@ -571,6 +581,12 @@ ruby << EOF
                        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)")
+                       VIM::command(<<-'SEOF' % NotmuchHeaders.collect { |h| 
"Notmuch-#{h}" }.join('\|'))
+                               syntax region nmComposeNotmuchHeaders 
contains=nmComposeNotmuchHeaderLine start='^\(%1$s\):' end='^\(\(%1$s\):\)\@!'
+                               syntax match nmComposeNotmuchHeaderLine 
/\(%1$s\):/ contained
+                               highlight link nmComposeNotmuchHeaders Include
+                               highlight link nmComposeNotmuchHeaderLine Error
+                       SEOF
                end
        end
 
diff --git a/vim/syntax/notmuch-compose.vim b/vim/syntax/notmuch-compose.vim
index 19adb75..8d45636 100644
--- a/vim/syntax/notmuch-compose.vim
+++ b/vim/syntax/notmuch-compose.vim
@@ -1,7 +1,2 @@
 runtime! syntax/mail.vim
 
-syntax region nmComposeHelp          contains=nmComposeHelpLine 
start='^Notmuch-Help:\%1l' end='^\(Notmuch-Help:\)\@!'
-syntax match  nmComposeHelpLine      /Notmuch-Help:/ contained
-
-highlight link nmComposeHelp        Include
-highlight link nmComposeHelpLine    Error
-- 
2.7.3

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to