evil-search-highlight-persist icon indicating copy to clipboard operation
evil-search-highlight-persist copied to clipboard

Configurable evil-search-highlight-persist-highlight-face

Open mpollmeier opened this issue 8 years ago • 5 comments

I just wanted to send you a PR, but since I'm an elisp newbie I ran into a problem, maybe you can help me fix it:

I wanted to change this:

(defface evil-search-highlight-persist-highlight-face
  '((((class color))
     (:background "yellow1")))
  "Face for the highlighted text."
  :group 'evil-search-highlight-persist)

into this, to make the colour configurable:

(defvar evil-search-highlight-background-colour "yellow1" "background colour of highlighted text")
(defface evil-search-highlight-persist-highlight-face
  '((((class color))
     (:background evil-search-highlight-background-colour)))
  "Face for the highlighted text."
  :group 'evil-search-highlight-persist)

Emacs complains that it's the wrong type though (stringp) - I don't get it, you're using a string in the original code as well. Can you help?

mpollmeier avatar Dec 13 '16 13:12 mpollmeier

The problem is the ' before '((((class color... The quote in front basically means that nothing will be evaluated, so you weren't actually using a string. To fix it use a backquote: `((((class color ... (:background ,evil-search-highlight-background-colour) ...

naclander avatar Apr 02 '17 04:04 naclander

Thank you @naclander , I learned something! However now I have the problem that I can't override the default value - it always takes the default (yellow1). I assume the problem got to do with evaluation time, I tried different versions with backticks, single quotes, defun with no luck :(

From my init.el:

(setq evil-search-highlight-string-min-len 2) ;;works
(setq evil-search-highlight-background-colour "purple1") ;; doesn't work

After making the changes you suggested:

(defvar evil-search-highlight-background-colour "yellow1" "background colour of highlighted text")
(defface evil-search-highlight-persist-highlight-face
  `((((class color))
     (:background ,evil-search-highlight-background-colour)))
  "Face for the highlighted text."
  :group 'evil-search-highlight-persist)

For reference, here's the block that's using the min-length attribute that I can configure fine:

(defvar evil-search-highlight-string-min-len 1 "min legth")
(defun evil-search-highlight-persist-mark ()
  (let ((hlt-use-overlays-flag t)
        (hlt-last-face 'evil-search-highlight-persist-highlight-face)
        tmp)
    (if isearch-regexp
        (progn
          (setq tmp (car-safe regexp-search-ring))
          (setq evil-search-highlight-regex-flag t))
      (progn
        (setq tmp (car-safe search-ring))
        (setq evil-search-highlight-regex-flag nil)))
    (if (>= (length tmp) evil-search-highlight-string-min-len)
          (hlt-highlight-regexp-region-in-buffers tmp (list (current-buffer)))
      ))
  (setq evil-search-highlight-regex-flag t)
  )

mpollmeier avatar Apr 02 '17 22:04 mpollmeier

Hi guys,

Please note that currently this project is unmaintained because I went back to Vim and anyway I wasn't very good at elisp. If some of you want to take over it please fork and we can update the elpa links. I'll update the readme.

juanjux avatar Apr 03 '17 09:04 juanjux

@juanjux Sure thing, I forked it.

@mpollmeier You have to put the setq before loading evil-search-highlight-persist. Also, change your defvar to defcustom.

naclander avatar Apr 03 '17 22:04 naclander

Thank you, that did the trick. I made evil-search-highlight-string-min-len a defcustom as well for consistency.

mpollmeier avatar Apr 03 '17 22:04 mpollmeier