* rename many internal functions to have a mu4e~ prefix (WIP)

- this allows to distinguish between internal and external stuff
  - the ~ is behind the 'z' in ascii, so last in the completion buffer
This commit is contained in:
djcb
2012-04-23 20:35:14 +03:00
parent 2f2853c0dd
commit 927e26ec05
8 changed files with 473 additions and 484 deletions

View File

@ -38,7 +38,7 @@
(require 'mu4e-view)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mu4e--cite-original (msg)
(defun mu4e~compose-cite-original (msg)
"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."
@ -51,13 +51,13 @@ such all its settings apply."
(buffer-string)))
(defun mu4e--header (hdr val)
(defun mu4e~compose-header (hdr val)
"Return a header line of the form HDR: VAL\n. If VAL is nil,
return nil."
(when val (format "%s: %s\n" hdr val)))
(defun mu4e--refererences-construct (msg)
(defun mu4e~compose-refererences-construct (msg)
"Construct the value of the References: header based on MSG as a
comma-separated string. Normally, this the concatenation of the
existing References (which may be empty) and the message-id. If the
@ -76,7 +76,7 @@ return nil."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; determine the recipient fields for new messages
(defun mu4e--recipients-list-to-string (lst)
(defun mu4e~compose-recipients-list-to-string (lst)
"Convert a lst LST of address cells into a string with a list of
e-mail addresses. If LST is nil, returns nil."
(when lst
@ -89,7 +89,7 @@ e-mail addresses. If LST is nil, returns nil."
(format "%s" email))))
lst ", ")))
(defun mu4e--address-cell-equal (cell1 cell2)
(defun mu4e~compose-address-cell-equal (cell1 cell2)
"Return t if cell1 and cell2 have the same e-mail
address (case-insensitively), nil otherwise. cell1 and cell2 are
cons cells (NAME . EMAIL)."
@ -99,7 +99,7 @@ e-mail addresses. If LST is nil, returns nil."
(defun mu4e--create-to-lst (origmsg)
(defun mu4e~compose-create-to-lst (origmsg)
"Create a list of address for the To: in a new message, based on
the original message ORIGMSG. If the Reply-To address is set, use
that, otherwise use the From address. Note, whatever was in the To:
@ -109,10 +109,10 @@ field before, goes to the Cc:-list (if we're doing a reply-to-all)."
(or reply-to
(delete-duplicates
(plist-get origmsg :from)
:test #'mu4e--address-cell-equal))))
:test #'mu4e~compose-address-cell-equal))))
to-lst))
(defun mu4e--create-cc-lst (origmsg reply-all)
(defun mu4e~compose-create-cc-lst (origmsg reply-all)
"Create a list of address for the Cc: in a new message, based on
the original message ORIGMSG, and whether it's a reply-all."
(when reply-all
@ -121,7 +121,7 @@ the original message ORIGMSG, and whether it's a reply-all."
(append
(plist-get origmsg :to)
(plist-get origmsg :cc))
:test #'mu4e--address-cell-equal))
:test #'mu4e~compose-address-cell-equal))
;; now we have the basic list, but we must remove
;; addresses also in the to list
(cc-lst
@ -129,8 +129,8 @@ the original message ORIGMSG, and whether it's a reply-all."
(lambda (cc-cell)
(find-if
(lambda (to-cell)
(mu4e--address-cell-equal cc-cell to-cell))
(mu4e--create-to-lst origmsg)))
(mu4e~compose-address-cell-equal cc-cell to-cell))
(mu4e~compose-create-to-lst origmsg)))
cc-lst))
;; finally, we need to remove ourselves from the cc-list
(cc-lst
@ -138,27 +138,27 @@ the original message ORIGMSG, and whether it's a reply-all."
cc-lst
(delete-if
(lambda (cc-cell)
(mu4e--address-cell-equal cc-cell
(mu4e~compose-address-cell-equal cc-cell
(cons nil user-mail-address)))
cc-lst))))
cc-lst)))
(defun mu4e--recipients-construct (field origmsg &optional reply-all)
(defun mu4e~compose-recipients-construct (field origmsg &optional reply-all)
"Create value (a string) for the recipient field FIELD (a
symbol, :to or :cc), based on the original message ORIGMSG,
and (optionally) REPLY-ALL which indicates this is a reply-to-all
message. Return nil if there are no recipients for the particular field."
(mu4e--recipients-list-to-string
(mu4e~compose-recipients-list-to-string
(case field
(:to
(mu4e--create-to-lst origmsg))
(mu4e~compose-create-to-lst origmsg))
(:cc
(mu4e--create-cc-lst origmsg reply-all))
(mu4e~compose-create-cc-lst origmsg reply-all))
(otherwise
(error "Unsupported field")))))
(defun mu4e--from-construct ()
(defun mu4e~compose-from-construct ()
"Construct a value for the From:-field of the reply to MSG,
based on `user-full-name' and `user-mail-address'; if the latter is
nil, function returns nil."
@ -169,10 +169,10 @@ nil, function returns nil."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mu4e--insert-mail-header-separator ()
(defun mu4e~compose-insert-mail-header-separator ()
"Insert `mail-header-separator' in the first empty line of the
message. message-mode needs this line to know where the headers end
and the body starts. Note, in `mu4e-edit-mode, we use
and the body starts. Note, in `mu4e-compose-mode, we use
`before-save-hook' and `after-save-hook' to ensure that this
separator is never written to file. Also see
`mu4e-remove-mail-header-separator'."
@ -187,22 +187,22 @@ separator is never written to file. Also see
(goto-char (point-max))
(insert (concat "\n" mail-header-separator "\n"))))))
(defun mu4e--remove-mail-header-separator ()
(defun mu4e~compose-remove-mail-header-separator ()
"Remove `mail-header-separator; we do this before saving a
file (and restore it afterwardds), to ensure that the separator
never hits the disk. Also see `mu4e--insert-mail-header-separator."
never hits the disk. Also see `mu4e~compose-insert-mail-header-separator."
(save-excursion
(goto-char (point-min))
;; remove the --text follows this line-- separator
(when (search-forward-regexp (concat "^" mail-header-separator))
(replace-match ""))))
(defun mu4e--user-wants-reply-all (origmsg)
(defun mu4e~compose-user-wants-reply-all (origmsg)
"Ask user whether she wants to reply to *all* recipients if there
are more than 1 (based on ORIGMSG)."
(let* ((recipnum
(+ (length (mu4e--create-to-lst origmsg))
(length (mu4e--create-cc-lst origmsg t))))
(+ (length (mu4e~compose-create-to-lst origmsg))
(length (mu4e~compose-create-cc-lst origmsg t))))
(response
(if (= recipnum 1)
?a ;; with one recipient, we can reply to 'all'....
@ -213,68 +213,68 @@ are more than 1 (based on ORIGMSG)."
(= response ?a)))
(defun mu4e--reply-construct (origmsg)
(defun mu4e~compose-reply-construct (origmsg)
"Create a draft message as a reply to original message ORIGMSG."
(let* ((recipnum
(+ (length (mu4e--create-to-lst origmsg))
(length (mu4e--create-cc-lst origmsg t))))
(reply-all (mu4e--user-wants-reply-all origmsg))
(+ (length (mu4e~compose-create-to-lst origmsg))
(length (mu4e~compose-create-cc-lst origmsg t))))
(reply-all (mu4e~compose-user-wants-reply-all origmsg))
(old-msgid (plist-get origmsg :message-id))
(subject (or (plist-get origmsg :subject) "")))
(concat
(mu4e--header "From" (or (mu4e--from-construct) ""))
(mu4e--header "Reply-To" mu4e-reply-to-address)
(mu4e--header "To" (mu4e--recipients-construct :to origmsg))
(mu4e--header "Cc" (mu4e--recipients-construct :cc origmsg
(mu4e~compose-header "From" (or (mu4e~compose-from-construct) ""))
(mu4e~compose-header "Reply-To" mu4e-reply-to-address)
(mu4e~compose-header "To" (mu4e~compose-recipients-construct :to origmsg))
(mu4e~compose-header "Cc" (mu4e~compose-recipients-construct :cc origmsg
reply-all))
(mu4e--header "User-agent" (mu4e-user-agent))
(mu4e--header "References" (mu4e--refererences-construct origmsg))
(mu4e~compose-header "User-agent" (mu4e-user-agent))
(mu4e~compose-header "References" (mu4e~compose-refererences-construct origmsg))
(when old-msgid
(mu4e--header "In-reply-to" (format "<%s>" old-msgid)))
(mu4e~compose-header "In-reply-to" (format "<%s>" old-msgid)))
(mu4e--header "Subject"
(mu4e~compose-header "Subject"
(concat
;; if there's no Re: yet, prepend it
(if (string-match "^Re:" subject) "" "Re:")
subject))
"\n\n"
(mu4e--cite-original origmsg))))
(mu4e~compose-cite-original origmsg))))
(defun mu4e--forward-construct (origmsg)
(defun mu4e~compose-forward-construct (origmsg)
"Create a draft forward message for original message ORIGMSG."
(let ((subject
(or (plist-get origmsg :subject) "")))
(concat
(mu4e--header "From" (or (mu4e--from-construct) ""))
(mu4e--header "Reply-To" mu4e-reply-to-address)
(mu4e--header "To" "")
(mu4e--header "User-agent" (mu4e-user-agent))
(mu4e--header "References" (mu4e--refererences-construct origmsg))
(mu4e--header "Subject"
(mu4e~compose-header "From" (or (mu4e~compose-from-construct) ""))
(mu4e~compose-header "Reply-To" mu4e-reply-to-address)
(mu4e~compose-header "To" "")
(mu4e~compose-header "User-agent" (mu4e-user-agent))
(mu4e~compose-header "References" (mu4e~compose-refererences-construct origmsg))
(mu4e~compose-header "Subject"
(concat
;; if there's no Fwd: yet, prepend it
(if (string-match "^Fwd:" subject) "" "Fwd:")
subject))
"\n\n"
(mu4e--cite-original origmsg))))
(mu4e~compose-cite-original origmsg))))
(defun mu4e--newmsg-construct ()
(defun mu4e~compose-newmsg-construct ()
"Create a new message."
(concat
(mu4e--header "From" (or (mu4e--from-construct) ""))
(mu4e--header "Reply-To" mu4e-reply-to-address)
(mu4e--header "To" "")
(mu4e--header "User-agent" (mu4e-user-agent))
(mu4e--header "Subject" "")
(mu4e~compose-header "From" (or (mu4e~compose-from-construct) ""))
(mu4e~compose-header "Reply-To" mu4e-reply-to-address)
(mu4e~compose-header "To" "")
(mu4e~compose-header "User-agent" (mu4e-user-agent))
(mu4e~compose-header "Subject" "")
"\n"))
(defun mu4e--open-new-draft-file (compose-type &optional msg)
(defun mu4e~compose-open-new-draft-file (compose-type &optional msg)
"Open a draft file for a new message, creating it if it does not
already exist, and optionally fill it with STR. Function also adds
the new message to the database. When the draft message is added to
@ -293,9 +293,9 @@ use the new docid. Returns the full path to the new message."
(format-time-string "%Y%m%d" (current-time))
(emacs-pid) (random t) hostname)))
(str (case compose-type
(reply (mu4e--reply-construct msg))
(forward (mu4e--forward-construct msg))
(new (mu4e--newmsg-construct))
(reply (mu4e~compose-reply-construct msg))
(forward (mu4e~compose-forward-construct msg))
(new (mu4e~compose-newmsg-construct))
(t (error "unsupported compose-type %S" compose-type)))))
(when str
(with-current-buffer (find-file-noselect draft)
@ -303,13 +303,13 @@ use the new docid. Returns the full path to the new message."
draft)) ;; return the draft buffer file
(define-derived-mode mu4e-edit-mode message-mode "mu4e:edit"
(define-derived-mode mu4e-compose-mode message-mode "mu4e:compose"
"Major mode for the mu4e message composition, derived from `message-mode'.
\\{message-mode-map}."
(let ((message-hidden-headers
`("^References:" "^Face:" "^X-Face:" "^X-Draft-From:"
"^User-agent:")))
(use-local-map mu4e-edit-mode-map)
(use-local-map mu4e-compose-mode-map)
(message-hide-headers)
(make-local-variable 'before-save-hook)
(make-local-variable 'after-save-hook)
@ -325,23 +325,23 @@ use the new docid. Returns the full path to the new message."
;; hack-hack-hack... just before saving, we remove the
;; mail-header-separator; just after saving we restore it; thus, the
;; separator should never appear on disk
(add-hook 'before-save-hook 'mu4e--remove-mail-header-separator)
(add-hook 'before-save-hook 'mu4e~compose-remove-mail-header-separator)
(add-hook 'after-save-hook
(lambda ()
(mu4e--set-friendly-buffer-name)
(mu4e--insert-mail-header-separator)
(mu4e~compose-set-friendly-buffer-name)
(mu4e~compose-insert-mail-header-separator)
(set-buffer-modified-p nil)))
;; update the db when the file is saved...]
(add-hook 'after-save-hook
(lambda()
(mu4e-proc-add (buffer-file-name) mu4e-drafts-folder))))
(mu4e~proc-add (buffer-file-name) mu4e-drafts-folder))))
;; notify the backend that a message has been sent. The backend will respond
;; with (:sent ...) sexp, which is handled in `mu4e-compose-handler'.
(add-hook 'message-sent-hook
(lambda ()
(set-buffer-modified-p t)
(basic-save-buffer)
(mu4e-proc-sent (buffer-file-name) mu4e-drafts-folder)))
(mu4e~proc-sent (buffer-file-name) mu4e-drafts-folder)))
;; register the function; this function will be called when the '(:sent...)'
;; message is received (see mu4e-proc.el) with parameters docid and path
(setq mu4e-sent-func 'mu4e-sent-handler)
@ -351,10 +351,10 @@ use the new docid. Returns the full path to the new message."
(setq default-directory (expand-file-name "~/")))
(defconst mu4e--buffer-max-name-length 30
(defconst mu4e~compose-buffer-max-name-length 30
"Maximum length of the mu4e-send-buffer-name.")
(defun mu4e--set-friendly-buffer-name (&optional compose-type)
(defun mu4e~compose-set-friendly-buffer-name (&optional compose-type)
"Set some user-friendly buffer name based on the compose type."
(let* ((subj (message-field-value "subject"))
(subj (unless (and subj (string-match "^[:blank:]*$" subj)) subj))
@ -365,7 +365,7 @@ use the new docid. Returns the full path to the new message."
(otherwise "*draft*")))))
(rename-buffer (generate-new-buffer-name
(truncate-string-to-width str
mu4e--buffer-max-name-length
mu4e~compose-buffer-max-name-length
nil nil t)))))
@ -395,22 +395,22 @@ The name of the draft folder is constructed from the concatenation
The message file name is a unique name determined by
`mu4e-send-draft-file-name'.
The initial STR would be created from either `mu4e--reply-construct',
ar`mu4e--forward-construct' or `mu4e--newmsg-construct'. The editing buffer is
The initial STR would be created from either `mu4e~compose-reply-construct',
ar`mu4e~compose-forward-construct' or `mu4e~compose-newmsg-construct'. The editing buffer is
using Gnus' `message-mode'."
(unless mu4e-maildir (error "mu4e-maildir not set"))
(unless mu4e-drafts-folder (error "mu4e-drafts-folder not set"))
(let ((draft
(if (member compose-type '(reply forward new))
(mu4e--open-new-draft-file compose-type original-msg)
(mu4e~compose-open-new-draft-file compose-type original-msg)
(if (eq compose-type 'edit)
(plist-get original-msg :path)
(error "unsupported compose-type %S" compose-type)))))
(find-file draft)
(mu4e-edit-mode)
(mu4e-compose-mode)
;; insert mail-header-separator, which is needed by message mode to separate
;; headers and body. will be removed before saving to disk
(mu4e--insert-mail-header-separator)
(mu4e~compose-insert-mail-header-separator)
;; include files -- e.g. when forwarding a message with attachments,
;; we take those from the original.
(save-excursion
@ -428,7 +428,7 @@ using Gnus' `message-mode'."
(if (member compose-type '(new forward))
(message-goto-to)
(message-goto-body))
(mu4e--set-friendly-buffer-name compose-type)
(mu4e~compose-set-friendly-buffer-name compose-type)
;; buffer is not user-modified yet
(set-buffer-modified-p nil)))
@ -452,13 +452,13 @@ message."
(with-current-buffer(find-file-noselect path)
;; for Forward ('Passed') and Replied messages, try to set the appropriate
;; flag at the message forwarded or replied-to
(mu4e--set-parent-flag docid path)
(mu4e~compose-set-parent-flag docid path)
;; handle the draft -- should it be moved to the sent-folder, or elsewhere?
(mu4e--save-copy-maybe docid path)
(mu4e~compose-save-copy-maybe docid path)
;; now, get rid of the buffer
(kill-buffer)))
(defun mu4e--save-copy-maybe (docid path)
(defun mu4e~compose-save-copy-maybe (docid path)
"Handler function, called with DOCID and PATH for the just-sent
message, which will move it to the sent-folder or elsewhere,
depending on the value of `mu4e-sent-messages-behavior'.
@ -467,16 +467,16 @@ Function assumes that it's executed in the context of the message
buffer."
;; first, what to do with the draft message in PATH?
(if (eq mu4e-sent-messages-behavior 'delete)
(mu4e-proc-remove docid) ;; remove it
(mu4e~proc-remove docid) ;; remove it
;; otherwise,
(progn ;; prepare the message for saving
(basic-save-buffer)
;; now either move it to trash or to sent
(if (eq mu4e-sent-messages-behavior 'trash)
(mu4e-proc-move docid mu4e-trash-folder "+T-D+S")
(mu4e-proc-move docid mu4e-sent-folder "-T-D+S")))))
(mu4e~proc-move docid mu4e-trash-folder "+T-D+S")
(mu4e~proc-move docid mu4e-sent-folder "-T-D+S")))))
(defun mu4e--set-parent-flag (docid path)
(defun mu4e~compose-set-parent-flag (docid path)
"Set the 'replied' \"R\" flag on messages we replied to, and the
'passed' \"F\" flag on message we have forwarded.
@ -509,9 +509,9 @@ buffer.
(setq forwarded-from (first refs))))))
;; remove the <>
(when (and in-reply-to (string-match "<\\(.*\\)>" in-reply-to))
(mu4e-proc-move (match-string 1 in-reply-to) nil "+R"))
(mu4e~proc-move (match-string 1 in-reply-to) nil "+R"))
(when (and forwarded-from (string-match "<\\(.*\\)>" forwarded-from))
(mu4e-proc-move (match-string 1 forwarded-from) nil "+P"))))
(mu4e~proc-move (match-string 1 forwarded-from) nil "+P"))))
@ -519,7 +519,7 @@ buffer.
;; mu4e-compose-func and mu4e-send-func are wrappers so we can set ourselves
;; as default emacs mailer (define-mail-user-agent etc.)
(defun mu4e--compose-func (&optional to subject other-headers continue
(defun mu4e~compose-compose-func (&optional to subject other-headers continue
switch-function yank-action send-actions return-action)
"mu4e's implementation of `compose-mail'."