all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: ehud@unix.mvs.co.il
Cc: wojciech.meyer@googlemail.com, emacs-devel@gnu.org
Subject: Re: How to avoid put-text-property setting buffer modified flag, and messing with the undo history?
Date: Thu, 09 Jun 2011 12:33:00 -0300	[thread overview]
Message-ID: <jwvy61bqb22.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <201106091415.p59EFNcQ003457@beta.mvs.co.il> (Ehud Karni's message of "Thu, 9 Jun 2011 17:15:23 +0300")

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



      reply	other threads:[~2011-06-09 15:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=jwvy61bqb22.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=ehud@unix.mvs.co.il \
    --cc=emacs-devel@gnu.org \
    --cc=wojciech.meyer@googlemail.com \
    /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.