Skip to content

Commit

Permalink
Use setopt for "set" button if available
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonBreezes authored and Wilfred committed Oct 28, 2023
1 parent be6f7bb commit a32a5b3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions helpful.el
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ To disable cleanup entirely, set this variable to nil. See also
:type 'function
:group 'helpful)

(defcustom helpful-set-variable-function
(if (< 29 emacs-major-version) #'setopt #'setq)
"Function used by `helpful--set' to interactively set variables."
:type 'function
:group 'helpful)

;; TODO: explore whether more basic highlighting is fast enough to
;; handle larger functions. See `c-font-lock-init' and its use of
;; font-lock-keywords-1.
Expand Down Expand Up @@ -600,6 +606,7 @@ overrides that to include previously opened buffers."
(let* ((sym (button-get button 'symbol))
(buf (button-get button 'buffer))
(sym-value (helpful--sym-value sym buf))
(set-func (symbol-name helpful-set-variable-function))
;; Inspired by `counsel-read-setq-expression'.
(expr
(minibuffer-with-setup-hook
Expand All @@ -608,17 +615,17 @@ overrides that to include previously opened buffers."
#'elisp-eldoc-documentation-function)
(run-hooks 'eval-expression-minibuffer-setup-hook)
(goto-char (minibuffer-prompt-end))
(forward-char (length (format "(setq %S " sym))))
(forward-char (length (format "(%s %S " set-func sym))))
(read-from-minibuffer
"Eval: "
(format
(if (or (consp sym-value)
(and (symbolp sym-value)
(not (null sym-value))
(not (keywordp sym-value))))
"(setq %s '%S)"
"(setq %s %S)")
sym sym-value)
"(%s %s '%S)"
"(%s %s %S)")
set-func sym sym-value)
read-expression-map t
'read-expression-history))))
(save-current-buffer
Expand Down

0 comments on commit a32a5b3

Please sign in to comment.