esv.el: accept one package argument

This commit is contained in:
Jeremy Baxter 2024-07-20 14:26:28 +12:00
parent cbf4d0326f
commit a2934872ba

26
esv.el
View file

@ -69,31 +69,37 @@
(read-only-mode)) (read-only-mode))
(defun esv (book verses) (defun esv (passage)
"Fetch the Bible passage identified by BOOK and VERSES. "Fetch the Bible passage identified by BOOK and VERSES.
The result will be redirected to a buffer named after the passage. The result will be redirected to a buffer named after the passage.
Requires the esv command line tool to be in the system's PATH. Requires the esv command line tool to be in the system's PATH.
esv can be acquired at <https://sr.ht/~jeremy/esv>." esv can be acquired at <https://sr.ht/~jeremy/esv>."
(interactive "MBook: \nMVerses: ") (interactive "MPassage: ")
(let (let*
((buffer (concat book " " verses)) ((slices (split-string passage))
(verses (car (last slices)))
(book (mapconcat #'(lambda (e) e)
(take (1- (length slices)) slices) " "))
(buffer (concat book " " verses))
(arg-list (append esv-arguments (arg-list (append esv-arguments
(list (format "-l%d" esv-columns))))) (list (format "-l%d" esv-columns))
(list book) (list verses))))
(add-to-list 'arg-list book)
(add-to-list 'arg-list verses)
(catch 'buffer-exists (catch 'buffer-exists
(when (get-buffer buffer) (when (get-buffer buffer)
(unless esv-close-existing-buffers (unless esv-close-existing-buffers
(message "Buffer `%s' already exists" buffer) (message "Buffer `%s' already exists" buffer)
(throw 'buffer-exists nil)) (throw 'buffer-exists nil))
(kill-buffer buffer)) (kill-buffer buffer)))
(apply #'call-process esv-program nil buffer t (apply #'call-process esv-program nil buffer t arg-list)
(append arg-list (list book) (list verses)))
(display-buffer buffer) (display-buffer buffer)
(with-current-buffer buffer (with-current-buffer buffer
(esv-mode) (esv-mode)
(goto-char (point-min))) (goto-char (point-min)))
(set-window-start (get-buffer-window buffer) (point-min)) (set-window-start (get-buffer-window buffer) (point-min)))
t))) t)
(provide 'esv) (provide 'esv)