From 2f95a2a1c5ba9538e7b38a4b68e8c8abe3d54c5d Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Sat, 13 Aug 2022 15:53:05 +0500 Subject: [PATCH] refactor: extract transient class --- pomm.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pomm.el b/pomm.el index ba43790..54c71cd 100644 --- a/pomm.el +++ b/pomm.el @@ -627,21 +627,22 @@ minor mode." (read-number "Number of work periods before a long break:" pomm-number-of-periods))) -(defclass pomm--set-context-on-iteration-end-infix (transient-switch) - ((transient :initform t)) - "A transient class to toggle `pomm-reset-context-on-iteration-end'.") +(defclass pomm--transient-lisp-variable-switch (transient-switch) + ((transient :initform t) + (variable :initarg :variable))) -(cl-defmethod transient-init-value ((obj pomm--set-context-on-iteration-end-infix)) +(cl-defmethod transient-init-value ((obj pomm--transient-lisp-variable-switch)) (oset obj value - pomm-reset-context-on-iteration-end)) + (symbol-value (oref obj variable)))) -(cl-defmethod transient-infix-read ((_ pomm--set-context-on-iteration-end-infix)) - "Toggle the switch on or off." - (setq pomm-reset-context-on-iteration-end - (not pomm-reset-context-on-iteration-end))) +(cl-defmethod transient-infix-read ((obj pomm--transient-lisp-variable-switch)) + (oset obj value + (set (oref obj variable) + (not (symbol-value (oref obj variable)))))) (transient-define-infix pomm--set-reset-context-on-iteration-end () - :class 'pomm--set-context-on-iteration-end-infix + :class 'pomm--transient-lisp-variable-switch + :variable 'pomm-reset-context-on-iteration-end :argument "--context-reset" :key "-r" :description "Reset the context on the interation end")