unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#13178: Query-replace fails soon after narrow-to-region
@ 2012-12-14  4:03 Teika Kazura
  2015-02-27  8:12 ` Teika Kazura
  0 siblings, 1 reply; 12+ messages in thread
From: Teika Kazura @ 2012-12-14  4:03 UTC (permalink / raw)
  To: 13178

Hi, Emacs developers.

In Emacs 24.1, query-replace soon after narrow-to-region fails. More
precisely, minibuffer says "Replaced 0 occurrences", and the
query-replace finishes even if there're matches. I don't think it's a
recent regresion.

Steps to reproduce:
0. emacs -Q
1. Open a buffer.
2. Set mark, and do narrow-to-region
3. Move to the top of the narrowed buffer.
4. Do query-replace.
5. minibuffer says "Replaced 0 occurrences", and the query-replace
   finishes. If you do query-replace again, then it starts correctly.

It seems that some extra commands between each step hinder to reproduce.
Probably you have to enable narrow-to-region beforehand, and
query-replace history is necessary, so that "M-% <enter>" can invoke
a query-replace.

In fact, it was already reported in bug #8952:
  http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8952
but as a "wishlist", mixed with several other things. So I dare to
submit a separate entry.

I've been bothered by this bug for years, but I didn't know how to
reproduce it. Thank you in advance.

Best regards,
Teika (Teika kazura)






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

* bug#13178: Query-replace fails soon after narrow-to-region
  2012-12-14  4:03 bug#13178: Query-replace fails soon after narrow-to-region Teika Kazura
@ 2015-02-27  8:12 ` Teika Kazura
  2015-02-27 15:01   ` Drew Adams
  2015-03-03 23:31   ` Teika Kazura
  0 siblings, 2 replies; 12+ messages in thread
From: Teika Kazura @ 2015-02-27  8:12 UTC (permalink / raw)
  To: 13178

unarchive 13178

Sorry, it's not a bug, but a specification.

If a region is active, `query-replace' (together with `replace-string') gets narrowed inside there. I didn't know that, and activated a zero-size region in the procedure described above.

If you want to discuss it further, please go to bug #8952:
 http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8952

Thanks, 
Teika (Teika kazura)





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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-02-27  8:12 ` Teika Kazura
@ 2015-02-27 15:01   ` Drew Adams
  2015-02-27 19:50     ` Artur Malabarba
  2015-03-03 23:31   ` Teika Kazura
  1 sibling, 1 reply; 12+ messages in thread
From: Drew Adams @ 2015-02-27 15:01 UTC (permalink / raw)
  To: Teika Kazura, 13178

> Sorry, it's not a bug, but a specification.
> 
> If a region is active, `query-replace' (together with `replace-string') gets
> narrowed inside there.  I didn't know that, and activated a zero-size region
> in the procedure described above.

Just FYI - It might help you recognize this situation if you use library
`mode-line-posn.el'.  It has the following behavior, which addresses the
gotcha you mention:

1. The size of the region is shown in the mode line when the region is active.  
   Option `modelinepos-empty-region-flag' determines whether to also indicate
   an empty active region.  By default it is t, meaning indicate an empty
   active region.

2. Option `modelinepos-style' lets you choose the region info shown when the
   region is active: (a) number of chars, (b) number of chars and lines, or
   (c) anything else you might want.  Choice (b) is the default.

3. The region highlighting in the mode-line is changed to a different face
   when you invoke a command that behaves specially for an active region,
   such as `query-replace'.

The fact that `modelinepos-empty-region-flag' is non-nil by default means
that whenever the region is active but empty you can easily notice this.

#3 means that you can immediately tell when the region is active and you
are currently using a command whose behavior changes when the region is
active.

More info and screenshots here:
http://www.emacswiki.org/emacs/ModeLinePosition

I proposed such behavior for Emacs, but there was no interest in it.
It helps me.  Maybe it will help you too.





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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-02-27 15:01   ` Drew Adams
@ 2015-02-27 19:50     ` Artur Malabarba
  2015-03-02 17:23       ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: Artur Malabarba @ 2015-02-27 19:50 UTC (permalink / raw)
  Cc: Teika Kazura, 13178

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

Perhaps the "replace" family of commands ought to ignore the region if it's
empty? Or at least notify the user?

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

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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-02-27 19:50     ` Artur Malabarba
@ 2015-03-02 17:23       ` Stefan Monnier
  2015-03-02 20:14         ` Juri Linkov
  0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2015-03-02 17:23 UTC (permalink / raw)
  To: Artur Malabarba; +Cc: Teika Kazura, 13178

> Perhaps the "replace" family of commands ought to ignore the region if it's
> empty?

It should obey use-empty-active-region.

> Or at least notify the user?

It definitely shouldn't fail with an "unrelated" error.


        Stefan





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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-03-02 17:23       ` Stefan Monnier
@ 2015-03-02 20:14         ` Juri Linkov
  2015-03-02 21:51           ` Artur Malabarba
  0 siblings, 1 reply; 12+ messages in thread
From: Juri Linkov @ 2015-03-02 20:14 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Teika Kazura, 13178, Artur Malabarba

>> Perhaps the "replace" family of commands ought to ignore the region if it's
>> empty?
>
> It should obey use-empty-active-region.

This patch allows query-replace commands to obey use-empty-active-region:

diff --git a/lisp/replace.el b/lisp/replace.el
index e0636e0..8b62b54 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -312,15 +312,15 @@ (defun query-replace (from-string to-string &optional delimited start end backwa
 		   (if current-prefix-arg
 		       (if (eq current-prefix-arg '-) " backward" " word")
 		     "")
-		   (if (and transient-mark-mode mark-active) " in region" ""))
+		   (if (use-region-p) " in region" ""))
 	   nil)))
      (list (nth 0 common) (nth 1 common) (nth 2 common)
 	   ;; These are done separately here
 	   ;; so that command-history will record these expressions
 	   ;; rather than the values they had this time.
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-beginning))
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-end))
 	   (nth 3 common))))
   (perform-replace from-string to-string t nil delimited nil nil start end backward))
@@ -392,15 +392,15 @@ (defun query-replace-regexp (regexp to-string &optional delimited start end back
 		       (if (eq current-prefix-arg '-) " backward" " word")
 		     "")
 		   " regexp"
-		   (if (and transient-mark-mode mark-active) " in region" ""))
+		   (if (use-region-p) " in region" ""))
 	   t)))
      (list (nth 0 common) (nth 1 common) (nth 2 common)
 	   ;; These are done separately here
 	   ;; so that command-history will record these expressions
 	   ;; rather than the values they had this time.
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-beginning))
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-end))
 	   (nth 3 common))))
   (perform-replace regexp to-string t t delimited nil nil start end backward))
@@ -469,9 +469,9 @@ (defun query-replace-regexp-eval (regexp to-expr &optional delimited start end)
        ;; and the user might enter a single token.
        (replace-match-string-symbols to)
        (list from (car to) current-prefix-arg
-	     (if (and transient-mark-mode mark-active)
+	     (if (use-region-p)
 		 (region-beginning))
-	     (if (and transient-mark-mode mark-active)
+	     (if (use-region-p)
 		 (region-end))))))
   (perform-replace regexp (cons 'replace-eval-replacement to-expr)
 		   t 'literal delimited nil nil start end))
@@ -507,9 +507,9 @@ (defun map-query-replace-regexp (regexp to-strings &optional n start end)
      (list from to
 	   (and current-prefix-arg
 		(prefix-numeric-value current-prefix-arg))
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-beginning))
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-end)))))
   (let (replacements)
     (if (listp to-strings)
@@ -571,12 +571,12 @@ (defun replace-string (from-string to-string &optional delimited start end backw
 		       (if (eq current-prefix-arg '-) " backward" " word")
 		     "")
 		   " string"
-		   (if (and transient-mark-mode mark-active) " in region" ""))
+		   (if (use-region-p) " in region" ""))
 	   nil)))
      (list (nth 0 common) (nth 1 common) (nth 2 common)
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-beginning))
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-end))
 	   (nth 3 common))))
   (perform-replace from-string to-string nil nil delimited nil nil start end backward))
@@ -645,12 +645,12 @@ (defun replace-regexp (regexp to-string &optional delimited start end backward)
 		       (if (eq current-prefix-arg '-) " backward" " word")
 		     "")
 		   " regexp"
-		   (if (and transient-mark-mode mark-active) " in region" ""))
+		   (if (use-region-p) " in region" ""))
 	   t)))
      (list (nth 0 common) (nth 1 common) (nth 2 common)
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-beginning))
-	   (if (and transient-mark-mode mark-active)
+	   (if (use-region-p)
 	       (region-end))
 	   (nth 3 common))))
   (perform-replace regexp to-string nil t delimited nil nil start end backward))
@@ -816,7 +816,7 @@ (defun keep-lines (regexp &optional rstart rend interactive)
 		  (unless (or (bolp) (eobp))
 		    (forward-line 0))
 		  (point-marker)))))
-    (if (and interactive transient-mark-mode mark-active)
+    (if (and interactive (use-region-p))
 	(setq rstart (region-beginning)
 	      rend (progn
 		     (goto-char (region-end))
@@ -885,7 +885,7 @@ (defun flush-lines (regexp &optional rstart rend interactive)
       (progn
 	(goto-char (min rstart rend))
 	(setq rend (copy-marker (max rstart rend))))
-    (if (and interactive transient-mark-mode mark-active)
+    (if (and interactive (use-region-p))
 	(setq rstart (region-beginning)
 	      rend (copy-marker (region-end)))
       (setq rstart (point)
@@ -935,7 +935,7 @@ (defun how-many (regexp &optional rstart rend interactive)
               (setq rend (max rstart rend)))
           (goto-char rstart)
           (setq rend (point-max)))
-      (if (and interactive transient-mark-mode mark-active)
+      (if (and interactive (use-region-p))
 	  (setq rstart (region-beginning)
 		rend (region-end))
 	(setq rstart (point)





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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-03-02 20:14         ` Juri Linkov
@ 2015-03-02 21:51           ` Artur Malabarba
  2015-03-12 19:53             ` Juri Linkov
  0 siblings, 1 reply; 12+ messages in thread
From: Artur Malabarba @ 2015-03-02 21:51 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Teika Kazura, 13178

>> It should obey use-empty-active-region.
>
> This patch allows query-replace commands to obey use-empty-active-region:

Looks good to me.





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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-02-27  8:12 ` Teika Kazura
  2015-02-27 15:01   ` Drew Adams
@ 2015-03-03 23:31   ` Teika Kazura
  2015-03-04  1:16     ` Artur Malabarba
  1 sibling, 1 reply; 12+ messages in thread
From: Teika Kazura @ 2015-03-03 23:31 UTC (permalink / raw)
  To: 13178; +Cc: bruce.connor.am, juri

Docs of `use-empty-active-region' and `use-region-p' use the word "empty", but in fact the predicate is (> (region-end) (region-beginning)). It's confusing. (And also the Emacs Info, "Operating on the Region" section.)

For replace.el, the condition is correct (= what users expect.) Although I don't know other cases, maybe the explanation "empty" is too simplistic? (Sorry that I don't come up with a concise replacement description for that case.)

Thank you very much Emacs developers. And of course to Drew Adams for your kind reply and wide range, long time contributions.






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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-03-03 23:31   ` Teika Kazura
@ 2015-03-04  1:16     ` Artur Malabarba
  2015-03-05  0:16       ` Teika Kazura
  0 siblings, 1 reply; 12+ messages in thread
From: Artur Malabarba @ 2015-03-04  1:16 UTC (permalink / raw)
  To: Teika Kazura; +Cc: 13178, juri

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

On Mar 3, 2015 11:31 PM, "Teika Kazura" <teika@gmx.com> wrote:
>
> Docs of `use-empty-active-region' and `use-region-p' use the word
"empty", but in fact the predicate is (> (region-end) (region-beginning)).
It's confusing.

What's confusing about that? Isn't that a non empty region?

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

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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-03-04  1:16     ` Artur Malabarba
@ 2015-03-05  0:16       ` Teika Kazura
  0 siblings, 0 replies; 12+ messages in thread
From: Teika Kazura @ 2015-03-05  0:16 UTC (permalink / raw)
  To: 13178; +Cc: bruce.connor.am, juri

I was wrong. I'm sorry.

> What's confusing about that? Isn't that a non empty region?






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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-03-02 21:51           ` Artur Malabarba
@ 2015-03-12 19:53             ` Juri Linkov
  2015-11-13 23:39               ` Juri Linkov
  0 siblings, 1 reply; 12+ messages in thread
From: Juri Linkov @ 2015-03-12 19:53 UTC (permalink / raw)
  To: Artur Malabarba; +Cc: Teika Kazura, 13178

>>> It should obey use-empty-active-region.
>>
>> This patch allows query-replace commands to obey use-empty-active-region:
>
> Looks good to me.

bug#13178 could be handled together with bug#19829 and bug#20070.





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

* bug#13178: Query-replace fails soon after narrow-to-region
  2015-03-12 19:53             ` Juri Linkov
@ 2015-11-13 23:39               ` Juri Linkov
  0 siblings, 0 replies; 12+ messages in thread
From: Juri Linkov @ 2015-11-13 23:39 UTC (permalink / raw)
  To: 13178-done

>>>> It should obey use-empty-active-region.
>>>
>>> This patch allows query-replace commands to obey use-empty-active-region:
>>
>> Looks good to me.
>
> bug#13178 could be handled together with bug#19829 and bug#20070.

This is fixed by bug#19829.





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

end of thread, other threads:[~2015-11-13 23:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-14  4:03 bug#13178: Query-replace fails soon after narrow-to-region Teika Kazura
2015-02-27  8:12 ` Teika Kazura
2015-02-27 15:01   ` Drew Adams
2015-02-27 19:50     ` Artur Malabarba
2015-03-02 17:23       ` Stefan Monnier
2015-03-02 20:14         ` Juri Linkov
2015-03-02 21:51           ` Artur Malabarba
2015-03-12 19:53             ` Juri Linkov
2015-11-13 23:39               ` Juri Linkov
2015-03-03 23:31   ` Teika Kazura
2015-03-04  1:16     ` Artur Malabarba
2015-03-05  0:16       ` Teika Kazura

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).