summaryrefslogtreecommitdiff
path: root/lisp/wid-edit.el
diff options
context:
space:
mode:
authorMauro Aranda <maurooaranda@gmail.com>2020-10-24 21:40:42 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-10-24 21:40:42 +0200
commitc3835bd3803e5f395c4ebf0b2585cc9272173548 (patch)
tree8845900b858a89f267b73c173a4bf84af6fa4387 /lisp/wid-edit.el
parentdd16e46bb9d0099baea06d780ad8f62728addc2e (diff)
downloademacs-c3835bd3803e5f395c4ebf0b2585cc9272173548.tar.gz
Warn about a bad default value in restricted-sexp widget
* lisp/wid-edit.el (restricted-sexp widget): New :value-to-external function. If value is not in the internal format, then we might be dealing with a bad default value for the widget, so display a warning about that (bug#25152).
Diffstat (limited to 'lisp/wid-edit.el')
-rw-r--r--lisp/wid-edit.el25
1 files changed, 24 insertions, 1 deletions
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 009c6b4faf2..4e2cf7416d4 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -3585,7 +3585,30 @@ To use this type, you must define :match or :match-alternatives."
:value-to-internal (lambda (widget value)
(if (widget-apply widget :match value)
(widget-sexp-value-to-internal widget value)
- value)))
+ value))
+ :value-to-external (lambda (widget value)
+ ;; We expect VALUE to be a string, so we can convert it
+ ;; into the external format just by `read'ing it.
+ ;; But for a restricted-sexp widget with a bad default
+ ;; value, we might end up calling read with a nil
+ ;; argument, resulting in an undesired prompt to the
+ ;; user. A bad default value is not always a big
+ ;; problem, but might end up in a messed up buffer,
+ ;; so display a warning here. (Bug#25152)
+ (unless (stringp value)
+ (display-warning
+ 'widget-bad-default-value
+ (format-message
+ "\nA widget of type %S has a bad default value.
+value: %S
+match function: %S
+match-alternatives: %S"
+ (widget-type widget)
+ value
+ (widget-get widget :match)
+ (widget-get widget :match-alternatives))
+ :warning))
+ (read value)))
(defun widget-restricted-sexp-match (widget value)
(let ((alternatives (widget-get widget :match-alternatives))