[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: |
Wed, 07 May 2014 22:46:40 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.90 (gnu/linux) |
On Thu, 19 Sep 2013 17:21:33 +0200 Stephen Berman <stephen.berman@gmx.net>
wrote:
> By default, file name completion adds `/' only if needed, e.g. given the
> file name "~/test/bla/abc", if I type `C-x C-f ~/test/bla/abc' and in
> the minibuffer delete either "a" or "a/" after "bl", in both case TAB
> correctly completes to "~/test/bla/abc" -- unless you do the following:
>
> 1. emacs -Q
> 2. M-c customize-option RET completion-category-overrides RET, press INS
> to add a new category, choose "file" from the Value Menu. check
> Completion Styles, press INS and choose "substring" from the Value
> Menu, press State and choose "Set for Current Session".
> 3. Now if I type `C-x C-f ~/test/bla/abc' and in the minibuffer delete
> "a/" after "bl", TAB again correctly completes to "~/test/bla/abc",
> but if I delete just "a" after "bl", TAB incorrectly completes to
> "~/test/bla//abc".
>
> I think what is happening is that when completion-category-overrides is
> set as above, this makes completion-file-name-table call
> file-name-all-completions, which calls file_name_completion (dired.c),
> which, if the file is a directory, calls Ffile_name_as_directory
> (fileio.c), which unconditionally adds `/' to the file name. (Without
> the file override, completion-file-name-table does not call
> file-name-all-completions in the above test case, but completes when (eq
> action 'lambda).) It looks like this could be fixed by adding a
> condition to the following code from file_name_completion to the effect
> that in the absolute file name containing `name', the next character
> after the last character in `name' is not `/'; but I don't know how to
> do this in Emacs C.
>
> if (directoryp)
> /* This completion is a directory; make it end with '/'. */
> name = Ffile_name_as_directory (name);
I finally took another look at this bug and, while I don't know if my
above proposal would be a suitable fix (and anyway still don't know how
to implement it), I did come up with the following workaround; but it
seems too ad hoc to be a real fix, so I hope someone familiar with the
completion code will look at this bug. It would be nice to have it
fixed in the next release.
Steve Berman
=== modified file 'lisp/minibuffer.el'
*** lisp/minibuffer.el 2014-05-04 19:37:56 +0000
--- lisp/minibuffer.el 2014-05-07 20:06:19 +0000
***************
*** 3197,3203 ****
(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)
--- 3197,3208 ----
(merged (completion-pcm--pattern->string (nreverse mergedpat))))
(setq suffix (completion--merge-suffix merged newpos suffix))
! ;; 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))
! (+ newpos (length prefix)))))))
(defun completion-pcm-try-completion (string table pred point)
(pcase-let ((`(,pattern ,all ,prefix ,suffix)
- bug#15419: 24.3.50; file name as directory completion problem,
Stephen Berman <=