GNU bug report logs - #17239
inconsistent completion of paths with ~

Previous Next

Package: emacs;

Reported by: Nicolas Richard <theonewiththeevillook <at> yahoo.fr>

Date: Fri, 11 Apr 2014 09:03:02 UTC

Severity: minor

Tags: confirmed

Found in versions 25.0.95, 24.3.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 17239 in the body.
You can then email your comments to 17239 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#17239; Package emacs. (Fri, 11 Apr 2014 09:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Nicolas Richard <theonewiththeevillook <at> yahoo.fr>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 11 Apr 2014 09:03:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Nicolas Richard <theonewiththeevillook <at> yahoo.fr>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; competion error (cl-assertion-failed (string-prefix-p uprefix
 ustring))
Date: Fri, 11 Apr 2014 11:02:13 +0200
Hello,

Recipe:
$ emacs -Q
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))
  signal(cl-assertion-failed ((string-prefix-p uprefix ustring)))
  completion--file-name-table("~/sources/running-emacs//" 24 completion--unquote)
  complete-with-action(completion--unquote completion--file-name-table "~/sources/running-emacs//" 24)
  #[257 "\303\302\300\301$\207" ["~/sources/running-emacs//" 24 completion--unquote complete-with-action] 6 "\n\n(fn TABLE)"](completion--file-name-table)
  #[0 "\302\300\301\242\301\211\242A\240\210\242!\240\207" [#[257 "\303\302\300\301$\207" ["~/sources/running-emacs//" 24 completion--unquote complete-with-action] 6 "\n\n(fn TABLE)"] (nil) (nil)] 5 "\n\n(fn)"]()
  funcall(#[0 "\302\300\301\242\301\211\242A\240\210\242!\240\207" [#[257 "\303\302\300\301$\207" ["~/sources/running-emacs//" 24 completion--unquote complete-with-action] 6 "\n\n(fn TABLE)"] (nil) (nil)] 5 "\n\n(fn)"])
  completion--some(#[257 "\303\302\300\301$\207" ["~/sources/running-emacs//" 24 completion--unquote complete-with-action] 6 "\n\n(fn TABLE)"] (completion--embedded-envvar-table completion--file-name-table))
  read-file-name-internal("~/sources/running-emacs//" 24 completion--unquote)
  completion--nth-completion(1 "~/sources/running-emacs//" read-file-name-internal file-exists-p 24 (metadata (category . file) (completion--unquote-requote . t)))
  completion-try-completion("~/sources/running-emacs//" read-file-name-internal file-exists-p 24 (metadata (category . file) (completion--unquote-requote . t)))
  completion--do-completion(12 37)
  completion--in-region-1(12 37)
  #[1028 "\n\203!\304!\203\202\305!\305\306\"F\307\310!\210\311\"*\207" [minibuffer-completion-predicate minibuffer-completion-table completion-in-region-mode-predicate completion-in-region--data markerp copy-marker t completion-in-region-mode 1 completion--in-region-1] 8 "\n\n(fn START END COLLECTION PREDICATE)"](12 37 read-file-name-internal file-exists-p)
  apply(#[1028 "\n\203!\304!\203\202\305!\305\306\"F\307\310!\210\311\"*\207" [minibuffer-completion-predicate minibuffer-completion-table completion-in-region-mode-predicate completion-in-region--data markerp copy-marker t completion-in-region-mode 1 completion--in-region-1] 8 "\n\n(fn START END COLLECTION PREDICATE)"] (12 37 read-file-name-internal file-exists-p))
  #[771 ":\2030@\301=\203\300\242\302A\"\303#\207\304@\305\306\307\310\311\312\300!\313\"\314\315%A##\207\304\316\"\207" [(#0) t append nil apply apply-partially make-byte-code 642 "\300\242#\207" vconcat vector [] 7 "\n\n(fn FUNS GLOBAL &rest ARGS)" #[1028 "\n\203!\304!\203\202\305!\305\306\"F\307\310!\210\311\"*\207" [minibuffer-completion-predicate minibuffer-completion-table completion-in-region-mode-predicate completion-in-region--data markerp copy-marker t completion-in-region-mode 1 completion--in-region-1] 8 "\n\n(fn START END COLLECTION PREDICATE)"]] 12 "\n\n(fn FUNS GLOBAL ARGS)"](nil nil (12 37 read-file-name-internal file-exists-p))
  completion--in-region(12 37 read-file-name-internal file-exists-p)
  completion-in-region(12 37 read-file-name-internal file-exists-p)
  minibuffer-complete()
  call-interactively(minibuffer-complete nil nil)
  command-execute(minibuffer-complete)
  read-from-minibuffer("Find file: " "~/sources/running-emacs/" (keymap (keymap (32)) keymap (10 . minibuffer-complete-and-exit) (13 . minibuffer-complete-and-exit) keymap (menu-bar keymap (minibuf "Minibuf" keymap (tab menu-item "Complete" minibuffer-complete :help "Complete as far as possible") (space menu-item "Complete Word" minibuffer-complete-word :help "Complete at most one word") (63 menu-item "List Completions" minibuffer-completion-help :help "Display all possible completions") "Minibuf")) (27 keymap (118 . switch-to-completions)) (prior . switch-to-completions) (63 . minibuffer-completion-help) (32 . minibuffer-complete-word) (9 . minibuffer-complete) keymap (menu-bar keymap (minibuf "Minibuf" keymap (previous menu-item "Previous History Item" previous-history-element :help "Put previous minibuffer history element in the minibuffer") (next menu-item "Next History Item" next-history-element :help "Put next minibuffer history element in the minibuffer") (isearch-backward menu-item "Isearch History Backward" isearch-backward :help "Incrementally search minibuffer history backward") (isearch-forward menu-item "Isearch History Forward" isearch-forward :help "Incrementally search minibuffer history forward") (return menu-item "Enter" exit-minibuffer :key-sequence "" :help "Terminate input and exit minibuffer") (quit menu-item "Quit" abort-recursive-edit :help "Abort input and exit minibuffer") "Minibuf")) (10 . exit-minibuffer) (13 . exit-minibuffer) (7 . abort-recursive-edit) (C-tab . file-cache-minibuffer-complete) (9 . self-insert-command) (XF86Back . previous-history-element) (up . previous-history-element) (prior . previous-history-element) (XF86Forward . next-history-element) (down . next-history-element) (next . next-history-element) (27 keymap (114 . previous-matching-history-element) (115 . next-matching-history-element) (112 . previous-history-element) (110 . next-history-element))) nil file-name-history "~/sources/running-emacs/" nil)
  completing-read-default("Find file: " read-file-name-internal file-exists-p confirm-after-completion "~/sources/running-emacs/" file-name-history "~/sources/running-emacs/" nil)
  completing-read("Find file: " read-file-name-internal file-exists-p confirm-after-completion "~/sources/running-emacs/" file-name-history "~/sources/running-emacs/")
  read-file-name-default("Find file: " nil "~/sources/running-emacs/" confirm-after-completion nil nil)
  read-file-name("Find file: " nil "~/sources/running-emacs/" confirm-after-completion)
  find-file-read-args("Find file: " confirm-after-completion)
  byte-code("\300\301\302 \"\207" [find-file-read-args "Find file: " confirm-nonexistent-file-or-buffer] 3)
  call-interactively(find-file nil nil)
  command-execute(find-file)


In GNU Emacs 24.3.50.10 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2014-04-07 on geodiff-mac3

-- 
Nico.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17239; Package emacs. (Mon, 05 May 2014 01:55:01 GMT) Full text and rfc822 format available.

Message #8 received at 17239 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Nicolas Richard <theonewiththeevillook <at> yahoo.fr>
Cc: 17239 <at> debbugs.gnu.org
Subject: Re: bug#17239: 24.3.50;
 competion error (cl-assertion-failed (string-prefix-p uprefix
 ustring))
Date: Sun, 04 May 2014 21:54:26 -0400
> 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 <at> 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 <at> 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)





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17239; Package emacs. (Mon, 05 May 2014 10:54:02 GMT) Full text and rfc822 format available.

Message #11 received at 17239 <at> debbugs.gnu.org (full text, mbox):

From: Nicolas Richard <theonewiththeevillook <at> yahoo.fr>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 17239 <at> debbugs.gnu.org
Subject: Re: bug#17239: 24.3.50;
 competion error (cl-assertion-failed (string-prefix-p
 uprefix ustring))
Date: Mon, 05 May 2014 12:53:58 +0200
Le 05/05/2014 03:54, Stefan Monnier a écrit :
>> 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).

Thanks, the assertion failure is indeed gone.

> The resulting behavior is not great, but it's not really clear what we
> should do anyway.

As a point of comparison, when I do
C-x C-f ~ / C-b TAB
the behaviour of emacs depends on the current content of the minibuffer
(which is default-directory by default I guess).

I spotted these behaviours ("=>" means "hit C-b TAB and the minibuffer
becomes") :

~/~/     => ~/~/ [Complete, but not unique]
~/foo/~/ => ~/
/foo/~/  => /foo/~/ [Complete, but not unique]

(not hitting "C-b" doesn't change these results).

-- 
Nico.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17239; Package emacs. (Mon, 05 May 2014 12:53:02 GMT) Full text and rfc822 format available.

Message #14 received at 17239 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Nicolas Richard <theonewiththeevillook <at> yahoo.fr>
Cc: 17239 <at> debbugs.gnu.org
Subject: Re: bug#17239: 24.3.50;
 competion error (cl-assertion-failed (string-prefix-p uprefix
 ustring))
Date: Mon, 05 May 2014 08:52:19 -0400
>> The resulting behavior is not great, but it's not really clear what we
>> should do anyway.
> As a point of comparison, when I do
> C-x C-f ~ / C-b TAB
> the behaviour of emacs depends on the current content of the minibuffer
> (which is default-directory by default I guess).

It shouldn't: it should complete the username (since the general form
of the ~ thingy is "~<user>/<filename>").

> I spotted these behaviours ("=>" means "hit C-b TAB and the minibuffer
> becomes") :
> ~/~/     => ~/~/ [Complete, but not unique]
> ~/foo/~/ => ~/
> /foo/~/  => /foo/~/ [Complete, but not unique]

Indeed, I'm not sure why ~/foo/~/ behaves differently.  It's probably
a side-effect of completion--sifn-requote.  You can take a look at that
function's leading comment to get an idea for why it might not always
behave perfectly ;-)


        Stefan




Changed bug title to 'inconsistent completion of paths with ~' from '24.3.50; competion error (cl-assertion-failed (string-prefix-p uprefix ustring))' Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 26 Jun 2016 05:04:02 GMT) Full text and rfc822 format available.

Severity set to 'minor' from 'normal' Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 26 Jun 2016 05:04:02 GMT) Full text and rfc822 format available.

Added tag(s) confirmed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 26 Jun 2016 05:04:02 GMT) Full text and rfc822 format available.

bug Marked as found in versions 25.0.95. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 26 Jun 2016 05:04:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17239; Package emacs. (Tue, 25 Aug 2020 10:47:01 GMT) Full text and rfc822 format available.

Message #25 received at 17239 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Nicolas Richard <theonewiththeevillook <at> yahoo.fr>, 17239 <at> debbugs.gnu.org
Subject: Re: bug#17239: 24.3.50; competion error (cl-assertion-failed
 (string-prefix-p uprefix ustring))
Date: Tue, 25 Aug 2020 12:46:34 +0200
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> I spotted these behaviours ("=>" means "hit C-b TAB and the minibuffer
>> becomes") :
>> ~/~/     => ~/~/ [Complete, but not unique]
>> ~/foo/~/ => ~/
>> /foo/~/  => /foo/~/ [Complete, but not unique]
>
> Indeed, I'm not sure why ~/foo/~/ behaves differently.  It's probably
> a side-effect of completion--sifn-requote.  You can take a look at that
> function's leading comment to get an idea for why it might not always
> behave perfectly ;-)

This is perhaps a bit inconsistent, but it's unclear what a consistent
behaviour here would be, anyway -- it's all a bit DWIM, and I think
that's OK.  So I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug closed, send any further explanations to 17239 <at> debbugs.gnu.org and Nicolas Richard <theonewiththeevillook <at> yahoo.fr> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 25 Aug 2020 10:47:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 22 Sep 2020 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 216 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.