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
276 stars 57 forks source link

Possibly better default html styling for codeblocks (#115) #116

Closed roblem closed 3 years ago

roblem commented 3 years ago

This does a few things

  1. Creates a light grey background for src blocks
  2. Adds a light grey border around codeblocks
  3. Adds some margins around the blocks to set them apart from nearby elements

The upside is that it looks pretty good: org-msg-change

There are two downsides:

  1. If you have a light grey background, this hardcoded change won't help you very much visually- although it is probably no worse than the original.
  2. Output blocks have the same grey shading. Ideally, I'd like them different, but again, this is no worse than the original
roblem commented 3 years ago

Partly addresses #115

obar commented 3 years ago

The syntax highlighting that you get in org-msg is coming from htmlize, which uses the coloring from your emacs screen, down to the background color. Hard-coding a background color in the package would be problematic for some themes—consider a user with a dark theme that uses light foreground for fonts, where this would result in light text on a light background.

Of course you can customize this in your own config! Just edit org-msg-default-style. The colors look great with your emacs theme (I presume a light one) per that screenshot. I've got a few tweaks to the package myself.

roblem commented 3 years ago

Thanks. I completely understand that it wouldn't work with some background colors. Since I am using Leuven (a white background) my customization works great IMO. BTW, I tried several other themes without my customizations and when exporting using C-c C-e from org-msg, default background for src blocks is always white (which surprised me) and at times this made light colored fontified src text very hard to read. It just depends on the theme whether things work.

So is the recommended way of customizing things by editing org-msg-default-style in org-msg.el and re-byte compiling it?

obar commented 3 years ago

default background for src blocks is always white

Are you sure you're running the original code? I see my emacs background color in src blocks when looking at html emails in gmail.

So is the recommended way of customizing things by editing org-msg-default-style in org-msg.el and re-byte compiling it?

You should be able setq that variable in your emacs config which will override that variable, and leave the package as-is (so you don't need to maintain your own version). I'm not certain if the fact that it's defined as a constant will affect this, per the defconst docs:

Define SYMBOL as a constant variable.
This declares that neither programs nor users should ever change the
value.  This constancy is not actually enforced by Emacs Lisp, but
SYMBOL is marked as a special variable so that it is never lexically
bound.
roblem commented 3 years ago

Are you sure you're running the original code?

Yes. I just setup a minimal environment and had to install everything from melpa. Screenshot of the email compose buffer (to see theme):

so src backgrounds are always white for me.

You should be able setq that variable in your emacs config which will override that variable

Unfortunately, I have been unable to make this work. I have tried things like

(setq org-msg-default-style
        (let* ((font-family '(font-family . "\"Arial\""))
           (font-size '(font-size . "10pt"))
            ....

or

(with-eval-after-load "org-msg" ;; or org-msg-mode
  (setq org-msg-default-style
        (let* ((font-family '(font-family . "\"Arial\""))
           (font-size '(font-size . "10pt"))
           (font `(,font-family ,font-size))
           (line-height '(line-height . "10pt"))
     ...

and the changes never have an effect on the output. The only way I have been able to make it work is to edit org-msg.el and byte compile it.

obar commented 3 years ago

I still couldn't tell you about the background color of src blocks (looks quite different for me) but looking at the next sexp in the source showed how to customize the style and this worked in a test:

(setq org-msg-enforce-css
      (let* ((font-family '(font-family . "\"Arial\""))
         (font-size '(font-size . "10pt"))
...
jeremy-compostella commented 3 years ago

So is the recommended way of customizing things by editing org-msg-default-style in org-msg.el and re-byte compiling it?

No, as @obar mentioned, the right way is to use the org-msg-enforce-css variable. org-msg-default-style is the default style and is a constant you should not touch. Even though I am sure plenty of user are modifying but as @obar emphasizes, it creates a maintenance burden to these users . This default style should work well is most cases as it dynamically gets the information from your current theme so that the output always looks similar to what it looks like in your Emacs.

By default, org-msg-enforce-css contains org-msg-default-style but you can change that by either redefining entirely this customization variable or by running some emacs-lisp code to perform some automatic changes such as update all the face-background and face-foreground colors to fit your preferences.

Also, I suppose that if your background color is not adapting automatically between themes this is because you have not re-evaluate the org-msg-default-style constant and org-msg-enforce-css variable between these theme changes.

obar commented 3 years ago

as @obar mentioned, the right way is to use the org-msg-enforce-css variable.

Actually I screwed it up at first :) At any rate, @roblem are you good to close #115 and #116?

roblem commented 3 years ago

Yes thanks for all the help.

roblem commented 3 years ago

This default style should work well is most cases as it dynamically gets the information from your current theme so that the output always looks similar to what it looks like in your Emacs.

To follow up on this: I believe a recent update to emacs in Fedora now allows org-msg to pull the font-faces from emacs so

  1. that it does indeed look similar to what I see in emacs
  2. there is no longer a need to set org-msg-enforce-css for code block tweaks