aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--helpful.el26
-rw-r--r--test/helpful-unit-test.el14
3 files changed, 42 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87dbced..d58b274 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
# v0.18 (unreleased)
+Show the original value for custom variables whose value has changed.
+
# v0.17
Fixed a minor docstring formatting issue when keymap references were
diff --git a/helpful.el b/helpful.el
index 5b1b1c8..854453c 100644
--- a/helpful.el
+++ b/helpful.el
@@ -2021,6 +2021,25 @@ may contain duplicates."
(t
(helpful--pretty-print value))))
+(defun helpful--original-value (sym)
+ "Return the original value for SYM, if any.
+
+If SYM has an original value, return it in a list. Return nil
+otherwise."
+ (let* ((orig-val-expr (get sym 'standard-value)))
+ (when (consp orig-val-expr)
+ (ignore-errors
+ (list
+ (eval (car orig-val-expr)))))))
+
+(defun helpful--original-value-differs-p (sym)
+ "Return t if SYM has an original value, and its current
+value is different."
+ (let ((orig-val-list (helpful--original-value sym)))
+ (and (consp orig-val-list)
+ (not (eq (car orig-val-list)
+ (symbol-value sym))))))
+
(defun helpful-update ()
"Update the current *Helpful* buffer to the latest
state of the current symbol."
@@ -2105,6 +2124,13 @@ state of the current symbol."
(t "Value")))
(helpful--format-value sym val)
"\n\n")
+ (when (helpful--original-value-differs-p sym)
+ (insert
+ (helpful--heading "Original Value")
+ (helpful--format-value
+ sym
+ (car (helpful--original-value sym)))
+ "\n\n"))
(when multiple-views-p
(insert (helpful--make-toggle-literal-button) " "))
diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el
index 64c9f02..d1d4840 100644
--- a/test/helpful-unit-test.el
+++ b/test/helpful-unit-test.el
@@ -950,3 +950,17 @@ find the source code."
;; loaded.
;;
(helpful-function #'tetris))
+
+(defcustom helpful-test-custom-var 123
+ "I am an example custom variable."
+ :type 'number
+ :group 'helpful)
+
+;; Ensure the current value differs from the original value.
+(setq helpful-test-custom-var 456)
+
+(ert-deftest helpful--original-value ()
+ "Show the original value for defcustom variables."
+ (helpful-variable 'helpful-test-custom-var)
+ (should
+ (s-contains-p "Original Value\n123" (buffer-string))))