0

I have some code that I borrowed from a long while ago that sets a long-line face when the line is too long:

 (add-hook 'font-lock-mode-hook
           (function
            (lambda ()
              (setq font-lock-keywords
                    (append font-lock-keywords
                            '( ("^.\\{133,\\}$" (0 'my-long-line-face t))
                              )
                            )
                    )
              )
            ))

(I know about font-lock-add-keywords now, BTW; like I said, this is kind of old.)

The problem is that this changes the face of the entire line. So if I indicate that long-line-face is bold, I lose all the contextual customization of the line, and it appears in the default face, but bold.

How would I get it to keep the contextual colouring but make everything bold?

Drew
  • 29,895
  • 7
  • 74
  • 104
RealityMonster
  • 1,881
  • 2
  • 12
  • 11

2 Answers2

2

You are overriding the fontification with the t in your font-lock spec. Try changing the (0 'my-long-line-face t) to either (0 'my-long-line-face prepend) or (0 'my-long-line-face append).

scottfrazer
  • 17,079
  • 4
  • 51
  • 49
  • Correct, with one minor correction. It needs to be either (0 'my-long-line-face prepend) or (0 'my-long-line-face append). But now it works like a charm; I didn't know about append and prepend. :) – RealityMonster Dec 01 '11 at 15:42
1

Try this modification to your code:

(add-hook 'font-lock-mode-hook
       (function
    (lambda ()
      (setq font-lock-keywords
        (append font-lock-keywords
            '( ("^.\\{133\\}\\(.*\\)$" (1 'my-long-line-face t))
              )
            )
        )
      )
    ))

The key being that you want the regexp to have a sub expression that follows the 133 characters that aren't too long, and then apply my-long-line-face to that following sub expression - as indicated by the 1 (instead of the 0 that you had). See the info page for Search-based Fontification for more details.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229