all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "Emacs-Devel" <emacs-devel@gnu.org>
Subject: RE: how to prevent font-lock from messing with a portion of text?
Date: Fri, 23 Mar 2007 18:33:21 -0700	[thread overview]
Message-ID: <EIENLHALHGIMHGDOLMIMIEBJDAAA.drew.adams@oracle.com> (raw)
In-Reply-To: <jwvbqij61qd.fsf-monnier+emacs@gnu.org>

> > 2. It doesn't prevent font-lock from clobbering the highlighted
> >    text when doing syntactic font lock (e.g. in comments).
>
> It's true that font-lock's own faces take precedence.  But the
> font-lock-face property is not clobbered.

I said that the "highlighted text", that is, the _highlighting_, is
clobbered.

> > 3. The highlighting is removed when font-lock-mode is turned off.
>
> Again, the lont-lock-face properties are not removed.  But yes, it is made
> inactive.

Again, I didn't say anything about removal of the `font-lock-face' property.
I said that the "highlighting" is removed. Highlighting is a visual effect.
The highlighting that a user adds is wiped out. The text property might
still be there, but the highlighting that was its purpose is gone.

> > IOW, no, `font-lock-face' property was not at all designed
> > specifically for this kind of case. Highlight some text, and have
> > it stay highlighted whether or not font-lock-mode is on. Have
> > font-lock ignore that text when it does its own highlighting.
>
> Well, with those extra conditions, then indeed, no it doesn't quite fit
> your bill.

Not much "extra" about that. Do you think that users who want to highlight
portions of a buffer (e.g. matching regexps) only want to do so in buffers
that are not font-locked?

For example, facemenu stuff such as `facemenu-set-face' is useless for
font-locked buffers, only because of this limitation. We give users a lame
message telling them, in effect, Fuggedabowdit!, only because we are unable
to tell font-lock "Hands off!" of the highlighting that users add using
facemenu (or other highlighting packages).

I have a highlighting library, for instance
(http://www.emacswiki.org/cgi-bin/wiki/HighLight), that lets you use either
overlays or text properties. If you choose to use text properties, font-lock
clobbers the highlighting. One use of text properties is to do essentially
what `facemenu-set-face' does, including entering new text in some face.
Useless in a font-locked buffer, only because of this silly limitation.

Now, if font-lock didn't itself use the `face' property, things might be
OK...

Or, as I said, if one could at least set some other property (e.g.
`font-lock-ignore') that told font-lock "Hands off!" this text...

> How 'bout:
> - use font-lock-mode-hook to move `face' properties to/from a new property
>   `persistent-face' when turning font-lock-mode on/off.

It's a joke, right? Why don't you make font-lock use such a property itself,
all the time? Make it independent of `face' altogether.

> - add a font-lock-fontify-region-function so that after fontifying
>   the region normally, you scan the region for `persistent-face'
>   properties and copy those to the `face' property.

Right (ridiculous). Move all of `face' to `persistent-face' and then back
again. And besides such a convoluted, heavy workaround?

What about all of those "many different ways, each one with advantages and
quirks" that you promised? How about _one_ simple way to tell font-lock
"Hands off!" this text?

> > That's too bad.  How about adding that, after the release?
>
> I'm not interested in coding it up because I don't see a need for
> it, but if someone provides a clean patch, I don't see any reason
> why I'd oppose it.

I hope someone does. I would myself, if FFS could accept it without employer
papers. I can't believe it would be hard for font-lock to check if text it
wants to work with has an ignore-me property.

Or some other mechanism that allows the same feature: be able to apply
property `face' to some text and not have that highlighting overridden by
what font-lock does. I'm not wedded to any particular way to implement that
feature, but I think it's a needed feature.

> > From what you say, it sounds as if that whole passage about
> > that property should be stated in terms of jit-lock only. And there
> > should be a cross reference to the place where jit-lock is introduced.
>
> Yes, that's probably right.

Glad we could agree about something.

I'd add that the Elisp manual is pretty poor on explaining font lock,
generally. Start with `i font-lock' and see what you get. Keep hitting `,'
and see if you get a good view of what font-lock is all about.

Or start with node _Font Lock Mode_ (the best place to start, and in the
main menu, but not easy to stumble upon with `i'). There's not much in that
first node.  That's fine, but what happens when you go to the next node,
_Font Lock Basics_, which has the menu-item description "Overview of
customizing Font Lock"?

1. That node is simply a description of variable `font-lock-defaults'.

2. That node has nothing to do with "customizing Font Lock", in spite of
what was advertised.

3. That node is _not_ an overview of font lock or a description of "font
lock basics". It's almost the farthest thing from the basics.

Node _Search-based Fontification_ is closer to an overview of font-lock
customization ("the most important variable for customizing..."), but it is
still not the place to start. There should be a real overview of font lock
at the beginning: what it is, what it's for (why), how to customize it
(although that really belongs in the Emacs manual), and how it works. It
should include a getting-started example or two, showing how to use font
lock in your own code (including how to get around it).

I submit that the font-lock doc is not easy to read. You pointed out one
area where it is also incorrect. It would be good if someone who is familiar
with the purpose, use, and implementation of font lock would reread the doc
and try to improve it.

  reply	other threads:[~2007-03-24  1:33 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 [this message]
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
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

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

  git send-email \
    --in-reply-to=EIENLHALHGIMHGDOLMIMIEBJDAAA.drew.adams@oracle.com \
    --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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.