* org-mu4e.el: make using compose-mode key chords a bit less rubegoldbergish

This commit is contained in:
djcb
2012-09-24 17:05:14 +03:00
parent a136e163fe
commit c333930fee

View File

@ -96,7 +96,7 @@ the query (for paths starting with 'query:')."
(mu4e-view-message-with-msgid (match-string 1 path))) (mu4e-view-message-with-msgid (match-string 1 path)))
((string-match "^query:\\(.+\\)" path) ((string-match "^query:\\(.+\\)" path)
(mu4e-headers-search (match-string 1 path) current-prefix-arg)) (mu4e-headers-search (match-string 1 path) current-prefix-arg))
(t (message "mu4e: unrecognized link type '%s'" path)))) (t (mu4e-error "mu4e: unrecognized link type '%s'" path))))
@ -151,8 +151,10 @@ and images in a multipart/related part."
(defun org~mu4e-mime-convert-to-html () (defun org~mu4e-mime-convert-to-html ()
"Convert the current body to html." "Convert the current body to html."
(if (not (fboundp 'org-export-string)) (unless (fboundp 'org-export-string)
(mu4e-error "require function 'org-export-string not found.") (mu4e-error "require function 'org-export-string not found."))
(unless (executable-find "dvipng")
(mu4e-error "Required program dvipng not found"))
(let* ((begin (let* ((begin
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
@ -217,20 +219,9 @@ function is called when sending a message (from
`message-send-hook') and, if non-nil, will send the message as the `message-send-hook') and, if non-nil, will send the message as the
rich-text version of the what is assumed to be an org-mode body." rich-text version of the what is assumed to be an org-mode body."
(when org-mu4e-convert-to-html (when org-mu4e-convert-to-html
(message "Converting to html") (mu4e-message "Converting to html")
(org~mu4e-mime-convert-to-html))) (org~mu4e-mime-convert-to-html)))
(defun org~mu4e-execute-key-sequence-in-compose-mode (keyseq)
"Execute keysequence KEYSEQ by (temporarily) switching to compose
mode."
(mu4e-compose-mode)
(add-hook 'post-command-hook 'org~mu4e-mime-switch-headers-or-body t t)
(let ((func (lookup-key (current-local-map) keyseq)))
(unless (functionp func)
(mu4e-error "Invalid key binding"))
(add-hook 'message-send-hook 'org~mu4e-mime-convert-to-html-maybe t t)
(funcall func)))
(defun org~mu4e-mime-switch-headers-or-body () (defun org~mu4e-mime-switch-headers-or-body ()
"Switch the buffer to either mu4e-compose-mode (when in headers) "Switch the buffer to either mu4e-compose-mode (when in headers)
or org-mode (when in the body)." or org-mode (when in the body)."
@ -254,19 +245,18 @@ or org-mode (when in the body)."
nil t) nil t)
(org~mu4e-mime-decorate-headers) (org~mu4e-mime-decorate-headers)
(local-set-key (kbd "M-m") (local-set-key (kbd "M-m")
(lambda (key) (lambda (keyseq)
(interactive "kEnter mu4e-compose-mode key sequence: ") (interactive "kEnter mu4e-compose-mode key sequence: ")
(org~mu4e-execute-key-sequence-in-compose-mode key)))) (let ((func (lookup-key mu4e-compose-mode-map keyseq)))
(if func (funcall func) (insert keyseq))))))
;; we're in the headers, but in org-mode? ;; we're in the headers, but in org-mode?
;; if so, switch to mu4e-compose-mode ;; if so, switch to mu4e-compose-mode
((and (<= (point) sepapoint) (eq major-mode 'org-mode)) ((and (<= (point) sepapoint) (eq major-mode 'org-mode))
(org~mu4e-mime-undecorate-headers) (org~mu4e-mime-undecorate-headers)
(mu4e-compose-mode) (mu4e-compose-mode)
(add-hook 'message-send-hook (add-hook 'message-send-hook 'org~mu4e-mime-convert-to-html-maybe nil t)))
'org~mu4e-mime-convert-to-html-maybe nil t)))
;; and add the hook ;; and add the hook
(add-hook 'post-command-hook (add-hook 'post-command-hook 'org~mu4e-mime-switch-headers-or-body t t))))
'org~mu4e-mime-switch-headers-or-body t t))))
(defun org-mu4e-compose-org-mode () (defun org-mu4e-compose-org-mode ()
@ -275,10 +265,9 @@ or org-mode (when in the body)."
(interactive) (interactive)
(unless (member major-mode '(org-mode mu4e-compose-mode)) (unless (member major-mode '(org-mode mu4e-compose-mode))
(mu4e-error "Need org-mode or mu4e-compose-mode")) (mu4e-error "Need org-mode or mu4e-compose-mode"))
(unless (executable-find "dvipng") ;; we can check if we're already in org-mu4e-compose-mode by checking if the
(mu4e-error "Required program dvipng not found")) ;; post-command-hook is set; hackish...but a buffer-local variable does not
;; we can check if we're already in mu4e-compose-mode by checking ;; seem to survive buffer switching
;; if the post-command-hook is set; hackish...
(if (not (member 'org~mu4e-mime-switch-headers-or-body post-command-hook)) (if (not (member 'org~mu4e-mime-switch-headers-or-body post-command-hook))
(progn (progn
(org~mu4e-mime-switch-headers-or-body) (org~mu4e-mime-switch-headers-or-body)