protesilaos / modus-themes

Highly accessible themes for GNU Emacs, conforming with the highest standard for colour contrast between background and foreground values (WCAG AAA).
https://protesilaos.com/emacs/modus-themes
GNU General Public License v3.0
526 stars 29 forks source link

Indentation of description lists #87

Closed TitusMu closed 11 months ago

TitusMu commented 11 months ago

Dear Prot,

I often use description lists in orgmode. And I like your modus themes, as they make everything easier to read. In the description lists though, the theme I used before is doing it better. The spaces before and the space after the character that is used to display the item (I use org-superstar) are done in a variable-pitch-font in the modus themes, as opposed to a fixed-pitch-font in doom-solarized-light, where I come from. That results in the text being very close to the symbol at the start of the line in your themes, making it harder to read. And, what is worse, it is responsible for an unorderly indent. With fixed-pitch, all the list-sub-items that are further indented start where the text of the upper level started. With variable-pitch, they start much earlier and it looks "fuzzy". See the picture I added.

It seems, doom-solarized-light uses the face org-list-dt for the spaces around the item symbol, which is fixed-pitch. In the modus themes, no special face is used for the spaces. Is there a way for me to make the modus themes use a fixed-pitch font there, to make things look nicer?

First example is modus operandi tinted, second example is doom-solarized-light.

Indent

I use emacs 29.1, org 9.6.6 and modus themes 4.2.0.

Thank you so much for your great themes! And for any help with this wish of mine.

Titus

protesilaos commented 11 months ago

Hello @TitusMu! Looking at the screenshots, it seems that doom-solarized-light makes the dashes in the list monospaced. Can you check what is the underlying face by placing the cursor over the dash and doing M-x describe-char? A Help buffer will pop up and it will mention the applicable face, if any, towards the bottom.

Alternatively, send me the text and I can give it a try.

TitusMu commented 11 months ago

The space characters before the dash show (org-indent), written like this in brackets. The dash itself shows (org-list-dt), also in brackets. Thank you for looking into this!

protesilaos commented 11 months ago

Can you do M-x describe-face for org-list-dt with the doom-solarized-light theme? It will produce a help buffer. We need to learn what attributes it has. Please share the contents of that Help buffer.

TitusMu commented 11 months ago

This is the output on org-list-dt:

Face: org-list-dt (sample) (customize this face)

Documentation:
Default face for definition terms in lists.

Defined in ‘org-faces.el’.

           Family: unspecified
          Foundry: unspecified
            Width: unspecified
           Height: unspecified
           Weight: unspecified
            Slant: unspecified
       Foreground: #268bd2
DistantForeground: unspecified
       Background: unspecified
        Underline: unspecified
         Overline: unspecified
   Strike-through: unspecified
              Box: unspecified
          Inverse: unspecified
          Stipple: unspecified
             Font: unspecified
          Fontset: unspecified
           Extend: unspecified
          Inherit: unspecified

And org-indent has the following output on M-x describe-face:

Face: org-indent (sample) (customize this face)

Documentation:
Face for outline indentation.
The default is to make it look like whitespace.  But you may find it
useful to make it ever so slightly different.

Defined in ‘org-indent.el’.

           Family: unspecified
          Foundry: unspecified
            Width: unspecified
           Height: unspecified
           Weight: unspecified
            Slant: unspecified
       Foreground: unspecified
DistantForeground: unspecified
       Background: unspecified
        Underline: unspecified
         Overline: unspecified
   Strike-through: unspecified
              Box: unspecified
          Inverse: unspecified
          Stipple: unspecified
             Font: unspecified
          Fontset: unspecified
           Extend: unspecified
          Inherit: org-hide

The inherited face org-hide ist defined as:

Face: org-hide (sample) (customize this face)

Documentation:
Face used to hide leading stars in headlines.
The foreground color of this face should be equal to the background
color of the frame.

Defined in ‘org-faces.el’.

           Family: unspecified
          Foundry: unspecified
            Width: unspecified
           Height: unspecified
           Weight: unspecified
            Slant: unspecified
       Foreground: #FDF6E3
DistantForeground: unspecified
       Background: unspecified
        Underline: unspecified
         Overline: unspecified
   Strike-through: unspecified
              Box: unspecified
          Inverse: unspecified
          Stipple: unspecified
             Font: unspecified
          Fontset: unspecified
           Extend: unspecified
          Inherit: unspecified
TitusMu commented 11 months ago

If I do M-x describe char in the white space before the item symbol in the list, in doom-solarized-theme for the display it gives:

display: by this font (glyph code):
    ftcrhb:-IBM -IBM Plex Mono-regular-normal-normal-*-24-*-*-*-m-0-iso10646-1 (#x03)

So, it is a fixed-pitch font. In the modus-themes, at the same spot the command gives:

display: by this font (glyph code):
    ftcrhb:-ADBO-Source Serif Pro-regular-normal-normal-*-24-*-*-*-*-0-iso10646-1 (#x01)

I would love to be able to set the face to the fixed-pitch face in your theme too. But how come in doom-solarized the spaces in front have a face (org-indent), and in modus-themes they have no face at all?

I checked the active modes, they are exactly the same with either theme active (I always restarted emacs when changing the theme):

Minor modes enabled in this buffer: Auto-Save Font-Lock Hl-Line
Mixed-Pitch Org-Auto-Tangle Org-Indent Org-Superstar Prettify-Symbols
Subword Undo-Fu-Session Visual-Line

Could it be that org-indent mode is set up differently by doom-solarized theme? It feels like we are so close to a solution, but I am not able to see it ...

protesilaos commented 11 months ago

I notice that the doom-themes come packaged with some extensions which should, in my opinion, be provided as standalone minor modes. One such extension is in the file doom-themes-ext-org.el, which includes this:

(defun doom-themes-enable-org-fontification ()
  "Correct (and improve) org-mode's font-lock keywords.

  1. Re-set `org-todo' & `org-headline-done' faces, to make them respect
     (inherit) underlying faces.
  2. Make statistic cookies respect (inherit) underlying faces.
  3. Fontify item bullets (make them stand out)
  4. Fontify item checkboxes (and when they're marked done), like TODOs that are
     marked done.
  5. Fontify dividers/separators (5+ dashes)
  6. Fontify #hashtags and @at-tags, for personal convenience; see
     `doom-org-special-tags' to disable this."
  (let ((org-todo (format org-heading-keyword-regexp-format
                          org-todo-regexp))
        (org-done (format org-heading-keyword-regexp-format
                          (concat "\\(?:" (mapconcat #'regexp-quote org-done-keywords
                                                     "\\|")
                                  "\\)"))))
    (setq
     org-font-lock-extra-keywords
     (append (org-delete-all
              (append `(("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
                         (0 (org-get-checkbox-statistics-face) t))
                        (,org-todo (2 (org-get-todo-face 2) t)))
                      (when org-fontify-done-headline
                        `((,org-done (2 'org-headline-done t))))
                      (when (memq 'date org-activate-links)
                        '((org-activate-dates (0 'org-date t)))))
              org-font-lock-extra-keywords)
             ;; respsect underlying faces!
             `((,org-todo (2 (org-get-todo-face 2) prepend)))
             (when org-fontify-done-headline
               `((,org-done (2 'org-headline-done prepend))))
             (when (memq 'date org-activate-links)
               '((org-activate-dates (0 'org-date prepend))))
             ;; Make checkbox statistic cookies respect underlying faces
             '(("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
                (0 (org-get-checkbox-statistics-face) prepend))
               ;; make plain list bullets stand out.
               ;; give spaces before and after list bullet org-indent face to
               ;; keep correct indentation on mixed-pitch-mode
               ("^\\( *\\)\\([-+]\\|\\(?:[0-9]+\\|[a-zA-Z]\\)[).]\\)\\([ \t]\\)"
                (1 'org-indent append)
                (2 'org-list-dt append)
                (3 'org-indent append))
               ;; and separators/dividers
               ("^ *\\(-----+\\)$" 1 'org-meta-line))
             ;; I like how org-mode fontifies checked TODOs and want this to
             ;; extend to checked checkbox items:
             (when org-fontify-done-headline
               '(("^[ \t]*\\(?:[-+*]\\|[0-9]+[).]\\)[ \t]+\\(\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\(?:X\\|\\([0-9]+\\)/\\2\\)\\][^\n]*\n\\)"
                  1 'org-headline-done prepend)))
             ;; custom #hashtags & @at-tags for another level of organization
             (when doom-themes-org-fontify-special-tags
               '(("\\(?:\\s-\\|^\\)\\(\\([#@]\\)[A-Za-z0-9_.-]+\\)"
                  1 (doom-themes--org-tag-face 2) prepend)))))))

(add-hook 'org-font-lock-set-keywords-hook #'doom-themes-enable-org-fontification)

Notice this snippet:

;; make plain list bullets stand out.
;; give spaces before and after list bullet org-indent face to
;; keep correct indentation on mixed-pitch-mode
("^\\( *\\)\\([-+]\\|\\(?:[0-9]+\\|[a-zA-Z]\\)[).]\\)\\([ \t]\\)"
 (1 'org-indent append)
 (2 'org-list-dt append)
 (3 'org-indent append))

What happens if you disable mixed-pitch-mode while using one of the doom themes? Note that the Modus themes do not need mixed-pitch-mode: you can simply set the user option modus-themes-mixed-fonts to t and reload the theme for changes to take effect.

TitusMu commented 11 months ago

Oh, wow, you're wonderful, Prot! This is the solution.

You're right, though, they should have put it in a minor mode. It would have been nice for another reason too, not only because it doesn't belong into a theme: It would be available for everyone then.

I took out just two parts of the defun, the one that keeps the background of org-date consistent with the surrounding, and the one gives spaces before and after the list bullet org-indent face.

(defun enable-org-fontification-taken-from-doom-themes ()
            "Correct (and improve) org-mode's font-lock keywords."
            (setq org-font-lock-extra-keywords
                  (append 
                   (org-delete-all
                    (append `(("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"))
                            (when (memq 'date org-activate-links)
                              '((org-activate-dates (0 'org-date t)))))
                    org-font-lock-extra-keywords)
                   ;; Datumsangaben sollen sich an den Hintergrund anpassen (respect underlying faces)
                   (when (memq 'date org-activate-links)
                     '((org-activate-dates (0 'org-date prepend))))
                   '(
                     ;; make plain list bullets stand out.
                     ;; give spaces before and after list bullet org-indent face to
                     ;; keep correct indentation on mixed-pitch-mode
                     ("^\\( *\\)\\([-+]\\|\\(?:[0-9]+\\|[a-zA-Z]\\)[).]\\)\\([ \t]\\)"
                      (1 'org-indent append)
                      (2 'org-list-dt append)
                      (3 'org-indent append)))
                   )))
          (add-hook 'org-font-lock-set-keywords-hook #'enable-org-fontification-taken-from-doom-themes))

Thank you so much for your help!

TitusMu commented 11 months ago

It's even better when I omit the line (2 'org-list-dt append), I just commented it out. Now not only the face org-superstar-item is respected again, also, when indenting, the lines are exactly below each other. With (2 'org-list-dt append), they were still slightly off.

protesilaos commented 11 months ago

Very well! We can safely close this issue then.