nschum / highlight-symbol.el

Emacs: automatic and manual symbol highlighting
http://nschum.de/src/emacs/highlight-symbol/
274 stars 41 forks source link

[Idea] I think `highlight-symbol-colors' can be set foreground face colors matched background face colors. #40

Open mrlee23 opened 8 years ago

mrlee23 commented 8 years ago

I'm using command highlight-symbol with default set of highlight-symbol-colors and set highlight-symbol-foreground-color as "white".

Then, some colors highlighted like yellow, cyan or SpringGreen1, difficult to read the words.

So, My idea is to make highlight-symbol-colors variable can set foreground color and background color as cons or just background color string(before way) matched foreground color as highlight-symbol-foreground-color variable.

Here is sample set of highlight-symbol-colors

(setq highlight-symbol-colors
        '(("black" . "yellow")
          ("black" . "DeepPink")
          ("black" . "cyan")
          ("white" . "MediumPurple1")
          ("black" . "SpringGreen1")
          ("white" . "DarkOrange")
          ("white" . "HotPink1")
          ("black" . "RoyalBlue1")
          ("white" . "OliveDrab")))
;; below is same
(setq highlight-symbol-foreground-color "white")
(setq highlight-symbol-colors
        '("yellow"
          ("black" . "DeepPink")
          ("black" . "cyan")
          "MediumPurple1"
          ("black" . "SpringGreen1")
          "DarkOrange"
          "HotPink1"
          ("black" . "RoyalBlue1")
          "OliveDrab"))

And I override highlight-symbol-add-symbol function.

(defun highlight-symbol-add-symbol (symbol &optional color)
  "Override this function for support convenience set foreground and background"
  (unless (highlight-symbol-symbol-highlighted-p symbol)
    (when (equal symbol highlight-symbol)
      (highlight-symbol-mode-remove-temp))
    (let ((color (or color (highlight-symbol-next-color)))
          f-color b-color)
      (unless (facep color)
        (if (consp color)
            (setq f-color (car color)
                  b-color (cdr color))
          (setq f-color highlight-symbol-foreground-color
                b-color color))
        (setq color `((background-color . ,b-color)
                      (foreground-color . ,f-color))))
      ;; highlight
      (highlight-symbol-add-symbol-with-face symbol color)
      (push symbol highlight-symbol-list))))

Above override function works find.

May be I can use faces but it has to many sequence(define face, face naming) and inconvenient customize.

But foreground and background cons way is very easy to customize and it also support before way (just list of background colors).

Thank you:)