unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Nicolas Richard <theonewiththeevillook@yahoo.fr>
Cc: 17239@debbugs.gnu.org
Subject: bug#17239: 24.3.50; competion error (cl-assertion-failed (string-prefix-p uprefix ustring))
Date: Sun, 04 May 2014 21:54:26 -0400	[thread overview]
Message-ID: <jwvoazdj8to.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <871tx4qlwq.fsf@yahoo.fr> (Nicolas Richard's message of "Fri, 11 Apr 2014 11:02:13 +0200")

> C-x C-f
> / C-b TAB ;; hit tab between the last two slashes.
> => error.

> Debugger entered--Lisp error: (cl-assertion-failed (string-prefix-p uprefix ustring))

Thanks.  I installed the patch below which fixes the most glaring
problem (the assertion failure).  The resulting behavior is not great,
but it's not really clear what we should do anyway.


        Stefan


=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2014-05-03 08:47:50 +0000
+++ lisp/ChangeLog	2014-05-05 01:44:49 +0000
@@ -1,3 +1,8 @@
+2014-05-05  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* minibuffer.el (completion-table-with-quoting) <completion--unquote>:
+	Make sure the new point we return is within the new string (bug#17239).
+
 2014-05-03  Eli Zaretskii  <eliz@gnu.org>
 
 	* mail/rmailsum.el (rmail-new-summary-1): Fix a typo in a comment.

=== modified file 'lisp/minibuffer.el'
--- lisp/minibuffer.el	2014-05-01 23:55:25 +0000
+++ lisp/minibuffer.el	2014-05-05 01:24:34 +0000
@@ -519,11 +519,35 @@
         completions))
 
      ((eq action 'completion--unquote)
-      (let ((ustring (funcall unquote string))
-            (uprefix (funcall unquote (substring string 0 pred))))
-        ;; We presume (more or less) that `concat' and `unquote' commute.
-        (cl-assert (string-prefix-p uprefix ustring))
-        (list ustring table (length uprefix)
+      ;; PRED is really a POINT in STRING.
+      ;; We should return a new set (STRING TABLE POINT REQUOTE)
+      ;; where STRING is a new (unquoted) STRING to match against the new TABLE
+      ;; using a new POINT inside it, and REQUOTE is a requoting function which
+      ;; should reverse the unquoting, (i.e. it receives the completion result
+      ;; of using the new TABLE and should turn it into the corresponding
+      ;; quoted result).
+      (let* ((qpos pred)
+	     (ustring (funcall unquote string))
+	     (uprefix (funcall unquote (substring string 0 qpos)))
+	     ;; FIXME: we really should pass `qpos' to `unuote' and have that
+	     ;; function give us the corresponding `uqpos'.  But for now we
+	     ;; presume (more or less) that `concat' and `unquote' commute.
+	     (uqpos (if (string-prefix-p uprefix ustring)
+			;; Yay!!  They do seem to commute!
+			(length uprefix)
+		      ;; They don't commute this time!  :-(
+		      ;; Maybe qpos is in some text that disappears in the
+		      ;; ustring (bug#17239).  Let's try a second chance guess.
+		      (let ((usuffix (funcall unquote (substring string qpos))))
+			(if (string-suffix-p usuffix ustring)
+			    ;; Yay!!  They still "commute" in a sense!
+			    (- (length ustring) (length usuffix))
+			  ;; Still no luck!  Let's just choose *some* position
+			  ;; within ustring.
+			  (/ (+ (min (length uprefix) (length ustring))
+				(max (- (length ustring) (length usuffix)) 0))
+			     2))))))
+        (list ustring table uqpos
               (lambda (unquoted-result op)
                 (pcase op
                   (1 ;;try
@@ -853,6 +877,7 @@
              (setq string (pop new))
              (setq table (pop new))
              (setq point (pop new))
+	     (cl-assert (<= point (length string)))
              (pop new))))
         (result
          (completion--some (lambda (style)






  reply	other threads:[~2014-05-05  1:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-11  9:02 bug#17239: 24.3.50; competion error (cl-assertion-failed (string-prefix-p uprefix ustring)) Nicolas Richard
2014-05-05  1:54 ` Stefan Monnier [this message]
2014-05-05 10:53   ` Nicolas Richard
2014-05-05 12:52     ` Stefan Monnier
2020-08-25 10:46       ` Lars Ingebrigtsen

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=jwvoazdj8to.fsf-monnier+emacsbugs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=17239@debbugs.gnu.org \
    --cc=theonewiththeevillook@yahoo.fr \
    /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).