Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bug#8463: 24.0.50; [PATCH] Direct Edit in *Occur* Buffer

38 views
Skip to first unread message

Leo

unread,
May 29, 2011, 12:04:36 AM5/29/11
to Chong Yidong, 84...@debbugs.gnu.org, Daniel Colascione
On 2011-05-29 07:05 +0800, Chong Yidong wrote:
[snipped 11 lines]
> Looks good. I've made a couple of tweaks, and have committed it to
> trunk. The C-c c-c binding was removed in favor of just C-x C-q, as
> Stefan suggested. For now, I also left out the part where C-x C-q in
> Occur Edit mode saves the associated buffers, because this doesn't seem
> to be properly thought out; what if the buffers have no associated
> files?
>
> Also, I added a small fix to occur-after-change-function to avoid
> screwing up the Occur Edit buffer when multi-line text is inserted.
> Since we can't create new Occur entries, this just ignores everything
> after the inserted newline. If you want to try and handle this properly
> (i.e. by inserting a new Occur entry for each inserted line), go ahead.

Yidong, many thanks for the tweaks and fixes.

Let's keep this bug open for a bit longer. I am thinking of generalising
occur-edit-mode (probably rename it to match-line-edit) so that it
covers buffers from grep and the like.

Leo

Andrew W. Nosenko

unread,
May 30, 2011, 10:04:33 AM5/30/11
to Leo, 84...@debbugs.gnu.org, Daniel Colascione
On Sun, Apr 10, 2011 at 11:14, Leo <sdl...@gmail.com> wrote:
> I have extended the occur feature in Emacs to allow direct editing in
> the *Occur* buffer by propagating the changes to the original buffers.
>
> With the attached preliminary patch, one can press `C-x C-q' or `C-c
> C-c' to enter occur-edit-mode and start editing. Pressing `C-x C-q' or
> `C-c C-c' again finishes the edit.
>
> Comments are highly welcomed. Thanks in advance.

Is there a way to _disable_ this feature? I'm quite often edit the
*Occur* and *grep* buffers for line-up results, etc, just for easier
understanding results, but I don't want these edits to be mirrored
into original lines or files from where they are come.

--
Andrew W. Nosenko <andrew.w...@gmail.com>

Richard Stallman

unread,
May 30, 2011, 7:10:51 PM5/30/11
to Andrew W. Nosenko, 84...@debbugs.gnu.org, dan.col...@gmail.com, sdl...@gmail.com
> I have extended the occur feature in Emacs to allow direct editing in
> the *Occur* buffer by propagating the changes to the original buffers.

I am not surprised you want to disable it.
Maybe it should be disabled by default.

--
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org, www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
Use free telephony http://directory.fsf.org/category/tel/

Glenn Morris

unread,
Jun 1, 2011, 7:03:36 PM6/1/11
to Andrew W. Nosenko, 84...@debbugs.gnu.org, Daniel Colascione, Leo
"Andrew W. Nosenko" wrote:

> Is there a way to _disable_ this feature? I'm quite often edit the
> *Occur* and *grep* buffers for line-up results, etc, just for easier
> understanding results, but I don't want these edits to be mirrored
> into original lines or files from where they are come.

Me too.

I expect C-x C-q to toggle the read-only state of a buffer, not switch
me into some unusual mode. I suggest binding this new mode to some other
key.

Other issues with this:

1. After C-x C-q, I can no longer kill entire lines in the occur buffer.
Trying to do so reports "Text is read-only".

2. After C-x C-q, If I delete some text in the occur buffer, then use
"undo", when I reach the point at which there is no more to undo, I get:
"Wrong type argument: markerp, nil" rather than "No further undo information".

Debugger entered--Lisp error: (wrong-type-argument markerp nil)
marker-buffer(nil)
occur-after-change-function(1 40 39)
primitive-undo(1 ((nil font-lock-face underline 1 . 40) (t 0 . 0)))
undo-more(1)
undo(nil)
call-interactively(undo nil nil)

3. After C-x C-q, M-x revert-buffer in the occur buffer triggers an error:

apply: Wrong number of arguments: #[(regexp nlines bufs &optional buf-name)

occur-1("*Occur*")
apply(occur-1 "*Occur*")
occur-revert-function(t nil)
revert-buffer(t)
call-interactively(revert-buffer t nil)
execute-extended-command(nil)
call-interactively(execute-extended-command nil nil)

I guess the mode change clobbers occur-revert-arguments.

Leo

unread,
Jun 2, 2011, 10:36:02 PM6/2/11
to Glenn Morris, 84...@debbugs.gnu.org
On 2011-06-02 07:03 +0800, Glenn Morris wrote:
[snipped 50 lines]

Thank you for this feedback. I will try to address these issues when I
am back from a trip on Tuesday.

Leo

Stefan Monnier

unread,
Jun 3, 2011, 11:38:07 AM6/3/11
to Leo, 84...@debbugs.gnu.org
> Thank you for this feedback. I will try to address these issues when I
> am back from a trip on Tuesday.

I think it makes sense to bind the occur-edit feature to some other key
than C-x C-q.
While C-x C-q is a cute binding for it, it does hide a command that is
also useful.


Stefan

Chong Yidong

unread,
Jun 4, 2011, 5:34:14 PM6/4/11
to Stefan Monnier, 84...@debbugs.gnu.org, Leo
Stefan Monnier <mon...@iro.umontreal.ca> writes:

Unfortunately, C-x C-q is consistent with the command for switching to
wdired mode.

Štěpán Němec

unread,
Jun 5, 2011, 5:30:57 AM6/5/11
to Chong Yidong, 84...@debbugs.gnu.org, Leo
Chong Yidong <c...@stupidchicken.com> writes:

I don't think this argument is really valid. First of all, C-x C-q is
consistent with the command to switch read-only-ness of a buffer, and
that's apparently what at least some people still expect and are used to
in this case. It might have made sense to override it for Wdired, but
not necessarily here.

Štěpán

Stefan Monnier

unread,
Jun 6, 2011, 11:34:36 AM6/6/11
to Chong Yidong, 84...@debbugs.gnu.org, Leo
>>> Thank you for this feedback. I will try to address these issues when I
>>> am back from a trip on Tuesday.
>> I think it makes sense to bind the occur-edit feature to some other
>> key than C-x C-q. While C-x C-q is a cute binding for it, it does
>> hide a command that is also useful.
> Unfortunately, C-x C-q is consistent with the command for switching to
> wdired mode.

Right, but wdired and occur-edit are two different things.
Editing a dired buffer in wdired does not have any other side effect
(at least not until you "commit" those changes), so its behavior is
still pretty close to toggle-read-only. Occur-edit is somewhat
reminiscent of wdired, but does not match the behavior of
toggle-read-only quite as closely.


Stefan

Leo

unread,
Jun 9, 2011, 12:47:00 AM6/9/11
to Glenn Morris, Chong Yidong, 84...@debbugs.gnu.org, Richard Stallman
On 2011-06-02 07:03 +0800, Glenn Morris wrote:
> 2. After C-x C-q, If I delete some text in the occur buffer, then use
> "undo", when I reach the point at which there is no more to undo, I get:
> "Wrong type argument: markerp, nil" rather than "No further undo information".
>
> Debugger entered--Lisp error: (wrong-type-argument markerp nil)
> marker-buffer(nil)
> occur-after-change-function(1 40 39)
> primitive-undo(1 ((nil font-lock-face underline 1 . 40) (t 0 . 0)))
> undo-more(1)
> undo(nil)
> call-interactively(undo nil nil)

This can be fixed with:

diff --git a/lisp/replace.el b/lisp/replace.el
index 0578ed09..fc2db2ec 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -882,11 +882,11 @@ (define-derived-mode occur-edit-mode occur-mode "Occur-Edit"

(defun occur-after-change-function (beg end length)
(save-excursion
- (goto-char beg)
(let* ((m (get-text-property (line-beginning-position) 'occur-target))
(buf (marker-buffer m))
(col (current-column)))
(when (= length 0)
+ (goto-char beg)
;; Apply occur-target property to inserted (e.g. yanked) text.
(put-text-property beg end 'occur-target m)
;; Did we insert a newline? Occur Edit mode can't create new

The cause:

When switching major-mode (in this case occur-edit-mode), an undo entry
containing text-property only change is added due to this line in
occur-mode:

(add-hook 'change-major-mode-hook 'font-lock-defontify nil t)

That line seems useless due to change made in revid 22063400b. If no one
objects, I intend to also remove it.

Leo

Glenn Morris

unread,
Jun 9, 2011, 1:14:18 AM6/9/11
to Leo, 84...@debbugs.gnu.org
Leo wrote:

> revid 22063400b.

Speaking for myself, I have no idea what that means.

Leo

unread,
Jun 9, 2011, 5:42:47 AM6/9/11
to Glenn Morris, Chong Yidong, 84...@debbugs.gnu.org
I think maybe we should assign C-c C-c to occur-edit-mode instead.

1. After C-x C-q, I can no longer kill entire lines in the occur buffer.
Trying to do so reports "Text is read-only".

The text properties are now added when entering occur-edit-mode.

2. After C-x C-q, If I delete some text in the occur buffer, then use
"undo", when I reach the point at which there is no more to undo, I get:
"Wrong type argument: markerp, nil" rather than "No further undo information".

Debugger entered--Lisp error: (wrong-type-argument markerp nil)
marker-buffer(nil)
occur-after-change-function(1 40 39)
primitive-undo(1 ((nil font-lock-face underline 1 . 40) (t 0 . 0)))
undo-more(1)
undo(nil)
call-interactively(undo nil nil)

Fixed.

3. After C-x C-q, M-x revert-buffer in the occur buffer triggers an error

occur-revert-arguments is killed after any major-mode change. In the
patch this has been made permanent-local.

Comments welcome. Thanks.

occur-edit.diff

Leo

unread,
Jun 9, 2011, 5:44:11 AM6/9/11
to Glenn Morris, 84...@debbugs.gnu.org
On 2011-06-09 13:14 +0800, Glenn Morris wrote:
>> revid 22063400b.
>
> Speaking for myself, I have no idea what that means.

That's what I saw on the annotation buffer (from C-x v g). I was able to
view the diff there with 'd'.

Leo

Eli Zaretskii

unread,
Jun 9, 2011, 5:54:49 AM6/9/11
to Leo, 84...@debbugs.gnu.org
> From: Leo <sdl...@gmail.com>
> Date: Thu, 09 Jun 2011 17:44:11 +0800
> Cc: 84...@debbugs.gnu.org

Git sha values are generally not useful for someone who uses bzr. It
would be nice if people who report problems could also mention the bzr
revision or revid.

Leo

unread,
Jun 9, 2011, 5:58:57 AM6/9/11
to Eli Zaretskii, 84...@debbugs.gnu.org
On 2011-06-09 17:54 +0800, Eli Zaretskii wrote:
>> That's what I saw on the annotation buffer (from C-x v g). I was able to
>> view the diff there with 'd'.
>
> Git sha values are generally not useful for someone who uses bzr. It
> would be nice if people who report problems could also mention the bzr
> revision or revid.

My bad. I thought I was on the bzr repo.

Leo

Glenn Morris

unread,
Jun 9, 2011, 2:09:49 PM6/9/11
to Leo, Chong Yidong, 84...@debbugs.gnu.org
Leo wrote:

> I think maybe we should assign C-c C-c to occur-edit-mode instead.

Or "e" (for edit; like in Rmail).

> 1. After C-x C-q, I can no longer kill entire lines in the occur buffer.
> Trying to do so reports "Text is read-only".
>
> The text properties are now added when entering occur-edit-mode.

I don't understand if that means it's fixed. Deleting whole or even
multiple lines is an operation I might want to do in occur-edit-mode.

Stefan Monnier

unread,
Jun 10, 2011, 9:59:16 AM6/10/11
to Glenn Morris, Chong Yidong, 84...@debbugs.gnu.org, Leo
>> I think maybe we should assign C-c C-c to occur-edit-mode instead.

I don't like that: C-c C-c means "done" usually so it'd be OK to leave
edit mode, but not to enter it.

> Or "e" (for edit; like in Rmail).

That sounds good.

>> 1. After C-x C-q, I can no longer kill entire lines in the occur buffer.
>> Trying to do so reports "Text is read-only".
>> The text properties are now added when entering occur-edit-mode.
> I don't understand if that means it's fixed. Deleting whole or even
> multiple lines is an operation I might want to do in occur-edit-mode.

But its meaning is unclear and we get to choose what is allowed and what
is not in edit mode since it's a new mode that the user
requested explicitly.


Stefan

Ted Zlatanov

unread,
Jun 10, 2011, 12:14:16 PM6/10/11
to Stefan Monnier, Chong Yidong, 84...@debbugs.gnu.org, Leo
On Fri, 10 Jun 2011 10:59:16 -0300 Stefan Monnier <mon...@iro.umontreal.ca> wrote:

>>> 1. After C-x C-q, I can no longer kill entire lines in the occur buffer.
>>> Trying to do so reports "Text is read-only".
>>> The text properties are now added when entering occur-edit-mode.
>> I don't understand if that means it's fixed. Deleting whole or even
>> multiple lines is an operation I might want to do in occur-edit-mode.

SM> But its meaning is unclear and we get to choose what is allowed and what
SM> is not in edit mode since it's a new mode that the user
SM> requested explicitly.

I'd suggest binding `d' to "delete entire line" outside the edit mode,
so the edit mode does not need to provide it and still it's available in
a convenient way.

Ted

Andrew W. Nosenko

unread,
Jun 11, 2011, 5:58:41 AM6/11/11
to Stefan Monnier, Chong Yidong, 84...@debbugs.gnu.org, Leo
On Fri, Jun 10, 2011 at 16:59, Stefan Monnier <mon...@iro.umontreal.ca> wrote:
>>> I think maybe we should assign C-c C-c to occur-edit-mode instead.
>
> I don't like that: C-c C-c means "done" usually so it'd be OK to leave
> edit mode, but not to enter it.
>
>> Or "e" (for edit; like in Rmail).
>
> That sounds good.

But not for case, when user already switched the *Occur* buffer into
read/write mode for editing the buffer itself (not the underlying
files/buffers, where occurrences come from).

The same applied for Ted's proposal for 'd' key and any other keys
that used for regular text typing.

Juri Linkov

unread,
Jun 11, 2011, 2:00:23 PM6/11/11
to Andrew W. Nosenko, Chong Yidong, 84...@debbugs.gnu.org, Leo
>>> Or "e" (for edit; like in Rmail).
>>
>> That sounds good.
>
> But not for case, when user already switched the *Occur* buffer into
> read/write mode for editing the buffer itself (not the underlying
> files/buffers, where occurrences come from).

Then maybe `M-e' (like in isearch mode)?

> The same applied for Ted's proposal for 'd' key and any other keys
> that used for regular text typing.

There is already `C-k' to do this.

Andrew W. Nosenko

unread,
Jun 12, 2011, 7:10:07 PM6/12/11
to Juri Linkov, Chong Yidong, 84...@debbugs.gnu.org, Leo
On Sat, Jun 11, 2011 at 21:00, Juri Linkov <ju...@jurta.org> wrote:
>>>> Or "e" (for edit; like in Rmail).
>>>
>>> That sounds good.
>>
>> But not for case, when user already switched the *Occur* buffer into
>> read/write mode for editing the buffer itself (not the underlying
>> files/buffers, where occurrences come from).
>
> Then maybe `M-e' (like in isearch mode)?

If separate apply-changes-to-underlying-buffers action to the own
function (may be even it already implemented in that way) then all
controversy will gone. -- Enter to read-write mode -- the same,
editing commands -- the same, all other behavior -- the same. Just
because there will work one and the same code in the one and the same
mode. Difference is only one between my usage model and usage model
of Leo (original author) -- after finishing I simple kill the occur
buffer, while Leo call the "apply-cachanges-to-underlying-buffers" for
"commit" the final results.

IMHO anyone can benefit from solving the problem in that way.

Chong Yidong

unread,
Jun 18, 2011, 3:35:41 PM6/18/11
to Andrew W. Nosenko, 84...@debbugs.gnu.org, Leo
"Andrew W. Nosenko" <andrew.w...@gmail.com> writes:

>>> Or "e" (for edit; like in Rmail).
>>
>> That sounds good.
>
> But not for case, when user already switched the *Occur* buffer into
> read/write mode for editing the buffer itself (not the underlying
> files/buffers, where occurrences come from).

That's already the case with "r" (occur-rename-buffer), "c"
(clone-buffer), and "o" (occur-mode-goto-occurrence-other-window).

Andrew W. Nosenko

unread,
Jun 18, 2011, 4:36:49 PM6/18/11
to Chong Yidong, 84...@debbugs.gnu.org, Leo

Yes, but: (1) these actions aren't destructive in respect to the
original data, and (2) I would to prefer to see the number of such
bindings decreasing, not increasing.

Juri Linkov

unread,
Sep 9, 2011, 7:39:23 AM9/9/11
to Leo, 84...@debbugs.gnu.org
I appreciate this new feature Occur-Edit. It's especially powerful with
the ability of syncing replacements made by `query-replace' from the
*Occur* buffer to the source buffer. It could provide a special
keybinding to start making replacements with the same regexp as used to run
`occur' like grep-x.el does in http://thread.gmane.org/gmane.emacs.devel/66418
and in http://thread.gmane.org/gmane.emacs.devel/108202/focus=108229

Also it has one little drawback: it adds too many undo boundaries,
so to undo changes in the source buffer, it requires too many `C-_'.
There is no such problem in all.el (from ELPA) because
`all-after-change-function' doesn't call `recenter' and `move-to-column'.

But there is a greater drawback: stealing the `C-x C-q' keybinding from
`toggle-read-only' and putting read-only properties on the *Occur* buffer
is unacceptable. I'm used to run `flush-lines' and `keep-lines' to narrow
the search results, but can't do this anymore. This is a regression.



Juri Linkov

unread,
Sep 14, 2011, 3:04:30 PM9/14/11
to Leo, 84...@debbugs.gnu.org
There is 2011-06-18 ChangeLog entry added by revno:104628 without actual
code changes:

* replace.el (occur-mode-map): Set occur-edit-mode binding to "e".

I guess it was supposed to bind "e" to `occur-edit-mode' in `occur-mode-map'?

Chong Yidong

unread,
Sep 17, 2011, 5:28:13 PM9/17/11
to Juri Linkov, 84...@debbugs.gnu.org, Leo
Juri Linkov <ju...@jurta.org> writes:

> But there is a greater drawback: stealing the `C-x C-q' keybinding
> from `toggle-read-only' and putting read-only properties on the
> *Occur* buffer is unacceptable. I'm used to run `flush-lines' and
> `keep-lines' to narrow the search results, but can't do this anymore.
> This is a regression.

OK, I rebound occur-edit-mode to "e" and removed the read-only
properties, with some additional code changes to make Occur Edit mode
work without requiring read-only text.

As for the other issue of single-char commands not being usable in
non-read-only Occur mode, we could handle it in a way similar to diff
mode (via minor-mode-overriding-map-alist), but that is for another day.



Juri Linkov

unread,
Sep 18, 2011, 3:33:14 PM9/18/11
to Chong Yidong, 84...@debbugs.gnu.org, Leo
> OK, I rebound occur-edit-mode to "e" and removed the read-only
> properties, with some additional code changes to make Occur Edit mode
> work without requiring read-only text.

Thanks, this is fine now except one little problem:
after finishing Occur-Edit, `g' (`revert-buffer') fails with
"Wrong number of arguments: #[(regexp nlines bufs &optional buf-name)..."

There is a fix in http://debbugs.gnu.org/8463#47
that makes `occur-revert-arguments' permanent-local.

Chong Yidong

unread,
Sep 19, 2011, 2:52:58 PM9/19/11
to Juri Linkov, 84...@debbugs.gnu.org, Leo
Juri Linkov <ju...@jurta.org> writes:

> Thanks, this is fine now except one little problem:
> after finishing Occur-Edit, `g' (`revert-buffer') fails with
> "Wrong number of arguments: #[(regexp nlines bufs &optional buf-name)..."
>
> There is a fix in http://debbugs.gnu.org/8463#47
> that makes `occur-revert-arguments' permanent-local.

Ah, I somehow missed that patch. I will incorporate it. Thanks.



0 new messages