;;; +message.el --- Extra message-mode functions -*- lexical-binding: t; -*-

;;; Commentary:

;;; Code:

;; Thanks to Alex Schroeder for this!
;; https://www.emacswiki.org/emacs/Change_Signature_Dynamically

(defun +message-check-for-signature-change (&rest ignore)
  "Check for a change in the To: or Cc: fields"
  (when (and (message--in-tocc-p)
             (not (buffer-narrowed-p)))
    (save-excursion
      (goto-char (point-max))
      (let ((end (point)))
        (when (re-search-backward message-signature-separator nil t)
          (delete-region (1- (match-beginning 0)) end)))
      (message-insert-signature))))

(defun +message-signature-setup ()
  (make-local-variable 'after-change-functions)
  (push '+message-check-for-signature-change after-change-functions))

(provide '+message)
;;; +message.el ends here
