all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: emacs-devel@gnu.org
Subject: Word Delimited Query Replace (was: read-regexp)
Date: Sat, 18 Oct 2008 19:23:09 +0300	[thread overview]
Message-ID: <878wsl27pv.fsf@jurta.org> (raw)
In-Reply-To: <uiqrqkrc8.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 18 Oct 2008 14:41:59 +0200")

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/




  parent reply	other threads:[~2008-10-18 16:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-18 12:41 read-regexp Eli Zaretskii
2008-10-18 16:19 ` read-regexp Juri Linkov
2008-10-18 19:13   ` read-regexp Stefan Monnier
2008-10-18 19:55     ` read-regexp Juri Linkov
2008-10-18 21:47       ` read-regexp Stefan Monnier
2008-10-18 23:29         ` read-regexp Juri Linkov
2008-10-18 19:21   ` read-regexp Eli Zaretskii
2008-10-18 19:59     ` read-regexp Juri Linkov
2008-10-18 16:23 ` Juri Linkov [this message]
2008-10-18 19:21   ` Word Delimited Query Replace Stefan Monnier
2008-10-18 19:52     ` Juri Linkov
2008-10-18 21:37       ` Stefan Monnier
2008-10-18 23:29         ` Juri Linkov
2008-10-19  2:08           ` Stefan Monnier
2008-10-19 22:48             ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878wsl27pv.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.