[darcs-users] Feature idea: Suggest replace operation

Henrik Hjelte henrik at evahjelte.com
Mon Sep 7 10:25:16 UTC 2009

Hello, maybe this is too obvious and has been discussed before? Anyway
I came to think of a great feature idea, so I wanted to tell the

Now, darcs has a replace operation. Which I too seldom use. Thinking
of how to best record my changes is not on the top of my head while
coding. Could darcs automatically detect that a series of hunks might
mean a replace and suggest the use of the replace operation?

This is my recent real-world example:

A search for twitteringNotice and replace with twitterPublishIcon.
In emacs the hunks looks like this:
    in directory ./src/js/gui/twitter:
    	      Modified                twitter-view.js
    -    var twitteringNoticeHtml = '<div class="twittering-notice"></div>';
    +    var twitterPublishIconHtml = '<div class="twittering-notice"></div>';
    -        var $twitterOff, $twitterBirdhead, $twitterMain,
$twitteringNotice, $twitterMessage, $counter, $account,
    +        var $twitterOff, $twitterBirdhead, $twitterMain,
$twitterPublishIcon, $twitterMessage, $counter, $account,
    -            $twitteringNotice =
    +            $twitterPublishIcon =
    -            $twitteringNotice.toggle();
    +            $twitterPublishIcon.toggle();
    -                $twitteringNotice.toggle();
    +                $twitterPublishIcon.toggle();

Look at the difference inside each hunk, it is possible for darcs to
see that in all cases have we replaced ingNotice with PublishIcon.

Darcs might even improve this by selecting the maximal possible
"enlargement", which means twitteringNotice with twitterPublishIcon.

Darcs can see that there are no more occurencies of ingNotice in the file.

Now darcs can ask us if we instead of recording 5 hunks meant to
record a replace operation?  We might even be given a choice between
ingNotice for PublishIcon or twitteringNotice for twitterPublishIcon
(but I think that the last form is probably what you would want, it
preserves more semantic meaning I guess).

This question should be possible to turned off using --no-replace-suggestions

Slightly off topic comment:

It seems I don't know enough about the replace command, I needed two
replace operations to do the same thing, replacing twitteringNotice
didn't have effect on twitteringNoticeHtml but it did work on
$twitteringNotice. So it treats a prefix and a postfix differently.

replace ./src/js/gui/twitter/twitter-view.js [A-Za-z_0-9]
twitteringNotice twitterPublishIcon
replace ./src/js/gui/twitter/twitter-view.js [A-Za-z_0-9]
twitteringNoticeHtml twitterPublishIconHtml

Best wishes to all developers, as a darcs-fan it is great to read of
all the work that is going on.

/Henrik Hjelte

More information about the darcs-users mailing list