unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "Stefan Monnier" <monnier@iro.umontreal.ca>
Cc: Emacs-Devel <emacs-devel@gnu.org>
Subject: RE: how to prevent font-lock from messing with a portion of text?
Date: Mon, 26 Mar 2007 08:56:57 -0700	[thread overview]
Message-ID: <BDEIJAFNGDOAGCJIPKPBMEIBCDAA.drew.adams@oracle.com> (raw)
In-Reply-To: <jwvmz20cgcr.fsf-monnier+emacs@gnu.org>

> > (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)
> >       (unless (get-text-property here 'font-lock-ignore object)
> >         (put-text-property here (1+ here) property value object))
> >       (setq here (1+ here)))))
>
> This will still override a face on a word inside a string, because
> (get-text-property <string-start> 'font-lock-ignore object) will be nil.
> You need to check for the presence of the property over the whole
> start..end region.

I have a string in an emacs-lisp-mode buffer. I highlight a word in the
string using property `face' and I put property `font-lock-ignore' on it
also. I turn font-lock on and off - the word highlighting stays. I modify
the file and save it - the word highlighting stays. I highlight the whole
string, or more than a word, with the highlighting starting or ending on or
off a word boundary - the highlighting stays. I don't see the problem you
mention.

Could you explain the problem differently (e.g. recipe to test)? I no doubt
misunderstand.

> > 2. In font-lock.el, use this definition of
> > `font-lock-default-unfontify-region':
>
> > (defun font-lock-default-unfontify-region (beg end)
> >   "Unfontify from BEG to END, unless text with property
> `font-lock-ignore'."
> >   (let ((here (min beg end))
> >         (end1 (max beg end)))
> >     (while (< here end1)
> >       (unless (get-text-property here 'font-lock-ignore)
> >         (remove-list-of-text-properties
> >          here (1+ here) (append font-lock-extra-managed-props
> >                                 (if font-lock-syntactic-keywords
> >                                     '(syntax-table face
> font-lock-multiline)
> >                                   '(face font-lock-multiline)))))
> >       (setq here (1+ here)))))
>
> Same thing here, except even more so.

Please give me a recipe to test. I don't say I don't believe you or that the
code above is foolproof, but I'd like to see what the problem is.

> Then the problem becomes that doing all those extra checks costs time, all
> the time, for a feature which will be almost never used.

I already spoke to performance. I don't claim that the above code is
optimized. I intended it to show in general terms what I meant, so there was
no misunderstanding about that.

> OK, here's another option: don't change anything to font-lock,
> don't fiddle
> with it at all, just don't use text-properties to add your special faces.
> Use overlays instead. Problem solved

As I said, my own highlighting library uses overlays by default. But
sometimes text properties are useful. Facemenu is one example. The
differences that generally make overlays more useful for highlighting also
mean that they are less useful in some contexts. The fact that copying and
pasting text doesn't pick up overlays is one example: sometimes you might
want the faces pasted.

Every difference implies advantages and disadvantages. Text properties are
associated with text; overlays are associated with buffer positions, and so
on. This request is about letting a user-applied `face' property play well
with font-locking. That's all.

As I said, I'm not glued to any particular mechanism or implementation for
allowing that. If it can be proven that any reasonable implementation would
slow things down unacceptably, then an option could be used to turn on the
more costly behavior.

As it stands now, any application that uses the `face' text property gets
that highlighting trampled on by font lock - there is no simple way for an
application to prevent that. That, to me, is undesirable.

  parent reply	other threads:[~2007-03-26 15:56 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-22 16:56 how to prevent font-lock from messing with a portion of text? Drew Adams
2007-03-22 18:35 ` Stefan Monnier
2007-03-22 19:20   ` Drew Adams
2007-03-22 20:09     ` Lennart Borgman (gmail)
2007-03-22 20:49       ` Drew Adams
2007-03-22 21:40         ` Lennart Borgman (gmail)
2007-03-22 21:57     ` Miles Bader
2007-03-23 16:07     ` Stefan Monnier
2007-03-23 17:13       ` Drew Adams
2007-03-23 17:31         ` Lennart Borgman (gmail)
2007-03-23 22:36         ` Stefan Monnier
2007-03-24  1:33           ` Drew Adams
2007-03-24  1:57             ` Lennart Borgman (gmail)
2007-03-24  4:21               ` Stefan Monnier
2007-03-24  8:20                 ` Lennart Borgman (gmail)
2007-03-25  3:11                   ` Stefan Monnier
2007-03-25  3:31                     ` Lennart Borgman (gmail)
2007-03-24  4:20             ` Stefan Monnier
2007-03-26  1:48               ` Drew Adams
2007-03-26  1:59                 ` Lennart Borgman (gmail)
2007-03-26  5:52                   ` Drew Adams
2007-03-26  8:47                     ` Lennart Borgman (gmail)
2007-03-26 14:49                       ` Drew Adams
2007-03-26 13:01                 ` Stefan Monnier
2007-03-26 13:26                   ` Miles Bader
2007-03-26 15:56                     ` Drew Adams
2007-03-26 15:56                   ` Drew Adams [this message]
2007-03-26 19:11                     ` Stefan Monnier
2007-03-26 20:14                       ` 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=BDEIJAFNGDOAGCJIPKPBMEIBCDAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).