all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Bill Wohler <wohler@newt.com>
Cc: Glenn Morris <rgm@gnu.org>,
	emacs-devel@gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>,
	Miles Bader <miles@gnu.org>
Subject: Re: undo weirdness with insert-file-contents
Date: Mon, 03 Mar 2008 10:09:28 +0100	[thread overview]
Message-ID: <47CBC048.3010200@gmx.at> (raw)
In-Reply-To: <12174.1204496311@olgas.newt.com>

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





  reply	other threads:[~2008-03-03  9:09 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-28  7:46 undo weirdness with insert-file-contents Miles Bader
2008-02-28  9:56 ` martin rudalics
2008-02-28 11:01   ` Miles Bader
2008-02-28 13:12     ` martin rudalics
2008-02-28 16:52       ` Stefan Monnier
2008-02-28 19:31         ` martin rudalics
2008-02-28 20:01           ` Miles Bader
2008-02-28 22:19             ` martin rudalics
2008-02-28 21:35           ` Stefan Monnier
2008-02-28 22:21             ` martin rudalics
2008-02-28 17:45 ` Glenn Morris
2008-02-28 19:35   ` martin rudalics
2008-02-28 20:28     ` Glenn Morris
2008-02-28 22:20       ` martin rudalics
2008-02-29 22:42       ` martin rudalics
2008-03-02  5:02         ` Stefan Monnier
2008-03-02 12:44           ` martin rudalics
2008-03-02 19:07             ` Stefan Monnier
2008-03-02 22:05               ` martin rudalics
2008-03-03  2:15                 ` Stefan Monnier
2008-03-03  9:09                   ` martin rudalics
2008-03-03 21:03                     ` Stefan Monnier
2008-03-07  9:33                       ` martin rudalics
2008-03-07 22:04                         ` Stefan Monnier
2008-03-08  9:55                           ` martin rudalics
2008-03-02 22:18               ` Bill Wohler
2008-03-03  9:09                 ` martin rudalics [this message]
2008-02-29  5:50   ` Bill Wohler

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=47CBC048.3010200@gmx.at \
    --to=rudalics@gmx.at \
    --cc=emacs-devel@gnu.org \
    --cc=miles@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rgm@gnu.org \
    --cc=wohler@newt.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.