unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Richard Copley <rcopley@gmail.com>
Cc: 23127@debbugs.gnu.org, acm@muc.de
Subject: bug#23127: 25.0.92; Assertion failure when editing history in query-replace in cc-mode
Date: 28 Mar 2016 22:02:10 -0000	[thread overview]
Message-ID: <20160328220210.57301.qmail@mail.muc.de> (raw)
In-Reply-To: <mailman.8469.1459108386.843.bug-gnu-emacs@gnu.org>

Hello, Richard.

In article <mailman.8469.1459108386.843.bug-gnu-emacs@gnu.org> you wrote:
> In cc-mode, while doing query-replace, edit a previous replacement in
> the minibuffer, and insert characters after the " → " separator. The
> subsequent emacs-lisp chokes on the text properties of the resulting
> string, with an assertion failure.

> Recipe starting from 'emacs -Q':

> M-x c-mode RET
> M-<
> C-% a RET b RET !
> M-<
> C-% M-p C-e <backspace> c RET

> ==> error "cl--assertion-failed: Assertion failed: (not
> (text-property-any (1+ split-pos) length (quote separator) t string))"

> The callstack looks like this (except that here I've replaced a NUL with "^@"):

> Debugger entered: ((cl-assertion-failed (not (text-property-any (1+
> split-pos) length (quote separator) t string)) nil))
>   cl--assertion-failed((not (text-property-any (1+ split-pos) length
> (quote separator) t string)))
>   query-replace--split-string(#("a^@c" 1 2 (display #(" → " 0 3 (face
> minibuffer-prompt)) separator t) 2 3 (separator t)))
>   query-replace-read-from("Query replace" nil)
>   query-replace-read-args("Query replace" nil)
>   (let ((common (query-replace-read-args (concat "Query replace" (if
> current-prefix-arg (if (eq current-prefix-arg ...) " backward" "
> word") "") (if (use-region-p) " in region" "")) nil))) (list (nth 0
> common) (nth 1 common) (nth 2 common) (if (use-region-p)
> (region-beginning)) (if (use-region-p) (region-end)) (nth 3 common)
> (if (use-region-p) (region-noncontiguous-p))))
>   call-interactively(query-replace nil nil)
>   command-execute(query-replace)

> As you can see, the "c" inherited the separator property, and
> query-replace--split-string choked on that.
> It doesn't happen in all modes. It does happen in c-mode and c++-mode.

Thanks for such a high quality bug report.  The cause was a critical
variable being buffer local in C Mode and C++ Mode.  This buffer local
binding was not available in `read-from-minibuffer', with the result that
the `separator' text property got spread to the newly inserted 'c'.

The following patch should fix the bug.  Would you please try it out and
confirm that the bug is indeed fixed, or report what's still wrong.
Thanks!

> In GNU Emacs 25.0.92.1 (x86_64-w64-mingw32)
>  of 2016-03-21 built on MACHINE
> Repository revision: 76ef52267cf887e3e1aa6d25b3b16dd0601dd459
> Windowing system distributor 'Microsoft Corp.', version 10.0.10586
> Configured using:
>  'configure --prefix /c/emacs/emacs-20160321-102640
>  --without-imagemagick --disable-dependency-tracking
>  --enable-locallisppath=%emacs_dir%/../site-lisp 'CFLAGS=-Og -g -ggdb''



diff --git a/lisp/replace.el b/lisp/replace.el
index 428be3c..412f827 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -167,8 +167,6 @@ query-replace-read-from
     ;; unavailable while preparing to dump.
     (custom-reevaluate-setting 'query-replace-from-to-separator)
     (let* ((history-add-new-input nil)
-	   (text-property-default-nonsticky
-	    (cons '(separator . t) text-property-default-nonsticky))
 	   (separator
 	    (when query-replace-from-to-separator
 	      (propertize "\0"
@@ -195,9 +193,16 @@ query-replace-read-from
 	    (save-excursion
 	      (if regexp-flag
 		  (read-regexp prompt nil 'query-replace-from-to-history)
-		(read-from-minibuffer
-		 prompt nil nil nil 'query-replace-from-to-history
-		 (car (if regexp-flag regexp-search-ring search-ring)) t))))
+                ;; The `with-current-buffer' ensures that the binding
+                ;; for `text-property-default-nonsticky' isn't a
+                ;; buffer local binding in the current buffer, which
+                ;; `read-from-minibuffer' wouldn't see.
+                (with-current-buffer (window-buffer (minibuffer-window))
+                  (let ((text-property-default-nonsticky
+                         (cons '(separator . t) text-property-default-nonsticky)))
+                    (read-from-minibuffer
+                     prompt nil nil nil 'query-replace-from-to-history
+                     (car (if regexp-flag regexp-search-ring search-ring)) t))))))
            (to))
       (if (and (zerop (length from)) query-replace-defaults)
 	  (cons (caar query-replace-defaults)



-- 
Alan Mackenzie (Nuremberg, Germany).






  parent reply	other threads:[~2016-03-28 22:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-27 19:51 bug#23127: 25.0.92; Assertion failure when editing history in query-replace in cc-mode Richard Copley
     [not found] ` <mailman.8469.1459108386.843.bug-gnu-emacs@gnu.org>
2016-03-28 22:02   ` Alan Mackenzie [this message]
2016-03-28 23:24     ` Richard Copley
2016-03-29 10:03       ` Alan Mackenzie
2016-03-29 10:04       ` Alan Mackenzie

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=20160328220210.57301.qmail@mail.muc.de \
    --to=acm@muc.de \
    --cc=23127@debbugs.gnu.org \
    --cc=rcopley@gmail.com \
    /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 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).