emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/transient f5d81ef0ed 186/366: transient-lisp-variable:


From: Jonas Bernoulli
Subject: [elpa] externals/transient f5d81ef0ed 186/366: transient-lisp-variable: New class
Date: Tue, 25 Jan 2022 18:54:39 -0500 (EST)

branch: externals/transient
commit f5d81ef0ed24be935f3c0192b746a1738d903d37
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    transient-lisp-variable: New class
---
 lisp/transient.el | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/lisp/transient.el b/lisp/transient.el
index 8428674a04..ed1cabb01d 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -651,6 +651,7 @@ slot is non-nil."
    (shortarg    :initarg :shortarg)
    (value                             :initform nil)
    (multi-value :initarg :multi-value :initform nil)
+   (always-read :initarg :always-read :initform nil)
    (allow-empty :initarg :allow-empty :initform nil)
    (history-key :initarg :history-key :initform nil)
    (reader      :initarg :reader      :initform nil)
@@ -2371,9 +2372,10 @@ limited number of possible values should you replace 
this with a
 simple method that does not handle history.  (E.g. for a command
 line switch the only possible values are \"use it\" and \"don't use
 it\", in which case it is pointless to preserve history.)"
-  (with-slots (value multi-value allow-empty choices) obj
+  (with-slots (value multi-value always-read allow-empty choices) obj
     (if (and value
              (not multi-value)
+             (not always-read)
              transient--prefix)
         (oset obj value nil)
       (let* ((overriding-terminal-local-map nil)
@@ -3413,6 +3415,35 @@ we stop there."
 
 (font-lock-add-keywords 'emacs-lisp-mode transient-font-lock-keywords)
 
+;;; Auxiliary Classes
+;;;; `transient-lisp-variable'
+
+(defclass transient-lisp-variable (transient-variable)
+  ((reader :initform transient-lisp-variable--reader)
+   (always-read :initform t))
+  "[Experimental] Class used for Lisp variables.")
+
+(cl-defmethod transient-init-value ((obj transient-lisp-variable))
+  (oset obj value (symbol-value (oref obj variable))))
+
+(cl-defmethod transient-infix-set ((obj transient-lisp-variable) value)
+  (set (oref obj variable)
+       (oset obj value value)))
+
+(cl-defmethod transient-format-description ((obj transient-lisp-variable))
+  (or (oref obj description)
+      (oref obj variable)))
+
+(cl-defmethod transient-format-value ((obj transient-lisp-variable))
+  (propertize (prin1-to-string (oref obj value))
+              'face 'transient-value))
+
+(cl-defmethod transient-prompt ((obj transient-lisp-variable))
+  (format "Set %s: " (oref obj variable)))
+
+(defun transient-lisp-variable--reader (prompt initial-input _history)
+  (read--expression prompt initial-input))
+
 ;;; _
 (provide 'transient)
 ;; Local Variables:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]