Skip to content

Instantly share code, notes, and snippets.

@wrightmikea
Created March 15, 2021 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrightmikea/b33601f9d97be504b526b65df796804c to your computer and use it in GitHub Desktop.
Save wrightmikea/b33601f9d97be504b526b65df796804c to your computer and use it in GitHub Desktop.
Elisp related to 2021 March 5th Emacs-SF online Demo of (magit) transient by Mike Wright
;; Elisp related to 2021 March 5th Emacs-SF online Demo of (magit) transient by Mike Wright
;; from: https://github.com/magit/transient/blob/master/docs/transient.org
;; under section "Hydra"
;; A Hydra “body” is equivalent to a Transient “prefix” and a Hydra “head” is equivalent to a Transient “suffix”.
;; Hydra has no equivalent of a Transient “infix”.
(transient-define-prefix outline-navigate ()
:transient-suffix 'transient--do-stay
:transient-non-suffix 'transient--do-warn
[("p" "previous visible heading" outline-previous-visible-heading)
("n" "next visible heading" outline-next-visible-heading)])
;; from: https://gist.github.com/abrochard/dd610fc4673593b7cbce7a0176d897de#modern-ux
;; "Conquering Kubernetes with Emacs" Adrien Brochard
;; A simple transient
(progn
(defun test-function ()
(interactive)
(message "Test function"))
(define-transient-command test-transient ()
"Test Transient Title"
["Actions"
("a" "Action a" test-function)
("s" "Action s" test-function)
("d" "Action d" test-function)])
(test-transient))
;; Transient with switches
(progn
(defun test-function (&optional args)
(interactive
(list (transient-args 'test-transient)))
(message "args: %s" args))
(define-transient-command test-transient ()
"Test Transient Title"
["Arguments"
("-s" "Switch" "--switch")
("-a" "Another switch" "--another")]
["Actions"
("d" "Action d" test-function)])
(test-transient))
;; Transient with params
(progn
(defun test-function (&optional args)
(interactive
(list (transient-args 'test-transient)))
(message "args %s" args))
(define-infix-argument test-transient:--message ()
:description "Message"
:class 'transient-option
:shortarg "-m"
:argument "--message=")
(define-transient-command test-transient ()
"Test Transient Title"
["Arguments"
("-s" "Switch" "--switch")
("-a" "Another switch" "--another")
(test-transient:--message)]
["Actions"
("d" "Action d" test-function)])
(test-transient))
;; simplified
(progn
(define-transient-command test-transient ()
"Test Transient Title"
["Arguments"
("-s" "Switch" "--switch")
("-a" "Another switch" "--another")
("-m" "Message" "--message=")] ;; simpler
["Actions"
("d" "Action d" test-function)])
(test-transient))
;; kubernetes-transient (stub version)
(progn
(defun kubernetes-get-logs (&optional args)
(interactive
(list (transient-args 'kubernetes-transient)))
(princ "stub"))
(define-infix-argument kubernetes-transient:--tail ()
:description "Tail"
:class 'transient-option
:shortarg "-t"
:argument "--tail=")
(define-transient-command kubernetes-transient ()
"Test Transient Title"
["Arguments"
("-f" "Follow" "-f")
(kubernetes-transient:--tail)]
["Actions"
("l" "Log" kubernetes-get-logs)])
(kubernetes-transient))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment