From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel 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 Message-ID: References: <871uz6h7vf.fsf@gmail.com> <201106091415.p59EFNcQ003457@beta.mvs.co.il> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1307633954 17521 80.91.229.12 (9 Jun 2011 15:39:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Jun 2011 15:39:14 +0000 (UTC) Cc: wojciech.meyer@googlemail.com, emacs-devel@gnu.org To: ehud@unix.mvs.co.il Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 09 17:39:10 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QUhK6-0007dK-UN for ged-emacs-devel@m.gmane.org; Thu, 09 Jun 2011 17:39:07 +0200 Original-Received: from localhost ([::1]:36027 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUhK5-0002gy-JQ for ged-emacs-devel@m.gmane.org; Thu, 09 Jun 2011 11:39:05 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:37634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUhEI-00017J-Tl for emacs-devel@gnu.org; Thu, 09 Jun 2011 11:33:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QUhEG-0002pg-O8 for emacs-devel@gnu.org; Thu, 09 Jun 2011 11:33:06 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]:60006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUhEG-0002pZ-FE for emacs-devel@gnu.org; Thu, 09 Jun 2011 11:33:04 -0400 Original-Received: from 213-159-126-200.fibertel.com.ar ([200.126.159.213]:39281 helo=ceviche.home) by fencepost.gnu.org with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1QUhEG-0007y1-0u; Thu, 09 Jun 2011 11:33:04 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 381F3667EF; Thu, 9 Jun 2011 12:33:00 -0300 (ART) In-Reply-To: <201106091415.p59EFNcQ003457@beta.mvs.co.il> (Ehud Karni's message of "Thu, 9 Jun 2011 17:15:23 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.10 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:140323 Archived-At: >> 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