Subject: bug#7779: Miserable widget completion for type 'directory on w32

From: Mauro Aranda <[email-masked]>
Date: Wed, 28 Aug 2019 12:47:50 -0300

I can reproduce the bug in the latest master.  On a Windows machine,
and starting with emacs -Q, I do:
M-x customize-option RET tutorial-directory
and try to complete with C-M-i inside the editable-field, with different
names,
and different cases.
It doesn't work, because the completion is made case sensitive, even though
read-file-name-completion-ignore-case is t.

Also, the completion is made not only for directory names,
but also for file names.  This also happens on a GNU/Linux machine.

Since the 'file widget suffers from the first mentioned bug as well,
the attached patch tries to improve the completion for both of these
widgets.

Best regards,
Mauro.
From 24be0bc9760e16af80747b4bc06fd953e050be4f Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Wed, 28 Aug 2019 08:29:57 -0300
Subject: [PATCH] Improve file name completion in file and directory widgets
 (Bug#7779)

* lisp/wid-edit.el (widget 'file, widget 'directory): Respect the option
read-file-name-completion-ignore-case.
(widget 'directory): Filter the file names, to only perform directory name
completion.
---
 lisp/wid-edit.el | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 1ddc461..ad65ca6 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -3083,7 +3083,9 @@ widget-regexp-validate
 (define-widget 'file 'string
   "A file widget.
 It reads a file name from an editable text field."
-  :completions #'completion-file-name-table
+  :completions (completion-table-case-fold
+                #'completion-file-name-table
+                (not read-file-name-completion-ignore-case))
   :prompt-value 'widget-file-prompt-value
   :format "%{%t%}: %v"
   ;; Doesn't work well with terminating newline.
@@ -3118,6 +3120,11 @@ widget-file-prompt-value
 (define-widget 'directory 'file
   "A directory widget.
 It reads a directory name from an editable text field."
+  :completions (apply-partially #'completion-table-with-predicate
+                                (completion-table-case-fold
+                                 #'completion-file-name-table
+                                 (not read-file-name-completion-ignore-case))
+                                #'directory-name-p 'strict)
   :tag "Directory")
 
 (defvar widget-symbol-prompt-value-history nil
-- 
2.7.4