2

I start with this:

(setq test (propertize "foobar" 'face 'font-lock-keyword-face))
;;=> #("foobar" 0 6 (face font-lock-keyword-face))
(add-face-text-property 0 3 'font-lock-type-face nil test)
test
;;=> 
;; #("foobar"
;;   0 3 (face (font-lock-type-face font-lock-keyword-face))
;;   3 6 (face font-lock-keyword-face))

Now I'd like to remove font-lock-type-face in the whole string, while preserving font-lock-keyword-face and all other possible faces.

What's an easy way to do this?

  • You could add an attribute that is an alias to face and use to to set font-lock-type-face (font-lock does something similar with the relatively unknown property font-lock-face). If you do that, it would be trivial to remove it. (Of course, this might not match your use case at all.) – Lindydancer Feb 9 '15 at 16:21
  • 1
    What @Lindydancer said. Or if you don't need to do this a lot or in a general way, them maybe (?): (1) just (put-text-property 0 6 'face 'font-lock-keyword-face test) ;-) or (2) use get-text-property to get the full face property, then remove font-lock-type-face from it, and set that value for the string. AFAIK, there is not a handy function for doing what you ask. – Drew Feb 9 '15 at 16:28
4

You can try to use font-lock--remove-face-from-text-property, tho as the "--" indicates, this is not really meant to be used.

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.