From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers 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 07:41:47 -0600 Message-ID: References: Reply-To: Kevin Rodgers , 4587@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1256479654 27099 80.91.229.12 (25 Oct 2009 14:07:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 25 Oct 2009 14:07:34 +0000 (UTC) To: bug-gnu-emacs@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 25 15:07:27 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 1N23kk-0003jO-QB for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Oct 2009 15:07:27 +0100 Original-Received: from localhost ([127.0.0.1]:45778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N23kk-0003IW-7B for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Oct 2009 10:07:26 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N23kf-0003I4-Ev for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 10:07:21 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N23kb-0003HE-0i for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 10:07:21 -0400 Original-Received: from [199.232.76.173] (port=60722 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N23ka-0003HA-Qx for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 10:07:16 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:35928) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N23kZ-0000AB-VE for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 10:07: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 n9PE7DOb006606; Sun, 25 Oct 2009 07:07:13 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n9PDo5sd002511; Sun, 25 Oct 2009 06:50:05 -0700 Resent-Date: Sun, 25 Oct 2009 06:50:05 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Kevin Rodgers Original-Sender: news Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Sun, 25 Oct 2009 13:50: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.12564781391298 (code B ref -1); Sun, 25 Oct 2009 13:50:05 +0000 Original-Received: (at submit) by emacsbugs.donarmstrong.com; 25 Oct 2009 13:42:19 +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 n9PDgGX9001293 for ; Sun, 25 Oct 2009 06:42:19 -0700 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N23MO-0000Ve-8P for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 09:42:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N23MJ-0000Uc-QK for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 09:42:15 -0400 Original-Received: from [199.232.76.173] (port=48499 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N23MJ-0000UZ-K1 for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 09:42:11 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:40585) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N23MJ-0005Nb-6u for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 09:42:11 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1N23MG-0003Jl-Kr for bug-gnu-emacs@gnu.org; Sun, 25 Oct 2009 14:42:08 +0100 Original-Received: from c-71-237-24-138.hsd1.co.comcast.net ([71.237.24.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 25 Oct 2009 14:42:08 +0100 Original-Received: from kevin.d.rodgers by c-71-237-24-138.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 25 Oct 2009 14:42:08 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 59 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: c-71-237-24-138.hsd1.co.comcast.net User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Sun, 25 Oct 2009 10:07:21 -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:32231 Archived-At: Stefan Monnier wrote: >>> I'd indeed expect that to implement the feature you request, the code >>> would have to do something like that. Most likely not copying the text >>> itself, but instead storing an md5 or somesuch hash of the text. > >> Not suitable for Emacs, but maybe useful for Roland: > >> (defadvice sort-lines (around restore-buffer-modified-p activate) >> (let* ((buffer-was-modified-p (buffer-modified-p)) >> (buffer-was-not-modified-md5 (if (not buffer-was-modified-p) >> (md5 (current-buffer))))) >> ad-do-it >> (when (and (not buffer-was-modified-p) >> (buffer-modified-p) >> (not (equal buffer-was-not-modified-md5 (md5 (current-buffer))))) >> (restore-buffer-modified-p buffer-was-modified-p)))) > > 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? (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." `(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))) ;; (orig-buffer-undo-list buffer-undo-list) (with-maybe-region-modified-result (progn ,@body))) ; save-current-buffer? (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)) -- Kevin Rodgers Denver, Colorado, USA