helpful

a fork of Wilfred's helpful
git clone https://git.trogloxene.org/helpful.git
Log | Files | Refs | README

commit 866d5daecb168c0b62c91ccf5dec833d5cdcac5c
parent ddd1f2c6794972e16393614716532fc1753edd31
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Thu, 11 Jul 2019 00:56:22 +0100

Show the original value for defcustom variables

Fixes #199

Diffstat:
MCHANGELOG.md | 2++
Mhelpful.el | 26++++++++++++++++++++++++++
Mtest/helpful-unit-test.el | 14++++++++++++++
3 files changed, 42 insertions(+), 0 deletions(-)

diff --git 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 @@ -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 @@ -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))))