Massimiliano Mirra

Notes



















Date:
Tags: emacs
Status: notes

Emacs package quickstart with Eldev

Install Eldev

Eldev is make (and then some) for Emacs Lisp development.

curl -fsSL https://raw.github.com/doublep/eldev/master/webinstall/eldev | sh

The eldev executable will be installed in ~/.local/bin.

Create a project directory

~/projects$ mkdir emacs-simple-calculator
~/projects$ cd emacs-simple-calculator
~/projects/emacs-simple-calculator$ git init

Create the main project file

simple-calculator.el:

;;; simple-calculator.el --- Simple Calculator -*- lexical-binding: t -*-

;; Copyright (C) 2022 Some One

;; Author: Some One <[email protected]>
;; URL: https://github.com/someone/emacs-simple-calculator
;; Version: 0.1.0
;; Package-Requires: ((emacs "27.1"))
;; Keywords: examples

;; This file is not part of GNU Emacs

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; For a full copy of the GNU General Public License
;; see <https://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; [This will contain a description of the package]

;;; Code:

(defun simple-calculator-add (a b)
  (+ a b))

(provide 'simple-calculator)

;;; simple-calculator.el ends here

Initialize Eldev project

~/projects/emacs-simple-calculator$ eldev init --non-interactive
Created file ‘Eldev’ for this project
Modified file ‘.gitignore’

In the file Eldev, uncomment the gnu-elpa and melpa sources:

; -*- mode: emacs-lisp; lexical-binding: t -*-

;; Uncomment some calls below as needed for your project.
(eldev-use-package-archive 'gnu-elpa)
;(eldev-use-package-archive 'nongnu-elpa)
(eldev-use-package-archive 'melpa)

Add a test file

simple-calculator-test.el:

(require 'simple-calculator)
(require 'buttercup)

(describe "A calculator"
  (it "adds two numbers"
    (expect (simple-calculator-add 1 2) :to-be 3)))

Run tests

~/projects/emacs-simple-calculator$ eldev test
Loading /home/user/projects/emacs-simple-calculator/simple-calculator.el (source)...

[1/1] Installing package ‘buttercup’ (1.28) from ‘melpa-stable’...
Running 1 specs.

A calculator
  adds two numbers (0.05ms)

Ran 1 specs, 0 failed, in 0.10ms.

Run tests in watch mode

Using watchexec:

~/projects/emacs-simple-calculator$ watchexec eldev test

If you’re using FlyCheck with ELisp, a temporary file gets written to the current folder whenever flycheck runs, which cannot be moved to the system temporary directory. Prevent unnecessary test runs with:

~/projects/emacs-simple-calculator$ watchexec --ignore 'flycheck_*' eldev test

I write in the hope of making other people’s developer journey smoother and more rewarding. If you noticed a mistake or have suggestions on how to improve this article, please let me know. If you think this article can be useful to others, please consider sharing it:

Stay in touch

© 2020-2024 Massimiliano Mirra