mu4e-contacts: cleanups, save-match-data
Whitespace cleanups Flycheck cleanups Save the match data for (after|before)-save-hook
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
;; -*-mode: emacs-lisp; tab-width: 8; indent-tabs-mode: t -*-
|
||||
;; mu4e-compose.el -- part of mu4e, the mu mail user agent for emacs
|
||||
;;
|
||||
;; Copyright (C) 2011-2016 Dirk-Jan C. Binnema
|
||||
;; Copyright (C) 2011-2019 Dirk-Jan C. Binnema
|
||||
|
||||
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
@ -171,10 +170,6 @@ We have the following choices:
|
||||
:safe 'symbolp
|
||||
:group 'mu4e-compose))
|
||||
|
||||
(defcustom mu4e-compose-crypto-reply-policy nil "The use of the
|
||||
'mu4e-compose-crypto-reply-policy' variable is deprecated.
|
||||
'mu4e-compose-crypto-reply-plain-policy' and
|
||||
'mu4e-compose-crypto-reply-encrypted-policy' should be used instead")
|
||||
(make-obsolete-variable 'mu4e-compose-crypto-reply-policy "The use of the
|
||||
'mu4e-compose-crypto-reply-policy' variable is deprecated.
|
||||
'mu4e-compose-crypto-reply-plain-policy' and
|
||||
@ -182,10 +177,10 @@ We have the following choices:
|
||||
"2017-09-02")
|
||||
|
||||
(defcustom mu4e-compose-format-flowed nil
|
||||
"Whether to compose messages to be sent as format=flowed (or
|
||||
with long lines if `use-hard-newlines' is set to nil). The
|
||||
variable `fill-flowed-encode-column' lets you customize the
|
||||
width beyond which format=flowed lines are wrapped."
|
||||
"Whether to compose messages to be sent as format=flowed.
|
||||
\(Or with long lines if variable `use-hard-newlines' is set to
|
||||
nil). The variable `fill-flowed-encode-column' lets you customize
|
||||
the width beyond which format=flowed lines are wrapped."
|
||||
:type 'boolean
|
||||
:safe 'booleanp
|
||||
:group 'mu4e-compose)
|
||||
@ -206,8 +201,8 @@ place to do that."
|
||||
:group 'mu4e-compose)
|
||||
|
||||
(defvar mu4e-compose-type nil
|
||||
"The compose-type for this buffer, which is a symbol, `new',
|
||||
`forward', `reply' or `edit'.")
|
||||
"The compose-type for this buffer.
|
||||
This is a symbol, `new', `forward', `reply' or `edit'.")
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@ -262,7 +257,8 @@ If needed, set the Fcc header, and register the handler function."
|
||||
(trash (mu4e-get-trash-folder mu4e-compose-parent-message))
|
||||
(sent (mu4e-get-sent-folder mu4e-compose-parent-message))
|
||||
(otherwise
|
||||
(mu4e-error "unsupported value '%S' `mu4e-sent-messages-behavior'."
|
||||
(mu4e-error "Unsupported value '%S'
|
||||
`mu4e-sent-messages-behavior'"
|
||||
mu4e-sent-messages-behavior))))
|
||||
(fccfile (and mdir
|
||||
(concat mu4e-maildir mdir "/cur/"
|
||||
@ -300,13 +296,16 @@ If needed, set the Fcc header, and register the handler function."
|
||||
"^\\(To\\|B?Cc\\|Reply-To\\|From\\):")
|
||||
|
||||
(defun mu4e~compose-register-message-save-hooks ()
|
||||
"Just before saving, we remove the mail-header-separator; just
|
||||
after saving we restore it; thus, the separator should never
|
||||
"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~draft-remove-mail-header-separator nil t)
|
||||
(lambda()
|
||||
(save-match-data
|
||||
(mu4e~draft-remove-mail-header-separator))) nil t)
|
||||
(add-hook 'after-save-hook
|
||||
(lambda ()
|
||||
(save-match-data
|
||||
(mu4e~compose-set-friendly-buffer-name)
|
||||
(mu4e~draft-insert-mail-header-separator)
|
||||
;; hide some headers again
|
||||
@ -315,12 +314,13 @@ appear on disk."
|
||||
(set-buffer-modified-p nil)
|
||||
(mu4e-message "Saved (%d lines)" (count-lines (point-min) (point-max)))
|
||||
;; update the file on disk -- ie., without the separator
|
||||
(mu4e~proc-add (buffer-file-name) mu4e~draft-drafts-folder)) nil t))
|
||||
(mu4e~proc-add (buffer-file-name) mu4e~draft-drafts-folder))) nil t))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; address completion; inspired by org-contacts.el and
|
||||
;; https://github.com/nordlow/elisp/blob/master/mine/completion-styles-cycle.el
|
||||
(defun mu4e~compose-complete-handler (str pred action)
|
||||
"Complete address STR with predication PRED for ACTION."
|
||||
(cond
|
||||
((eq action nil)
|
||||
(try-completion str mu4e~contacts pred))
|
||||
@ -363,9 +363,9 @@ Ie. either 'name <email>' or 'email')."
|
||||
'mu4e~compose-complete-contact nil t))
|
||||
|
||||
(defun mu4e~remove-refs-maybe ()
|
||||
"Remove the References: header if the In-Reply-To header is
|
||||
missing. This allows the user to effectively start a new
|
||||
message-thread by removing the In-Reply-To header."
|
||||
"Remove References: if In-Reply-To: is missing.
|
||||
This allows the user to effectively start a new message-thread by
|
||||
removing the In-Reply-To header."
|
||||
(unless (message-fetch-field "in-reply-to")
|
||||
(message-remove-header "References")))
|
||||
|
||||
@ -382,10 +382,11 @@ message-thread by removing the In-Reply-To header."
|
||||
map)))
|
||||
|
||||
(defun mu4e-fill-paragraph (&optional region)
|
||||
"If `use-hard-newlines', takes a multi-line paragraph and makes
|
||||
it into a single line of text. Assume paragraphs are separated
|
||||
by blank lines. If `use-hard-newlines' is not enabled, this
|
||||
simply executes `fill-paragraph'."
|
||||
"Re-layout either the whole message or REGION.
|
||||
If variable `use-hard-newlines', takes a multi-line paragraph and
|
||||
makes it into a single line of text. Assume paragraphs are
|
||||
separated by blank lines. If variable `use-hard-newlines' is not
|
||||
set, this simply executes `fill-paragraph'."
|
||||
;; Inspired by https://www.emacswiki.org/emacs/UnfillParagraph
|
||||
(interactive (progn (barf-if-buffer-read-only) '(t)))
|
||||
(if mu4e-compose-format-flowed
|
||||
@ -404,7 +405,8 @@ simply executes `fill-paragraph'."
|
||||
(turn-on-auto-fill)))
|
||||
|
||||
(defun mu4e~compose-remap-faces ()
|
||||
"Our parent `message-mode' uses font-locking for the compose
|
||||
"Remap `message-mode' faces to mu4e ones.
|
||||
Our parent `message-mode' uses font-locking for the compose
|
||||
buffers; lets remap its faces so it uses the ones for mu4e."
|
||||
;; normal headers
|
||||
(face-remap-add-relative 'message-header-name
|
||||
@ -533,7 +535,7 @@ buffers; lets remap its faces so it uses the ones for mu4e."
|
||||
"Maximum length of the mu4e-send-buffer-name.")
|
||||
|
||||
(defun mu4e~compose-set-friendly-buffer-name (&optional compose-type)
|
||||
"Set some user-friendly buffer name based on the 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))
|
||||
(str (or subj
|
||||
@ -548,7 +550,8 @@ buffers; lets remap its faces so it uses the ones for mu4e."
|
||||
(buffer-name)))))
|
||||
|
||||
(defun mu4e~compose-crypto-reply (parent compose-type)
|
||||
"When composing a reply to an encrypted message, we can
|
||||
"Possibly encrypt or sign a message based on PARENT and COMPOSE-TYPE.
|
||||
When composing a reply to an encrypted message, we can
|
||||
automatically encrypt that reply. When the message is unencrypted,
|
||||
we can decide what we want to do."
|
||||
(if (and (eq compose-type 'reply)
|
||||
@ -667,9 +670,9 @@ tempfile)."
|
||||
(when (fboundp 'mu4e) (mu4e))))))
|
||||
|
||||
(defun mu4e-sent-handler (docid path)
|
||||
"Handler function, called with DOCID and PATH for the just-sent
|
||||
message. For Forwarded ('Passed') and Replied messages, try to set
|
||||
the appropriate flag at the message forwarded or replied-to."
|
||||
"Handler called with DOCID and PATH for the just-sent message.
|
||||
For Forwarded ('Passed') and Replied messages, try to set the
|
||||
appropriate flag at the message forwarded or replied-to."
|
||||
(mu4e~compose-set-parent-flag path)
|
||||
(when (file-exists-p path) ;; maybe the draft was not saved at all
|
||||
(mu4e~proc-remove docid))
|
||||
@ -697,8 +700,9 @@ It restores mu4e window layout after killing the compose-buffer."
|
||||
(mu4e~switch-back-to-mu4e-buffer)))))
|
||||
|
||||
(defun mu4e~compose-set-parent-flag (path)
|
||||
"Set the 'replied' \"R\" flag on messages we replied to, and the
|
||||
'passed' \"F\" flag on message we have forwarded.
|
||||
"Set flags for replied-t and forwarded for the message at PATH.
|
||||
That is, set the 'replied' \"R\" flag on messages we replied to,
|
||||
and the 'passed' \"F\" flag on message we have forwarded.
|
||||
|
||||
If a message has an 'in-reply-to' header, it is considered a reply
|
||||
to the message with the corresponding message id. If it does not
|
||||
@ -738,10 +742,10 @@ buffer."
|
||||
(mu4e~proc-move (match-string 1 forwarded-from) nil "+P-N")))))))
|
||||
|
||||
(defun mu4e-compose (compose-type)
|
||||
"Start composing a message of COMPOSE-TYPE, where COMPOSE-TYPE
|
||||
is a symbol, one of `reply', `forward', `edit', `resend'
|
||||
`new'. All but `new' take the message at point as input. Symbol
|
||||
`edit' is only allowed for draft messages."
|
||||
"Start composing a message of COMPOSE-TYPE.
|
||||
COMPOSE-TYPE is a symbol, one of `reply', `forward', `edit',
|
||||
`resend' `new'. All but `new' take the message at point as input.
|
||||
Symbol `edit' is only allowed for draft messages."
|
||||
(let ((msg (mu4e-message-at-point 'noerror)))
|
||||
;; some sanity checks
|
||||
(unless (or msg (eq compose-type 'new))
|
||||
@ -810,10 +814,40 @@ draft message."
|
||||
;;;###autoload
|
||||
(defun mu4e~compose-mail (&optional to subject other-headers continue
|
||||
switch-function yank-action send-actions return-action)
|
||||
"This is mu4e's implementation of `compose-mail'."
|
||||
"This is mu4e's implementation of `compose-mail'.
|
||||
Quoting its docstring:
|
||||
Start composing a mail message to send.
|
||||
This uses the user’s chosen mail composition package
|
||||
as selected with the variable ‘mail-user-agent’.
|
||||
The optional arguments TO and SUBJECT specify recipients
|
||||
and the initial Subject field, respectively.
|
||||
|
||||
;; create a new draft message 'resetting' (as below) is not actually needed in
|
||||
;; this case, but let's prepare for the re-edit case as well
|
||||
OTHER-HEADERS is an alist specifying additional
|
||||
header fields. Elements look like (HEADER . VALUE) where both
|
||||
HEADER and VALUE are strings.
|
||||
|
||||
CONTINUE, if non-nil, says to continue editing a message already
|
||||
being composed. Interactively, CONTINUE is the prefix argument.
|
||||
|
||||
SWITCH-FUNCTION, if non-nil, is a function to use to
|
||||
switch to and display the buffer used for mail composition.
|
||||
|
||||
YANK-ACTION, if non-nil, is an action to perform, if and when necessary,
|
||||
to insert the raw text of the message being replied to.
|
||||
It has the form (FUNCTION . ARGS). The user agent will apply
|
||||
FUNCTION to ARGS, to insert the raw text of the original message.
|
||||
\(The user agent will also run ‘mail-citation-hook’, *after* the
|
||||
original text has been inserted in this way.)
|
||||
|
||||
SEND-ACTIONS is a list of actions to call when the message is sent.
|
||||
Each action has the form (FUNCTION . ARGS).
|
||||
|
||||
RETURN-ACTION, if non-nil, is an action for returning to the
|
||||
caller. It has the form (FUNCTION . ARGS). The function is
|
||||
called after the mail has been sent or put aside, and the mail
|
||||
buffer buried."
|
||||
;; create a new draft message 'resetting' (as below) is not actually needed in this case, but
|
||||
;; let's prepare for the re-edit case as well
|
||||
(mu4e~compose-handler 'new)
|
||||
|
||||
(when (message-goto-to) ;; reset to-address, if needed
|
||||
@ -891,7 +925,4 @@ end of the buffer."
|
||||
(vector 'remap 'end-of-buffer) 'mu4e-compose-goto-bottom)
|
||||
|
||||
(provide 'mu4e-compose)
|
||||
|
||||
;; Load mu4e completely even when this file was loaded through
|
||||
;; autoload.
|
||||
(require 'mu4e)
|
||||
;;; mu4e-compose.el ends here
|
||||
|
||||
Reference in New Issue
Block a user