3

first time StackExchange user here.

I'm having trouble with highlight-chars (probably font-lock) and magit. Enabling hc-toggle-highlight-* functions will remove the coloring from magit buffers.

enter image description here

Possibly duplicate: Font-lock for strings messes up non-code buffers

Anyone else have this trouble, or know some possible workaround?

Minimum .emacs:

(require 'package)
(add-to-list 'package-archives
         '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

(require 'magit) ;; Current version 20160210.555
(require 'highlight-chars) ;; Current version 20151231.1335

;; (hc-toggle-highlight-tabs t)
;; (hc-toggle-highlight-trailing-whitespace t)
(add-hook 'font-lock-mode-hook 'hc-highlight-tabs)
(add-hook 'font-lock-mode-hook 'hc-highlight-trailing-whitespace)
  • I've seen this happen when enabling whitespace-mode in a magit buffer. Never got around to investigating further though. – npostavs Feb 11 '16 at 14:39
1

You might need to look at the Magit code to see what it is doing. You don't say what highlighting Magit does normally, and just what changes when highlight-chars.el (Highlight Library) is added to the mix. I don't use Magit -- maybe someone else can speak to this.

But highlight-chars.el does add to font-lock-keywords for things like highlighting tabs and trailing whitespace. It's possible that this interferes with the font-lock keywords used by Magit.

However, user option hc-font-lock-override controls whether the current highlighting face used by hc-* commands overrides (t), is overridden by (keep), or merges with (append or prepend) any existing highlighting.

You should thus be able to make hc-* highlighting cohabit well with other text-property highlighting - you can control which highlighting of a given piece of text, highlighting by hc-* or highlighting by some other code, has precedence, and how much it dominates the other highlighting.

E.g., you can set the value of hc-font-lock-override to keep (e.g., using M-x customize-option hc-font-lock-override), to prevent hc-* highlighting from overwriting any already existing highlighting.

See also options hc-other-chars and hc-other-chars-NOT, which control which chars are governed by hc-toggle-highlight-other-chars.

You might also try changing the order (i.e., when you turn on the hc-* highlighting). hc-highlight-trailing-whitespace and hc-highlight-tabs just add patterns to match at the end of font-lock-keywords.

However, be aware that highlighting from text properties (e.g. face or font-lock-face) always has less precedence than highlighting from overlays. Library highlight-chars.el uses text-property highlighting, as does all use of font-lock. If some other library uses overlay highlighting on the same text area then the overlay highlighting wins in case of conflict - always.


[2018-04-07: I updated highlight-chars.el to let option hc-font-lock-override (previously called hc-other-chars-font-lock-override) control all hc-* highlighting, not just other-char highlighting.]

| improve this answer | |
  • Good idea, but unfortunately it did not solve the problem. I started digging in the magit code, and especially the magit-section-make-overlay function. My newest hypothesis is that font-lock conflicts with overlay-put from the built in buffer.c. – Seba Feb 11 '16 at 19:52
  • Overlay properties always override text properties. highlight-chars.el uses font-lock, which, yes, uses text properties. If Magit uses overlays then they should take precedence. If its overlays use property face then that face should be seen, not a face used by highlight-chars.el. But it sounds like you are seeing the opposite (you said that h-c breaks Magit, not the other way around). – Drew Feb 11 '16 at 20:05
  • What makes you think that Magit is using overlays at the locations where h-c is trying to highlight? Glancing at some of the code, I see that the overlay is used for magit-section-highlight and magit-section-highlight-selection. What happens if you remove those from option magit-section-highlight-hook, as a test? That presumably will take overlays out of the equation. – Drew Feb 11 '16 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.