[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature request: text property to prevent font-locking

From: Drew Adams
Subject: feature request: text property to prevent font-locking
Date: Thu, 28 Aug 2014 14:18:28 -0700 (PDT)

Excuse me if I'm missing something that is already available.
And in that case, please let me know what it is, so I can use it.

I want to apply some ad-hoc highlighting with text property `face'
in a font-locked buffer (whether font-locking occurs before or after
I apply `face' for this highlighting).

I do not want font-lock to override this highlighting.  I do not want
to use `font-lock-keywords' (e.g. with KEEP) in order to create this
highlighting.  I just want to prevent font-lock from overriding it.

I want to apply some other text property to the highlighted text, to
tell font-lock not to fiddle with it ("hands off this text").

1. Does this possibility already exist in Emacs?  I looked but didn't
   find anything.

2. If not, can we please add it?

Wrt #2:

Years ago I added this feature to code that I use.  It works for me,
but I don't claim that the way I implemented it is the way to go.

The code I use is here:

Essentially I did this:

1. Defined function `put-text-property-unless-ignore', which is the
   same as `put-text-property' but ignores text that has property

2. Redefined function `font-lock-default-unfontify-region' to not
   unfontify text that has property `font-lock-ignore',
3. Redefined these functions to use `put-text-property-unless-ignore'
   instead of `put-text-property':


   That is, the change to each of these functions is ONLY to use
   `put-text-property-unless-ignore' instead of `put-text-property'.

My implementation of `put-text-property-unless-ignore':

(defun put-text-property-unless-ignore (start end property value
                                        &optional object)
  "`put-text-property', but ignore text with property `font-lock-ignore'."
  (let ((here  (min start end))
        (end1  (max start end))
    (while (< here end1)
      (setq chg  (next-single-property-change here 'font-lock-ignore
                                              object end1))
      (unless (get-text-property here 'font-lock-ignore object)
        (put-text-property here chg property value object))
      (setq here  chg))))

Perhaps there is a better way to do this.  Dunno.

In any case, my request is just for Emacs to have such a feature,
however it might be implemented.  Even better would be an answer that
Emacs already has something like this that I'm unaware of.

I use this feature for various highlighting (and unhighlighting)
commands, so that the highlighting works for font-locked text too.
This includes `facemenu-add-face' (my version).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]