all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to avoid put-text-property setting buffer modified flag, and messing with the undo history?
@ 2011-06-06 23:12 Wojciech Meyer
  2011-06-06 23:18 ` Lennart Borgman
  2011-06-09 14:15 ` Ehud Karni
  0 siblings, 2 replies; 4+ messages in thread
From: Wojciech Meyer @ 2011-06-06 23:12 UTC (permalink / raw)
  To: emacs-devel


Hi,

I'm trying to dynamically color the buffer using text properties. It
works as follows:

1. I send modified buffer contents to the inferior process

2. Along with the contents I send the location information, what portion
of the buffer has been modified, e.g. for the first time I send whole
buffer and notify the inferior process that whole buffer shall be
invalidated.

3. After that inferior process sends back, syntax information in form of
pair range of characters and type of associated token.

4. Since the inferior process uses specials way of parsing (packrat) it
is efficient way of extracting it, and there is no real latency.

5. The language I am writing mode for allows complete redefinition of
syntax, and modifying it on the fly, so I can't use any of the
conventional ways, or even LALR parsing provided by CEDET is not enough
as it can only can approximate the base syntax, and it will not cope
well with this language.

6. For coloring I use text properties, but they change buffer marking it
as modified and altering undo information, and I don't want that.

How would you implement desired behaviour? How to efficiently workaround
this problem? Is there any other way to change faces of the buffer?
Would overlays be a solution?

Thank you,
Wojciech



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

* Re: How to avoid put-text-property setting buffer modified flag, and messing with the undo history?
  2011-06-06 23:12 How to avoid put-text-property setting buffer modified flag, and messing with the undo history? Wojciech Meyer
@ 2011-06-06 23:18 ` Lennart Borgman
  2011-06-09 14:15 ` Ehud Karni
  1 sibling, 0 replies; 4+ messages in thread
From: Lennart Borgman @ 2011-06-06 23:18 UTC (permalink / raw)
  To: Wojciech Meyer; +Cc: emacs-devel

On Tue, Jun 7, 2011 at 01:12, Wojciech Meyer
<wojciech.meyer@googlemail.com> wrote:
>
> Hi,
>
> I'm trying to dynamically color the buffer using text properties. It
> works as follows:
>
> 1. I send modified buffer contents to the inferior process
>
> 2. Along with the contents I send the location information, what portion
> of the buffer has been modified, e.g. for the first time I send whole
> buffer and notify the inferior process that whole buffer shall be
> invalidated.
>
> 3. After that inferior process sends back, syntax information in form of
> pair range of characters and type of associated token.
>
> 4. Since the inferior process uses specials way of parsing (packrat) it
> is efficient way of extracting it, and there is no real latency.
>
> 5. The language I am writing mode for allows complete redefinition of
> syntax, and modifying it on the fly, so I can't use any of the
> conventional ways, or even LALR parsing provided by CEDET is not enough
> as it can only can approximate the base syntax, and it will not cope
> well with this language.
>
> 6. For coloring I use text properties, but they change buffer marking it
> as modified and altering undo information, and I don't want that.
>
> How would you implement desired behaviour? How to efficiently workaround
> this problem? Is there any other way to change faces of the buffer?
> Would overlays be a solution?

Please see with-silent-modifications.



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

* Re: How to avoid put-text-property setting buffer modified flag, and messing with the undo history?
  2011-06-06 23:12 How to avoid put-text-property setting buffer modified flag, and messing with the undo history? Wojciech Meyer
  2011-06-06 23:18 ` Lennart Borgman
@ 2011-06-09 14:15 ` Ehud Karni
  2011-06-09 15:33   ` Stefan Monnier
  1 sibling, 1 reply; 4+ messages in thread
From: Ehud Karni @ 2011-06-09 14:15 UTC (permalink / raw)
  To: wojciech.meyer; +Cc: emacs-devel

On Tue, 07 Jun 2011 00:12:36 +0100, Wojciech Meyer wrote:
>
> I'm trying to dynamically color the buffer using text properties. It
> works as follows:
>
       [snip]
>
> 6. For coloring I use text properties, but they change buffer marking it
> as modified and altering undo information, and I don't want that.

Here is a snippet that i use for exactly the same purpose.
I don't know if it is the best solution, but it works.

   (let ((sbul buffer-undo-list)           ;; undo list for selected buffer
         (bmp (buffer-modified-p))         ;; modify state
         (buffer-read-only nil))           ;; allow change!
       (put-text-property P1 P2 'face FACE);; change face (color)
       (set-buffer-modified-p bmp)         ;; restore modify state
       (setq buffer-undo-list sbul))       ;; restore undo

Ehud.


--
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7976-561  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry



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

* Re: How to avoid put-text-property setting buffer modified flag, and messing with the undo history?
  2011-06-09 14:15 ` Ehud Karni
@ 2011-06-09 15:33   ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2011-06-09 15:33 UTC (permalink / raw)
  To: ehud; +Cc: wojciech.meyer, emacs-devel

>> I'm trying to dynamically color the buffer using text properties. It
>> works as follows:
>> 
>        [snip]
>> 
>> 6. For coloring I use text properties, but they change buffer marking it
>> as modified and altering undo information, and I don't want that.

> Here is a snippet that i use for exactly the same purpose.
> I don't know if it is the best solution, but it works.

>    (let ((sbul buffer-undo-list)           ;; undo list for selected buffer
>          (bmp (buffer-modified-p))         ;; modify state
>          (buffer-read-only nil))           ;; allow change!
>        (put-text-property P1 P2 'face FACE);; change face (color)
>        (set-buffer-modified-p bmp)         ;; restore modify state
>        (setq buffer-undo-list sbul))       ;; restore undo

Compared to what with-silent-modifications does, here are the differences:

- if the code signal an error or `throw's during put-text-property, the
  buffer-undo-list might not be restored.
- same for buffer-modified flag.
- you use set-buffer-modified-p instead of restore-buffer-modified-p
  (minor optimization).
- you bind buffer-read-only rather than inhibit-read-only.
- many other details are missing such as binding buffer-file-name
  (which is needed to avoid file-lock checks) and deactivate-mark.

Just goes to show that getting it right is tricky and hence this rather
recent macro should have been added a long time ago.


        Stefan



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

end of thread, other threads:[~2011-06-09 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-06 23:12 How to avoid put-text-property setting buffer modified flag, and messing with the undo history? Wojciech Meyer
2011-06-06 23:18 ` Lennart Borgman
2011-06-09 14:15 ` Ehud Karni
2011-06-09 15:33   ` Stefan Monnier

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.