Skip to content

Commit

Permalink
Add orgdiff-- to transient-lisp-variable-formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
tecosaur committed Jan 9, 2022
1 parent 98d8c88 commit 61ea5b6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions orgdiff.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,35 @@
;;
;;; Code:

(defclass transient-lisp-variable-formatted (transient-variable)
(defclass orgdiff--transient-lisp-variable-formatted (transient-variable)
((reader :initform #'transient-lisp-variable--reader)
(always-read :initform t)
(set-value :initarg :set-value :initform #'set))
"Class used for Lisp variables, modified version of `transient-lisp-variable'.")

(cl-defmethod transient-init-value ((obj transient-lisp-variable-formatted))
(cl-defmethod transient-init-value ((obj orgdiff--transient-lisp-variable-formatted))
(oset obj value (symbol-value (oref obj variable))))

(cl-defmethod transient-infix-set ((obj transient-lisp-variable-formatted) value)
(cl-defmethod transient-infix-set ((obj orgdiff--transient-lisp-variable-formatted) value)
(funcall (oref obj set-value)
(oref obj variable)
(oset obj value value)))

(cl-defmethod transient-format-description ((obj transient-lisp-variable-formatted))
(cl-defmethod transient-format-description ((obj orgdiff--transient-lisp-variable-formatted))
(or (oref obj description)
(symbol-name (oref obj variable))))

(cl-defmethod transient-format-value ((obj transient-lisp-variable-formatted))
(cl-defmethod transient-format-value ((obj orgdiff--transient-lisp-variable-formatted))
(let ((val (oref obj value)))
(pcase val
('t (propertize "yes" 'face 'transient-argument))
('nil (propertize "no" 'face 'transient-unreachable))
(_ (propertize (prin1-to-string val) 'face 'transient-value)))))

(cl-defmethod transient-prompt ((obj transient-lisp-variable-formatted))
(cl-defmethod transient-prompt ((obj orgdiff--transient-lisp-variable-formatted))
(format "Set %s: " (oref obj variable)))

(defun transient-lisp-variable-formatted--reader (prompt initial-input _history)
(defun orgdiff--transient-lisp-variable-formatted--reader (prompt initial-input _history)
(read--expression prompt initial-input))

(eval-when-compile
Expand All @@ -61,7 +61,7 @@
:group 'orgdiff)
(transient-define-infix ,(intern (concat "orgdiff--set-" name)) ()
"Set `orgdiff--theme' from a popup buffer."
:class 'transient-lisp-variable-formatted
:class 'orgdiff--transient-lisp-variable-formatted
:variable ',(intern (concat "orgdiff-" name))
:key ,key
:description ,description
Expand Down

0 comments on commit 61ea5b6

Please sign in to comment.