old_bear
old_bear

Reputation: 399

emacs query-replace jump to the beginning of buffer

I'm using emacs 23.4.1. In most cases, query-replace works fine just as expected. However sometimes when I try to replace something at the middle of buffer and type y for the first appearance after point, the point will immediately jump to the first appearance of the whole buffer. For example:

foo ------- // beginning

bar ------- // use replace foo with bar here

foo ------- // type y here, then jump to the beginning

This is very annoying, and I can't reproduce this problem using some exact input. But every time it occurs, close emacs and reopen can solve it. Anybody can help me?

Upvotes: 2

Views: 285

Answers (5)

jhh
jhh

Reputation: 1

query-replace again showed the annoying behaviour of searching for the word to replace from the beginning after having replaced the word somewhere in the middle of the text by pressing 'y'.

What I found out now:

Pressing CTRL-space once doesn't change anything but pressing CTRL-space CTRL-space (so invoke this command twice -> activating a mark and deactivating it) makes query-replace work again.

Update: When the problem was there again, pressing C-space twice did NOT help. So, this is no workaround.

Upvotes: 0

yamitai
yamitai

Reputation: 21

Another observation: I notice the same problem, the point even jumps around back and forth several times. I could make it disappear by turning off the semantic-change-hooks using (setq semantic-change-hooks nil). semantic-change-hooks was set to run semantic-edits-change-function-handle-changes. All this happens in semantic-edit.el which adds semantic-change-function to after-change-functions. In short, I can't point the finger to the actual culprit but it has to do with semantic, which was also my initial suspicion (and I guess jhh's who mentioned CEDET).

Note: turning off the semantic-change-hooks is not a solution unless you're willing to give up some semantic functionality.

Upvotes: 2

jhh
jhh

Reputation: 1

If I set a mark (using C-space directly before the region, where the words to replace are inside) and then invoke the query-replace command it stops immediately without having replaced anything.

Upvotes: 0

jhh
jhh

Reputation: 1

Just an observation I made toady: I am using Emacs 23.2.1 and have the same problem as described above. So I tested query-replace when starting emacs with option -q. Then it worked, so thought the reason for the problem is my ".emacs". Later I found out that a second instance of emacs starting with the same ".emacs" does not have the issue while the first instance still has the problem. Unfortunately the issue returns after a while of coding, compiling, using CEDET. After all, I can also not reproduce the problem at the moment and don't know what causes it.

Upvotes: 0

Andreas Röhler
Andreas Röhler

Reputation: 4804

query-replace makes a guess where to start:

... (if (and transient-mark-mode mark-active) (region-beginning))

To make sure, mark is not above, type \C-<SPACE> at start, i.e. set mark at current position.

Upvotes: 0

Related Questions