* re-use the `message-mode' citation engine for generating cited messages (WIP)

This commit is contained in:
djcb
2012-04-16 22:06:49 +03:00
parent 57c261ef87
commit 127a9108fb
3 changed files with 70 additions and 92 deletions

View File

@ -35,27 +35,21 @@
(require 'mu4e-utils) (require 'mu4e-utils)
(require 'mu4e-vars) (require 'mu4e-vars)
(require 'mu4e-proc) (require 'mu4e-proc)
(require 'mu4e-view)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mu4e--cite-original (msg) (defun mu4e--cite-original (msg)
"Cite the body text of MSG, with a \"On %s, %s wrote:\" "Return a cited version of the original message MSG (ie., the
line (with the %s's replaced with the date of MSG and the name plist). This function use gnus' `message-cite-function', and as
or e-mail address of its sender (or 'someone' if nothing such all its settings apply."
else)), followed of the quoted body of MSG, constructed by by (with-temp-buffer
prepending `mu4e-citation-prefix' to each line. If there is (insert (mu4e-view-message-text msg))
no body in MSG, return nil." (goto-char (point-min))
(let* ((from (plist-get msg :from)) (push-mark (point-max))
(body (mu4e-body-text msg))) (funcall message-cite-function)
(when body (pop-mark)
(concat (buffer-string)))
(format "On %s, %s wrote:"
(format-time-string "%c" (plist-get msg :date))
(if (and from (car from)) ;; a list ((<name> . <email>))
(or (caar from) (cdar from) "someone")
"someone"))
"\n\n"
(replace-regexp-in-string "^"
mu4e-citation-prefix body)))))
(defun mu4e--header (hdr val) (defun mu4e--header (hdr val)
"Return a header line of the form HDR: VAL\n. If VAL is nil, "Return a header line of the form HDR: VAL\n. If VAL is nil,
@ -243,8 +237,7 @@ are more than 1 (based on ORIGMSG)."
(mu4e--header "Subject" (mu4e--header "Subject"
(concat (concat
;; if there's no Re: yet, prepend it ;; if there's no Re: yet, prepend it
(if (string-match (concat "^" mu4e-reply-prefix) subject) (if (string-match "^Re:" subject) "" "Re:")
"" mu4e-reply-prefix)
subject)) subject))
"\n\n" "\n\n"
(mu4e--cite-original origmsg)))) (mu4e--cite-original origmsg))))
@ -263,9 +256,8 @@ are more than 1 (based on ORIGMSG)."
(mu4e--header "References" (mu4e--refererences-construct origmsg)) (mu4e--header "References" (mu4e--refererences-construct origmsg))
(mu4e--header "Subject" (mu4e--header "Subject"
(concat (concat
;; if there's no Re: yet, prepend it ;; if there's no Fwd: yet, prepend it
(if (string-match (concat "^" mu4e-forward-prefix) subject) (if (string-match "^Fwd:" subject) "" "Fwd:")
"" mu4e-forward-prefix)
subject)) subject))
"\n\n" "\n\n"
(mu4e--cite-original origmsg)))) (mu4e--cite-original origmsg))))

View File

@ -109,11 +109,6 @@ show up in the UI), and KEY is a shortcut key for the query.")
* anything else: don't split (show either headers or messages, not both) * anything else: don't split (show either headers or messages, not both)
Also see `mu4e-headers-visible-lines' and `mu4e-headers-visible-columns'.") Also see `mu4e-headers-visible-lines' and `mu4e-headers-visible-columns'.")
;; Sending
(defgroup mu4e-sending nil
"E-mail-sending related settings for mu4e."
:group 'mu4e)
;; Folders ;; Folders
(defgroup mu4e-folders nil (defgroup mu4e-folders nil
@ -266,21 +261,6 @@ display with `mu4e-view-toggle-hide-cited (default keybinding:
"Customizations for composing/sending messages." "Customizations for composing/sending messages."
:group 'mu4e) :group 'mu4e)
(defcustom mu4e-citation-prefix " > "
"String to prefix cited message parts with."
:type 'string
:group 'mu4e-compose)
(defcustom mu4e-reply-prefix "Re: "
"String to prefix the subject of replied messages with."
:type 'string
:group 'mu4e-compose)
(defcustom mu4e-forward-prefix "Fwd: "
"String to prefix the subject of forwarded messages with."
:type 'string
:group 'mu4e-compose)
(defcustom mu4e-reply-to-address nil (defcustom mu4e-reply-to-address nil
"The Reply-To address (if this, for some reason, is not equal to "The Reply-To address (if this, for some reason, is not equal to
the From: address.)" the From: address.)"
@ -307,7 +287,6 @@ sent folder."
;; Faces ;; Faces
(defgroup mu4e-faces nil (defgroup mu4e-faces nil
"Type faces (fonts) used in mu4e." "Type faces (fonts) used in mu4e."
:group 'mu4e :group 'mu4e

View File

@ -43,23 +43,10 @@
wanting to show specific messages - for example, `mu4e-org'." wanting to show specific messages - for example, `mu4e-org'."
(mu4e-proc-view msgid)) (mu4e-proc-view msgid))
(defun mu4e-view (msg hdrsbuf &optional update) (defun mu4e-view-message-text (msg)
"Display the message MSG in a new buffer, and keep in sync with HDRSBUF. "Return the message to display (as a string), based on the MSG
'In sync' here means that moving to the next/previous message in plist."
the the message view affects HDRSBUF, as does marking etc. If (concat
UPDATE is nil, the current message may be (visually) 'massaged',
based on the settings of `mu4e-view-wrap-lines' and
`mu4e-view-hide-cited'.
As a side-effect, a message that is being viewed loses its 'unread'
marking if it still had that."
(let ((buf (get-buffer-create mu4e-view-buffer-name))
(inhibit-read-only t))
(with-current-buffer buf
(setq mu4e-view-buffer buf)
(setq mu4e-attach-map nil) ;; clear any old attachment stuff
(erase-buffer)
(insert
(mapconcat (mapconcat
(lambda (field) (lambda (field)
(let ((fieldname (cdr (assoc field mu4e-header-names))) (let ((fieldname (cdr (assoc field mu4e-header-names)))
@ -84,7 +71,6 @@ marking if it still had that."
(if (and from (string-match mu4e-user-mail-address-regexp from)) (if (and from (string-match mu4e-user-mail-address-regexp from))
(mu4e-view-contacts msg :to) (mu4e-view-contacts msg :to)
(mu4e-view-contacts msg :from)))) (mu4e-view-contacts msg :from))))
;; date ;; date
(:date (:date
(let ((datestr (let ((datestr
@ -101,7 +87,26 @@ marking if it still had that."
(t (error "Unsupported field: %S" field))))) (t (error "Unsupported field: %S" field)))))
mu4e-view-fields "") mu4e-view-fields "")
"\n" "\n"
(mu4e-body-text msg)) (mu4e-body-text msg)))
(defun mu4e-view (msg hdrsbuf &optional update)
"Display the message MSG in a new buffer, and keep in sync with HDRSBUF.
'In sync' here means that moving to the next/previous message in
the the message view affects HDRSBUF, as does marking etc. If
UPDATE is nil, the current message may be (visually) 'massaged',
based on the settings of `mu4e-view-wrap-lines' and
`mu4e-view-hide-cited'.
As a side-effect, a message that is being viewed loses its 'unread'
marking if it still had that."
(let ((buf (get-buffer-create mu4e-view-buffer-name))
(inhibit-read-only t))
(with-current-buffer buf
(setq mu4e-view-buffer buf)
(setq mu4e-attach-map nil) ;; clear any old attachment stuff
(erase-buffer)
(insert (mu4e-view-message-text msg))
;; initialize view-mode ;; initialize view-mode
(mu4e-view-mode) (mu4e-view-mode)
@ -130,6 +135,8 @@ marking if it still had that."
(unless update (unless update
(mu4e-view-mark-as-read-maybe))))) (mu4e-view-mark-as-read-maybe)))))
(defun mu4e-view-header (key val &optional dont-propertize-val) (defun mu4e-view-header (key val &optional dont-propertize-val)
"Show header FIELD for MSG with KEY. ie. <KEY>: value-of-FIELD." "Show header FIELD for MSG with KEY. ie. <KEY>: value-of-FIELD."
(if val (if val