all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Interactive query-replace
@ 2017-02-09 21:27 Ole Laursen
  2017-02-09 21:37 ` Kaushal Modi
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Ole Laursen @ 2017-02-09 21:27 UTC (permalink / raw)
  To: emacs-devel; +Cc: Ole Laursen

Hi!

I realized the other day that search and replace in Emacs isn't very
interactive when a coworker showed me another editor he was
experimenting with. What he somehow did there seemed like something
Emacs would do when query-replacing, only it doesn't.

Search and replace has three phases:

- Enter search term
- Enter replacement term
- Confirmation

Only confirmation is interactive in Emacs.

The search phase could move the cursor and highlight all matches as
you type, just like isearch. Then we can see what we're about to
overwrite.

Replacement text phase could overwrite each match visible in the
buffer with the replacement text as you type it. The replacements
would still be highlighted so it's obvious what's happening. Then we
can actually evaluate how the replacement works in practice in the
buffer before committing to it.

Confirmation then actually commits the changes to the buffer, just like today.

Doesn't this sound like something Emacs should be doing?

I'll admit I have no idea how to actually implement it.


Ole



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interactive query-replace
  2017-02-09 21:27 Interactive query-replace Ole Laursen
@ 2017-02-09 21:37 ` Kaushal Modi
  2017-02-09 21:38   ` Kaushal Modi
  2017-02-09 21:42 ` Clément Pit-Claudel
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Kaushal Modi @ 2017-02-09 21:37 UTC (permalink / raw)
  To: Ole Laursen, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 791 bytes --]

On Thu, Feb 9, 2017 at 4:27 PM Ole Laursen <olau@iola.dk> wrote:

> Hi!
>
> I realized the other day that search and replace in Emacs isn't very
> interactive when a coworker showed me another editor he was
> experimenting with. What he somehow did there seemed like something
> Emacs would do when query-replacing, only it doesn't.
>
> Search and replace has three phases:
>
> - Enter search term
> - Enter replacement term
> - Confirmation
>
> Only confirmation is interactive in Emacs.
>
> The search phase could move the cursor and highlight all matches as
> you type, just like isearch. Then we can see what we're about to
> overwrite.
>

Looks like the multiple-cursors package (
https://github.com/magnars/multiple-cursors.el ) will do it. It's available
via Melpa.
-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 1591 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interactive query-replace
  2017-02-09 21:37 ` Kaushal Modi
@ 2017-02-09 21:38   ` Kaushal Modi
  0 siblings, 0 replies; 8+ messages in thread
From: Kaushal Modi @ 2017-02-09 21:38 UTC (permalink / raw)
  To: Ole Laursen, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

Here's a demo: https://www.youtube.com/watch?v=jNa3axo40qM

On Thu, Feb 9, 2017 at 4:37 PM Kaushal Modi <kaushal.modi@gmail.com> wrote:

>
> Looks like the multiple-cursors package (
> https://github.com/magnars/multiple-cursors.el ) will do it. It's
> available via Melpa.
> --
>
> Kaushal Modi
>
-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 1188 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interactive query-replace
  2017-02-09 21:27 Interactive query-replace Ole Laursen
  2017-02-09 21:37 ` Kaushal Modi
@ 2017-02-09 21:42 ` Clément Pit-Claudel
  2017-02-09 22:27   ` Ole Laursen
  2017-02-10  4:38 ` Chunyang Xu
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Clément Pit-Claudel @ 2017-02-09 21:42 UTC (permalink / raw)
  To: Ole Laursen, emacs-devel

On 2017-02-09 16:27, Ole Laursen wrote:
> Doesn't this sound like something Emacs should be doing?

I think you'll like https://github.com/benma/visual-regexp.el :)



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interactive query-replace
  2017-02-09 21:42 ` Clément Pit-Claudel
@ 2017-02-09 22:27   ` Ole Laursen
  0 siblings, 0 replies; 8+ messages in thread
From: Ole Laursen @ 2017-02-09 22:27 UTC (permalink / raw)
  To: emacs-devel; +Cc: Ole Laursen

2017-02-09 22:42 GMT+01:00 Clément Pit-Claudel <cpitclaudel@gmail.com>:
> On 2017-02-09 16:27, Ole Laursen wrote:
>> Doesn't this sound like something Emacs should be doing?
>
> I think you'll like https://github.com/benma/visual-regexp.el :)

Thanks for the suggestions! I have installed both.

Multiple cursors is a bit too general/fiddly for this problem I think,
although the concept seems useful for solving problems that otherwise
call for a keyboard macro and apply-macro-to-region-lines.

As for visual-regexp, after setting vr/default-replace-preview to t,
vr/query-replace seems to do what I'm suggesting. Neat. Would it make
sense to integrate behavior like this into stock Emacs?


Ole



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interactive query-replace
  2017-02-09 21:27 Interactive query-replace Ole Laursen
  2017-02-09 21:37 ` Kaushal Modi
  2017-02-09 21:42 ` Clément Pit-Claudel
@ 2017-02-10  4:38 ` Chunyang Xu
  2017-02-10  4:47 ` Chunyang Xu
  2017-02-10  6:03 ` Stefan Monnier
  4 siblings, 0 replies; 8+ messages in thread
From: Chunyang Xu @ 2017-02-10  4:38 UTC (permalink / raw)
  To: Ole Laursen; +Cc: emacs-devel


Ole Laursen writes:

> Hi!
>
> I realized the other day that search and replace in Emacs isn't very
> interactive when a coworker showed me another editor he was
> experimenting with. What he somehow did there seemed like something
> Emacs would do when query-replacing, only it doesn't.
>
> Search and replace has three phases:
>
> - Enter search term
> - Enter replacement term
> - Confirmation
>
> Only confirmation is interactive in Emacs.
>
> The search phase could move the cursor and highlight all matches as
> you type, just like isearch. Then we can see what we're about to
> overwrite.
>
> Replacement text phase could overwrite each match visible in the
> buffer with the replacement text as you type it. The replacements
> would still be highlighted so it's obvious what's happening. Then we
> can actually evaluate how the replacement works in practice in the
> buffer before committing to it.
>
> Confirmation then actually commits the changes to the buffer, just like today.
>
> Doesn't this sound like something Emacs should be doing?
>
> I'll admit I have no idea how to actually implement it.
>
>
> Ole






^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interactive query-replace
  2017-02-09 21:27 Interactive query-replace Ole Laursen
                   ` (2 preceding siblings ...)
  2017-02-10  4:38 ` Chunyang Xu
@ 2017-02-10  4:47 ` Chunyang Xu
  2017-02-10  6:03 ` Stefan Monnier
  4 siblings, 0 replies; 8+ messages in thread
From: Chunyang Xu @ 2017-02-10  4:47 UTC (permalink / raw)
  To: Ole Laursen; +Cc: emacs-devel

(I replied a empty message a minute ago by accident, sorry about that)

Ole Laursen writes:

> Search and replace has three phases:
>
> - Enter search term
> - Enter replacement term
> - Confirmation
>
> Only confirmation is interactive in Emacs.
>
> The search phase could move the cursor and highlight all matches as
> you type, just like isearch. Then we can see what we're about to
> overwrite.

The search term is also interactive if you start your query-replace from
isearch via the same keys (that is M-% ('isearch-query-replace')). I use
this whenever I am not sure if my search pattern is correct.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Interactive query-replace
  2017-02-09 21:27 Interactive query-replace Ole Laursen
                   ` (3 preceding siblings ...)
  2017-02-10  4:47 ` Chunyang Xu
@ 2017-02-10  6:03 ` Stefan Monnier
  4 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2017-02-10  6:03 UTC (permalink / raw)
  To: emacs-devel

> Search and replace has three phases:
>
> - Enter search term
> - Enter replacement term
> - Confirmation
>
> Only confirmation is interactive in Emacs.

That's the old search and replace.  I think we should deprecate it.
The new one goes like this:

   C-s blabla M-% blibli RET

the "Enter replacement term" is indeed not interactive (yet), but the
"enter search term" is.


        Stefan




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-02-10  6:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-09 21:27 Interactive query-replace Ole Laursen
2017-02-09 21:37 ` Kaushal Modi
2017-02-09 21:38   ` Kaushal Modi
2017-02-09 21:42 ` Clément Pit-Claudel
2017-02-09 22:27   ` Ole Laursen
2017-02-10  4:38 ` Chunyang Xu
2017-02-10  4:47 ` Chunyang Xu
2017-02-10  6:03 ` Stefan Monnier

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.