jeremy-compostella / org-msg

OrgMsg is a GNU/Emacs global minor mode mixing up Org mode and Message mode to compose and reply to emails in a Outlook HTML friendly style.
GNU General Public License v3.0
275 stars 58 forks source link

Feature Request - Set HTML or Text behavior using a custom function #90

Closed guibor closed 3 years ago

guibor commented 3 years ago

e.g when replying to certain addresses or certain types of email, dynamically set the alernative. Currently I implement this behavior using a message-send-hook that determines the value of org-msg-default-alternatives which is hacky.

jeremy-compostella commented 3 years ago

I like this idea but this is likely not going to be used by a lot of users so I would like to avoid creating a dedicated customization variable which is going to make the code cumbersome and for which I would have to make decisions like do we want a list of hooks and the first which returns something wins or do we want to override systematically with this function ...

However, in order to make it possible, I made org-msg-post-setup call a new function named org-msg-get-alternatives which is in charge of returning the list of alternatives. Now, to implement this behavior all you have to do is to advise the org-msg-get-alternatives in the way you like.

What do you think?

jeremy-compostella commented 3 years ago

@guibor, I pushed to master. Could you give it a shot ?

guibor commented 3 years ago

Just used this as follows - suppose this is what you had in mind:

(setq mu4e-plain-reply-regexp "Reply.*docs\\.google\\.com\\|.*email\\.figma\\.com")

(defun org-msg-should-force-plaintext ()
  (let ((to-value (message-field-value "To")))
    (and (not (s-blank? to-value)) (s-matches? mu4e-plain-reply-regexp to-value))))

(defun org-msg-force-plaintext (alternative)
  (if (org-msg-should-force-plaintext)
      '(text)
    alternative))

(advice-add 'org-msg-get-alternatives :filter-return #'org-msg-force-plaintext)

And it works very nicely! I have another suggestion in the same vein regarding signature and style (I'll open a separate FR on that).

Another opportunity to thank you for this amazing package (that several other people at my workplace use as well and love).

jeremy-compostella commented 3 years ago

Just used this as follows - suppose this is what you had in mind:

Indeed, that's the sort of customization I had in mind. I have extended this "logic" to a level which should support your #104 FR.

Another opportunity to thank you for this amazing package (that several other people at my workplace use as well and love).

Thank you. That's always a great pleasure to get positive feedback on one of my little projects.

Closing this ticket now.