* Different fontification in temp buffer
@ 2019-01-20 0:48 Daniele Nicolodi
2019-01-20 2:14 ` Daniele Nicolodi
2019-01-21 2:51 ` Stefan Monnier
0 siblings, 2 replies; 7+ messages in thread
From: Daniele Nicolodi @ 2019-01-20 0:48 UTC (permalink / raw)
To: Emacs developers
Hello,
I'm hacking on a minor mode and I'm writing unit tests for the
fontification feature. I am encountering a strange issue: the
fontification is different if execute in a temp buffer or in a regular
buffer. In particular:
(with-temp-buffer
(insert string)
(fundamental-mode)
(beancount-mode)
(font-lock-ensure)
(buffer-string))
and
(with-current-buffer (generate-new-buffer "*test*")
(insert string)
(fundamental-mode)
(beancount-mode)
(font-lock-ensure)
(buffer-string))
strangely result in two different results. Why is it so?
Thank you.
Cheers,
Dan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Different fontification in temp buffer
2019-01-20 0:48 Different fontification in temp buffer Daniele Nicolodi
@ 2019-01-20 2:14 ` Daniele Nicolodi
2019-01-20 13:57 ` Noam Postavsky
2019-01-21 2:51 ` Stefan Monnier
1 sibling, 1 reply; 7+ messages in thread
From: Daniele Nicolodi @ 2019-01-20 2:14 UTC (permalink / raw)
To: emacs-devel
On 19/01/2019 17:48, Daniele Nicolodi wrote:
> Hello,
>
> I'm hacking on a minor mode and I'm writing unit tests for the
> fontification feature. I am encountering a strange issue: the
> fontification is different if execute in a temp buffer or in a regular
> buffer. In particular:
>
> (with-temp-buffer
> (insert string)
> (fundamental-mode)
> (beancount-mode)
> (font-lock-ensure)
> (buffer-string))
>
> and
>
> (with-current-buffer (generate-new-buffer "*test*")
> (insert string)
> (fundamental-mode)
> (beancount-mode)
> (font-lock-ensure)
> (buffer-string))
>
> strangely result in two different results. Why is it so?
Investigating further, the difference between the two cases is that
with-temp-buffer creates a buffer that does not keep undo information.
Surely enough, if I modify the second code to do the same (using a
buffer name starting with a space character) I obtain the same behavior.
What's left to understand is why this results in two different syntax
table being applied to the buffer.
Cheers,
Dan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Different fontification in temp buffer
2019-01-20 2:14 ` Daniele Nicolodi
@ 2019-01-20 13:57 ` Noam Postavsky
2019-01-20 15:55 ` Daniele Nicolodi
0 siblings, 1 reply; 7+ messages in thread
From: Noam Postavsky @ 2019-01-20 13:57 UTC (permalink / raw)
To: Daniele Nicolodi; +Cc: Emacs developers
On Sat, 19 Jan 2019 at 21:14, Daniele Nicolodi <daniele@grinta.net> wrote:
>
> On 19/01/2019 17:48, Daniele Nicolodi wrote:
> > I'm hacking on a minor mode and I'm writing unit tests for the
> > fontification feature. I am encountering a strange issue: the
> > fontification is different if execute in a temp buffer or in a regular
> > buffer.
> Investigating further, the difference between the two cases is that
> with-temp-buffer creates a buffer that does not keep undo information.
It's not about undo info, but rather that font-lock mode doesn't turn
on in temp buffers.
See in the definition of font-lock-mode:
http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/font-core.el?h=emacs-26.1#n135
;; Don't turn on Font Lock mode if we don't have a display (we're running a
;; batch job) or if the buffer is invisible (the name starts with a space).
(when (or noninteractive (eq (aref (buffer-name) 0) ?\s))
(setq font-lock-mode nil))
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Different fontification in temp buffer
2019-01-20 13:57 ` Noam Postavsky
@ 2019-01-20 15:55 ` Daniele Nicolodi
2019-01-20 17:56 ` Noam Postavsky
0 siblings, 1 reply; 7+ messages in thread
From: Daniele Nicolodi @ 2019-01-20 15:55 UTC (permalink / raw)
To: emacs-devel
Hi Noam,
On 20/01/2019 06:57, Noam Postavsky wrote:
> On Sat, 19 Jan 2019 at 21:14, Daniele Nicolodi <daniele@grinta.net> wrote:
>>
>> On 19/01/2019 17:48, Daniele Nicolodi wrote:
>
>>> I'm hacking on a minor mode and I'm writing unit tests for the
>>> fontification feature. I am encountering a strange issue: the
>>> fontification is different if execute in a temp buffer or in a regular
>>> buffer.
>
>> Investigating further, the difference between the two cases is that
>> with-temp-buffer creates a buffer that does not keep undo information.
>
> It's not about undo info, but rather that font-lock mode doesn't turn
> on in temp buffers.
>
> See in the definition of font-lock-mode:
> http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/font-core.el?h=emacs-26.1#n135
>
> ;; Don't turn on Font Lock mode if we don't have a display (we're running a
> ;; batch job) or if the buffer is invisible (the name starts with a space).
> (when (or noninteractive (eq (aref (buffer-name) 0) ?\s))
> (setq font-lock-mode nil))
I'm explicitly turning on font-lock mode with (font-lock-ensure). The
buffer is indeed fontified, but apparently with a different syntax
table. However, I don't fully understand what beancount-mode does with
the syntax table, thus I cannot exclude a bug there.
Cheers,
Dan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Different fontification in temp buffer
2019-01-20 15:55 ` Daniele Nicolodi
@ 2019-01-20 17:56 ` Noam Postavsky
2019-01-20 18:32 ` Daniele Nicolodi
0 siblings, 1 reply; 7+ messages in thread
From: Noam Postavsky @ 2019-01-20 17:56 UTC (permalink / raw)
To: Daniele Nicolodi; +Cc: Emacs developers
On Sun, 20 Jan 2019 at 10:55, Daniele Nicolodi <daniele@grinta.net> wrote:
> > http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/font-core.el?h=emacs-26.1#n135
> >
> > ;; Don't turn on Font Lock mode if we don't have a display (we're running a
> > ;; batch job) or if the buffer is invisible (the name starts with a space).
> > (when (or noninteractive (eq (aref (buffer-name) 0) ?\s))
> > (setq font-lock-mode nil))
>
> I'm explicitly turning on font-lock mode with (font-lock-ensure). The
> buffer is indeed fontified, but apparently with a different syntax
> table. However, I don't fully understand what beancount-mode does with
> the syntax table, thus I cannot exclude a bug there.
As far as I can tell, font-lock-ensure doesn't actually turn on
font-lock mode, it just goes ahead and fontifies the buffer anyway.
Perhaps beancount-mode's fontification functions don't quite work
properly in that case.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Different fontification in temp buffer
2019-01-20 17:56 ` Noam Postavsky
@ 2019-01-20 18:32 ` Daniele Nicolodi
0 siblings, 0 replies; 7+ messages in thread
From: Daniele Nicolodi @ 2019-01-20 18:32 UTC (permalink / raw)
To: emacs-devel
On 20/01/2019 10:56, Noam Postavsky wrote:
> On Sun, 20 Jan 2019 at 10:55, Daniele Nicolodi <daniele@grinta.net> wrote:
>
>>> http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/font-core.el?h=emacs-26.1#n135
>>>
>>> ;; Don't turn on Font Lock mode if we don't have a display (we're running a
>>> ;; batch job) or if the buffer is invisible (the name starts with a space).
>>> (when (or noninteractive (eq (aref (buffer-name) 0) ?\s))
>>> (setq font-lock-mode nil))
>>
>> I'm explicitly turning on font-lock mode with (font-lock-ensure). The
>> buffer is indeed fontified, but apparently with a different syntax
>> table. However, I don't fully understand what beancount-mode does with
>> the syntax table, thus I cannot exclude a bug there.
>
> As far as I can tell, font-lock-ensure doesn't actually turn on
> font-lock mode, it just goes ahead and fontifies the buffer anyway.
> Perhaps beancount-mode's fontification functions don't quite work
> properly in that case.
Ah! I didn't know that there is a difference between fontifying a buffer
and enabling font-lock mode. I'll try to understand the differences.
Thanks!
Cheers,
Dan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Different fontification in temp buffer
2019-01-20 0:48 Different fontification in temp buffer Daniele Nicolodi
2019-01-20 2:14 ` Daniele Nicolodi
@ 2019-01-21 2:51 ` Stefan Monnier
1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2019-01-21 2:51 UTC (permalink / raw)
To: emacs-devel
> fontification is different if execute in a temp buffer or in a regular
> buffer. In particular:
Sounds like a bug. Please report it (and describe the actual difference
you see).
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-01-21 2:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-20 0:48 Different fontification in temp buffer Daniele Nicolodi
2019-01-20 2:14 ` Daniele Nicolodi
2019-01-20 13:57 ` Noam Postavsky
2019-01-20 15:55 ` Daniele Nicolodi
2019-01-20 17:56 ` Noam Postavsky
2019-01-20 18:32 ` Daniele Nicolodi
2019-01-21 2:51 ` Stefan Monnier
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).