unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* set-text-properties and jit-lock-mode
@ 2016-02-21 18:02 Alan Schmitt
  2016-02-21 19:04 ` Alan Mackenzie
  2016-02-21 20:30 ` Eli Zaretskii
  0 siblings, 2 replies; 8+ messages in thread
From: Alan Schmitt @ 2016-02-21 18:02 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 969 bytes --]

Hello,

I'm tracking down a bug in ledger-mode and I'm now at the point where I
think I need some help about some emacs core code.

The problem: if jit-lock-mode it t, then using set-text-properties to
change the face does not work.

To reproduce: start emacs with -Q. In the scratch buffer, type "foo".
Then evaluate:
(set-text-properties 192 195 (list 'face 'italic))

Nothing changes, and when I do a `describe-char' on one letter of "foo"
I don't see the face.

If I then evaluate
(setq jit-lock-mode nil)
(set-text-properties 192 195 (list 'face 'italic))

then I see the face change to italic, confirmed by `describe-char'.

As `set-text-properties' is a function in C, I don't know how to look at
its source (any pointers on how to do this would be great). Is it
supposed not to work for faces when jit-lock is on?

Thanks,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-01, Mauna Loa Obs.): 402.52

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: set-text-properties and jit-lock-mode
  2016-02-21 18:02 set-text-properties and jit-lock-mode Alan Schmitt
@ 2016-02-21 19:04 ` Alan Mackenzie
  2016-02-22  7:29   ` Alan Schmitt
  2016-02-24  3:40   ` Stefan Monnier
  2016-02-21 20:30 ` Eli Zaretskii
  1 sibling, 2 replies; 8+ messages in thread
From: Alan Mackenzie @ 2016-02-21 19:04 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-devel

Hello, Alan.

On Sun, Feb 21, 2016 at 07:02:31PM +0100, Alan Schmitt wrote:
> Hello,

> I'm tracking down a bug in ledger-mode and I'm now at the point where I
> think I need some help about some emacs core code.

> The problem: if jit-lock-mode it t, then using set-text-properties to
> change the face does not work.

> To reproduce: start emacs with -Q. In the scratch buffer, type "foo".
> Then evaluate:
> (set-text-properties 192 195 (list 'face 'italic))

> Nothing changes, and when I do a `describe-char' on one letter of "foo"
> I don't see the face.

At a guess, what's happening here is this: your `set-text-properties'
does indeed work.  But setting text properties is a buffer change.  So
`before-change-functions' and `after-change-functions' will both be
executed.  `a-c-f' contains `jit-lock-after-change', which helpfully
refontifies the line for you.  All this happens before the screen is
redisplayed.

If you bind these hooks to nil around your call, I think it will work:

(let (before-change-functions after-change-functions)
  (set-text-properties 192 195 (list 'face 'italic)))

> If I then evaluate
> (setq jit-lock-mode nil)
> (set-text-properties 192 195 (list 'face 'italic))

> then I see the face change to italic, confirmed by `describe-char'.

> As `set-text-properties' is a function in C, I don't know how to look at
> its source (any pointers on how to do this would be great). Is it
> supposed not to work for faces when jit-lock is on?

> Thanks,

> Alan

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: set-text-properties and jit-lock-mode
  2016-02-21 18:02 set-text-properties and jit-lock-mode Alan Schmitt
  2016-02-21 19:04 ` Alan Mackenzie
@ 2016-02-21 20:30 ` Eli Zaretskii
  2016-02-22  7:38   ` Alan Schmitt
  1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2016-02-21 20:30 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-devel

> From: Alan Schmitt <alan.schmitt@polytechnique.org>
> Date: Sun, 21 Feb 2016 19:02:31 +0100
> 
> The problem: if jit-lock-mode it t, then using set-text-properties to
> change the face does not work.
> 
> To reproduce: start emacs with -Q. In the scratch buffer, type "foo".
> Then evaluate:
> (set-text-properties 192 195 (list 'face 'italic))
> 
> Nothing changes, and when I do a `describe-char' on one letter of "foo"
> I don't see the face.
> 
> If I then evaluate
> (setq jit-lock-mode nil)
> (set-text-properties 192 195 (list 'face 'italic))
> 
> then I see the face change to italic, confirmed by `describe-char'.
> 
> As `set-text-properties' is a function in C, I don't know how to look at
> its source (any pointers on how to do this would be great).

You don't need to look at its source.  The documentation clearly says
that it completely replaces the property list of the specified region
with the properties you specify as its arguments.

> Is it supposed not to work for faces when jit-lock is on?

Yes.  Font-lock overwrites the 'face' text properties with its own,
because it uses set-text-properties.



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

* Re: set-text-properties and jit-lock-mode
  2016-02-21 19:04 ` Alan Mackenzie
@ 2016-02-22  7:29   ` Alan Schmitt
  2016-02-24  3:40   ` Stefan Monnier
  1 sibling, 0 replies; 8+ messages in thread
From: Alan Schmitt @ 2016-02-22  7:29 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1245 bytes --]

On 2016-02-21 20:04, Alan Mackenzie <acm@muc.de> writes:

>> The problem: if jit-lock-mode it t, then using set-text-properties to
>> change the face does not work.
>
>> To reproduce: start emacs with -Q. In the scratch buffer, type "foo".
>> Then evaluate:
>> (set-text-properties 192 195 (list 'face 'italic))
>
>> Nothing changes, and when I do a `describe-char' on one letter of "foo"
>> I don't see the face.
>
> At a guess, what's happening here is this: your `set-text-properties'
> does indeed work.  But setting text properties is a buffer change.  So
> `before-change-functions' and `after-change-functions' will both be
> executed.  `a-c-f' contains `jit-lock-after-change', which helpfully
> refontifies the line for you.  All this happens before the screen is
> redisplayed.
>
> If you bind these hooks to nil around your call, I think it will work:
>
> (let (before-change-functions after-change-functions)
>   (set-text-properties 192 195 (list 'face 'italic)))

Thanks a lot for the suggestion, but unfortunately it does not work. I
guess some other function must be re-fontifying the text.

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-01, Mauna Loa Obs.): 402.52

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: set-text-properties and jit-lock-mode
  2016-02-21 20:30 ` Eli Zaretskii
@ 2016-02-22  7:38   ` Alan Schmitt
  2016-02-22  8:51     ` Anders Lindgren
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Schmitt @ 2016-02-22  7:38 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1108 bytes --]

Hello Eli,

On 2016-02-21 21:30, Eli Zaretskii <eliz@gnu.org> writes:

>> As `set-text-properties' is a function in C, I don't know how to look at
>> its source (any pointers on how to do this would be great).
>
> You don't need to look at its source.  The documentation clearly says
> that it completely replaces the property list of the specified region
> with the properties you specify as its arguments.

Yes, I read that. But as I was not seeing this happen, I wanted to
understand why. I was wrongly assuming set-text-properties was not
changing them, but if I understand your message it does change them, but
they are changed back because of font-lock.

>> Is it supposed not to work for faces when jit-lock is on?
>
> Yes.  Font-lock overwrites the 'face' text properties with its own,
> because it uses set-text-properties.

Is there a way to change the face that plays well with font-lock? I
tried `font-lock-append-text-property' but it did not work.

Thanks,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-01, Mauna Loa Obs.): 402.52

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: set-text-properties and jit-lock-mode
  2016-02-22  7:38   ` Alan Schmitt
@ 2016-02-22  8:51     ` Anders Lindgren
  2016-02-22  9:02       ` Alan Schmitt
  0 siblings, 1 reply; 8+ messages in thread
From: Anders Lindgren @ 2016-02-22  8:51 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 459 bytes --]

>
> Is there a way to change the face that plays well with font-lock? I
> tried `font-lock-append-text-property' but it did not work.
>
>
You can set the text property `font-lock-face' instead of `face'. When
`font-lock' is activated, it sets up this as a low-level alias to `face'
but after that doesn't touch it. Effectively, it allows face properties
defined by normal code and by font-lock to live side by side in the same
buffer.

    -- Anders Lindgren

[-- Attachment #2: Type: text/html, Size: 801 bytes --]

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

* Re: set-text-properties and jit-lock-mode
  2016-02-22  8:51     ` Anders Lindgren
@ 2016-02-22  9:02       ` Alan Schmitt
  0 siblings, 0 replies; 8+ messages in thread
From: Alan Schmitt @ 2016-02-22  9:02 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 742 bytes --]

On 2016-02-22 09:51, Anders Lindgren <andlind@gmail.com> writes:

>     Is there a way to change the face that plays well with font-lock? I
>     tried `font-lock-append-text-property' but it did not work.
>
> You can set the text property `font-lock-face' instead of `face'. When
> `font-lock' is activated, it sets up this as a low-level alias to `face' but
> after that doesn't touch it. Effectively, it allows face properties defined by
> normal code and by font-lock to live side by side in the same buffer.

It works great, thanks a lot. I think I now see how to get around the
ledger-mode bug.

Thanks again,

Alan

-- 
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-01, Mauna Loa Obs.): 402.52

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

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

* Re: set-text-properties and jit-lock-mode
  2016-02-21 19:04 ` Alan Mackenzie
  2016-02-22  7:29   ` Alan Schmitt
@ 2016-02-24  3:40   ` Stefan Monnier
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2016-02-24  3:40 UTC (permalink / raw)
  To: emacs-devel

> (let (before-change-functions after-change-functions)
>   (set-text-properties 192 195 (list 'face 'italic)))

Please never ever let-bind those hooks.
Let-bind `inhibit-buffer-modification-hooks' instead, thank you.


        Stefan




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

end of thread, other threads:[~2016-02-24  3:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-21 18:02 set-text-properties and jit-lock-mode Alan Schmitt
2016-02-21 19:04 ` Alan Mackenzie
2016-02-22  7:29   ` Alan Schmitt
2016-02-24  3:40   ` Stefan Monnier
2016-02-21 20:30 ` Eli Zaretskii
2016-02-22  7:38   ` Alan Schmitt
2016-02-22  8:51     ` Anders Lindgren
2016-02-22  9:02       ` Alan Schmitt

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