* 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-vars)
(require 'mu4e-proc)
(require 'mu4e-view)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mu4e--cite-original (msg)
"Cite the body text of MSG, with a \"On %s, %s wrote:\"
line (with the %s's replaced with the date of MSG and the name
or e-mail address of its sender (or 'someone' if nothing
else)), followed of the quoted body of MSG, constructed by by
prepending `mu4e-citation-prefix' to each line. If there is
no body in MSG, return nil."
(let* ((from (plist-get msg :from))
(body (mu4e-body-text msg)))
(when body
(concat
(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)))))
"Return a cited version of the original message MSG (ie., the
plist). This function use gnus' `message-cite-function', and as
such all its settings apply."
(with-temp-buffer
(insert (mu4e-view-message-text msg))
(goto-char (point-min))
(push-mark (point-max))
(funcall message-cite-function)
(pop-mark)
(buffer-string)))
(defun mu4e--header (hdr val)
"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"
(concat
;; if there's no Re: yet, prepend it
(if (string-match (concat "^" mu4e-reply-prefix) subject)
"" mu4e-reply-prefix)
(if (string-match "^Re:" subject) "" "Re:")
subject))
"\n\n"
(mu4e--cite-original origmsg))))
@ -263,9 +256,8 @@ are more than 1 (based on ORIGMSG)."
(mu4e--header "References" (mu4e--refererences-construct origmsg))
(mu4e--header "Subject"
(concat
;; if there's no Re: yet, prepend it
(if (string-match (concat "^" mu4e-forward-prefix) subject)
"" mu4e-forward-prefix)
;; if there's no Fwd: yet, prepend it
(if (string-match "^Fwd:" subject) "" "Fwd:")
subject))
"\n\n"
(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)
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
(defgroup mu4e-folders nil
@ -266,21 +261,6 @@ display with `mu4e-view-toggle-hide-cited (default keybinding:
"Customizations for composing/sending messages."
: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
"The Reply-To address (if this, for some reason, is not equal to
the From: address.)"
@ -307,7 +287,6 @@ sent folder."
;; Faces
(defgroup mu4e-faces nil
"Type faces (fonts) used in mu4e."
:group 'mu4e

View File

@ -43,23 +43,10 @@
wanting to show specific messages - for example, `mu4e-org'."
(mu4e-proc-view msgid))
(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
(defun mu4e-view-message-text (msg)
"Return the message to display (as a string), based on the MSG
plist."
(concat
(mapconcat
(lambda (field)
(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))
(mu4e-view-contacts msg :to)
(mu4e-view-contacts msg :from))))
;; date
(:date
(let ((datestr
@ -101,7 +87,26 @@ marking if it still had that."
(t (error "Unsupported field: %S" field)))))
mu4e-view-fields "")
"\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
(mu4e-view-mode)
@ -130,6 +135,8 @@ marking if it still had that."
(unless update
(mu4e-view-mark-as-read-maybe)))))
(defun mu4e-view-header (key val &optional dont-propertize-val)
"Show header FIELD for MSG with KEY. ie. <KEY>: value-of-FIELD."
(if val