Use functions instead of lambdas in add-hook calls

This commit is contained in:
Thierry Volpiatto 2020-11-13 11:38:50 +01:00
parent 861194f9a1
commit 0109172ad4
No known key found for this signature in database
GPG Key ID: 08FDB07A7433A7F2
7 changed files with 84 additions and 55 deletions

View File

@ -354,25 +354,32 @@ Just after saving we restore it; thus, the separator should never
appear on disk. Also update the Date and ensure we have a
Message-ID."
(add-hook 'before-save-hook
(lambda()
;; replace the date
(save-excursion
(message-remove-header "Date")
(message-generate-headers '(Date Message-ID))
(save-match-data
(mu4e~draft-remove-mail-header-separator)))) nil t)
#'mu4e~compose-before-save-hook-fn
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
(widen)
(mu4e~compose-hide-headers)
(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)))) nil t))
#'mu4e~compose-after-save-hook-fn
nil t))
(defun mu4e~compose-before-save-hook-fn ()
;; replace the date
(save-excursion
(message-remove-header "Date")
(message-generate-headers '(Date Message-ID))
(save-match-data
(mu4e~draft-remove-mail-header-separator))))
(defun mu4e~compose-after-save-hook-fn ()
(save-match-data
(mu4e~compose-set-friendly-buffer-name)
(mu4e~draft-insert-mail-header-separator)
;; hide some headers again
(widen)
(mu4e~compose-hide-headers)
(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))))
;;; address completion
@ -563,26 +570,34 @@ buffers; lets remap its faces so it uses the ones for mu4e."
;; setup the fcc-stuff, if needed
(add-hook 'message-send-hook
(lambda () ;; mu4e~compose-save-before-sending
;; when in-reply-to was removed, remove references as well.
(when (eq mu4e-compose-type 'reply)
(mu4e~remove-refs-maybe))
(when use-hard-newlines
(mu4e-send-harden-newlines))
;; for safety, always save the draft before sending
(set-buffer-modified-p t)
(save-buffer)
(mu4e~compose-setup-fcc-maybe)
(widen)) nil t)
#'mu4e~setup-fcc-message-sent-hook-fn
nil t)
;; when the message has been sent.
(add-hook 'message-sent-hook
(lambda () ;; mu4e~compose-mark-after-sending
(setq mu4e-sent-func 'mu4e-sent-handler)
(mu4e~proc-sent (buffer-file-name))) nil t))
#'mu4e~set-sent-handler-message-sent-hook-fn
nil t))
;; mark these two hooks as permanent-local, so they'll survive mode-changes
;; (put 'mu4e~compose-save-before-sending 'permanent-local-hook t)
(put 'mu4e~compose-mark-after-sending 'permanent-local-hook t))
(defun mu4e~setup-fcc-message-sent-hook-fn ()
;; mu4e~compose-save-before-sending
;; when in-reply-to was removed, remove references as well.
(when (eq mu4e-compose-type 'reply)
(mu4e~remove-refs-maybe))
(when use-hard-newlines
(mu4e-send-harden-newlines))
;; for safety, always save the draft before sending
(set-buffer-modified-p t)
(save-buffer)
(mu4e~compose-setup-fcc-maybe)
(widen))
(defun mu4e~set-sent-handler-message-sent-hook-fn ()
;; mu4e~compose-mark-after-sending
(setq mu4e-sent-func 'mu4e-sent-handler)
(mu4e~proc-sent (buffer-file-name)))
(defun mu4e-send-harden-newlines ()
"Set the hard property to all newlines."
(save-excursion

View File

@ -59,16 +59,18 @@
;;
;; Allow bookmarking a mu4e buffer in regular emacs bookmarks.
(defun mu4e~view-set-bookmark-make-record-fn ()
(set (make-local-variable 'bookmark-make-record-function)
'mu4e-view-bookmark-make-record))
(defun mu4e~headers-set-bookmark-make-record-fn ()
(set (make-local-variable 'bookmark-make-record-function)
'mu4e-view-bookmark-make-record))
;; Probably this can be moved to mu4e-view.el.
(add-hook 'mu4e-view-mode-hook
(lambda ()
(set (make-local-variable 'bookmark-make-record-function)
'mu4e-view-bookmark-make-record)))
(add-hook 'mu4e-view-mode-hook #'mu4e~view-set-bookmark-make-record-fn)
;; And this can be moved to mu4e-headers.el.
(add-hook 'mu4e-headers-mode-hook
(lambda ()
(set (make-local-variable 'bookmark-make-record-function)
'mu4e-view-bookmark-make-record)))
(add-hook 'mu4e-headers-mode-hook #'mu4e~headers-set-bookmark-make-record-fn)
(defun mu4e-view-bookmark-make-record ()
"Make a bookmark entry for a mu4e buffer. Note that this is an

View File

@ -1136,7 +1136,8 @@ no user-interaction ongoing."
;; maybe update the current headers upon indexing changes
(add-hook 'mu4e-index-updated-hook 'mu4e~headers-maybe-auto-update)
(add-hook 'mu4e-index-updated-hook
(lambda() (run-hooks 'mu4e-message-changed-hook)) t)
#'mu4e~headers-index-updated-hook-fn
t)
(setq
truncate-lines t
buffer-undo-list t ;; don't record undo information
@ -1146,6 +1147,9 @@ no user-interaction ongoing."
(mu4e~mark-initialize) ;; initialize the marking subsystem
(hl-line-mode 1))
(defun mu4e~headers-index-updated-hook-fn ()
(run-hooks 'mu4e-message-changed-hook))
;;; Highlighting
(defvar mu4e~highlighted-docid nil

View File

@ -163,10 +163,12 @@ response in icalendar format."
;; also trash the message (thus must be appended to hooks).
(add-hook
'message-sent-hook
(lambda () (setq mu4e-sent-func
(mu4e~icalendar-trash-message original-msg)))
#'mu4e~icalendar-setup-sent-hook-fn
t t))))
(defun mu4e~icalendar-setup-sent-hook-fn ()
(setq mu4e-sent-func
(mu4e~icalendar-trash-message original-msg)))
(defun mu4e~icalendar-insert-diary (event reply-status filename)
"Insert a diary entry for the EVENT in file named FILENAME.

View File

@ -55,11 +55,7 @@
(defun mu4e-speedbar-install-variables ()
"Install those variables used by speedbar to enhance mu4e."
(add-hook 'mu4e-context-changed-hook
(lambda()
(when (buffer-live-p speedbar-buffer)
(with-current-buffer speedbar-buffer
(let ((inhibit-read-only t))
(mu4e-speedbar-buttons))))))
#'mu4e~speedbar-context-changed-hook-fn)
(dolist (keymap
'( mu4e-main-speedbar-key-map
mu4e-headers-speedbar-key-map
@ -69,6 +65,12 @@
(define-key keymap "RET" 'speedbar-edit-line)
(define-key keymap "e" 'speedbar-edit-line))))
(defun mu4e~speedbar-context-changed-hook-fn ()
(when (buffer-live-p speedbar-buffer)
(with-current-buffer speedbar-buffer
(let ((inhibit-read-only t))
(mu4e-speedbar-buttons)))))
;; Make sure our special speedbar major mode is loaded
(if (featurep 'speedbar)
(mu4e-speedbar-install-variables)

View File

@ -407,13 +407,15 @@ article-mode."
(mu4e-view-mode)
(setq gnus-article-decoded-p gnus-article-decode-hook)
(set-buffer-modified-p nil)
(add-hook 'kill-buffer-hook
(lambda() ;; cleanup the mm-* buffers that the view spawns
(when mu4e~gnus-article-mime-handles
(mm-destroy-parts mu4e~gnus-article-mime-handles)
(setq mu4e~gnus-article-mime-handles nil))))
(add-hook 'kill-buffer-hook #'mu4e~view-kill-buffer-hook-fn)
(read-only-mode)))
(defun mu4e~view-kill-buffer-hook-fn ()
;; cleanup the mm-* buffers that the view spawns
(when mu4e~gnus-article-mime-handles
(mm-destroy-parts mu4e~gnus-article-mime-handles)
(setq mu4e~gnus-article-mime-handles nil)))
(defun mu4e~view-gnus-display-mime (msg)
"Same as `gnus-display-mime' but add a mu4e headers to MSG."
(lambda (&optional ihandles)

View File

@ -185,8 +185,7 @@ or org-mode (when in the body)."
((and (> (point) sepapoint) (eq major-mode 'mu4e-compose-mode))
(org-mode)
(add-hook 'before-save-hook
(lambda ()
(mu4e-error "Switch to mu4e-compose-mode (M-m) before saving"))
#'org~mu4e-error-before-save-hook-fn
nil t)
(org~mu4e-mime-decorate-headers)
(local-set-key (kbd "M-m")
@ -203,6 +202,9 @@ or org-mode (when in the body)."
;; and add the hook
(add-hook 'post-command-hook 'org~mu4e-mime-switch-headers-or-body t t))))
(defun org~mu4e-error-before-save-hook-fn ()
(mu4e-error "Switch to mu4e-compose-mode (M-m) before saving"))
(defun org-mu4e-compose-org-mode ()
"Defines a pseudo-minor mode for mu4e-compose-mode.
Edit the message body using org mode. DEPRECATED."