86 lines
2.7 KiB
EmacsLisp
86 lines
2.7 KiB
EmacsLisp
;;; esv.el --- read the Bible from Emacs -*- lexical-binding:t -*-
|
|
|
|
;; Copyright (C) 2024 Jeremy Baxter
|
|
|
|
;; Author: Jeremy Baxter <jeremy@baxters.nz>
|
|
;; Maintainer: Jeremy Baxter <jeremy@baxters.nz>
|
|
;; Created: May 2024
|
|
;; Keywords: bible
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;; esv.el 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 of the License, or
|
|
;; (at your option) any later version.
|
|
;;
|
|
;; esv.el 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.
|
|
;;
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with esv.el. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; esv.el provides `esv', a command for fetching a given passage of
|
|
;; the ESV Bible. The majority of the work is done by the esv command
|
|
;; line tool; esv.el just presents the text nicely in an Emacs buffer
|
|
;; for a pleasurable viewing experience.
|
|
;;
|
|
;; If you do not already have esv, find it on its website:
|
|
;; https://sr.ht/~jeremy/esv
|
|
|
|
;;; Code:
|
|
|
|
(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'.
|
|
|
|
Requires the esv command line tool to be in the system's PATH.
|
|
esv can be acquired at <https://sr.ht/~jeremy/esv>."
|
|
(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))
|
|
(call-process esv-program nil buffer t
|
|
(format "-l%d" esv-columns) book verses)
|
|
(display-buffer buffer)
|
|
(with-current-buffer buffer
|
|
(esv-mode)
|
|
(goto-char (point-min)))
|
|
(set-window-start (get-buffer-window buffer) (point-min))
|
|
t)))
|
|
|
|
(provide 'esv)
|