Subject: Re: bug#25678: 25.1; defcustom type `(file :must-match t)' seems not to work

From: Mauro Aranda <[email-masked]>
Date: Sat, 29 Aug 2020 12:33:15 -0300

I think it makes sense to expand the impact of :must-match t to
Customization buffers, like in the attached patch.
From 10896dedfc6861dcc64dd8705818dacc6aaa0a98 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Wed, 26 Aug 2020 12:49:58 -0300
Subject: [PATCH] Respect :must-match for file types in customization buffers

* lisp/wid-edit.el (file widget): Add a :match and a :validate
  function to the 'file widget, to be able to check if the widget
  value is an existent file, when required.  (Bug#25678)
---
 lisp/wid-edit.el | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index ea7e266e0d..1015f010ce 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -3161,6 +3161,15 @@ 'file
   :completions (completion-table-case-fold
                 #'completion-file-name-table
                 (not read-file-name-completion-ignore-case))
+  :match #'(lambda (widget value)
+             (or (not (widget-get widget :must-match))
+                 (file-exists-p value)))
+  :validate #'(lambda (widget)
+                (let ((value (widget-value widget)))
+                  (unless (widget-apply widget :match value)
+                    (widget-put widget
+                                :error (format "File %s does not exist" value))
+                    widget)))
   :prompt-value 'widget-file-prompt-value
   :format "%{%t%}: %v"
   ;; Doesn't work well with terminating newline.
-- 
2.28.0