bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#15419: 24.3.50; file name as directory completion problem


From: Stephen Berman
Subject: bug#15419: 24.3.50; file name as directory completion problem
Date: Sat, 10 May 2014 23:24:57 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.90 (gnu/linux)

On Thu, 08 May 2014 16:51:27 +0200 Stephen Berman <stephen.berman@gmx.net> 
wrote:

> On Wed, 07 May 2014 20:53:36 -0400 Stefan Monnier <monnier@iro.umontreal.ca> 
> wrote:
>
>>> !       ;; If we're using the substring style for file name completion
>>> !       ;; and completing a directory name, this ends up tacking "/"
>>> !       ;; onto the name, resulting in "//" if the suffix begins with
>>> !       ;; "/".  So drop one "/" (bug#15419).
>>> !       (cons (replace-regexp-in-string "//" "/" (concat prefix merged 
>>> suffix))
>>
>> This will remove // from file names where they're valid such
>> a "http://blabla/"; (using url-handler-mode).
>>
>> The call to completion--merge-suffix is supposed to handle the
>> particular problem you're after, tho, so you might want to try and
>> figure out why it doesn't.
>
> Thanks for the pointer.  The problem is the merge point passed by
> completion-pcm--merge-try to completion--merge-suffix and used as the
> starting position for string-match: in the present case, when there is
> only one completion, the merge point is the length of the completion
> string, but since string-match is zero-based, this means it looks for a
> match starting one position after the end of the completion string and
> fails.  So the merge point should be one less.  However, if there is
> more than one completion, further input is needed, so in this case the
> merge point should not be smaller, otherwise point will not be at the
> end of the string in the minibuffer.
>
> The following patch fixes the problem for me and account for the case of
> multiple completions; does it look ok to you?

As you may have already noticed, there was a typo in the patch that
prevented it from working.  But in addition, after fixing the typo so it
correctly eliminates cases of "//", it leaves point on the remaining "/"
instead of just after it, so subsequent attempts to complete don't DTRT.
The following patch fixes this, and also prevents another buggy behavior
of the current implementation (also with -Q) that I encountered while
testing: if you type TAB on e.g. "~/bzr/emacs/tr/lisp/" with point after
"tr", it correctly complete to "~/bzr/emacs/trunk/lisp/", but if you now
type TAB again, the completion is this: "~/bzr/emacs/trunk/lisp//".
This and the bug of my OP are fixed by the patch.  Unless you find some
other problem with it, is it ok to commit to emacs-24 in time for the
next pretest?

Steve Berman

=== modified file 'lisp/minibuffer.el'
*** lisp/minibuffer.el  2014-05-04 19:37:56 +0000
--- lisp/minibuffer.el  2014-05-10 21:22:36 +0000
***************
*** 3191,3203 ****
                           (memq 'star  mergedpat)
                           ;; Not `prefix'.
                           mergedpat))
!            ;; New pos from the start.
!            (newpos (length (completion-pcm--pattern->string pointpat)))
             ;; Do it afterwards because it changes `pointpat' by side effect.
             (merged (completion-pcm--pattern->string (nreverse mergedpat))))
  
        (setq suffix (completion--merge-suffix merged newpos suffix))
!       (cons (concat prefix merged suffix) (+ newpos (length prefix)))))))
  
  (defun completion-pcm-try-completion (string table pred point)
    (pcase-let ((`(,pattern ,all ,prefix ,suffix)
--- 3191,3215 ----
                           (memq 'star  mergedpat)
                           ;; Not `prefix'.
                           mergedpat))
!          (completion (and (not (consp (cdr all))) (car all)))
!          (pos (length (completion-pcm--pattern->string pointpat)))
!            ;; New pos from the start.  If it equals the length of the
!            ;; completion, make it one less to ensure that string-match
!            ;; (which is 0-based) in completion--merge-suffix does not
!            ;; start trying to match too late (bug#15419).  If there is
!            ;; more than one completion, pos is already shorter, so use
!            ;; it in order to leave point at the end of the string for
!            ;; further minibuffer input.
!            (newpos (if (and completion (eq pos (length completion)))
!                      (1- pos)
!                    pos))
             ;; Do it afterwards because it changes `pointpat' by side effect.
             (merged (completion-pcm--pattern->string (nreverse mergedpat))))
  
        (setq suffix (completion--merge-suffix merged newpos suffix))
!       ;; Use pos instead of newpos here to make sure point is in the
!       ;; right place for getting further completions.
!       (cons (concat prefix merged suffix) (+ pos (length prefix)))))))
  
  (defun completion-pcm-try-completion (string table pred point)
    (pcase-let ((`(,pattern ,all ,prefix ,suffix)







reply via email to

[Prev in Thread] Current Thread [Next in Thread]