Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions helpful.el
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,24 @@ overrides that to include previously opened buffers."
(eval-expression expr))
(helpful-update)))

(define-button-type 'helpful-reset-button
'action #'helpful--reset
'symbol nil
'buffer nil
'follow-link t
'help-echo "Reset the value of this symbol")

(defun helpful--reset (button)
"Reset the value of this symbol to its standard value."
(let* ((sym (button-get button 'symbol))
(buf (button-get button 'buffer))
(standard-value (car (helpful--original-value sym))))
(save-current-buffer
(when buf
(set-buffer buf))
(set sym standard-value))
(helpful-update)))

(define-button-type 'helpful-view-literal-button
'action #'helpful--view-literal
'help-echo "Toggle viewing as a literal")
Expand Down Expand Up @@ -1823,6 +1841,14 @@ POSITION-HEADS takes the form ((123 (defun foo)) (456 (defun bar)))."
'symbol sym
'buffer buffer))

(defun helpful--make-reset-button (sym buffer)
"Make a reset button for SYM in BUFFER."
(helpful--button
"Reset"
'helpful-reset-button
'symbol sym
'buffer buffer))

(defun helpful--make-toggle-literal-button ()
"Make set button for SYM in BUFFER."
(helpful--button
Expand Down Expand Up @@ -2315,6 +2341,8 @@ state of the current symbol."
(when (memq (helpful--sym-value helpful--sym helpful--associated-buffer) '(nil t))
(insert (helpful--make-toggle-button helpful--sym helpful--associated-buffer) " "))
(insert (helpful--make-set-button helpful--sym helpful--associated-buffer))
(when (helpful--original-value-differs-p helpful--sym)
(insert " " (helpful--make-reset-button helpful--sym helpful--associated-buffer)))
(when (custom-variable-p helpful--sym)
(insert " " (helpful--make-customize-button helpful--sym)))))

Expand Down
13 changes: 13 additions & 0 deletions test/helpful-unit-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,19 @@ find the source code."
(should
(s-contains-p "Original Value\n123" (buffer-string))))

(ert-deftest helpful--reset-only-if-original-value-differs ()
"Show the reset button for defcustom variables that have been modified."
(let ((previous-value helpful-test-custom-var))
(helpful-variable 'helpful-test-custom-var)
(should
(s-contains-p "Set Reset Customize\n" (buffer-string)))
(button-activate (button-at (+ 1 (string-match "Reset" (buffer-string)))))
(should (equal helpful-test-custom-var
(eval (car (get 'helpful-test-custom-var 'standard-value)))))
(should
(s-contains-p "Set Customize\n" (buffer-string)))
(setq helpful-test-custom-var previous-value)))

(ert-deftest helpful--preserve-position ()
"Show the original value for defcustom variables."
(-let [(buf _pos _opened) (helpful--definition 'helpful-test-custom-var nil)]
Expand Down