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
553 stars 30 forks source link

Please support highlight-indent-guides package #98

Open CsBigDataHub opened 8 months ago

CsBigDataHub commented 8 months ago

https://github.com/DarthFennec/highlight-indent-guides

CsBigDataHub commented 8 months ago

my config to get the package work with modus themes -

(custom-set-variables
 ;; Only highlight the first character of each indent level instead of the
 ;; entire column. This works better with minimap-mode.
 '(highlight-indent-guides-method 'character)
 ;; Whether to calculuate the faces for the indent guides automatically based
 ;; on the current theme. I have found that this method does not work well with
 ;; the Modus themes, so be warned. You may need to set the faces manually.
 '(highlight-indent-guides-auto-enabled nil)
 ;; How to visualize your current position in the guide stack.
 ;; Must be one of:
 ;;   nil (default) - Disable responsive guides.
 ;;   top - Use a different color to highlight the "current" guide
 ;;         (the indentation block of the line that the cursor is on).
 ;;   stack - Like `top', but also use a third color for all "ancestor"
 ;;           guides of the current guide.
 '(highlight-indent-guides-responsive 'stack))

(defun my/set-highlight-indent-guides-faces-default ()
  "Set theme-agnostic `highlight-indent-guides' faces.

Not pretty or dynamic, but they should be serviceable."
  (when (not highlight-indent-guides-auto-enabled)
    (set-face-background 'highlight-indent-guides-odd-face "darkgray")
    (set-face-background 'highlight-indent-guides-even-face "dimgray")
    (set-face-foreground 'highlight-indent-guides-character-face "dimgray")
    (set-face-background 'highlight-indent-guides-top-odd-face "darkgray")
    (set-face-background 'highlight-indent-guides-top-even-face "dimgray")
    (set-face-foreground 'highlight-indent-guides-top-character-face "dimgray")
    (set-face-background 'highlight-indent-guides-stack-odd-face "darkgray")
    (set-face-background 'highlight-indent-guides-stack-even-face "dimgray")
    (set-face-foreground 'highlight-indent-guides-stack-character-face "dimgray")))

(defun my/set-highlight-indent-guides-faces-for-modus ()
  "Customize `highlight-indent-guides' faces for Modus themes.

These faces rely on Modus themes' custom color variables."
  (modus-themes-with-colors
    ;; Customize faces for `highlight-indent-guides-mode' when using
    ;; `modus-themes' since `highlight-indent-guides-mode' cannot seem to
    ;; figure out its faces on its own.
    (when (not highlight-indent-guides-auto-enabled)
      (set-face-background 'highlight-indent-guides-odd-face bg-dim)
      (set-face-background 'highlight-indent-guides-even-face bg-dim)
      (set-face-foreground 'highlight-indent-guides-character-face bg-dim)
      (set-face-background 'highlight-indent-guides-top-odd-face magenta-intense)
      (set-face-background 'highlight-indent-guides-top-even-face magenta-intense)
      (set-face-foreground 'highlight-indent-guides-top-character-face magenta-intense)
      (set-face-background 'highlight-indent-guides-stack-odd-face bg-magenta-subtle)
      (set-face-background 'highlight-indent-guides-stack-even-face bg-magenta-subtle)
      (set-face-foreground 'highlight-indent-guides-stack-character-face bg-magenta-subtle))))

(add-hook 'highlight-indent-guides-mode-hook
          (lambda ()
            (if (seq-some (lambda (th) (string-match "^modus-" (symbol-name th)))
                          custom-enabled-themes)
                (my/set-highlight-indent-guides-faces-for-modus)
              (my/set-highlight-indent-guides-faces-default))))
protesilaos commented 8 months ago

Hello @CsBigDataHub!

From the README of that package, we find this:

By default, this mode dynamically chooses colors that look acceptable with the loaded theme. It does this by altering the luminosity of the theme's background color by a given percentage. These percentages can be tweaked, to make the colors more intense or subtle.

I have always understood this to be enough for getting the values right. The README then mentions some user options to tweak the percentages. Is this not working?

CsBigDataHub commented 8 months ago

Thanks for your reply @protesilaos

Does not work as expected without the complete configuration below.

(custom-set-variables
 ;; Only highlight the first character of each indent level instead of the
 ;; entire column. This works better with minimap-mode.
 '(highlight-indent-guides-method 'character)
 ;; Whether to calculuate the faces for the indent guides automatically based
 ;; on the current theme. I have found that this method does not work well with
 ;; the Modus themes, so be warned. You may need to set the faces manually.
 '(highlight-indent-guides-auto-enabled nil)
 ;; How to visualize your current position in the guide stack.
 ;; Must be one of:
 ;;   nil (default) - Disable responsive guides.
 ;;   top - Use a different color to highlight the "current" guide
 ;;         (the indentation block of the line that the cursor is on).
 ;;   stack - Like `top', but also use a third color for all "ancestor"
 ;;           guides of the current guide.
 '(highlight-indent-guides-responsive 'stack)
 '(highlight-indent-guides-auto-odd-face-perc 30)
 '(highlight-indent-guides-auto-even-face-perc 30)
 '(highlight-indent-guides-auto-character-face-perc 50))

(defun my/set-highlight-indent-guides-faces-default ()
  "Set theme-agnostic `highlight-indent-guides' faces.

Not pretty or dynamic, but they should be serviceable."
  (when (not highlight-indent-guides-auto-enabled)
    (set-face-background 'highlight-indent-guides-odd-face "darkgray")
    (set-face-background 'highlight-indent-guides-even-face "dimgray")
    (set-face-foreground 'highlight-indent-guides-character-face "dimgray")
    (set-face-background 'highlight-indent-guides-top-odd-face "darkgray")
    (set-face-background 'highlight-indent-guides-top-even-face "dimgray")
    (set-face-foreground 'highlight-indent-guides-top-character-face "dimgray")
    (set-face-background 'highlight-indent-guides-stack-odd-face "darkgray")
    (set-face-background 'highlight-indent-guides-stack-even-face "dimgray")
    (set-face-foreground 'highlight-indent-guides-stack-character-face "dimgray")))

(defun my/set-highlight-indent-guides-faces-for-modus ()
  "Customize `highlight-indent-guides' faces for Modus themes.

These faces rely on Modus themes' custom color variables."
  (modus-themes-with-colors
    ;; Customize faces for `highlight-indent-guides-mode' when using
    ;; `modus-themes' since `highlight-indent-guides-mode' cannot seem to
    ;; figure out its faces on its own.
    (when (not highlight-indent-guides-auto-enabled)
      (set-face-background 'highlight-indent-guides-odd-face bg-dim)
      (set-face-background 'highlight-indent-guides-even-face bg-dim)
      (set-face-foreground 'highlight-indent-guides-character-face bg-dim)
      (set-face-background 'highlight-indent-guides-top-odd-face magenta-intense)
      (set-face-background 'highlight-indent-guides-top-even-face magenta-intense)
      (set-face-foreground 'highlight-indent-guides-top-character-face magenta-intense)
      (set-face-background 'highlight-indent-guides-stack-odd-face magenta-faint)
      (set-face-background 'highlight-indent-guides-stack-even-face magenta-faint)
      (set-face-foreground 'highlight-indent-guides-stack-character-face magenta-faint))))

(add-hook 'highlight-indent-guides-mode-hook
          (lambda ()
            (if (seq-some (lambda (th) (string-match "^modus-" (symbol-name th)))
                          custom-enabled-themes)
                (my/set-highlight-indent-guides-faces-for-modus)
              (my/set-highlight-indent-guides-faces-default))))

(add-hook 'yaml-ts-mode-hook 'highlight-indent-guides-mode)
protesilaos commented 8 months ago

From: CsBigDataHub @.***> Date: Thu, 25 Jan 2024 07:20:28 -0800

Thanks for your reply @protesilaos

You are welcome!

Does not work as expected with the complete configuration below.

[... 68 lines elided]

I don't see any obvious error in your code. This does not look like a theme issue. Does the 'my/set-highlight-indent-guides-faces-for-modus' work if you call it without a hook? Meaning, if you do M-x eval-expression and then run it from there?

-- Protesilaos Stavrou https://protesilaos.com

CsBigDataHub commented 8 months ago

Does the 'my/set-highlight-indent-guides-faces-for-modus' work if you call it without a hook? Meaning, if you do M-x eval-expression and then run it from there?

Yes it does.

There is no error in the code. It is working fine.

The problem here is with out the code above, highlight-indent-guides package does not work as expected.

Essentially when this option is used (highlight-indent-guides-method 'character) in dark theme, I am not able to see any vertical lines. I suspect by default the package uses black or darkgrey which is not visible in dark theme.

kaixiong commented 8 months ago

The problem here is with out the code above, highlight-indent-guides package does not work as expected.

Essentially when this option is used (highlight-indent-guides-method 'character) in dark theme, I am not able to see any vertical lines. I suspect by default the package uses black or darkgrey which is not visible in dark theme.

@CsBigDataHub Are you using Emacs 29? See this highlight-indent-guides issue.

CsBigDataHub commented 8 months ago

The problem here is with out the code above, highlight-indent-guides package does not work as expected.

Essentially when this option is used (highlight-indent-guides-method 'character) in dark theme, I am not able to see any vertical lines. I suspect by default the package uses black or darkgrey which is not visible in dark theme.

@CsBigDataHub Are you using Emacs 29? See this highlight-indent-guides issue.

Yes I am. Thank you for the link.