From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#4587: Antwort: Re: bug#4587: 23.1; sort-lines and sort-fields always set buffer modified Date: Sun, 25 Oct 2009 11:27:21 -0400 Message-ID: References: Reply-To: Stefan Monnier , 4587@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1256485657 10766 80.91.229.12 (25 Oct 2009 15:47:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 25 Oct 2009 15:47:37 +0000 (UTC) Cc: 4587@emacsbugs.donarmstrong.com, bug-gnu-emacs@gnu.org To: Kevin Rodgers Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 25 16:47:30 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N25JW-0002L7-KX for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Oct 2009 16:47:26 +0100 Original-Received: from localhost ([127.0.0.1]:58944 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N25JV-0002EW-Tt for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Oct 2009 11:47:25 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N25JR-0002ED-6M for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 11:47:21 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N25JM-0002Df-KV for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 11:47:20 -0400 Original-Received: from [199.232.76.173] (port=60986 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N25JM-0002DV-B8 for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 11:47:16 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:44335) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N25JL-0005kc-OA for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 11:47:16 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n9PFlD7f023321; Sun, 25 Oct 2009 08:47:13 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n9PFZ5PU021203; Sun, 25 Oct 2009 08:35:05 -0700 Resent-Date: Sun, 25 Oct 2009 08:35:05 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Stefan Monnier Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Sun, 25 Oct 2009 15:35:05 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: followup 4587 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by submit@emacsbugs.donarmstrong.com id=B.125648445120160 (code B ref -1); Sun, 25 Oct 2009 15:35:05 +0000 Original-Received: (at submit) by emacsbugs.donarmstrong.com; 25 Oct 2009 15:27:31 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n9PFRT8U020153 for ; Sun, 25 Oct 2009 08:27:30 -0700 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N250C-0007ly-Pr for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 11:27:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2507-0007jj-IG for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 11:27:28 -0400 Original-Received: from [199.232.76.173] (port=45325 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2507-0007jd-9k for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 11:27:23 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.183]:27247 helo=ironport2-out.pppoe.ca) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N2506-00039l-Vx for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 11:27:23 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtkEAF8L5EpLd/xb/2dsb2JhbACBT9JuhD8EiDQ X-IronPort-AV: E=Sophos;i="4.44,621,1249272000"; d="scan'208";a="48131225" Original-Received: from 75-119-252-91.dsl.teksavvy.com (HELO pastel.home) ([75.119.252.91]) by ironport2-out.pppoe.ca with ESMTP; 25 Oct 2009 11:27:22 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id D0D468225; Sun, 25 Oct 2009 11:27:21 -0400 (EDT) In-Reply-To: (Kevin Rodgers's message of "Sun, 25 Oct 2009 07:41:47 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-CrossAssassin-Score: 2 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Sun, 25 Oct 2009 11:47:20 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:32234 Archived-At: >> Maybe we could make it suitable, turn it into a macro and use it around >> the various candidates. AFAICT, here are the problems I see with it: >> - the call to md5 should use as much as possible the internal encoding. >> I.e. at least pass an `emacs-internal' arg, tho it would be even >> better to let md5 work directly on the internal representation. >> - it should only work on the afected region rather than the whole buffer >> (i.e. it needs start..end arguments). >> - should it fiddle with the undo list? or even revert the whole >> "without-effect" set of changes (the changes may result in the same >> final text, but they may very well have moved markers and changed >> text-properties, and it might be desirable to undo those changes, so >> as to better pretend nothing happened). > Is this what you have in mind? That looks almost right. Here are some nitpicks: > (defmacro with-maybe-region-modified (beg end &rest body) > "Execute BODY, then `restore-buffer-modified-p' if the contents are unchanged. > BODY should not change the current buffer or modify the contents outside the region > between BEG and END." The docstring is wider then our convention. > `(let* ((region-beg ,beg) > (region-end ,end) > (buffer-was-modified-p (buffer-modified-p)) > (buffer-was-not-modified-md5 (if (not buffer-was-modified-p) > (md5 (current-buffer) region-beg region-end > 'emacs-mule))) Use `emacs-internal' here (in Emacs-23, the internal encoding is not emacs-mule any more). Don't use hardcoded symbols, since `body' might actually refer to identically-named variables. Add a FIXME-comment indicating that md5 should be improved to compute this result without actually performing the encoding. Or better yet, provide a patch to `md5' which does just that. > ;; (orig-buffer-undo-list buffer-undo-list) > (with-maybe-region-modified-result > (progn ,@body))) ; save-current-buffer? Yes, save-current-buffer seems to be necessary here, otherwise the code will misbehave. > (when (and (not buffer-was-modified-p) > (buffer-modified-p) > (not (equal buffer-was-not-modified-md5 > (md5 (current-buffer) region-beg region-end > 'emacs-mule)))) > (restore-buffer-modified-p buffer-was-modified-p) > ;; (setq buffer-undo-list orig-buffer-undo-list) > ) > with-maybe-region-modified-result)) I think region-end should be assisted by a marker so we can detect if the size of the region has changed and skip the second md5 call in that case. More importantly, I think the "(not (equal ...))" should be "(equal ...)". Also, please add a FIXME-comment about whether we should maybe use `undo' to revert the "effectless" changes. Stefan