unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* feature request: text property to prevent font-locking
@ 2014-08-28 21:18 Drew Adams
  2014-08-30  9:27 ` Alan Mackenzie
  2014-08-31 14:31 ` Wolfgang Jenkner
  0 siblings, 2 replies; 18+ messages in thread
From: Drew Adams @ 2014-08-28 21:18 UTC (permalink / raw)
  To: emacs-devel

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:
http://www.emacswiki.org/emacs-en/download/font-lock%2b.el

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
   `font-lock-ignore'.

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':

   font-lock-prepend-text-property
   font-lock-append-text-property
   font-lock-fillin-text-property
   font-lock-apply-syntactic-highlight
   font-lock-fontify-syntactically-region
   font-lock-apply-highlight
   font-lock-fontify-anchored-keywords
   font-lock-fontify-keywords-region

   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))
        chg)
    (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).



^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-09-02  6:04 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-28 21:18 feature request: text property to prevent font-locking Drew Adams
2014-08-30  9:27 ` Alan Mackenzie
2014-08-30 20:15   ` Drew Adams
2014-08-30 21:34     ` Thien-Thi Nguyen
2014-08-31  6:06       ` Drew Adams
2014-08-31 16:11         ` Drew Adams
2014-08-31 12:40     ` Stefan Monnier
2014-08-31 15:30       ` Drew Adams
2014-08-31 19:57         ` Stefan Monnier
2014-08-31 21:07           ` Drew Adams
2014-08-31 21:43           ` Alan Mackenzie
2014-09-01  1:37             ` Stephen J. Turnbull
2014-09-01 20:45               ` Stefan Monnier
2014-09-02  2:02                 ` Stephen J. Turnbull
2014-09-02  2:33                 ` Richard Stallman
2014-09-02  6:04                   ` David Kastrup
2014-08-31 14:31 ` Wolfgang Jenkner
2014-08-31 16:03   ` Drew Adams

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).