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
|
;; 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>
|
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
;; Maintainer: 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
|
:safe 'symbolp
|
||||||
:group 'mu4e-compose))
|
: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
|
(make-obsolete-variable 'mu4e-compose-crypto-reply-policy "The use of the
|
||||||
'mu4e-compose-crypto-reply-policy' variable is deprecated.
|
'mu4e-compose-crypto-reply-policy' variable is deprecated.
|
||||||
'mu4e-compose-crypto-reply-plain-policy' and
|
'mu4e-compose-crypto-reply-plain-policy' and
|
||||||
@ -182,10 +177,10 @@ We have the following choices:
|
|||||||
"2017-09-02")
|
"2017-09-02")
|
||||||
|
|
||||||
(defcustom mu4e-compose-format-flowed nil
|
(defcustom mu4e-compose-format-flowed nil
|
||||||
"Whether to compose messages to be sent as format=flowed (or
|
"Whether to compose messages to be sent as format=flowed.
|
||||||
with long lines if `use-hard-newlines' is set to nil). The
|
\(Or with long lines if variable `use-hard-newlines' is set to
|
||||||
variable `fill-flowed-encode-column' lets you customize the
|
nil). The variable `fill-flowed-encode-column' lets you customize
|
||||||
width beyond which format=flowed lines are wrapped."
|
the width beyond which format=flowed lines are wrapped."
|
||||||
:type 'boolean
|
:type 'boolean
|
||||||
:safe 'booleanp
|
:safe 'booleanp
|
||||||
:group 'mu4e-compose)
|
:group 'mu4e-compose)
|
||||||
@ -206,8 +201,8 @@ place to do that."
|
|||||||
:group 'mu4e-compose)
|
:group 'mu4e-compose)
|
||||||
|
|
||||||
(defvar mu4e-compose-type nil
|
(defvar mu4e-compose-type nil
|
||||||
"The compose-type for this buffer, which is a symbol, `new',
|
"The compose-type for this buffer.
|
||||||
`forward', `reply' or `edit'.")
|
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))
|
(trash (mu4e-get-trash-folder mu4e-compose-parent-message))
|
||||||
(sent (mu4e-get-sent-folder mu4e-compose-parent-message))
|
(sent (mu4e-get-sent-folder mu4e-compose-parent-message))
|
||||||
(otherwise
|
(otherwise
|
||||||
(mu4e-error "unsupported value '%S' `mu4e-sent-messages-behavior'."
|
(mu4e-error "Unsupported value '%S'
|
||||||
|
`mu4e-sent-messages-behavior'"
|
||||||
mu4e-sent-messages-behavior))))
|
mu4e-sent-messages-behavior))))
|
||||||
(fccfile (and mdir
|
(fccfile (and mdir
|
||||||
(concat mu4e-maildir mdir "/cur/"
|
(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\\):")
|
"^\\(To\\|B?Cc\\|Reply-To\\|From\\):")
|
||||||
|
|
||||||
(defun mu4e~compose-register-message-save-hooks ()
|
(defun mu4e~compose-register-message-save-hooks ()
|
||||||
"Just before saving, we remove the mail-header-separator; just
|
"Just before saving, we remove the `mail-header-separator'.
|
||||||
after saving we restore it; thus, the separator should never
|
Just after saving we restore it; thus, the separator should never
|
||||||
appear on disk."
|
appear on disk."
|
||||||
(add-hook 'before-save-hook
|
(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
|
(add-hook 'after-save-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
(save-match-data
|
||||||
(mu4e~compose-set-friendly-buffer-name)
|
(mu4e~compose-set-friendly-buffer-name)
|
||||||
(mu4e~draft-insert-mail-header-separator)
|
(mu4e~draft-insert-mail-header-separator)
|
||||||
;; hide some headers again
|
;; hide some headers again
|
||||||
@ -315,12 +314,13 @@ appear on disk."
|
|||||||
(set-buffer-modified-p nil)
|
(set-buffer-modified-p nil)
|
||||||
(mu4e-message "Saved (%d lines)" (count-lines (point-min) (point-max)))
|
(mu4e-message "Saved (%d lines)" (count-lines (point-min) (point-max)))
|
||||||
;; update the file on disk -- ie., without the separator
|
;; 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
|
;; address completion; inspired by org-contacts.el and
|
||||||
;; https://github.com/nordlow/elisp/blob/master/mine/completion-styles-cycle.el
|
;; https://github.com/nordlow/elisp/blob/master/mine/completion-styles-cycle.el
|
||||||
(defun mu4e~compose-complete-handler (str pred action)
|
(defun mu4e~compose-complete-handler (str pred action)
|
||||||
|
"Complete address STR with predication PRED for ACTION."
|
||||||
(cond
|
(cond
|
||||||
((eq action nil)
|
((eq action nil)
|
||||||
(try-completion str mu4e~contacts pred))
|
(try-completion str mu4e~contacts pred))
|
||||||
@ -363,9 +363,9 @@ Ie. either 'name <email>' or 'email')."
|
|||||||
'mu4e~compose-complete-contact nil t))
|
'mu4e~compose-complete-contact nil t))
|
||||||
|
|
||||||
(defun mu4e~remove-refs-maybe ()
|
(defun mu4e~remove-refs-maybe ()
|
||||||
"Remove the References: header if the In-Reply-To header is
|
"Remove References: if In-Reply-To: is missing.
|
||||||
missing. This allows the user to effectively start a new
|
This allows the user to effectively start a new message-thread by
|
||||||
message-thread by removing the In-Reply-To header."
|
removing the In-Reply-To header."
|
||||||
(unless (message-fetch-field "in-reply-to")
|
(unless (message-fetch-field "in-reply-to")
|
||||||
(message-remove-header "References")))
|
(message-remove-header "References")))
|
||||||
|
|
||||||
@ -382,10 +382,11 @@ message-thread by removing the In-Reply-To header."
|
|||||||
map)))
|
map)))
|
||||||
|
|
||||||
(defun mu4e-fill-paragraph (&optional region)
|
(defun mu4e-fill-paragraph (&optional region)
|
||||||
"If `use-hard-newlines', takes a multi-line paragraph and makes
|
"Re-layout either the whole message or REGION.
|
||||||
it into a single line of text. Assume paragraphs are separated
|
If variable `use-hard-newlines', takes a multi-line paragraph and
|
||||||
by blank lines. If `use-hard-newlines' is not enabled, this
|
makes it into a single line of text. Assume paragraphs are
|
||||||
simply executes `fill-paragraph'."
|
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
|
;; Inspired by https://www.emacswiki.org/emacs/UnfillParagraph
|
||||||
(interactive (progn (barf-if-buffer-read-only) '(t)))
|
(interactive (progn (barf-if-buffer-read-only) '(t)))
|
||||||
(if mu4e-compose-format-flowed
|
(if mu4e-compose-format-flowed
|
||||||
@ -404,7 +405,8 @@ simply executes `fill-paragraph'."
|
|||||||
(turn-on-auto-fill)))
|
(turn-on-auto-fill)))
|
||||||
|
|
||||||
(defun mu4e~compose-remap-faces ()
|
(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."
|
buffers; lets remap its faces so it uses the ones for mu4e."
|
||||||
;; normal headers
|
;; normal headers
|
||||||
(face-remap-add-relative 'message-header-name
|
(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.")
|
"Maximum length of the mu4e-send-buffer-name.")
|
||||||
|
|
||||||
(defun mu4e~compose-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."
|
"Set some user-friendly buffer name based on the COMPOSE-TYPE."
|
||||||
(let* ((subj (message-field-value "subject"))
|
(let* ((subj (message-field-value "subject"))
|
||||||
(subj (unless (and subj (string-match "^[:blank:]*$" subj)) subj))
|
(subj (unless (and subj (string-match "^[:blank:]*$" subj)) subj))
|
||||||
(str (or subj
|
(str (or subj
|
||||||
@ -548,7 +550,8 @@ buffers; lets remap its faces so it uses the ones for mu4e."
|
|||||||
(buffer-name)))))
|
(buffer-name)))))
|
||||||
|
|
||||||
(defun mu4e~compose-crypto-reply (parent compose-type)
|
(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,
|
automatically encrypt that reply. When the message is unencrypted,
|
||||||
we can decide what we want to do."
|
we can decide what we want to do."
|
||||||
(if (and (eq compose-type 'reply)
|
(if (and (eq compose-type 'reply)
|
||||||
@ -667,9 +670,9 @@ tempfile)."
|
|||||||
(when (fboundp 'mu4e) (mu4e))))))
|
(when (fboundp 'mu4e) (mu4e))))))
|
||||||
|
|
||||||
(defun mu4e-sent-handler (docid path)
|
(defun mu4e-sent-handler (docid path)
|
||||||
"Handler function, called with DOCID and PATH for the just-sent
|
"Handler called with DOCID and PATH for the just-sent message.
|
||||||
message. For Forwarded ('Passed') and Replied messages, try to set
|
For Forwarded ('Passed') and Replied messages, try to set the
|
||||||
the appropriate flag at the message forwarded or replied-to."
|
appropriate flag at the message forwarded or replied-to."
|
||||||
(mu4e~compose-set-parent-flag path)
|
(mu4e~compose-set-parent-flag path)
|
||||||
(when (file-exists-p path) ;; maybe the draft was not saved at all
|
(when (file-exists-p path) ;; maybe the draft was not saved at all
|
||||||
(mu4e~proc-remove docid))
|
(mu4e~proc-remove docid))
|
||||||
@ -697,8 +700,9 @@ It restores mu4e window layout after killing the compose-buffer."
|
|||||||
(mu4e~switch-back-to-mu4e-buffer)))))
|
(mu4e~switch-back-to-mu4e-buffer)))))
|
||||||
|
|
||||||
(defun mu4e~compose-set-parent-flag (path)
|
(defun mu4e~compose-set-parent-flag (path)
|
||||||
"Set the 'replied' \"R\" flag on messages we replied to, and the
|
"Set flags for replied-t and forwarded for the message at PATH.
|
||||||
'passed' \"F\" flag on message we have forwarded.
|
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
|
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
|
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")))))))
|
(mu4e~proc-move (match-string 1 forwarded-from) nil "+P-N")))))))
|
||||||
|
|
||||||
(defun mu4e-compose (compose-type)
|
(defun mu4e-compose (compose-type)
|
||||||
"Start composing a message of COMPOSE-TYPE, where COMPOSE-TYPE
|
"Start composing a message of COMPOSE-TYPE.
|
||||||
is a symbol, one of `reply', `forward', `edit', `resend'
|
COMPOSE-TYPE is a symbol, one of `reply', `forward', `edit',
|
||||||
`new'. All but `new' take the message at point as input. Symbol
|
`resend' `new'. All but `new' take the message at point as input.
|
||||||
`edit' is only allowed for draft messages."
|
Symbol `edit' is only allowed for draft messages."
|
||||||
(let ((msg (mu4e-message-at-point 'noerror)))
|
(let ((msg (mu4e-message-at-point 'noerror)))
|
||||||
;; some sanity checks
|
;; some sanity checks
|
||||||
(unless (or msg (eq compose-type 'new))
|
(unless (or msg (eq compose-type 'new))
|
||||||
@ -810,10 +814,40 @@ draft message."
|
|||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mu4e~compose-mail (&optional to subject other-headers continue
|
(defun mu4e~compose-mail (&optional to subject other-headers continue
|
||||||
switch-function yank-action send-actions return-action)
|
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
|
OTHER-HEADERS is an alist specifying additional
|
||||||
;; this case, but let's prepare for the re-edit case as well
|
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)
|
(mu4e~compose-handler 'new)
|
||||||
|
|
||||||
(when (message-goto-to) ;; reset to-address, if needed
|
(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)
|
(vector 'remap 'end-of-buffer) 'mu4e-compose-goto-bottom)
|
||||||
|
|
||||||
(provide 'mu4e-compose)
|
(provide 'mu4e-compose)
|
||||||
|
;;; mu4e-compose.el ends here
|
||||||
;; Load mu4e completely even when this file was loaded through
|
|
||||||
;; autoload.
|
|
||||||
(require 'mu4e)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user