From 34e7617365f16f9dfa6f31f968a0b5dee6d7d54b Mon Sep 17 00:00:00 2001 From: Mauro Aranda Date: Sun, 30 Aug 2020 15:55:19 +0200 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 ea7e266e0d0..f58a0fb7a3a 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el @@ -3161,6 +3161,15 @@ It reads a file name from an editable text field." :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.39.2