all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Mauro Aranda <maurooaranda@gmail.com>
To: 64649@debbugs.gnu.org
Subject: bug#64649: 30.0.50; Customize: Comments on face customization not being saved
Date: Sat, 15 Jul 2023 18:59:29 -0300	[thread overview]
Message-ID: <a8e86907-922e-9ced-35b6-9be1153dffb3@gmail.com> (raw)
In-Reply-To: <b04ddb20-1066-026e-b547-525c7de0fb8d@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 206 bytes --]

I attach a patch to fix this.  The commit that introduced this
regression showed that we weren't taking care of preserving the comments
when redrawing either the custom-face or the custom-variable widget.

[-- Attachment #2: 0001-Preserve-comments-when-redrawing-a-widget-Bug-64649.patch --]
[-- Type: text/x-patch, Size: 4015 bytes --]

From d77851ba8b434697a7e5a797e9115fe008b4ecf5 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <maurooaranda@gmail.com>
Date: Sat, 15 Jul 2023 18:54:14 -0300
Subject: [PATCH] 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.
---
 lisp/cus-edit.el | 45 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index dbef5f47cd6..1c4de92db12 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -2330,6 +2330,7 @@ custom-redraw
 	(from (marker-position (widget-get widget :from)))
 	(to (marker-position (widget-get widget :to))))
     (save-excursion
+      (custom-comment-preserve widget)
       (widget-value-set widget (widget-value widget))
       (custom-redraw-magic widget))
     (when (and (>= pos from) (<= pos to))
@@ -2509,7 +2510,9 @@ custom-comment-create
   (let* ((null-comment (equal "" (widget-value widget))))
     (if (or (widget-get (widget-get widget :parent) :comment-shown)
 	    (not null-comment))
-	(widget-default-create widget)
+        (progn
+          (widget-default-create widget)
+          (widget-put (widget-get widget :parent) :comment-shown t))
       ;; `widget-default-delete' expects markers in these slots --
       ;; maybe it shouldn't.
       (widget-put widget :from (point-marker))
@@ -2542,6 +2545,14 @@ custom-comment-invisible-p
     (and (equal "" val)
 	 (not (widget-get widget :comment-shown)))))
 
+;; This is useful when we want to redraw a widget, but we want to preserve
+;; edits made by the user in the comment widget.  (See Bug#64649)
+(defun custom-comment-preserve (widget)
+  "Preserve the comment that belongs to WIDGET."
+  (when (widget-get widget :comment-shown)
+    (let ((comment-widget (widget-get widget :comment-widget)))
+      (widget-put comment-widget :value (widget-value comment-widget)))))
+
 ;;; The `custom-variable' Widget.
 
 (defface custom-variable-obsolete
@@ -2821,12 +2832,16 @@ custom-variable-value-create
 
       ;; The comment field
       (unless (eq state 'hidden)
-	(let* ((comment (get symbol 'variable-comment))
-	       (comment-widget
-		(widget-create-child-and-convert
-		 widget 'custom-comment
-		 :parent widget
-		 :value (or comment ""))))
+        (let ((comment-widget
+               (widget-create-child-and-convert
+                widget 'custom-comment
+                :parent widget
+                :value (or
+                        (and
+                         (widget-get widget :comment-shown)
+                         (widget-value (widget-get widget :comment-widget)))
+                        (get symbol 'variable-comment)
+                        ""))))
 	  (widget-put widget :comment-widget comment-widget)
 	  ;; Don't push it !!! Custom assumes that the first child is the
 	  ;; value one.
@@ -3831,12 +3846,16 @@ custom-face-value-create
 	 widget :visibility-widget 'custom-visibility)
 	;; The comment field
 	(unless hiddenp
-	  (let* ((comment (get symbol 'face-comment))
-		 (comment-widget
-		  (widget-create-child-and-convert
-		   widget 'custom-comment
-		   :parent widget
-		   :value (or comment ""))))
+	  (let ((comment-widget
+                 (widget-create-child-and-convert
+                  widget 'custom-comment
+                  :parent widget
+                  :value (or
+                          (and
+                           (widget-get widget :comment-shown)
+                           (widget-value (widget-get widget :comment-widget)))
+                          (get symbol 'face-comment)
+                          ""))))
 	    (widget-put widget :comment-widget comment-widget)
 	    (push comment-widget children))))
 
-- 
2.34.1


  reply	other threads:[~2023-07-15 21:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-15 13:38 bug#64649: 30.0.50; Customize: Comments on face customization not being saved Mauro Aranda
2023-07-15 21:59 ` Mauro Aranda [this message]
2023-07-20 15:53   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a8e86907-922e-9ced-35b6-9be1153dffb3@gmail.com \
    --to=maurooaranda@gmail.com \
    --cc=64649@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.