[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Word Delimited Query Replace (was: read-regexp)
From: |
Juri Linkov |
Subject: |
Word Delimited Query Replace (was: read-regexp) |
Date: |
Sat, 18 Oct 2008 19:23:09 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) |
BTW, I discovered a UI problem: to prepare the patch it was necessary
to rename the string "default" but not its plural form "defaults" in
read-regexp. So I selected the region around the body of read-regexp
and typed `C-s default C-u M-%'. The C-u prefix argument of query-replace
means to replace only matches surrounded by word boundaries, but while
implementing isearch-query-replace a few years ago we missed this case,
so currently isearch-query-replace just ignores it.
The patch below fixes this problem by adding the prefix argument
DELIMITED to isearch-query-replace and isearch-query-replace-regexp that
has the same meaning as the prefix argument DELIMITED of query-replace
and query-replace-regexp.
Also I found another problem: there is no indication in the query-replace
minibuffer prompts about the fact that replacements are word-delimited.
This is unlike the regexp mode where there is such indication.
So in addition to currently existing possible replacement prompts:
Query replace regexp
Query replace regexp in region
the patch below adds similar prompts when the word-delimited argument
is non-nil:
Query replace word
Query replace word in region
Index: lisp/isearch.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.330
diff -c -r1.330 isearch.el
*** lisp/isearch.el 25 Sep 2008 17:06:22 -0000 1.330
--- lisp/isearch.el 18 Oct 2008 16:21:40 -0000
***************
*** 1333,1341 ****
(sit-for 1)
(isearch-update))
! (defun isearch-query-replace (&optional regexp-flag)
! "Start `query-replace' with string to replace from last search string."
! (interactive)
(barf-if-buffer-read-only)
(if regexp-flag (setq isearch-regexp t))
(let ((case-fold-search isearch-case-fold-search)
--- 1333,1344 ----
(sit-for 1)
(isearch-update))
! (defun isearch-query-replace (&optional delimited regexp-flag)
! "Start `query-replace' with string to replace from last search string.
! The arg DELIMITED (prefix arg if interactive), if non-nil, means replace
! only matches surrounded by word boundaries."
! (interactive
! (list current-prefix-arg))
(barf-if-buffer-read-only)
(if regexp-flag (setq isearch-regexp t))
(let ((case-fold-search isearch-case-fold-search)
***************
*** 1356,1371 ****
isearch-string
(query-replace-read-to
isearch-string
! (if isearch-regexp "Query replace regexp" "Query replace")
isearch-regexp)
! t isearch-regexp isearch-word nil nil
(if (and transient-mark-mode mark-active) (region-beginning))
(if (and transient-mark-mode mark-active) (region-end)))))
! (defun isearch-query-replace-regexp ()
! "Start `query-replace-regexp' with string to replace from last search
string."
! (interactive)
! (isearch-query-replace t))
(defun isearch-occur (regexp &optional nlines)
"Run `occur' with regexp to search from the current search string.
--- 1359,1380 ----
isearch-string
(query-replace-read-to
isearch-string
! (concat "Query replace"
! (if (or delimited isearch-word) " word" "")
! (if isearch-regexp " regexp" "")
! (if (and transient-mark-mode mark-active) " in region" ""))
isearch-regexp)
! t isearch-regexp (or delimited isearch-word) nil nil
(if (and transient-mark-mode mark-active) (region-beginning))
(if (and transient-mark-mode mark-active) (region-end)))))
! (defun isearch-query-replace-regexp (&optional delimited)
! "Start `query-replace-regexp' with string to replace from last search
string.
! The arg DELIMITED (prefix arg if interactive), if non-nil, means replace
! only matches surrounded by word boundaries."
! (interactive
! (list current-prefix-arg))
! (isearch-query-replace delimited t))
(defun isearch-occur (regexp &optional nlines)
"Run `occur' with regexp to search from the current search string.
Index: lisp/replace.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/replace.el,v
retrieving revision 1.276
diff -u -w -b -r1.276 replace.el
--- lisp/replace.el 12 Sep 2008 00:37:41 -0000 1.276
+++ lisp/replace.el 18 Oct 2008 16:21:50 -0000
@@ -223,11 +223,12 @@
Fourth and fifth arg START and END specify the region to operate on.
To customize possible responses, change the \"bindings\" in
`query-replace-map'."
- (interactive (let ((common
+ (interactive
+ (let ((common
(query-replace-read-args
- (if (and transient-mark-mode mark-active)
- "Query replace in region"
- "Query replace")
+ (concat "Query replace"
+ (if current-prefix-arg " word" "")
+ (if (and transient-mark-mode mark-active) " in region" ""))
nil)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
;; These are done separately here
@@ -289,9 +290,10 @@
(interactive
(let ((common
(query-replace-read-args
- (if (and transient-mark-mode mark-active)
- "Query replace regexp in region"
- "Query replace regexp")
+ (concat "Query replace"
+ (if current-prefix-arg " word" "")
+ " regexp"
+ (if (and transient-mark-mode mark-active) " in region" ""))
t)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
;; These are done separately here
@@ -447,9 +449,10 @@
(interactive
(let ((common
(query-replace-read-args
- (if (and transient-mark-mode mark-active)
- "Replace string in region"
- "Replace string")
+ (concat "Replace"
+ (if current-prefix-arg " word" "")
+ " string"
+ (if (and transient-mark-mode mark-active) " in region" ""))
nil)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
(if (and transient-mark-mode mark-active)
@@ -504,9 +507,10 @@
(interactive
(let ((common
(query-replace-read-args
- (if (and transient-mark-mode mark-active)
- "Replace regexp in region"
- "Replace regexp")
+ (concat "Replace"
+ (if current-prefix-arg " word" "")
+ " regexp"
+ (if (and transient-mark-mode mark-active) " in region" ""))
t)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
(if (and transient-mark-mode mark-active)
@@ -1714,6 +1720,7 @@
(with-output-to-temp-buffer "*Help*"
(princ
(concat "Query replacing "
+ (if delimited-flag "word " "")
(if regexp-flag "regexp " "")
from-string " with "
next-replacement ".\n\n"
--
Juri Linkov
http://www.jurta.org/emacs/
Word Delimited Query Replace (was: read-regexp),
Juri Linkov <=
- Re: Word Delimited Query Replace, Stefan Monnier, 2008/10/18
- Re: Word Delimited Query Replace, Juri Linkov, 2008/10/18
- Re: Word Delimited Query Replace, Stefan Monnier, 2008/10/18
- Re: Word Delimited Query Replace, Juri Linkov, 2008/10/18
- Re: Word Delimited Query Replace, Stefan Monnier, 2008/10/18
- Re: Word Delimited Query Replace, Juri Linkov, 2008/10/19