Skip to content

Instantly share code, notes, and snippets.

@thomp
Last active August 17, 2023 19:54
Show Gist options
  • Save thomp/ff0fb98d4239af4e3f26a7b0cc64f4b6 to your computer and use it in GitHub Desktop.
Save thomp/ff0fb98d4239af4e3f26a7b0cc64f4b6 to your computer and use it in GitHub Desktop.
transient-el-sandbox
;; https://gist.github.com/thomp/ff0fb98d4239af4e3f26a7b0cc64f4b6
(require 'transient)
;; simple transient
(transient-define-prefix tsc-hello ()
"Prefix that is minimal and uses an anonymous command suffix."
;; Binding suffixes with the ("key" "description" suffix-or-command) form within a group is extremely common.
[("s" "call suffix"
(lambda ()
(interactive)
(message "Called a suffix")))])
;; toy fn
(defun tsc-suffix-wave ()
"Wave at the user."
(interactive)
(message "Waves at the user at: %s." (current-time-string)))
;; controlling exposure/visibility:
;; - Visibility predicates
;; - Levels
;; https://github.com/positron-solutions/transient-showcase/tree/master
;;
;; 'Visibility predicates'
;;
(transient-define-prefix tsc-visibility-predicates ()
"Prefix with visibility predicates.
Try opening this prefix in buffers with modes deriving from different
abstract major modes."
["Empty Groups Not Displayed"
;; in org mode for example, this group doesn't appear.
("we" "wave elisp" tsc-suffix-wave :if-mode emacs-lisp-mode)
("wc" "wave in C" tsc-suffix-wave :if-mode cc-mode)]
["Lists of Modes"
("wm" "wave multiply" tsc-suffix-wave :if-mode (dired-mode gnus-mode))]
[["Function Predicates"
;; note, after toggling, the transient needs to be re-displayed for the
;; predicate to take effect
("bt" "toggle busy" tsc--toggle-busy)
("bw" "wave busily" tsc-suffix-wave :if tsc--busy-p)]
["Programming Actions"
:if-derived prog-mode
("pw" "wave programishly" tsc-suffix-wave)
("pe" "wave in elisp" tsc-suffix-wave :if emacs-lisp-mode)]
["Special Mode Actions"
:if-derived special-mode
("sw" "wave specially" tsc-suffix-wave)
("sd" "wave dired" tsc-suffix-wave :if-mode dired-mode)]
["Text Mode Actions"
:if-derived text-mode
("tw" "wave textually" tsc-suffix-wave)
("to" "wave org-modeishly" tsc-suffix-wave :if-mode org-mode)]
["tsc hello"
("th" "run tsc-hello" tsc-hello)
]
])
;; define simple predicate
(defvar tsc-busy nil "Are we busy?")
(defun tsc--busy-p () "Are we busy?" tsc-busy)
(transient-define-suffix tsc--toggle-busy ()
"Toggle busy."
(interactive)
(setf tsc-busy (not tsc-busy))
(message (propertize (format "busy: %s" tsc-busy)
'face 'success)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment