From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: undo weirdness with insert-file-contents Date: Mon, 03 Mar 2008 10:09:28 +0100 Message-ID: <47CBC048.3010200@gmx.at> References: <47C70CFC.30203@gmx.at> <47C88A51.7020205@gmx.at> <47CAA13E.3040909@gmx.at> <12174.1204496311@olgas.newt.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1204535975 3159 80.91.229.12 (3 Mar 2008 09:19:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 3 Mar 2008 09:19:35 +0000 (UTC) Cc: Glenn Morris , emacs-devel@gnu.org, Stefan Monnier , Miles Bader To: Bill Wohler Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 03 10:20:01 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JW6px-0003kk-SK for ged-emacs-devel@m.gmane.org; Mon, 03 Mar 2008 10:19:58 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JW6pQ-0006m2-NP for ged-emacs-devel@m.gmane.org; Mon, 03 Mar 2008 04:19:24 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JW6oa-0005yE-Us for emacs-devel@gnu.org; Mon, 03 Mar 2008 04:18:33 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JW6oV-0005md-IV for emacs-devel@gnu.org; Mon, 03 Mar 2008 04:18:32 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JW6oV-0005mK-DI for emacs-devel@gnu.org; Mon, 03 Mar 2008 04:18:27 -0500 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1JW6oU-0000gd-Ok for emacs-devel@gnu.org; Mon, 03 Mar 2008 04:18:27 -0500 Original-Received: (qmail invoked by alias); 03 Mar 2008 09:11:46 -0000 Original-Received: from N778P022.adsl.highway.telekom.at (EHLO [62.47.41.54]) [62.47.41.54] by mail.gmx.net (mp044) with SMTP; 03 Mar 2008 10:11:46 +0100 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX183QtUuWbQ3Mq7xCoPJYK9v/eac2CQekjq6BQwiJW oi+6FZ9A4EVSwR User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en In-Reply-To: <12174.1204496311@olgas.newt.com> X-Y-GMX-Trusted: 0 X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:91158 Archived-At: >>The handling of the undo-list and modified-p status in >>insert-file-contents is a real mess. It'd be good to take a step back >>and think about how it *should* work. E.g. I don't think >>insert-file-contents should mess with modified-p: it should behave just >>like a normal `insert' in this respect. > > I agree. The semantics of insert-file-contents seems to be identical to > insert--only the text comes from a file rather than an argument. `insert-file-contents' is used to set up the buffer when visiting a file. In that case you hardly want the buffer appear modified after reading in the file or `point' appear at eob. Also the whole REPLACE handling is hardly comparable to what `insert' does (although it's similar to active region handling with `delete-selection-mode'). > I'd therefore be against Martin's suggestion of inserting an undo > boundary since that should be the caller's responsibility (typically, > the command loop). Consider the following: > > (defun bw-foo () > (insert "abc") > (insert "def")) > > (defun bw-bar () > (insert-file-contents "/etc/motd") > (insert-file-contents "/etc/motd")) > > A single undo in either case will remove both insertions and reset > buffer-modified-p to nil if that's what it was beforehand. I have no opinion here. But if you insert the second region _before_ the first region you need two undos anway. Making the behavior depend on some imaginary left-to-right order is hardly reasonable. But I agree that my undo boundary is purely artifical here I should remove it after it has served its purpose. A cleaner solution would be to use an extra variable, say record_insert_no_combine, bind it to Qt in `insert-file-contents', and have record_insert not combine two adjacent insertions when this variable is non-nil. Afterwards I can always combine the insertions if people want it. > There is, regrettably, a large difference between these two. Point is > left where insert-file-contents was run rather than at the end of the > inserted string as is the case with insert. Maybe we should consider > fixing this at this time as well. Maybe this is the way it used to work, > or maybe this is the way people expect it to work: I took a quick look > at the MH-E code and many invocations of insert-file-contents are > immediately followed by (goto-char (point-min)) before the inserted file > is processed. As explained above: The primary use of `insert-file-contents' is to set up file-visiting buffers not to modify them.