unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: emacs-devel@gnu.org
Subject: feature request: text property to prevent font-locking
Date: Thu, 28 Aug 2014 14:18:28 -0700 (PDT)	[thread overview]
Message-ID: <b896ecdd-2457-4f84-8d0d-f58445db89f6@default> (raw)

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



             reply	other threads:[~2014-08-28 21:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-28 21:18 Drew Adams [this message]
2014-08-30  9:27 ` feature request: text property to prevent font-locking 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b896ecdd-2457-4f84-8d0d-f58445db89f6@default \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).