all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: 15419@debbugs.gnu.org
Subject: bug#15419: 24.3.50; file name as directory completion problem
Date: Wed, 07 May 2014 22:46:40 +0200	[thread overview]
Message-ID: <87r445mi4v.fsf@rosalinde.fritz.box> (raw)
In-Reply-To: <87pps44z2a.fsf@rosalinde.fritz.box>

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)






  parent reply	other threads:[~2014-05-07 20:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-19 15:21 bug#15419: 24.3.50; file name as directory completion problem Stephen Berman
     [not found] ` <handler.15419.B.137960413312666.ack@debbugs.gnu.org>
2014-05-07 20:46   ` Stephen Berman [this message]
2014-05-08  0:53     ` Stefan Monnier
2014-05-08 14:51       ` Stephen Berman
2014-05-10 21:24         ` Stephen Berman
     [not found]           ` <877g5r5tab.fsf@rosalinde.fritz.box>
     [not found]             ` <jwva9akwh03.fsf-monnier+emacsbugs@gnu.org>
     [not found]               ` <87a9akxheh.fsf@rosalinde.fritz.box>
2014-05-14 20:40                 ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to=87r445mi4v.fsf@rosalinde.fritz.box \
    --to=stephen.berman@gmx.net \
    --cc=15419@debbugs.gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.