From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Kevin Rodgers <kevin.d.rodgers@gmail.com>
Cc: 4587@emacsbugs.donarmstrong.com, bug-gnu-emacs@gnu.org
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 [thread overview]
Message-ID: <jwveiorh5c3.fsf-monnier+emacsbugreports@gnu.org> (raw)
In-Reply-To: <hc1kiq$m1o$1@ger.gmane.org> (Kevin Rodgers's message of "Sun, 25 Oct 2009 07:41:47 -0600")
>> 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
next prev parent reply other threads:[~2009-10-25 15:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-29 16:38 bug#4587: 23.1; sort-lines and sort-fields always set buffer modified Roland.Meier
2009-09-30 4:44 ` Stefan Monnier
2009-09-30 10:00 ` bug#4597: Antwort: " Roland.Meier
2009-09-30 13:51 ` bug#4587: " Stefan Monnier
2009-10-01 12:25 ` Kevin Rodgers
2009-10-01 14:19 ` Stefan Monnier
2009-10-25 13:41 ` Kevin Rodgers
2009-10-25 15:27 ` Stefan Monnier [this message]
2009-09-30 16:56 ` bug#4597: " Magnus Henoch
2022-05-03 19:24 ` bug#4587: " Lars Ingebrigtsen
2022-05-04 7:21 ` Eli Zaretskii
2022-05-04 7:53 ` Lars Ingebrigtsen
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=jwveiorh5c3.fsf-monnier+emacsbugreports@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=4587@emacsbugs.donarmstrong.com \
--cc=bug-gnu-emacs@gnu.org \
--cc=kevin.d.rodgers@gmail.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.