;;; 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)