GNU bug report logs - #70820
[PATCH] Editable grep buffers

Previous Next

Package: emacs;

Reported by: Visuwesh <visuweshm <at> gmail.com>

Date: Tue, 7 May 2024 16:26:01 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 70820 in the body.
You can then email your comments to 70820 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Tue, 07 May 2024 16:26:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Visuwesh <visuweshm <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 07 May 2024 16:26:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Editable grep buffers
Date: Tue, 07 May 2024 21:55:09 +0530
[Message part 1 (text/plain, inline)]
Tags: patch

Attached patch is a proof of concept for an occur-edit-mode alike for
*grep* buffers.  It uses the new track-changes library to track the
edits made in the *grep* buffer to then finally save these edits to the
corresponding files.  I've tested this with:

    1. pure deletions: If you have a match that says "(cur-beg start"
       and you change it to "(cur- start".  This is special because
       track-changes-fetch passes equal BEG and END to
       grep-edit--track-changes-finalise.
    2. edits: something like "(cur-beg start" -> "(cur-beg start balh"
       is handled like you would expect.
    3. edits with newline: if the edit includes a newline, then that is
       reproduced.

and what is not handled currently: deleting a match line to imply
deletion of that line from the matched file.  I don't know how to handle
this currently, I need to learn the library more.

There's also definitely a million more cases that I didn't anticipate
when I wrote the logic for grep-edit--track-changes-finalise.

I'm sending the patch now to see if there's enough interest before I go
about fixing the edge cases (there's bug#52815).  If there is enough
interest, I will take a shot at implementing something like this for
xref result buffers too.



In GNU Emacs 30.0.50 (build 8, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.18.0, Xaw scroll bars) of 2024-05-07 built on astatine
Repository revision: 4b31074f5f49898ba0499a2b617cad425750eafa
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101011
System Description: Debian GNU/Linux trixie/sid

Configured using:
 'configure --with-sound=alsa --with-x-toolkit=lucid --with-json
 --without-xaw3d --without-gconf --without-libsystemd --with-cairo
 --with-xft'
[grep-edit.diff (text/patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Tue, 07 May 2024 17:25:02 GMT) Full text and rfc822 format available.

Message #8 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Visuwesh <visuweshm <at> gmail.com>, 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Tue, 7 May 2024 10:23:30 -0700
On 5/7/2024 9:25 AM, Visuwesh wrote:
> I'm sending the patch now to see if there's enough interest before I go
> about fixing the edge cases (there's bug#52815).  If there is enough
> interest, I will take a shot at implementing something like this for
> xref result buffers too.

How does this compare to the existing wgrep package? That doesn't have 
copyright assignment to the FSF, but otherwise, I think it's the bar 
against which any similar package should be measured. I use it pretty 
frequently (and have even written a plugin for it for my own grep-like 
major mode), and it's pretty much exactly the way I'd want this sort of 
thing to work. Something with feature-parity that lives in the Emacs 
tree would be great though.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Tue, 07 May 2024 18:10:02 GMT) Full text and rfc822 format available.

Message #11 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Tue, 07 May 2024 21:08:37 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Date: Tue, 07 May 2024 21:55:09 +0530
> 
> Attached patch is a proof of concept for an occur-edit-mode alike for
> *grep* buffers.  It uses the new track-changes library to track the
> edits made in the *grep* buffer to then finally save these edits to the
> corresponding files.  I've tested this with:
> 
>     1. pure deletions: If you have a match that says "(cur-beg start"
>        and you change it to "(cur- start".  This is special because
>        track-changes-fetch passes equal BEG and END to
>        grep-edit--track-changes-finalise.
>     2. edits: something like "(cur-beg start" -> "(cur-beg start balh"
>        is handled like you would expect.
>     3. edits with newline: if the edit includes a newline, then that is
>        reproduced.
> 
> and what is not handled currently: deleting a match line to imply
> deletion of that line from the matched file.  I don't know how to handle
> this currently, I need to learn the library more.
> 
> There's also definitely a million more cases that I didn't anticipate
> when I wrote the logic for grep-edit--track-changes-finalise.
> 
> I'm sending the patch now to see if there's enough interest before I go
> about fixing the edge cases (there's bug#52815).  If there is enough
> interest, I will take a shot at implementing something like this for
> xref result buffers too.

Thanks for working on this.

I wonder if this could be somehow either based on or at least have the
same look-and-feel as occur-edit-mode, which provides a very similar
feature in *occur* buffers.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 03:14:02 GMT) Full text and rfc822 format available.

Message #14 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 08 May 2024 08:42:30 +0530
[செவ்வாய் மே 07, 2024] Jim Porter wrote:

> On 5/7/2024 9:25 AM, Visuwesh wrote:
>> I'm sending the patch now to see if there's enough interest before I go
>> about fixing the edge cases (there's bug#52815).  If there is enough
>> interest, I will take a shot at implementing something like this for
>> xref result buffers too.
>
> How does this compare to the existing wgrep package? That doesn't have
> copyright assignment to the FSF, but otherwise, I think it's the bar
> against which any similar package should be measured. I use it pretty
> frequently (and have even written a plugin for it for my own grep-like
> major mode), and it's pretty much exactly the way I'd want this sort
> of thing to work. Something with feature-parity that lives in the
> Emacs tree would be great though.

I definitely agree that wgrep is the standard to which my patch should
be compared with.  I haven't actually used wgrep before but I took a
look at its README and so far, the features that are missing are:

    · I already quoted: deleting lines from the file.  I may tackle this
      once I get the basic editing features reliable.
    · Aborting changes wholesale: this should be easy and is already on
      my list.
    · Aborting changes in a region: I wonder if we cannot simply use
      undo restricted to a region to do it.  But otherwise, I can take a
      look at implementing this since I am also interested in this (but
      once I get the basics reliable).

Thanks for your input.  If I missed something from wgrep that you use,
please let me known.  I will play around with wgrep in some time to
learn more about what it offers myself.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 03:24:01 GMT) Full text and rfc822 format available.

Message #17 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 08 May 2024 08:52:51 +0530
[செவ்வாய் மே 07, 2024] Eli Zaretskii wrote:

> [...]
> Thanks for working on this.
>
> I wonder if this could be somehow either based on 

Basing it on occur-edit-mode would be a lot more work I think, but I
understand your concern wrt it being already established and bug-free,
etc.  This was my original plan but I bailed since the occur buffer's
text-properties has marker objects (IIRC) but I want to avoid using
markers since having many buffers open was a personal pet peeve of mine,
along with the slow-typing experience due to occur's
after-change-function immediately reflecting the changes in the original
buffer.  The latter is avoided in my patch since we commit the changes
only at the end so the typing during the edit is smooth.

> or at least have the
> same look-and-feel as occur-edit-mode, which provides a very similar
> feature in *occur* buffers.

This is what I am aiming for ideally since I am a fan of its interface
myself (preferring it over xref).  The major difference between
occur-edit-mode and my patch's grep-edit-minor-mode is that it is
implemented as a minor mode: I chose a minor-mode because all the buffer
local variables that are required to make the commands from the *grep*
buffer functional are killed when switching major-modes (so even g
doesn't work!). We could work around this by marking the relevant
variables permanent-local but this feels unclean?

The other difference that I can see now: the filename and the line
number parts aren't marked read-only so it can be edited when
grep-edit-minor-mode is active.  I will mark them read-only to have the
experience closer to occur-edit-mode.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 04:13:02 GMT) Full text and rfc822 format available.

Message #20 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Tue, 7 May 2024 21:11:42 -0700
On 5/7/2024 8:12 PM, Visuwesh wrote:
> Thanks for your input.  If I missed something from wgrep that you use,
> please let me known.  I will play around with wgrep in some time to
> learn more about what it offers myself.

In addition to the things you mentioned, here are the most important 
features from wgrep for me:

* Mark all non-result parts of the buffer (the command string, file 
names, line numbers, etc) as read-only. This is especially valuable if 
you want to use 'query-replace' or similar to modify the results. Then 
you can't inadvertently edit those bits.

* Fontify any results with changes (both in the grep-mode buffer and the 
original files). This is really useful for being able to see what I've 
changed.

* Adding all the necessary hooks/functions so other grep-like modes can 
use this. For example, see this file from wgrep, which lets you use 
wgrep with ag.el: 
<https://github.com/mhayashi1120/Emacs-wgrep/blob/master/wgrep-ag.el>. 
(This matters to me partly because I'm the author of Urgrep - a 
"universal recursive grep" mode that can use any grep-like program to do 
searches. I've added my own support in Urgrep for wgrep.)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 05:12:00 GMT) Full text and rfc822 format available.

Message #23 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 08 May 2024 10:41:10 +0530
[Message part 1 (text/plain, inline)]
[செவ்வாய் மே 07, 2024] Jim Porter wrote:

> On 5/7/2024 8:12 PM, Visuwesh wrote:
>> Thanks for your input.  If I missed something from wgrep that you use,
>> please let me known.  I will play around with wgrep in some time to
>> learn more about what it offers myself.
>
> In addition to the things you mentioned, here are the most important
> features from wgrep for me:

Thanks.

> * Mark all non-result parts of the buffer (the command string, file
>   names, line numbers, etc) as read-only. This is especially valuable
>   if you want to use 'query-replace' or similar to modify the
>   results. Then you can't inadvertently edit those bits.

This is now done.

> * Fontify any results with changes (both in the grep-mode buffer and
>   the original files). This is really useful for being able to see
>   what I've changed.

I agree that it would be nice to have this in *grep* buffer but I would
like to avoid editing the file on-the-fly since it introduces typing lag
IME with occur-edit-mode.  If you want to know the edits that were made,
you can use diff-buffer-with-file so I hope leaving out the highlighting
in the file would be okay.

> * Adding all the necessary hooks/functions so other grep-like modes
>   can use this. For example, see this file from wgrep, which lets you
>   use wgrep with ag.el:
>   <https://github.com/mhayashi1120/Emacs-wgrep/blob/master/wgrep-ag.el>. (This
>   matters to me partly because I'm the author of Urgrep - a "universal
>   recursive grep" mode that can use any grep-like program to do
>   searches. I've added my own support in Urgrep for wgrep.)

With grep-edit-minor-mode, as long as the compilation-message
text-property is present at the beginning of the line, you do not need
to do anything extra.  I look at this to gain the information about the
filename and the line number.

[grep-edit.diff (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 12:00:03 GMT) Full text and rfc822 format available.

Message #26 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 08 May 2024 14:58:50 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Cc: 70820 <at> debbugs.gnu.org
> Date: Wed, 08 May 2024 08:52:51 +0530
> 
> [செவ்வாய் மே 07, 2024] Eli Zaretskii wrote:
> 
> > [...]
> > Thanks for working on this.
> >
> > I wonder if this could be somehow either based on 
> 
> Basing it on occur-edit-mode would be a lot more work I think, but I
> understand your concern wrt it being already established and bug-free,
> etc.  This was my original plan but I bailed since the occur buffer's
> text-properties has marker objects (IIRC) but I want to avoid using
> markers since having many buffers open was a personal pet peeve of mine,
> along with the slow-typing experience due to occur's
> after-change-function immediately reflecting the changes in the original
> buffer.  The latter is avoided in my patch since we commit the changes
> only at the end so the typing during the edit is smooth.

I think having similar features that work very differently is not a
good thing for Emacs.  So I urge you to reconsider your decisions and
make this more like occur-edit-mode.  In particular, I don't
understand the difficulty with using the markers and what does it have
to do with the ability of having many Grep buffers.

> This is what I am aiming for ideally since I am a fan of its interface
> myself (preferring it over xref).  The major difference between
> occur-edit-mode and my patch's grep-edit-minor-mode is that it is
> implemented as a minor mode: I chose a minor-mode because all the buffer
> local variables that are required to make the commands from the *grep*
> buffer functional are killed when switching major-modes (so even g
> doesn't work!). We could work around this by marking the relevant
> variables permanent-local but this feels unclean?

I don't think I understand this difficulty, either: with
occur-edit-mode it is solved by making occur-edit-mode be derived from
occur-mode.  Couldn't you do the same with your mode?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 12:19:02 GMT) Full text and rfc822 format available.

Message #29 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 08 May 2024 17:48:02 +0530
[புதன் மே 08, 2024] Eli Zaretskii wrote:

>> From: Visuwesh <visuweshm <at> gmail.com>
>> Cc: 70820 <at> debbugs.gnu.org
>> Date: Wed, 08 May 2024 08:52:51 +0530
>> 
>> [செவ்வாய் மே 07, 2024] Eli Zaretskii wrote:
>> 
>> > [...]
>> > Thanks for working on this.
>> >
>> > I wonder if this could be somehow either based on 
>> 
>> Basing it on occur-edit-mode would be a lot more work I think, but I
>> understand your concern wrt it being already established and bug-free,
>> etc.  This was my original plan but I bailed since the occur buffer's
>> text-properties has marker objects (IIRC) but I want to avoid using
>> markers since having many buffers open was a personal pet peeve of mine,
>> along with the slow-typing experience due to occur's
>> after-change-function immediately reflecting the changes in the original
>> buffer.  The latter is avoided in my patch since we commit the changes
>> only at the end so the typing during the edit is smooth.
>
> I think having similar features that work very differently is not a
> good thing for Emacs.  So I urge you to reconsider your decisions and
> make this more like occur-edit-mode.  In particular, I don't
> understand the difficulty with using the markers and what does it have
> to do with the ability of having many Grep buffers.

It is not having many Grep buffers but visiting the "original" files
unnecessarily that tends to be annoying.  I am not sure if there is a
scheme to make these visits conservative, I would need to look further.

I do not think using track-changes to keep track of the edits will do
too much harm since the trickiest part of keeping track of the buffer
modifications proper is left to an "external" library.  If I'm not
wrong, track-changes was introduced to make looking at buffer
modifications less error-prone.

>> This is what I am aiming for ideally since I am a fan of its interface
>> myself (preferring it over xref).  The major difference between
>> occur-edit-mode and my patch's grep-edit-minor-mode is that it is
>> implemented as a minor mode: I chose a minor-mode because all the buffer
>> local variables that are required to make the commands from the *grep*
>> buffer functional are killed when switching major-modes (so even g
>> doesn't work!). We could work around this by marking the relevant
>> variables permanent-local but this feels unclean?
>
> I don't think I understand this difficulty, either: with
> occur-edit-mode it is solved by making occur-edit-mode be derived from
> occur-mode.  Couldn't you do the same with your mode?

No because occur-mode makes occur-revert-arguments permanent-local so
`g' survives the major-mode changes.

For revert-buffer alone, compilation-arguments needs to be marked
permanent-local.  As it is a part of compile.el, I am not sure if
marking it as such is safe.  This is why I think having a minor-mode is
better.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 13:51:02 GMT) Full text and rfc822 format available.

Message #32 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 08 May 2024 16:49:41 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Cc: 70820 <at> debbugs.gnu.org
> Date: Wed, 08 May 2024 17:48:02 +0530
> 
> [புதன் மே 08, 2024] Eli Zaretskii wrote:
> 
> > I think having similar features that work very differently is not a
> > good thing for Emacs.  So I urge you to reconsider your decisions and
> > make this more like occur-edit-mode.  In particular, I don't
> > understand the difficulty with using the markers and what does it have
> > to do with the ability of having many Grep buffers.
> 
> It is not having many Grep buffers but visiting the "original" files
> unnecessarily that tends to be annoying.

Why is this annoying?

> > I don't think I understand this difficulty, either: with
> > occur-edit-mode it is solved by making occur-edit-mode be derived from
> > occur-mode.  Couldn't you do the same with your mode?
> 
> No because occur-mode makes occur-revert-arguments permanent-local so
> `g' survives the major-mode changes.
> 
> For revert-buffer alone, compilation-arguments needs to be marked
> permanent-local.  As it is a part of compile.el, I am not sure if
> marking it as such is safe.  This is why I think having a minor-mode is
> better.

It sounds like a minor issue which shouldn't have such grave
consequences.  Why do you think making compilation-arguments
permanent-local would be a problem?  We could ask people who
frequently contribute to compile.e land grep.el if they see any
problem with doing that.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 17:39:02 GMT) Full text and rfc822 format available.

Message #35 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>, Visuwesh <visuweshm <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 8 May 2024 10:37:42 -0700
On 5/8/2024 4:58 AM, Eli Zaretskii wrote:
>> From: Visuwesh <visuweshm <at> gmail.com>
>> Cc: 70820 <at> debbugs.gnu.org
>> Date: Wed, 08 May 2024 08:52:51 +0530
>>
>> Basing it on occur-edit-mode would be a lot more work I think, but I
>> understand your concern wrt it being already established and bug-free,
>> etc.  This was my original plan but I bailed since the occur buffer's
>> text-properties has marker objects (IIRC) but I want to avoid using
>> markers since having many buffers open was a personal pet peeve of mine,
>> along with the slow-typing experience due to occur's
>> after-change-function immediately reflecting the changes in the original
>> buffer.  The latter is avoided in my patch since we commit the changes
>> only at the end so the typing during the edit is smooth.
> 
> I think having similar features that work very differently is not a
> good thing for Emacs.  So I urge you to reconsider your decisions and
> make this more like occur-edit-mode.  In particular, I don't
> understand the difficulty with using the markers and what does it have
> to do with the ability of having many Grep buffers.

I agree that using markers would probably be a good idea, assuming I'm 
imagining things correctly. (In particular, this needs to be robust 
about what happens if you have a file open with some changes already, 
run grep to find matches in that file, and then modify those matches.)

However, I agree with Visuwesh about not committing changes until the 
end. For the grep case, you could have results in many, many files, 
including (especially?) ones not open in Emacs yet. By waiting until the 
end to commit the changes, you don't have to worry about what happen to 
these files. (The only other options I can think of would be to visit 
those files, which could require opening hundreds or thousands of files 
at once; or to immediately change the files on disk, which could ruin 
those files.)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 18:44:01 GMT) Full text and rfc822 format available.

Message #38 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org, visuweshm <at> gmail.com
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 08 May 2024 21:42:50 +0300
> Date: Wed, 8 May 2024 10:37:42 -0700
> Cc: 70820 <at> debbugs.gnu.org
> From: Jim Porter <jporterbugs <at> gmail.com>
> 
> However, I agree with Visuwesh about not committing changes until the 
> end. For the grep case, you could have results in many, many files, 
> including (especially?) ones not open in Emacs yet.

I don't see why.  Grep shows all the matches in one file before it
goes to the next.  So each time you edit the matches, you have just
one file to care about, right?  Or what am I missing?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 19:21:01 GMT) Full text and rfc822 format available.

Message #41 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org, visuweshm <at> gmail.com
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 8 May 2024 12:19:41 -0700
On 5/8/2024 11:42 AM, Eli Zaretskii wrote:
>> Date: Wed, 8 May 2024 10:37:42 -0700
>> Cc: 70820 <at> debbugs.gnu.org
>> From: Jim Porter <jporterbugs <at> gmail.com>
>>
>> However, I agree with Visuwesh about not committing changes until the
>> end. For the grep case, you could have results in many, many files,
>> including (especially?) ones not open in Emacs yet.
> 
> I don't see why.  Grep shows all the matches in one file before it
> goes to the next.  So each time you edit the matches, you have just
> one file to care about, right?  Or what am I missing?

One of the ways I use wgrep is that I first search across my entire repo 
for some matching lines. Then, I activate wgrep and use query-replace to 
mass-change all those lines. (I use the "!" key with query-replace to 
tell it to change everything without prompting once I'm happy with my 
command.) This frequently involves me changing dozens of files at once 
even for relatively small projects.

Maybe there are better ways to perform this sort of action, but I find 
this method very useful because it shows me the steps along the way so 
that I can check my work before I commit to changing all those lines. I 
also don't have to manually step through each change once I'm happy with 
what I see.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 08 May 2024 19:24:02 GMT) Full text and rfc822 format available.

Message #44 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org, visuweshm <at> gmail.com
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 8 May 2024 12:23:00 -0700
On 5/8/2024 12:19 PM, Jim Porter wrote:
> Maybe there are better ways to perform this sort of action, but I find 
> this method very useful because it shows me the steps along the way so 
> that I can check my work before I commit to changing all those lines. I 
> also don't have to manually step through each change once I'm happy with 
> what I see.

Oh, one thing I forgot to add about this: If I perform this action and 
the changed lines in my grep buffer don't look right, I can just exit 
wgrep without saving the changes and try again.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Thu, 09 May 2024 04:43:01 GMT) Full text and rfc822 format available.

Message #47 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org, visuweshm <at> gmail.com
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Thu, 09 May 2024 07:41:25 +0300
> Date: Wed, 8 May 2024 12:23:00 -0700
> From: Jim Porter <jporterbugs <at> gmail.com>
> Cc: 70820 <at> debbugs.gnu.org, visuweshm <at> gmail.com
> 
> On 5/8/2024 12:19 PM, Jim Porter wrote:
> > Maybe there are better ways to perform this sort of action, but I find 
> > this method very useful because it shows me the steps along the way so 
> > that I can check my work before I commit to changing all those lines. I 
> > also don't have to manually step through each change once I'm happy with 
> > what I see.
> 
> Oh, one thing I forgot to add about this: If I perform this action and 
> the changed lines in my grep buffer don't look right, I can just exit 
> wgrep without saving the changes and try again.

We are not going to remove wgrep, so if you prefer that way of
operating on grep hits, you still can.  Here we are discussing a new
feature, and it doesn't have to be bit-by-bit compatible to all the
similar packages out there.  But it does need to make sense as part of
Emacs, if it is part of grep.el.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Thu, 09 May 2024 10:34:01 GMT) Full text and rfc822 format available.

Message #50 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Thu, 09 May 2024 16:02:35 +0530
[புதன் மே 08, 2024] Eli Zaretskii wrote:

>> From: Visuwesh <visuweshm <at> gmail.com>
>> Cc: 70820 <at> debbugs.gnu.org
>> Date: Wed, 08 May 2024 17:48:02 +0530
>> 
>> [புதன் மே 08, 2024] Eli Zaretskii wrote:
>> 
>> > I think having similar features that work very differently is not a
>> > good thing for Emacs.  So I urge you to reconsider your decisions and
>> > make this more like occur-edit-mode.  In particular, I don't
>> > understand the difficulty with using the markers and what does it have
>> > to do with the ability of having many Grep buffers.
>> 
>> It is not having many Grep buffers but visiting the "original" files
>> unnecessarily that tends to be annoying.
>
> Why is this annoying?
>
>> > I don't think I understand this difficulty, either: with
>> > occur-edit-mode it is solved by making occur-edit-mode be derived from
>> > occur-mode.  Couldn't you do the same with your mode?
>> 
>> No because occur-mode makes occur-revert-arguments permanent-local so
>> `g' survives the major-mode changes.
>> 
>> For revert-buffer alone, compilation-arguments needs to be marked
>> permanent-local.  As it is a part of compile.el, I am not sure if
>> marking it as such is safe.  This is why I think having a minor-mode is
>> better.
>
> It sounds like a minor issue which shouldn't have such grave
> consequences.  Why do you think making compilation-arguments
> permanent-local would be a problem?  We could ask people who
> frequently contribute to compile.e land grep.el if they see any
> problem with doing that.

It feels like a potential far-fetching change.  But in any case, I will
give a shot at recreating the required markers, etc. for
occur-after-change-function to work.  Will send a patch once I have a
working prototype.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Thu, 09 May 2024 16:16:01 GMT) Full text and rfc822 format available.

Message #53 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Jim Porter <jporterbugs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org, visuweshm <at> gmail.com
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Thu, 9 May 2024 09:14:50 -0700
On 5/8/2024 9:41 PM, Eli Zaretskii wrote:
> We are not going to remove wgrep, so if you prefer that way of
> operating on grep hits, you still can.  Here we are discussing a new
> feature, and it doesn't have to be bit-by-bit compatible to all the
> similar packages out there.  But it does need to make sense as part of
> Emacs, if it is part of grep.el.

I certainly don't expect this facility to be identical to wgrep (I 
didn't bother mentioning the bits of wgrep that I'm not interested in), 
but I think it does have some very good ideas too.

For the case of only making changes at the end, I mainly wanted to 
express my agreement with Visuwesh's initial implementation and to 
explain how wgrep's similar behavior makes certain tasks easier.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sun, 12 May 2024 04:47:02 GMT) Full text and rfc822 format available.

Message #56 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sun, 12 May 2024 10:15:33 +0530
[Message part 1 (text/plain, inline)]
[வியாழன் மே 09, 2024] Visuwesh wrote:

>>> > I don't think I understand this difficulty, either: with
>>> > occur-edit-mode it is solved by making occur-edit-mode be derived from
>>> > occur-mode.  Couldn't you do the same with your mode?
>>> 
>>> No because occur-mode makes occur-revert-arguments permanent-local so
>>> `g' survives the major-mode changes.
>>> 
>>> For revert-buffer alone, compilation-arguments needs to be marked
>>> permanent-local.  As it is a part of compile.el, I am not sure if
>>> marking it as such is safe.  This is why I think having a minor-mode is
>>> better.
>>
>> It sounds like a minor issue which shouldn't have such grave
>> consequences.  Why do you think making compilation-arguments
>> permanent-local would be a problem?  We could ask people who
>> frequently contribute to compile.e land grep.el if they see any
>> problem with doing that.
>
> It feels like a potential far-fetching change.  But in any case, I will
> give a shot at recreating the required markers, etc. for
> occur-after-change-function to work.  Will send a patch once I have a
> working prototype.

OK, please find attached patch.  I am still not using a major-mode
because of the change-major-mode-hook in compilation-setup:

    (add-hook 'change-major-mode-hook #'compilation--remove-properties nil t)

that strips off all the text-properties.  And there seem to be too many
important local variables that is set up by both grep.el and compile.el
so I think it is easier to use a minor-mode here.

[grep-edit.diff (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sat, 18 May 2024 09:29:02 GMT) Full text and rfc822 format available.

Message #59 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 18 May 2024 12:28:24 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Cc: 70820 <at> debbugs.gnu.org
> Date: Sun, 12 May 2024 10:15:33 +0530
> 
> [வியாழன் மே 09, 2024] Visuwesh wrote:
> 
> >>> > I don't think I understand this difficulty, either: with
> >>> > occur-edit-mode it is solved by making occur-edit-mode be derived from
> >>> > occur-mode.  Couldn't you do the same with your mode?
> >>> 
> >>> No because occur-mode makes occur-revert-arguments permanent-local so
> >>> `g' survives the major-mode changes.
> >>> 
> >>> For revert-buffer alone, compilation-arguments needs to be marked
> >>> permanent-local.  As it is a part of compile.el, I am not sure if
> >>> marking it as such is safe.  This is why I think having a minor-mode is
> >>> better.
> >>
> >> It sounds like a minor issue which shouldn't have such grave
> >> consequences.  Why do you think making compilation-arguments
> >> permanent-local would be a problem?  We could ask people who
> >> frequently contribute to compile.e land grep.el if they see any
> >> problem with doing that.
> >
> > It feels like a potential far-fetching change.  But in any case, I will
> > give a shot at recreating the required markers, etc. for
> > occur-after-change-function to work.  Will send a patch once I have a
> > working prototype.
> 
> OK, please find attached patch.  I am still not using a major-mode
> because of the change-major-mode-hook in compilation-setup:
> 
>     (add-hook 'change-major-mode-hook #'compilation--remove-properties nil t)
> 
> that strips off all the text-properties.  And there seem to be too many
> important local variables that is set up by both grep.el and compile.el
> so I think it is easier to use a minor-mode here.

Any reason not to modify compilation--remove-properties not to remove
all the text properties in this particular case?  AFAIU,
change-major-mode-hook is run by kill-all-local-variables, which the
major mode should call, so just before that you could remove
compilation--remove-properties from change-major-mode-hook, and that
would disable this face removal, no?

(I must admit that unconditionally removing the faces is not very
friendly on the part of compilation-mode.  Stefan, are there better
ways of doing that, perhaps?)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sat, 18 May 2024 13:25:02 GMT) Full text and rfc822 format available.

Message #62 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Jim Porter <jporterbugs <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org, Visuwesh <visuweshm <at> gmail.com>
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 18 May 2024 09:23:48 -0400
[Message part 1 (text/markdown, inline)]
> How does this compare to the existing wgrep package? That doesn't have
> copyright assignment to the FSF, but otherwise, I think it's the bar against
> which any similar package should be measured. I use it pretty frequently
> (and have even written a plugin for it for my own grep-like major mode), and
> it's pretty much exactly the way I'd want this sort of thing to
> work. Something with feature-parity that lives in the Emacs tree would be
> great though.

FWIW, I don't see "live in Emacs tree" as particularly desirable for
such a user-oriented package.  It's already in NonGNU ELPA, so trivially
installable.

Note: I have not looked at the code of `wgrep.el`, so maybe there are
good reasons to reinvent this wheel, but "live in the Emacs tree" isn't
a good reason.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sat, 18 May 2024 13:35:02 GMT) Full text and rfc822 format available.

Message #65 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org, Visuwesh <visuweshm <at> gmail.com>
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 18 May 2024 09:34:25 -0400
[Message part 1 (text/markdown, inline)]
>> > I don't think I understand this difficulty, either: with
>> > occur-edit-mode it is solved by making occur-edit-mode be derived from
>> > occur-mode.  Couldn't you do the same with your mode?
>> 
>> No because occur-mode makes occur-revert-arguments permanent-local so
>> `g' survives the major-mode changes.
>> 
>> For revert-buffer alone, compilation-arguments needs to be marked
>> permanent-local.  As it is a part of compile.el, I am not sure if
>> marking it as such is safe.  This is why I think having a minor-mode is
>> better.
>
> It sounds like a minor issue which shouldn't have such grave
> consequences.  Why do you think making compilation-arguments
> permanent-local would be a problem?  We could ask people who
> frequently contribute to compile.e land grep.el if they see any
> problem with doing that.

AFAICT it would be harmless to make it permanent-local.  Indeed, this
var belongs with the contents of the buffer rather than with its mode
(in a sense it is akin to `buffer-file-name` in that it says where the
contents comes from), so it makes a lot of sense to mark it
permanent-local.

Side note: I believe things become simpler&cleaner if you separate the
major mode function from the command that switches to it (just like
`wdired-change-to-wdired-mode` is separate from `wdired-mode`).

E.g. that lets you save&restore buffer-local vars like
`compilation-arguments`, and it let you remove or disable
`compilation--remove-properties` in a straightforward manner.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sat, 18 May 2024 13:37:01 GMT) Full text and rfc822 format available.

Message #68 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org, Visuwesh <visuweshm <at> gmail.com>
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 18 May 2024 09:35:58 -0400
[Message part 1 (text/markdown, inline)]
> (I must admit that unconditionally removing the faces is not very
> friendly on the part of compilation-mode.  Stefan, are there better
> ways of doing that, perhaps?)

These are properties which the major mode (unconditionally) added, so it
doesn't seem unfriendly to remove them unconditionally when switching to
an unrelated major mode.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sat, 18 May 2024 15:45:03 GMT) Full text and rfc822 format available.

Message #71 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 70820 <at> debbugs.gnu.org, visuweshm <at> gmail.com
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 18 May 2024 18:44:38 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: Visuwesh <visuweshm <at> gmail.com>,  70820 <at> debbugs.gnu.org
> Date: Sat, 18 May 2024 09:35:58 -0400
> 
> > (I must admit that unconditionally removing the faces is not very
> > friendly on the part of compilation-mode.  Stefan, are there better
> > ways of doing that, perhaps?)
> 
> These are properties which the major mode (unconditionally) added, so it
> doesn't seem unfriendly to remove them unconditionally when switching to
> an unrelated major mode.

Yes, but how does compilation-mode know the other major-mode is
"unrelated"?  It could be very related, as this discussion
demonstrates.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sat, 18 May 2024 16:28:02 GMT) Full text and rfc822 format available.

Message #74 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org, visuweshm <at> gmail.com
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 18 May 2024 12:27:06 -0400
[Message part 1 (text/markdown, inline)]
>> These are properties which the major mode (unconditionally) added, so it
>> doesn't seem unfriendly to remove them unconditionally when switching to
>> an unrelated major mode.
> Yes, but how does compilation-mode know the other major-mode is
> "unrelated"?  It could be very related, as this discussion
> demonstrates.

If it's related it has access to internals, so it can so things like
disabling `compilation--remoave-properties`.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sat, 18 May 2024 16:29:01 GMT) Full text and rfc822 format available.

Message #77 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 70820 <at> debbugs.gnu.org, visuweshm <at> gmail.com
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 18 May 2024 19:28:27 +0300
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: visuweshm <at> gmail.com,  70820 <at> debbugs.gnu.org
> Date: Sat, 18 May 2024 12:27:06 -0400
> 
> >> These are properties which the major mode (unconditionally) added, so it
> >> doesn't seem unfriendly to remove them unconditionally when switching to
> >> an unrelated major mode.
> > Yes, but how does compilation-mode know the other major-mode is
> > "unrelated"?  It could be very related, as this discussion
> > demonstrates.
> 
> If it's related it has access to internals, so it can so things like
> disabling `compilation--remoave-properties`.

OK, so my suggestion to Visuwesh is the best way of dealing with this.
Fine by me.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Mon, 20 May 2024 10:13:02 GMT) Full text and rfc822 format available.

Message #80 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Mon, 20 May 2024 15:40:47 +0530
[சனி மே 18, 2024] Eli Zaretskii wrote:

>> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
>> Cc: visuweshm <at> gmail.com,  70820 <at> debbugs.gnu.org
>> Date: Sat, 18 May 2024 12:27:06 -0400
>> 
>> >> These are properties which the major mode (unconditionally) added, so it
>> >> doesn't seem unfriendly to remove them unconditionally when switching to
>> >> an unrelated major mode.
>> > Yes, but how does compilation-mode know the other major-mode is
>> > "unrelated"?  It could be very related, as this discussion
>> > demonstrates.
>> 
>> If it's related it has access to internals, so it can so things like
>> disabling `compilation--remoave-properties`.
>
> OK, so my suggestion to Visuwesh is the best way of dealing with this.
> Fine by me.

Thank you Stefan & Eli, I will take a closer look at your suggestions
when time permits.  I have limited internet access outside my work hours
so I cannot reply to your messages in full.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sun, 28 Jul 2024 08:36:01 GMT) Full text and rfc822 format available.

Message #83 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sun, 28 Jul 2024 14:03:32 +0530
[Message part 1 (text/plain, inline)]
[சனி மே 18, 2024] Eli Zaretskii wrote:

>> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
>> Cc: visuweshm <at> gmail.com,  70820 <at> debbugs.gnu.org
>> Date: Sat, 18 May 2024 12:27:06 -0400
>> 
>> >> These are properties which the major mode (unconditionally) added, so it
>> >> doesn't seem unfriendly to remove them unconditionally when switching to
>> >> an unrelated major mode.
>> > Yes, but how does compilation-mode know the other major-mode is
>> > "unrelated"?  It could be very related, as this discussion
>> > demonstrates.
>> 
>> If it's related it has access to internals, so it can so things like
>> disabling `compilation--remoave-properties`.
>
> OK, so my suggestion to Visuwesh is the best way of dealing with this.
> Fine by me.

Sorry for the long delay.  I finally got the time to work on this
properly.  The attached patch uses a major-mode, akin to wdired-mode
like Stefan suggested in another message.  This side-steps previous
issues with buffer-local variables and compilation--remove-properties.
If this approach is okay, I will work on updating the documentation,
etc.

[grep-edit-v2.diff (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 14 Aug 2024 00:32:01 GMT) Full text and rfc822 format available.

Message #86 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Tue, 13 Aug 2024 20:30:53 -0400
> +(defun compilation--update-markers (loc marker screen-columns first-column)
> +  "Update markers in LOC, and set MARKER to location pointed by LOC.
> +SCREEN-COLUMNS and FIRST-COLUMN are the value of
> +`compilation-error-screen-columns' and `compilation-first-column' to use
> +if they are not set buffer-locally in the target buffer."
> +  (with-current-buffer
> +      (if (bufferp (caar (compilation--loc->file-struct loc)))
> +          (caar (compilation--loc->file-struct loc))
> +        (apply #'compilation-find-file
> +               marker
> +               (caar (compilation--loc->file-struct loc))
> +               (cadr (car (compilation--loc->file-struct loc)))
> +               (compilation--file-struct->formats
> +                (compilation--loc->file-struct loc))))
> +    (let ((screen-columns
> +           ;; Obey the compilation-error-screen-columns of the target
> +           ;; buffer if its major mode set it buffer-locally.
> +           (if (local-variable-p 'compilation-error-screen-columns)
> +               compilation-error-screen-columns screen-columns))
> +          (compilation-first-column
> +           (if (local-variable-p 'compilation-first-column)
> +               compilation-first-column first-column))
> +          (last 1))
> +      (save-restriction
> +        (widen)
> +        (goto-char (point-min))
> +        ;; Treat file's found lines in forward order, 1 by 1.
> +        (dolist (line (reverse (cddr (compilation--loc->file-struct loc))))
> +          (when (car line)     ; else this is a filename without a line#
> +            (compilation-beginning-of-line (- (car line) last -1))
> +            (setq last (car line)))
> +          ;; Treat line's found columns and store/update a marker for each.
> +          (dolist (col (cdr line))
> +            (if (compilation--loc->col col)
> +                (if (eq (compilation--loc->col col) -1)
> +                    ;; Special case for range end.
> +                    (end-of-line)
> +                  (compilation-move-to-column (compilation--loc->col col)
> +                                              screen-columns))
> +              (beginning-of-line)
> +              (skip-chars-forward " \t"))
> +            (if (compilation--loc->marker col)
> +                (set-marker (compilation--loc->marker col) (point))
> +              (setf (compilation--loc->marker col) (point-marker)))
> +            ;; (setf (compilation--loc->timestamp col) timestamp)
> +            ))))))

Are there any changes in this code, or is it "verbatim" the code
extracted from `compilation-next-error-function`?

> +(defvar grep-edit-mode-hook nil
> +  "Hooks run when changing to Grep-Edit mode.")

It's just "Hook" because `grep-edit-mode-hook` is a hook.  Hooks contain
functions, so when you run a hook, the corresponding functions are called.

> +(defun grep-edit-mode ()
> +  "Major mode for editing *grep* buffers.
> +In this mode, changes to the *grep* buffer are applied to the
> +originating files.
> +\\<grep-edit-mode-map>
> +Type \\[grep-edit-save-changes] to exit Grep-Edit mode, return to Grep
> +mode.
> +
> +The only editable texts in a Grep-Edit buffer are the match results."
> +  (interactive)
> +  (error "This mode can be enabled only by `grep-change-to-grep-edit-mode'"))
> +(put 'grep-edit-mode 'mode-class 'special)
> +
> +(defun grep-change-to-grep-edit-mode ()
> +  "Switch to `grep-edit-mode' to edit *grep* buffer."
> +  (interactive)
> +  (unless (derived-mode-p 'grep-mode)
> +    (error "Not a Grep buffer"))
> +  (when (get-buffer-process (current-buffer))
> +    (error "Cannot switch when grep is running"))
> +  (use-local-map grep-edit-mode-map)
> +  (grep-edit--prepare-buffer)
> +  (setq buffer-read-only nil)
> +  (setq major-mode 'grep-edit-mode)
> +  (setq mode-name "Grep-Edit")
> +  (buffer-enable-undo)
> +  (set-buffer-modified-p nil)
> +  (setq buffer-undo-list nil)
> +  (add-hook 'after-change-functions #'occur-after-change-function nil t)
> +  (run-mode-hooks 'grep-edit-mode-hook)
> +  (message "Editing: \\[grep-edit-save-changes] to return to Grep mode"))

I'm tempted to say you should use `major-mode-suspend/resume` (which
would avoid the duplication of parts of `grep-mode` in
`grep-edit-save-changes`), but I guess this might re-introduce the
problem with buffer-local variables.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 14 Aug 2024 02:46:02 GMT) Full text and rfc822 format available.

Message #89 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 14 Aug 2024 08:13:42 +0530
[செவ்வாய் ஆகஸ்ட் 13, 2024] Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" wrote:

>> +(defun compilation--update-markers (loc marker screen-columns first-column)
>> +  "Update markers in LOC, and set MARKER to location pointed by LOC.
>> +SCREEN-COLUMNS and FIRST-COLUMN are the value of
>> +`compilation-error-screen-columns' and `compilation-first-column' to use
>> +if they are not set buffer-locally in the target buffer."
>> +  (with-current-buffer
>> +      (if (bufferp (caar (compilation--loc->file-struct loc)))
>> +          (caar (compilation--loc->file-struct loc))
>> +        (apply #'compilation-find-file
>> +               marker
>> +               (caar (compilation--loc->file-struct loc))
>> +               (cadr (car (compilation--loc->file-struct loc)))
>> +               (compilation--file-struct->formats
>> +                (compilation--loc->file-struct loc))))
>> +    (let ((screen-columns
>> +           ;; Obey the compilation-error-screen-columns of the target
>> +           ;; buffer if its major mode set it buffer-locally.
>> +           (if (local-variable-p 'compilation-error-screen-columns)
>> +               compilation-error-screen-columns screen-columns))
>> +          (compilation-first-column
>> +           (if (local-variable-p 'compilation-first-column)
>> +               compilation-first-column first-column))
>> +          (last 1))
>> +      (save-restriction
>> +        (widen)
>> +        (goto-char (point-min))
>> +        ;; Treat file's found lines in forward order, 1 by 1.
>> +        (dolist (line (reverse (cddr (compilation--loc->file-struct loc))))
>> +          (when (car line)     ; else this is a filename without a line#
>> +            (compilation-beginning-of-line (- (car line) last -1))
>> +            (setq last (car line)))
>> +          ;; Treat line's found columns and store/update a marker for each.
>> +          (dolist (col (cdr line))
>> +            (if (compilation--loc->col col)
>> +                (if (eq (compilation--loc->col col) -1)
>> +                    ;; Special case for range end.
>> +                    (end-of-line)
>> +                  (compilation-move-to-column (compilation--loc->col col)
>> +                                              screen-columns))
>> +              (beginning-of-line)
>> +              (skip-chars-forward " \t"))
>> +            (if (compilation--loc->marker col)
>> +                (set-marker (compilation--loc->marker col) (point))
>> +              (setf (compilation--loc->marker col) (point-marker)))
>> +            ;; (setf (compilation--loc->timestamp col) timestamp)
>> +            ))))))
>
> Are there any changes in this code, or is it "verbatim" the code
> extracted from `compilation-next-error-function`?

It is extracted verbatim from compilation-next-error-function.

>> +(defvar grep-edit-mode-hook nil
>> +  "Hooks run when changing to Grep-Edit mode.")
>
> It's just "Hook" because `grep-edit-mode-hook` is a hook.  Hooks contain
> functions, so when you run a hook, the corresponding functions are called.

Ah, I was under the impression that the functions were also referred to
as hooks.  I will correct them in a future patch.

>> +(defun grep-edit-mode ()
>> +  "Major mode for editing *grep* buffers.
>> +In this mode, changes to the *grep* buffer are applied to the
>> +originating files.
>> +\\<grep-edit-mode-map>
>> +Type \\[grep-edit-save-changes] to exit Grep-Edit mode, return to Grep
>> +mode.
>> +
>> +The only editable texts in a Grep-Edit buffer are the match results."
>> +  (interactive)
>> +  (error "This mode can be enabled only by `grep-change-to-grep-edit-mode'"))
>> +(put 'grep-edit-mode 'mode-class 'special)
>> +
>> +(defun grep-change-to-grep-edit-mode ()
>> +  "Switch to `grep-edit-mode' to edit *grep* buffer."
>> +  (interactive)
>> +  (unless (derived-mode-p 'grep-mode)
>> +    (error "Not a Grep buffer"))
>> +  (when (get-buffer-process (current-buffer))
>> +    (error "Cannot switch when grep is running"))
>> +  (use-local-map grep-edit-mode-map)
>> +  (grep-edit--prepare-buffer)
>> +  (setq buffer-read-only nil)
>> +  (setq major-mode 'grep-edit-mode)
>> +  (setq mode-name "Grep-Edit")
>> +  (buffer-enable-undo)
>> +  (set-buffer-modified-p nil)
>> +  (setq buffer-undo-list nil)
>> +  (add-hook 'after-change-functions #'occur-after-change-function nil t)
>> +  (run-mode-hooks 'grep-edit-mode-hook)
>> +  (message "Editing: \\[grep-edit-save-changes] to return to Grep mode"))
>
> I'm tempted to say you should use `major-mode-suspend/resume` (which
> would avoid the duplication of parts of `grep-mode` in
> `grep-edit-save-changes`), but I guess this might re-introduce the
> problem with buffer-local variables.

Yes, unfortunately it will re-introduce the problem with buffer-local
variables.  

If everyone is okay with the current patch, I can get to writing the
NEWS entry and updating the manual.  Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Wed, 14 Aug 2024 11:39:02 GMT) Full text and rfc822 format available.

Message #92 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Wed, 14 Aug 2024 07:37:53 -0400
>> Are there any changes in this code, or is it "verbatim" the code
>> extracted from `compilation-next-error-function`?
> It is extracted verbatim from compilation-next-error-function.

Great, thanks.

>>> +(defvar grep-edit-mode-hook nil
>>> +  "Hooks run when changing to Grep-Edit mode.")
>> It's just "Hook" because `grep-edit-mode-hook` is a hook.  Hooks contain
>> functions, so when you run a hook, the corresponding functions are called.
> Ah, I was under the impression that the functions were also referred to
> as hooks.

You're far from the only one: it's a common confusion, and it's frequent
to see docstrings which encourage that confusion.

> If everyone is okay with the current patch, I can get to writing the
> NEWS entry and updating the manual.  Thanks.

+1


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sat, 31 Aug 2024 07:56:02 GMT) Full text and rfc822 format available.

Message #95 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 70820 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 31 Aug 2024 10:54:44 +0300
Ping! Can we make progress with this issue?  I think there were no
objections to your proposal.

> From: Visuwesh <visuweshm <at> gmail.com>
> Cc: Eli Zaretskii <eliz <at> gnu.org>,  70820 <at> debbugs.gnu.org
> Date: Wed, 14 Aug 2024 08:13:42 +0530
> 
> [செவ்வாய் ஆகஸ்ட் 13, 2024] Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" wrote:
> 
> >> +(defun compilation--update-markers (loc marker screen-columns first-column)
> >> +  "Update markers in LOC, and set MARKER to location pointed by LOC.
> >> +SCREEN-COLUMNS and FIRST-COLUMN are the value of
> >> +`compilation-error-screen-columns' and `compilation-first-column' to use
> >> +if they are not set buffer-locally in the target buffer."
> >> +  (with-current-buffer
> >> +      (if (bufferp (caar (compilation--loc->file-struct loc)))
> >> +          (caar (compilation--loc->file-struct loc))
> >> +        (apply #'compilation-find-file
> >> +               marker
> >> +               (caar (compilation--loc->file-struct loc))
> >> +               (cadr (car (compilation--loc->file-struct loc)))
> >> +               (compilation--file-struct->formats
> >> +                (compilation--loc->file-struct loc))))
> >> +    (let ((screen-columns
> >> +           ;; Obey the compilation-error-screen-columns of the target
> >> +           ;; buffer if its major mode set it buffer-locally.
> >> +           (if (local-variable-p 'compilation-error-screen-columns)
> >> +               compilation-error-screen-columns screen-columns))
> >> +          (compilation-first-column
> >> +           (if (local-variable-p 'compilation-first-column)
> >> +               compilation-first-column first-column))
> >> +          (last 1))
> >> +      (save-restriction
> >> +        (widen)
> >> +        (goto-char (point-min))
> >> +        ;; Treat file's found lines in forward order, 1 by 1.
> >> +        (dolist (line (reverse (cddr (compilation--loc->file-struct loc))))
> >> +          (when (car line)     ; else this is a filename without a line#
> >> +            (compilation-beginning-of-line (- (car line) last -1))
> >> +            (setq last (car line)))
> >> +          ;; Treat line's found columns and store/update a marker for each.
> >> +          (dolist (col (cdr line))
> >> +            (if (compilation--loc->col col)
> >> +                (if (eq (compilation--loc->col col) -1)
> >> +                    ;; Special case for range end.
> >> +                    (end-of-line)
> >> +                  (compilation-move-to-column (compilation--loc->col col)
> >> +                                              screen-columns))
> >> +              (beginning-of-line)
> >> +              (skip-chars-forward " \t"))
> >> +            (if (compilation--loc->marker col)
> >> +                (set-marker (compilation--loc->marker col) (point))
> >> +              (setf (compilation--loc->marker col) (point-marker)))
> >> +            ;; (setf (compilation--loc->timestamp col) timestamp)
> >> +            ))))))
> >
> > Are there any changes in this code, or is it "verbatim" the code
> > extracted from `compilation-next-error-function`?
> 
> It is extracted verbatim from compilation-next-error-function.
> 
> >> +(defvar grep-edit-mode-hook nil
> >> +  "Hooks run when changing to Grep-Edit mode.")
> >
> > It's just "Hook" because `grep-edit-mode-hook` is a hook.  Hooks contain
> > functions, so when you run a hook, the corresponding functions are called.
> 
> Ah, I was under the impression that the functions were also referred to
> as hooks.  I will correct them in a future patch.
> 
> >> +(defun grep-edit-mode ()
> >> +  "Major mode for editing *grep* buffers.
> >> +In this mode, changes to the *grep* buffer are applied to the
> >> +originating files.
> >> +\\<grep-edit-mode-map>
> >> +Type \\[grep-edit-save-changes] to exit Grep-Edit mode, return to Grep
> >> +mode.
> >> +
> >> +The only editable texts in a Grep-Edit buffer are the match results."
> >> +  (interactive)
> >> +  (error "This mode can be enabled only by `grep-change-to-grep-edit-mode'"))
> >> +(put 'grep-edit-mode 'mode-class 'special)
> >> +
> >> +(defun grep-change-to-grep-edit-mode ()
> >> +  "Switch to `grep-edit-mode' to edit *grep* buffer."
> >> +  (interactive)
> >> +  (unless (derived-mode-p 'grep-mode)
> >> +    (error "Not a Grep buffer"))
> >> +  (when (get-buffer-process (current-buffer))
> >> +    (error "Cannot switch when grep is running"))
> >> +  (use-local-map grep-edit-mode-map)
> >> +  (grep-edit--prepare-buffer)
> >> +  (setq buffer-read-only nil)
> >> +  (setq major-mode 'grep-edit-mode)
> >> +  (setq mode-name "Grep-Edit")
> >> +  (buffer-enable-undo)
> >> +  (set-buffer-modified-p nil)
> >> +  (setq buffer-undo-list nil)
> >> +  (add-hook 'after-change-functions #'occur-after-change-function nil t)
> >> +  (run-mode-hooks 'grep-edit-mode-hook)
> >> +  (message "Editing: \\[grep-edit-save-changes] to return to Grep mode"))
> >
> > I'm tempted to say you should use `major-mode-suspend/resume` (which
> > would avoid the duplication of parts of `grep-mode` in
> > `grep-edit-save-changes`), but I guess this might re-introduce the
> > problem with buffer-local variables.
> 
> Yes, unfortunately it will re-introduce the problem with buffer-local
> variables.  
> 
> If everyone is okay with the current patch, I can get to writing the
> NEWS entry and updating the manual.  Thanks.
> 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Sat, 31 Aug 2024 08:06:01 GMT) Full text and rfc822 format available.

Message #98 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 70820 <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 31 Aug 2024 13:33:03 +0530
[சனி ஆகஸ்ட் 31, 2024] Eli Zaretskii wrote:

> Ping! Can we make progress with this issue?  I think there were no
> objections to your proposal.

I will send a proper patch in the coming week then.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#70820; Package emacs. (Mon, 09 Sep 2024 14:41:01 GMT) Full text and rfc822 format available.

Message #101 received at 70820 <at> debbugs.gnu.org (full text, mbox):

From: Visuwesh <visuweshm <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 70820 <at> debbugs.gnu.org
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Mon, 09 Sep 2024 20:09:22 +0530
[Message part 1 (text/plain, inline)]
[புதன் ஆகஸ்ட் 14, 2024] Visuwesh wrote:

> [...]
> If everyone is okay with the current patch, I can get to writing the
> NEWS entry and updating the manual.  Thanks.

Sorry for the long delay.  I've now attached a patch with such
documentation changes.

[0001-Make-the-grep-buffer-editable.patch (text/x-diff, attachment)]

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 14 Sep 2024 09:45:01 GMT) Full text and rfc822 format available.

Notification sent to Visuwesh <visuweshm <at> gmail.com>:
bug acknowledged by developer. (Sat, 14 Sep 2024 09:45:02 GMT) Full text and rfc822 format available.

Message #106 received at 70820-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Visuwesh <visuweshm <at> gmail.com>
Cc: 70820-done <at> debbugs.gnu.org, monnier <at> iro.umontreal.ca
Subject: Re: bug#70820: [PATCH] Editable grep buffers
Date: Sat, 14 Sep 2024 12:43:52 +0300
> From: Visuwesh <visuweshm <at> gmail.com>
> Cc: Eli Zaretskii <eliz <at> gnu.org>,  70820 <at> debbugs.gnu.org
> Date: Mon, 09 Sep 2024 20:09:22 +0530
> 
> [புதன் ஆகஸ்ட் 14, 2024] Visuwesh wrote:
> 
> > [...]
> > If everyone is okay with the current patch, I can get to writing the
> > NEWS entry and updating the manual.  Thanks.
> 
> Sorry for the long delay.  I've now attached a patch with such
> documentation changes.

Thanks, installed on the master branch, and closing the bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 12 Oct 2024 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 266 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.