Better Emacs package development workflow

  |   Source

The Emacs Lisp syntax error should be automatically detected by CI (Continuous Integration).

Syntax errors could be a bit difficult to locate. For example, developers might use Emacs 28+ only APIs to develop packages running on Emacs 26.

Here is howto.

  • Step 1, create a file my-byte-compile.el in the directory "tests/",
(require 'find-lisp)

(let ((files (find-lisp-find-files-internal
              "."
              (lambda (file dir)
                (and (not (file-directory-p (expand-file-name file dir)))
                     (string-match "\\.el$" file)
                     (not (string-match "\\.dir-locals\\.el$" file))))
              (lambda (dir parent)
                (not (or (member dir '("." ".." ".git" ".svn" "deps" "tests"))
                         (file-symlink-p (expand-file-name dir parent))))))))
  (dolist (file files)
    (byte-compile-file file)))
  • Step 2, insert below command line into the project's Makefile,
compile:
    emacs --batch -Q -L . -l my-package-main-entry.el -l tests/my-byte-compile.el 2>&1 | grep -E "([Ee]rror|[Ww]arning):" && exit 1 || exit 0

DONE! Now Gitlab/Github could use command line make compile in their CI pipeline.

Screenshot of a tricky bug of evil-matchit detected by this new workflow.

byte-compile-ci.png

BTW, I also tried elint, but it's not as reliable as byte-compile.

Content of my-elint.el,

(require 'elint)

(let ((elint-directory-skip-re "\\(\\.dir-locals\\|ldefs-boot\\|loaddefs\\)\\.el\\'"))
  (elint-directory "."))

Here is link to the Makefile from my real world project.

I use below command lines to compile and test the project locally.

EMACS=~/myemacs/26.3/bin/emacs make compile # compile only
EMACS=~/myemacs/26.3/bin/emacs make test # compile and run unit test 
Comments powered by Disqus