From: Mauro Aranda <maurooaranda@gmail.com>
To: 5358@debbugs.gnu.org
Cc: dave@boostpro.com, ahyatt@gmail.com
Subject: bug#5358: 23.1; Adding comment loses customizations in progress
Date: Fri, 6 Sep 2019 11:47:57 -0300 [thread overview]
Message-ID: <CABczVwcwYuGqxJVXM7T6My+H_KzasvxXMzcjKs7emZz1sknQYQ@mail.gmail.com> (raw)
In-Reply-To: <m2zl4ka0pd.wl%dave@boostpro.com>
[-- Attachment #1.1: Type: text/plain, Size: 960 bytes --]
The possibility to preserve the customizations in progress is already
present in the customize machinery, but for some reason it wasn't used
in this case.
I propose a patch that makes use of the :shown-value property of the
custom-variable and custom-face widgets, thus allowing to preserve the
customizations in progress when redrawing a widget.
Since after redrawing customize recomputes the state of the widget, it
is necessary to check if the widget was modified. That isn't
possible with `custom-variable-state' or `custom-face-state',
because they are pretty "widget unaware". So I added a check in
`custom-variable-state-set' and `custom-face-state-set' to catch this
situation.
Finally, to be able to use the value of the widget in
`custom-face-state-set', it is necessary to rearrange the final part of
`custom-face-value-create'. Namely, add the children to the :children
property, before calling `custom-face-state-set'.
Best regards,
Mauro.
[-- Attachment #1.2: Type: text/html, Size: 1094 bytes --]
[-- Attachment #2: 0001-Don-t-discard-customizations-in-progress-when-adding.patch --]
[-- Type: text/x-patch, Size: 5155 bytes --]
From d2656c7da97acf689ec12f1fde496e608d8e90fb Mon Sep 17 00:00:00 2001
From: Mauro Aranda <maurooaranda@gmail.com>
Date: Fri, 6 Sep 2019 09:55:39 -0300
Subject: [PATCH] Don't discard customizations in progress when adding comments
(Bug#5358)
* lisp/cus-edit.el (custom-comment-show): Add docstring. Save the
widget value in the :shown-value property, before redrawing.
(custom-variable-modified-p): New function, to complement the return
values of custom-variable-state.
(custom-variable-state-set): Use it.
(custom-face-value-create): Add children to the custom-face widget
before setting the state, to be able to check for user edits.
(custom-face-state-set): Check for user edits before calling
custom-face-state.
---
lisp/cus-edit.el | 63 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 51 insertions(+), 12 deletions(-)
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 8a8bad9..60e6996 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -2411,9 +2411,21 @@ custom-comment-hide
;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
;; the global custom one
(defun custom-comment-show (widget)
- (widget-put widget :comment-shown t)
- (custom-redraw widget)
- (widget-setup))
+ "Show the comment editable field that belongs to WIDGET."
+ (let ((child (car (widget-get widget :children)))
+ ;; Just to be safe, we will restore this value after redrawing.
+ (old-shown-value (widget-get widget :shown-value)))
+ (widget-put widget :comment-shown t)
+ ;; Save the changes made by the user before redrawing, to avoid
+ ;; losing customizations in progress. (Bug#5358)
+ (if (eq (widget-type widget) 'custom-face)
+ (if (eq (widget-type child) 'custom-face-edit)
+ (widget-put widget :shown-value `((t ,(widget-value child))))
+ (widget-put widget :shown-value (widget-value child)))
+ (widget-put widget :shown-value (list (widget-value child))))
+ (custom-redraw widget)
+ (widget-put widget :shown-value old-shown-value)
+ (widget-setup)))
(defun custom-comment-invisible-p (widget)
(let ((val (widget-value (widget-get widget :comment-widget))))
@@ -2805,12 +2817,34 @@ custom-variable-state
'changed))
(t 'rogue))))
+(defun custom-variable-modified-p (widget)
+ "Non-nil if the variable value of WIDGET has been modified.
+WIDGET should be a custom-variable widget, whose first child is the widget
+that holds the value.
+Modified means that the widget that holds the value has been edited by the user
+in a customize buffer.
+To check for other states, call `custom-variable-state'."
+ (condition-case nil
+ (let* ((symbol (widget-get widget :value))
+ (get (or (get symbol 'custom-get) 'default-value))
+ (value (if (default-boundp symbol)
+ (funcall get symbol)
+ (symbol-value symbol))))
+ (not (equal value (widget-value (car (widget-get widget :children))))))
+ (error t)))
+
(defun custom-variable-state-set (widget &optional state)
"Set the state of WIDGET to STATE.
-If STATE is nil, the value is computed by `custom-variable-state'."
+If STATE is nil, the new state is computed by `custom-variable-modified-p' if
+WIDGET has been edited in the Custom buffer, or by `custom-variable-state'
+otherwise."
(widget-put widget :custom-state
- (or state (custom-variable-state (widget-value widget)
- (widget-get widget :value)))))
+ (or state
+ (and (custom-variable-modified-p widget) 'modified)
+ (custom-variable-state (widget-value widget)
+ (widget-value
+ (car
+ (widget-get widget :children)))))))
(defun custom-variable-standard-value (widget)
(get (widget-value widget) 'standard-value))
@@ -3630,9 +3664,9 @@ custom-face-value-create
(insert-char ?\s indent))
(widget-create-child-and-convert
widget 'sexp :value spec))))
- (custom-face-state-set widget)
- (push editor children)
- (widget-put widget :children children))))))
+ (push editor children)
+ (widget-put widget :children children)
+ (custom-face-state-set widget))))))
(defvar custom-face-menu
`(("Set for Current Session" custom-face-set)
@@ -3718,9 +3752,14 @@ custom-face-state
state)))
(defun custom-face-state-set (widget)
- "Set the state of WIDGET."
- (widget-put widget :custom-state
- (custom-face-state (widget-value widget))))
+ "Set the state of WIDGET, a custom-face widget.
+If the user edited the widget, set the state to modified. If not, the new
+state is one of the return values of `custom-face-state'."
+ (let ((face (widget-value widget)))
+ (widget-put widget :custom-state
+ (if (face-spec-match-p face (custom-face-widget-to-spec widget))
+ (custom-face-state face)
+ 'modified))))
(defun custom-face-action (widget &optional event)
"Show the menu for `custom-face' WIDGET.
--
2.7.4
next prev parent reply other threads:[~2019-09-06 14:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-11 19:41 bug#5358: 23.1; Adding comment loses customizations in progress David Abrahams
2016-02-17 3:48 ` Andrew Hyatt
2016-02-18 15:29 ` Dave Abrahams
2016-02-18 16:47 ` Glenn Morris
2016-02-19 16:18 ` Andrew Hyatt
2019-09-06 14:47 ` Mauro Aranda [this message]
2019-09-27 12:31 ` Mauro Aranda
2019-09-27 14:09 ` Lars Ingebrigtsen
2019-09-27 15:04 ` Mauro Aranda
2019-09-27 16:07 ` Lars Ingebrigtsen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABczVwcwYuGqxJVXM7T6My+H_KzasvxXMzcjKs7emZz1sknQYQ@mail.gmail.com \
--to=maurooaranda@gmail.com \
--cc=5358@debbugs.gnu.org \
--cc=ahyatt@gmail.com \
--cc=dave@boostpro.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).