Skip to content

Commit 43afe90

Browse files
committed
dev,enh: move demo to its own directory
1 parent 5d41174 commit 43afe90

File tree

3 files changed

+186
-1
lines changed

3 files changed

+186
-1
lines changed

Eldev

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
(eldev-use-package-archive 'melpa)
77

88
(eldev-use-plugin 'autoloads)
9-
(setq eldev-project-main-file "run-command.el")
109

10+
(setf eldev-lint-ignored-fileset
11+
`(:or ,(eldev-package-descriptor-file-name) "demo"))
12+
(setq eldev-project-main-file "run-command.el")

demo/demo.el

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
;; This demo is scripted using director.el: https://github.com/bard/emacs-director
2+
;;
3+
;; To record it:
4+
;;
5+
;; asciinema rec --overwrite -c 'emacs -Q -nw -l director-bootstrap.el -l demo.el' demo.asciicast
6+
;; agg --font-size 24 demo.asciicast ../docs/public/demo2.gif
7+
8+
(director-bootstrap
9+
:user-dir "/tmp/run-command-demo.userdir"
10+
:packages '(helm ivy async rust-mode)
11+
:load-path
12+
'("~/projects/emacs-run-command"
13+
"~/projects/emacs-director" ;; won't be needed after director is published on Melpa
14+
))
15+
16+
(director-run
17+
:version 1
18+
:before-start
19+
(lambda ()
20+
;; load required features
21+
(require 'run-command)
22+
(require 'helm)
23+
(require 'term)
24+
25+
;; remove distractions
26+
(setq initial-scratch-message "")
27+
(menu-bar-mode 'toggle)
28+
(setq helm-display-header-line nil)
29+
(set-face-attribute 'helm-source-header nil
30+
:background "transparent"
31+
:foreground "dim gray"
32+
:weight 'normal)
33+
(set-face-attribute 'helm-match nil
34+
:foreground "brightred "
35+
:weight 'bold
36+
:underline t)
37+
38+
;; create a fresh space for each demo run
39+
(setq demo-directory (make-temp-file "run-command-demo-" t))
40+
41+
;; prepare the environment
42+
(helm-mode 1)
43+
44+
;; configure package to be demo'd
45+
(setq run-command-recipes '(run-command-recipe-example))
46+
47+
;; prepare the buffer where most typing will happen
48+
(emacs-lisp-mode)
49+
(eldoc-mode -1))
50+
51+
:delay-between-steps 0.1
52+
53+
;; give useful feedback during development
54+
:on-error (lambda (err) (message "Error while executing director script: %S" err))
55+
56+
:after-end (lambda () (kill-emacs))
57+
58+
:typing-style 'human
59+
60+
:steps
61+
'( ;; don't rush
62+
(:wait 1)
63+
64+
;; define recipe for creating project
65+
(:eval (switch-to-buffer "*scratch*"))
66+
(:type "(defun run-command-recipe-example ()\r")
67+
(:wait 0.5)
68+
(:type "(list ")
69+
(:type "'( :command-name \"Create Rust project\"\r")
70+
(:wait 0.5)
71+
(:type ":command-line (lambda () (format \"cargo new %s\" (read-string \"Name: \"))))\r")
72+
(:type "))")
73+
(:eval (eval-buffer))
74+
75+
;; execute first recipe
76+
(:wait 1)
77+
(:eval (dired demo-directory))
78+
(:wait 1)
79+
(:type "\M-x")
80+
(:type "run-command")
81+
(:wait 0.5)
82+
(:type [return])
83+
(:wait 1.5)
84+
(:type "cre")
85+
(:wait 1)
86+
(:type [return])
87+
(:type "helloworld")
88+
(:wait 1.5)
89+
(:type [return])
90+
(:wait 2)
91+
(:eval (delete-other-windows))
92+
(:type "g")
93+
(:wait 2)
94+
95+
;; define second recipe
96+
(:eval (progn
97+
(switch-to-buffer "*scratch*")
98+
(goto-char (point-min))
99+
(re-search-forward "(list ")
100+
(forward-sexp)))
101+
(:wait 2)
102+
(:type [return])
103+
(:type "'( :command-name \"Run Rust project in watch mode\"\r")
104+
(:type ":command-line \"cargo watch --clear -x run\")")
105+
(:eval (eval-buffer))
106+
(:wait 2)
107+
108+
;; execute second recipe
109+
(:eval (dired demo-directory))
110+
(:wait 1)
111+
(:type [return])
112+
(:wait 1)
113+
(:type [down])
114+
(:wait 0.2)
115+
(:type [down])
116+
(:wait 0.2)
117+
(:type [down])
118+
(:wait 1)
119+
(:type [return])
120+
(:wait 1)
121+
(:type [return])
122+
(:wait 1)
123+
(:type "\M-x")
124+
(:type "run-command")
125+
(:wait 0.5)
126+
(:type [return])
127+
(:wait 1)
128+
(:type "run")
129+
(:wait 1)
130+
(:type [return])
131+
(:wait 2)
132+
133+
;; modify file
134+
(:eval (re-search-forward "world" nil t))
135+
(:wait 2)
136+
(:call backward-kill-word)
137+
(:wait 1)
138+
(:type "Emacs")
139+
(:wait 2)
140+
(:call save-buffer)
141+
(:wait 4)))

demo/director-bootstrap.el

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
;; Scenarios might be stored in a projects's source tree but are
2+
;; supposed to run in a clean environment. Disable reading
3+
;; `.dir-locals.el' so that Emacs doesn't try to load it from the
4+
;; project's source tree. This cannot come as part of the
5+
;; `director-bootstrap' function because, by the time that's called by
6+
;; a file in the source tree, Emacs will already have tried to load
7+
;; the corresponding `.dir-locals.el' file.
8+
9+
(setq enable-dir-local-variables nil)
10+
11+
(defun director-bootstrap (&rest config)
12+
"Setup the environment for a simulated user session."
13+
14+
(require 'package)
15+
16+
(setq byte-compile-warnings nil)
17+
(when (boundp 'comp-async-report-warnings-errors)
18+
(setq comp-async-report-warnings-errors nil))
19+
20+
(let ((user-dir (plist-get config :user-dir))
21+
(packages (plist-get config :packages))
22+
(additional-load-paths (plist-get config :load-path)))
23+
24+
(when user-dir
25+
(setq user-emacs-directory user-dir)
26+
(setq package-user-dir (expand-file-name "elpa" user-emacs-directory)))
27+
28+
(when additional-load-paths
29+
(setq load-path (append load-path additional-load-paths)))
30+
31+
;; attempt requiring director here; if error, add director to list of required
32+
;; packages, and retry after initializing packages
33+
34+
(package-initialize)
35+
(when packages
36+
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
37+
(dolist (package packages)
38+
(unless (package-installed-p package)
39+
(package-install package))))
40+
41+
(require 'director)))
42+

0 commit comments

Comments
 (0)