I'm trying to get rid of the auto-inserted trailing whitespace in message-mode signature. I have tried the advice below.

(defadvice message-insert-signature (around +amos*message-insert-signature activate)
  (let ((old-insert (symbol-function 'insert)))
    (flet ((insert (str) (eval-when-compile (require 'subr-x)) (funcall old-insert (string-trim-right str))))

But it doesn't have any effect.

  • Where does the trailing whitespace appear? After the double hyphen -- separator? Have you configured message-mode to insert a signature at all? If so, where does it get populated from? A string, file or elsewhere? It may help if you provide a sample mail transcript (e.g. an expected vs actual text comparison) to indicate which whitespace you are trying to eliminate.
    – Basil
    Oct 17 '17 at 22:22
  • Yep, after the double hyphen -- separator.
    – Amos
    Oct 18 '17 at 2:20

According to the last two paragraphs of (message) Insertion Variables and this comp.mail.headers post by the package's author:

Quoth RFC1036bis:

    If  a  poster or posting agent does append a signature to an
    article, the signature SHOULD be preceded with  a  delimiter
    line  containing  (only)  two hyphens (ASCII 45) followed by
    one blank (ASCII  32).

Note that this isn't a standard in any formal sense, and RFC1036 is a
Usenet news thing.  However, it has been the done thing since, well,
forever.  It works.  

the trailing space is considered conventional, if not a bit outdated, netiquette. In more practical terms, however, message-mode feels quite strongly about enforcing this convention in the messages it helps you compose by hard-coding the trailing space in at least a couple of places. I believe it is possible to work around these, but minor unforeseen complications are always possible:

(defun my-message-trim-signature ()
  "Delete trailing space of `message-mode' signature."
  (let ((marker (point-marker)))
    (goto-char (point-min))
    (when (re-search-forward "^-- $" nil t)
      (delete-char -1))
    (goto-char marker)))

(add-hook 'message-setup-hook #'my-message-trim-signature)

;; Teach paragraph motion commands about our signature
(defun my-message-fix-paragraphs ()
  "Adapt paragraph variables to `my-message-trim-signature'."
  (setq paragraph-start (concat "--$\\|" paragraph-start))
  (setq paragraph-separate paragraph-start))

(add-hook 'message-mode-hook #'my-message-fix-paragraphs)

;; "Loosen" regexp for `message-goto-signature' et al. to work
(setq message-signature-separator "^-- *$")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.