From 00e6e3d05d0fc485a08196060ec05a34823486f3 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Wed, 1 May 2024 11:20:52 +1200 Subject: [PATCH] esv.el: add a package for integrating into Emacs --- esv.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 esv.el diff --git a/esv.el b/esv.el new file mode 100644 index 0000000..ff3182a --- /dev/null +++ b/esv.el @@ -0,0 +1,53 @@ +;;; esv.el --- read the Bible from Emacs -*- lexical-binding:t -*- + +(defgroup esv nil + "Read the Bible." + :prefix "esv-" + :group 'applications) + +(defcustom esv-columns 72 + "Length of each line output by `esv'." + :type 'natnum + :group 'esv) +(defcustom esv-mode-hook nil + "Hook run after entering `esv-mode'." + :type 'hook + :group 'esv) +(defcustom esv-process "esv" + "Name of the process created by `esv'." + :type 'string + :group 'esv) +(defcustom esv-program "esv" + "Path to or name of the program started by `esv'." + :type 'string + :group 'esv) + +(define-derived-mode esv-mode text-mode "ESV-Bible" + "Major mode used for reading the Bible with `esv'." + :group 'esv + + (read-only-mode)) + +(defun esv (book verses) + "Fetch the Bible passage identified by BOOK and VERSES. +The result will be redirected to a buffer specified by `esv-buffer'." + (interactive "MBook: \nMVerses: ") + (let ((buffer (concat book " " verses))) + (catch 'buffer-exists + (when (get-buffer buffer) + (message "Buffer `%s' already exists" buffer) + (throw 'buffer-exists nil)) + ;; execute esv + (call-process esv-program nil buffer t + ;; arguments + (format "-l%d" esv-columns) book verses) + ;; display buffer in another window + (display-buffer buffer) + ;; move point to the beginning of the buffer + (with-current-buffer buffer + (esv-mode) + (goto-char (point-min))) + (set-window-start (get-buffer-window buffer) (point-min)) + t))) + +(provide 'esv)