Skip to content

Commit a5a8de4

Browse files
maurooarandaEli-Zaretskii
authored andcommitted
Preserve comments when redrawing a widget (Bug#64649)
* lisp/cus-edit.el (custom-comment-preserve): New function. (custom-redraw): Use it. (custom-comment-create): Make sure :comment-shown is set to t if the comment widget gets created. (custom-face-value-create, custom-variable-value-create): Recreate the custom-comment widget with the preserved value, if any.
1 parent bcb5bdc commit a5a8de4

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

lisp/cus-edit.el

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,7 @@ and `face'."
23302330
(from (marker-position (widget-get widget :from)))
23312331
(to (marker-position (widget-get widget :to))))
23322332
(save-excursion
2333+
(custom-comment-preserve widget)
23332334
(widget-value-set widget (widget-value widget))
23342335
(custom-redraw-magic widget))
23352336
(when (and (>= pos from) (<= pos to))
@@ -2509,7 +2510,9 @@ If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
25092510
(let* ((null-comment (equal "" (widget-value widget))))
25102511
(if (or (widget-get (widget-get widget :parent) :comment-shown)
25112512
(not null-comment))
2512-
(widget-default-create widget)
2513+
(progn
2514+
(widget-default-create widget)
2515+
(widget-put (widget-get widget :parent) :comment-shown t))
25132516
;; `widget-default-delete' expects markers in these slots --
25142517
;; maybe it shouldn't.
25152518
(widget-put widget :from (point-marker))
@@ -2542,6 +2545,14 @@ If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
25422545
(and (equal "" val)
25432546
(not (widget-get widget :comment-shown)))))
25442547

2548+
;; This is useful when we want to redraw a widget, but we want to preserve
2549+
;; edits made by the user in the comment widget. (See Bug#64649)
2550+
(defun custom-comment-preserve (widget)
2551+
"Preserve the comment that belongs to WIDGET."
2552+
(when (widget-get widget :comment-shown)
2553+
(let ((comment-widget (widget-get widget :comment-widget)))
2554+
(widget-put comment-widget :value (widget-value comment-widget)))))
2555+
25452556
;;; The `custom-variable' Widget.
25462557

25472558
(defface custom-variable-obsolete
@@ -2821,12 +2832,16 @@ try matching its doc string against `custom-guess-doc-alist'."
28212832

28222833
;; The comment field
28232834
(unless (eq state 'hidden)
2824-
(let* ((comment (get symbol 'variable-comment))
2825-
(comment-widget
2826-
(widget-create-child-and-convert
2827-
widget 'custom-comment
2828-
:parent widget
2829-
:value (or comment ""))))
2835+
(let ((comment-widget
2836+
(widget-create-child-and-convert
2837+
widget 'custom-comment
2838+
:parent widget
2839+
:value (or
2840+
(and
2841+
(widget-get widget :comment-shown)
2842+
(widget-value (widget-get widget :comment-widget)))
2843+
(get symbol 'variable-comment)
2844+
""))))
28302845
(widget-put widget :comment-widget comment-widget)
28312846
;; Don't push it !!! Custom assumes that the first child is the
28322847
;; value one.
@@ -3840,12 +3855,16 @@ the present value is saved to its :shown-value property instead."
38403855
widget :visibility-widget 'custom-visibility)
38413856
;; The comment field
38423857
(unless hiddenp
3843-
(let* ((comment (get symbol 'face-comment))
3844-
(comment-widget
3845-
(widget-create-child-and-convert
3846-
widget 'custom-comment
3847-
:parent widget
3848-
:value (or comment ""))))
3858+
(let ((comment-widget
3859+
(widget-create-child-and-convert
3860+
widget 'custom-comment
3861+
:parent widget
3862+
:value (or
3863+
(and
3864+
(widget-get widget :comment-shown)
3865+
(widget-value (widget-get widget :comment-widget)))
3866+
(get symbol 'face-comment)
3867+
""))))
38493868
(widget-put widget :comment-widget comment-widget)
38503869
(push comment-widget children))))
38513870

0 commit comments

Comments
 (0)