unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: peter.mao@gmail.com, 63676@debbugs.gnu.org
Subject: bug#63676: cancelling editable dired causes UI problems with dired
Date: Sun, 28 May 2023 03:36:50 +0200	[thread overview]
Message-ID: <87a5xp6xu5.fsf@web.de> (raw)
In-Reply-To: <83edn2jnqd.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 27 May 2023 09:24:26 +0300")

Eli Zaretskii <eliz@gnu.org> writes:

> > I think this should be appropriate [...]:

First, sorry for my initial confusion.  I had forgotten where I was
using a modified version of wdired code.  But please be assured that I
did not make this suggestion lightly.

> Thanks, but why removal of the comment? is the comment incorrect or
> inaccurate?  I think having comments that explain why we do
> non-trivial things is an advantage.

I think it was inaccurate: enabling and aborting wdired does not touch
local variables (unlike major mode changes that delete locals).  We only
need to revert the things that have been changed explicitly (plus
anything the user might have done in the meantime).  The code already
does do this carefully.  Going back to a fully functional dired buffer
is not something that was not being addressed.

This issue is a bit special because it was not trivially foreseeable:
because the old buffer contents are being restored, marker positions
are shredded.  I have verified that `dired-subdir-alist' is the only
local variable carrying markers.

> > Background: Aborting wdired (`wdired-abort-changes') erases the
> > buffer and insert the original buffer contents, then re-enters
> > dired-mode.  Positions in `dired-subdir-alist' (that are necessary for
> > $) are represented as markers.  These just have to be updated.
>
> Are we sure this is the _only_ thing that needs to be updated?

> dired-revert does much more, so we should audit what it does carefully
> to determine which parts may need re-doing here.

My point is that dired-revert does _too_ much - see below.  And I'm
relatively sure that what we used to do is not problematic, so this is
not necessary (please note that the installed patch introduces a mistake
into the code: we now remember the buffer contents when entering wdired
in a variable.  When aborting, we now erase the buffer, restore those
remembered old contents, throw all of that away again, and revert from
anew).

> If you did that, would you please present the analysis and the
> conclusions?

> In particular, wdired-abort-changes could be called
> after more commands than the original recipe shows, and that could
> affect other aspects of the Dired buffer, not just dired-subdir-alist.

You only edit a text buffer then whose contents are later completely
discarded.  Dired commands are completely unavailable and/or not
functional.  Marks are part of the saved original buffer contents. Local
variables are not touched.  ATM I can't imagine what else could go
wrong.

Note that the posted recipe doesn't involve doing anything in between:
already entering wdired and immediate aborting causes the problem.  What
you do in between is irrelevant in this case.

> And having said all that, I don't really understand why we should
> worry so much about the downsides of the solution: is
> wdired-abort-changes something that is used a lot?  At least its speed
> sounds not important at all, and if the information it loses is indeed
> important enough, the way to avoid that is to restore that information
> after reverting, perhaps the way wdired-finish-edit does (which, btw,
> does call revert).

This is not a trivial matter.  Reverting, for example, also gets rid of
information, like that of `dired-do-kill-lines' calls.  Note that
`dired-revert' is existing to _undo_ such things, to get to the initial,
starting state.  That's not what the user normally wants when aborting
wdired.  This is like aborting `query-replace' would call
`revert-buffer'!  An example:

When I'm in the middle of a complex renaming operation using wdired, I
might have done some preparations before entering wdired, like killing
some unrelated lines so that it's simpler to use rectangle commands on
the rest (to rename a "block" of files).  When aborting reverts the
buffer (Say, I made a mistake ans lost orientation), I now have to do
the preparations again.  This is not helpful.

Also note that there are things that we can't easily restore at all:
markers that are not under the control of dired are lost (also with the
original code).  For example, when you remember a (file) position in
dired using a register (say, you want to rename it later, or copy it
into another buffer after doing something else) the position is saved
using a marker - after reverting (or wdired-aborting) it is gone.  Other
packages or features might use markers and overlays for other purposes
(highlighting stuff, showing thumbnails, such things).

Since wdired has developed in a direction where it only very carefully
touches the buffer at all (good! toggling wdired should only toggle the
mode of operation and leave the rest as is), the right direction, in my
opinion, is to try to avoid not explicitly user requested modifications
as much as possible.  The current patch goes into the opposite direction
:-(


I'll have another look whether something else could be broken and
everything that is part of the dired buffer's state is restored
appropriately, ok?

And of course did I not want suggest to experiment with any further
things on the release branch.


Michael.





  reply	other threads:[~2023-05-28  1:36 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-24  4:51 bug#63676: cancelling editable dired causes UI problems with dired Peter Mao
2023-05-24 11:05 ` Eli Zaretskii
2023-05-24 12:09   ` Stephen Berman
2023-05-25  1:14   ` Peter Mao
2023-05-26  9:25     ` Eli Zaretskii
2023-05-26 23:51   ` Michael Heerdegen
2023-05-27  0:55   ` Michael Heerdegen
2023-05-27  2:39     ` Michael Heerdegen
2023-05-27  6:26       ` Eli Zaretskii
2023-05-27  6:24     ` Eli Zaretskii
2023-05-28  1:36       ` Michael Heerdegen [this message]
2023-05-28  4:09         ` Thierry Volpiatto
2023-05-28  5:01           ` Michael Heerdegen
2023-05-28  5:08             ` Thierry Volpiatto
2023-05-28 16:04             ` Drew Adams
2023-05-28 16:21               ` Thierry Volpiatto
2023-05-28 19:17                 ` Drew Adams
2023-05-29  3:43                   ` Thierry Volpiatto
2023-05-29  5:16                     ` Drew Adams
2023-05-29  9:43                       ` Thierry Volpiatto
2023-05-29 17:11                         ` Drew Adams
2023-05-28 16:05           ` Drew Adams
2023-05-28  3:39       ` Michael Heerdegen
2023-05-28  6:43         ` Eli Zaretskii
2023-05-29  1:35           ` Michael Heerdegen

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a5xp6xu5.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=63676@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=peter.mao@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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).