Add live demo to emacs package

  |   Source

Emacs package developers sometimes need add live demo to her/his project.

The requirement came from my discussion with pyim's developer.

With all the linting and unit tests running for ages, he still need a quick way to test if the package actually works on Emacs 25 (and other Emacs versions). I totally agree with him because my own projects have similar problems.

A live demo built into the project is very useful for developers and testers.

Besides, a live demo could help users. They try the new package with no hassle. They don't modify their own emacs configuration to try the new package.

So I figured out a simple solution. The best part is that any packages could use this solution with minimum change if their CI script is already set up.

In a package's CI script, Emacs is running in batch mode (with "–batch" option). What I suggest is add another Makefile task runemacs which is very similar to the original CI task. But in this task, the "–batch" options is removed.

See the solution I added for find-file-in-project,

diff --git a/Makefile b/Makefile
index 9005ca4..8f7a8ae 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
 SHELL = /bin/sh
 EMACS ?= emacs
-EMACS_BATCH_OPTS=--batch -Q -l find-file-in-project.el
+EMACS_GENERIC_OPTS=-Q -L . -L deps/ivy-0.13.4
 RM = @rm -rf

 .PHONY: test clean test compile
@@ -18,3 +19,8 @@ compile: clean
 # Run tests.
 test: compile
    @$(EMACS) $(EMACS_BATCH_OPTS) -l tests/ffip-tests.el
+   @mkdir -p deps;
+   @if [ ! -f deps/ivy-0.13.4/ivy.el ]; then curl -L | tar x -C deps/; fi;
+   @$(EMACS) $(EMACS_GENERIC_OPTS) --load ./tests/emacs-init.el
diff --git a/tests/emacs-init.el b/tests/emacs-init.el
new file mode 100644
index 0000000..a4df068
--- /dev/null
+++ b/tests/emacs-init.el
@@ -0,0 +1,17 @@
+(require 'find-file-in-project)
+(require 'ivy)
+(ivy-mode 1)
+(setq ffip-match-path-instead-of-filename t)
+ 1
+ nil
+ (lambda ()
+   (erase-buffer)
+   (goto-char (point-min))
+   (insert
+    ";; Setup of this demo,\n"
+    "(setq ffip-match-path-instead-of-filename t)\n\n\n"
+    ";; Run \"M-x find-file-in-project-by-selected\" and input search keyword \"el\" or \"tests\".\n\n\n"
+    ";; Move cursor above below paths and run \"M-x find-file-in-project-at-point\",\n\n"
+    ";;   tests/ffip-tests.el ; open file directly \n"
+    ";;   find-file-in-project.el:50 ; open file and jump to line 50\n")))

Similar solution is also used in pyim, it's one liner in shell to test it in Emacs 25,

EMACS=/home/cb/what-ever-path/25.1/bin/emacs make runemacs
Comments powered by Disqus