emacs/bible.el
2025-08-25 13:36:57 -05:00

184 lines
11 KiB
EmacsLisp

(defvar org-bible-directory "~/docs/bibles")
(defvar org-bible-books '("genesis" "exodus" "leviticus" "numbers" "dueteronomy" "joshua" "judges" "ruth" "1-samuel" "2-samuel" "1-kings" "2-kings" "1-chronicles" "2-chronicles" "ezra" "nehemiah" "esther" "job" "psalms" "proverbs" "ecclesiastes" "song-of-solomon" "isaiah" "jeremiah" "lamentations" "ezekiel" "daniel" "hosea" "joel" "amos" "obadiah" "jonah" "micah" "nahum" "habakkuk" "zephaniah" "haggai" "zechariah" "malachi" "matthew" "mark" "luke" "john" "acts" "romans" "1-corinthians" "2-corinthians" "galatians" "ephesians" "philipians" "colossians" "1-thessalonians" "2-thessalonians" "1-timothy" "2-timothy" "titus" "philemon" "hebrews" "james" "1-peter" "2-peter" "1-john" "2-john" "3-john" "jude" "revelation"))
(defvar org-bible-default "~/docs/bibles/esv.org")
(defvar org-bible-selected org-bible-default)
(defun org-bible-find-verse-imenu ()
"Using Imenu find the verse and jump to it using the default bible"
(interactive)
(find-file org-bible-selected)
(let ((location (list (imenu-choose-buffer-index))))
(imenu-default-goto-function nil (cdr (car location)))))
(defun org-bible-chapters (book)
"Get the chapters of the book in a list"
(save-excursion
(let ((book (org-bible-book-find book)))
(org-bible-children book))))
(defun org-bible-verses (chapter book)
"Get the verses of the chapter in a list"
(save-excursion
(let ((chapter (org-bible-chapter-find chapter book)))
(message "chapter: %s" chapter)
(org-bible-children chapter))))
(defun org-bible-children (item)
"Get the children of the current item in the form of a point"
(save-excursion
(org-with-wide-buffer
(goto-char item)
(when (org-goto-first-child)
(cl-loop collect (org-get-heading t t)
while (outline-get-next-sibling))))))
(defun org-bible-chapter-find (chapter book)
(let ((book (concat "* " (string-replace "-" " " book))))
(org-with-wide-buffer
(save-excursion
(widen)
(goto-char 1)
(search-forward book)
(search-forward chapter)
(point)))))
(defun org-bible-verse-find (verse chapter book)
(let ((book (concat "* " (string-replace "-" " " book))))
(org-with-wide-buffer
(save-excursion
(widen)
(goto-char 1)
(search-forward book)
(search-forward chapter)
(search-forward verse)
(point)))))
(defun org-bible-book-find (book)
(let ((book (concat "* " (string-replace "-" " " book))))
(org-with-wide-buffer
(save-excursion (widen)
(goto-char 1)
(search-forward book)
(point)))))
(defun org-bible-jump ()
"Jump to passage"
(interactive)
(with-current-buffer (find-file org-bible-selected)
(let* ((book (completing-read "Book: " org-bible-books))
(chapter (completing-read "Chapter: " (org-bible-chapters book)))
(verse (completing-read "Verse: " (org-bible-verses chapter book))))
(goto-char (org-bible-verse-find verse chapter book))
(beginning-of-line)
(pulsar-recenter-top))))
(defun org-bible-select ()
"Pick a different bible that is formatted in org-mode
If in a bible switch to the other version whilst keeping that position"
(interactive)
(let ((bible (completing-read "Pick a bible version: " '("ESV" "CSB" "NLT"))))
(cond ((string= bible "ESV") (setq org-bible-selected "~/docs/bibles/esv.org"))
((string= bible "CSB") (setq org-bible-selected "~/docs/bibles/csb.org"))
((string= bible "NLT") (setq org-bible-selected "~/docs/bibles/nlt.org")))
(if (or (string= (buffer-name) "csb.org")
(string= (buffer-name) "esv.org")
(string= (buffer-name) "nlt.org"))
(let* ((verse (search-backward "Verse" (beginning-of-line)))))
(find-file org-bible-selected))))
;; (define-minor-mode org-bible-mode
;; "Toggles the org bible minor mode"
;; nil
;; :global t
;; :lighter " bible")
;;; A helper function for creating org bibles from xml data
(defun org-bible-from-xml (&optional file)
"Get the bible from xml and render as org buffer"
(interactive)
(with-current-buffer (get-buffer-create "*nlt-bible*")
(insert-file "~/docs/bibles/Bible_English_NLT.xml")
(let ((bible (cddr (libxml-parse-xml-region))))
(erase-buffer)
(insert "#+title: NLT - New Living Translation Bible
#+description: The New Living Translation Bible formatted in Org syntax: Copyright © 2015 by Tyndale House.
#+STARTUP: hidedrawers
#+OPTIONS: ^:{}
")
(cl-loop for book in bible
do (progn (insert "* "
(cond
((string= (alist-get 'bnumber (cadr book)) "1") "Genesis")
((string= (alist-get 'bnumber (cadr book)) "2") "Exodus")
((string= (alist-get 'bnumber (cadr book)) "3") "Leviticus")
((string= (alist-get 'bnumber (cadr book)) "4") "Numbers")
((string= (alist-get 'bnumber (cadr book)) "5") "Dueteronomy")
((string= (alist-get 'bnumber (cadr book)) "6") "Joshua")
((string= (alist-get 'bnumber (cadr book)) "7") "Judges")
((string= (alist-get 'bnumber (cadr book)) "8") "Ruth")
((string= (alist-get 'bnumber (cadr book)) "9") "1 Samuel")
((string= (alist-get 'bnumber (cadr book)) "10") "2 Samuel")
((string= (alist-get 'bnumber (cadr book)) "11") "1 Kings")
((string= (alist-get 'bnumber (cadr book)) "12") "2 Kings")
((string= (alist-get 'bnumber (cadr book)) "13") "1 Chronicles")
((string= (alist-get 'bnumber (cadr book)) "14") "2 Chronicles")
((string= (alist-get 'bnumber (cadr book)) "15") "Ezra")
((string= (alist-get 'bnumber (cadr book)) "16") "Nehemiah")
((string= (alist-get 'bnumber (cadr book)) "17") "Esther")
((string= (alist-get 'bnumber (cadr book)) "18") "Job")
((string= (alist-get 'bnumber (cadr book)) "19") "Psalms")
((string= (alist-get 'bnumber (cadr book)) "20") "Proverbs")
((string= (alist-get 'bnumber (cadr book)) "21") "Ecclesiastes")
((string= (alist-get 'bnumber (cadr book)) "22") "Song of Solomon")
((string= (alist-get 'bnumber (cadr book)) "23") "Isaiah")
((string= (alist-get 'bnumber (cadr book)) "24") "Jeremiah")
((string= (alist-get 'bnumber (cadr book)) "25") "Lamentations")
((string= (alist-get 'bnumber (cadr book)) "26") "Ezekiel")
((string= (alist-get 'bnumber (cadr book)) "27") "Daniel")
((string= (alist-get 'bnumber (cadr book)) "28") "Hosea")
((string= (alist-get 'bnumber (cadr book)) "29") "Joel")
((string= (alist-get 'bnumber (cadr book)) "30") "Amos")
((string= (alist-get 'bnumber (cadr book)) "31") "Obadiah")
((string= (alist-get 'bnumber (cadr book)) "32") "Jonah")
((string= (alist-get 'bnumber (cadr book)) "33") "Micah")
((string= (alist-get 'bnumber (cadr book)) "34") "Nahum")
((string= (alist-get 'bnumber (cadr book)) "35") "Habakkuk")
((string= (alist-get 'bnumber (cadr book)) "36") "Zephaniah")
((string= (alist-get 'bnumber (cadr book)) "37") "Haggai")
((string= (alist-get 'bnumber (cadr book)) "38") "Zechariah")
((string= (alist-get 'bnumber (cadr book)) "39") "Malachi")
((string= (alist-get 'bnumber (cadr book)) "40") "Matthew")
((string= (alist-get 'bnumber (cadr book)) "41") "Mark")
((string= (alist-get 'bnumber (cadr book)) "42") "Luke")
((string= (alist-get 'bnumber (cadr book)) "43") "John")
((string= (alist-get 'bnumber (cadr book)) "44") "Acts")
((string= (alist-get 'bnumber (cadr book)) "45") "Romans")
((string= (alist-get 'bnumber (cadr book)) "46") "1 Corinthians")
((string= (alist-get 'bnumber (cadr book)) "47") "2 Corinthians")
((string= (alist-get 'bnumber (cadr book)) "48") "Galatians")
((string= (alist-get 'bnumber (cadr book)) "49") "Ephesians")
((string= (alist-get 'bnumber (cadr book)) "50") "Phillipians")
((string= (alist-get 'bnumber (cadr book)) "51") "Colossians")
((string= (alist-get 'bnumber (cadr book)) "52") "1 Thessalonians")
((string= (alist-get 'bnumber (cadr book)) "53") "2 Thessalonians")
((string= (alist-get 'bnumber (cadr book)) "54") "1 Timothy")
((string= (alist-get 'bnumber (cadr book)) "55") "2 Timothy")
((string= (alist-get 'bnumber (cadr book)) "56") "Titus")
((string= (alist-get 'bnumber (cadr book)) "57") "Philemon")
((string= (alist-get 'bnumber (cadr book)) "58") "Hebrews")
((string= (alist-get 'bnumber (cadr book)) "59") "James")
((string= (alist-get 'bnumber (cadr book)) "60") "1 Peter")
((string= (alist-get 'bnumber (cadr book)) "61") "2 Peter")
((string= (alist-get 'bnumber (cadr book)) "62") "1 John")
((string= (alist-get 'bnumber (cadr book)) "63") "2 John")
((string= (alist-get 'bnumber (cadr book)) "64") "3 John")
((string= (alist-get 'bnumber (cadr book)) "65") "Jude")
((string= (alist-get 'bnumber (cadr book)) "66") "Revelation"))
"\n")
(cl-loop for chapter in (cddr book)
do (progn (insert "** Chapter " (alist-get 'cnumber (cadr chapter)) "\n")
(cl-loop for verse in (cddr chapter)
do (insert "*** Verse " (alist-get 'vnumber (cadr verse)) "\n" (caddr verse) "\n")))))))))