bible.el 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. ;;; -*- mode: EMACS-LISP; lexical-binding: t -*-
  2. ;;
  3. ;; bible.el --- A browsing interface for the SWORD Project's Diatheke CLI
  4. ;;
  5. ;; Copyright (c) 2025 Fred Gilham
  6. ;; Author: Fred Gilham
  7. ;; URL: https://gitbot.homedns.org/fred/bible-mode
  8. ;; Version: 1.0.0
  9. ;; Keywords: files, text, hypermedia
  10. ;; Package-Requires: ((emacs "29.1"))
  11. ;;; Commentary:
  12. ;; Forked and extensively modified from package by Zacalot
  13. ;; Url: https://github.com/Zacalot/bible-mode
  14. ;; This package uses the `diatheke' program to browse and search
  15. ;; Biblical texts provided by the Sword project.
  16. ;; Word study is also supported.
  17. ;;; Usage:
  18. ;; Use M-x `bible-open' to open a Bible buffer.
  19. ;; Use C-h f `bible' to see available keybindings.
  20. ;; The program also installs a Bible menu with keybindings and other
  21. ;; commands.
  22. ;; You may customize `bible-module' to set a default browsing
  23. ;; module, as well as `bible-word-study-enabled' to enable word
  24. ;; study by default.
  25. ;;; Design:
  26. ;; The idea here is to use the diatheke program to insert text from
  27. ;; modules into buffers. The main bible display uses an "internal" XML
  28. ;; format. The whole buffer gets parsed by libxml-parse-html-region to
  29. ;; create a dom tree. This gets parsed by
  30. ;; bible--insert-domnode-recursive to render the text into
  31. ;; reading format.
  32. ;; The text is then decorated using information from the dom format as
  33. ;; necessary along with regular expressions to identify the verse
  34. ;; references. This is for red letters, purple highlighting of the
  35. ;; verse numbers, bold face of the divine name in the OT and so on.
  36. ;; If Strongs tags and/or morphological tags are present, they are
  37. ;; looked up in appropriate lexical and morphological modules and used
  38. ;; to add tooltips to the text so that mousing over words will bring
  39. ;; up a tooltip with information about the word. Clicking on a word
  40. ;; with lexical information will display that informatio in a "term"
  41. ;; buffer.
  42. ;;; Code:
  43. ;;;; Requirements
  44. (require 'dom)
  45. (require 'shr)
  46. ;; Turn off tool bar mode because we are greedy for pixels....
  47. (tool-bar-mode -1)
  48. ;;;; Variables
  49. (defgroup bible nil
  50. "Settings for `bible'."
  51. :group 'tools
  52. :link '(url-link "https://gitbot.homedns.org/fred/bible-mode"))
  53. (defcustom bible-module
  54. "KJV"
  55. "Book module for Diatheke to query."
  56. :type '(choice (const :tag "None" nil)
  57. (string :tag "Module abbreviation (e.g. \"KJV\")"))
  58. ;; :local t
  59. :group 'bible)
  60. ;;;
  61. ;;; XXX Not implememted yet
  62. (defcustom bible-font
  63. "Ezra SIL"
  64. "Default font for bible."
  65. :type '(string :tag "Font family name (e.g. \"Ezra SIL\")")
  66. :local t
  67. :group 'bible)
  68. (defcustom bible-sword-query
  69. "/usr/local/bin/diatheke"
  70. "Program used to query sword modules---some version of diatheke."
  71. :type '(string :tag "Sword library query executable (e.g. \"/usr/local/bin/diatheke\").")
  72. :local nil
  73. :group 'bible)
  74. (defcustom bible-greek-lexicon
  75. ;; AbbottSmithStrongs now has both links to lemmas and definitions
  76. ;; keyed by lemma. So we only need the AbbottSmithStrongs lexicon
  77. ;; and not the AbbottSmith lexicon.
  78. "AbbottSmithStrongs"
  79. "Lexicon used for displaying definitions of Greek words using Strong's codes."
  80. :type '(string :tag "Lexicon module (e.g. \"StrongsRealGreek\").")
  81. :local nil
  82. :group 'bible)
  83. (defcustom bible-use-index-for-lexicon t
  84. "Some lexicons are accessed by lemmas rather than Strong's numbers.
  85. Use an index to look up lemmas from Strong's numbers so these lexicons
  86. can be used. XXX AbbottSmithStrongs now has both links and complete
  87. entries instead of just links."
  88. :type 'boolean
  89. :local nil
  90. :group 'bible)
  91. (defcustom bible-lexicon-index "AbbottSmithStrongs"
  92. "A module that consists of an index mapping Strong's numbers to Greek lemmas.
  93. The code is written to use the entries in AbbottSmithStrongs
  94. which are of the form
  95. <strong's number>: @LINK <greek lemma>"
  96. :type '(string :tag "Lexicon index.")
  97. :local nil
  98. :group 'bible)
  99. (defcustom bible-greek-lexicon-short
  100. "StrongsRealGreek"
  101. "Lexicon used for displaying definitions of Greek words in tooltips."
  102. :type '(string :tag "Lexicon module (e.g. \"StrongsRealGreek\").")
  103. :local nil
  104. :group 'bible)
  105. ;;; XXX The Hebrew lexicons differ on whether they accept keys of the
  106. ;;; form `Hnnnn' or `nnnn'. The code does not yet handle this
  107. ;;; correctly, so stick with the following.
  108. (defcustom bible-hebrew-lexicon
  109. "BDBGlosses_Strongs" ; This seems to work
  110. "Lexicon used for displaying definitions of Hebrew words using Strong's codes."
  111. :type '(string :tag "Lexicon module (e.g. \"StrongsRealHebrew\")")
  112. :local nil
  113. :group 'bible)
  114. (defcustom bible-hebrew-lexicon-short
  115. "StrongsRealHebrew"
  116. ;; "NASHebrew"
  117. "Lexicon used for displaying definitions of Hebrew words in tooltips."
  118. :type '(string :tag "Lexicon module (e.g. \"StrongsRealHebrew\")")
  119. :local nil
  120. :group 'bible)
  121. (defcustom bible-word-study-enabled
  122. nil
  123. "Display Strong's Hebrew, Strong's Greek, and Lemma words for study."
  124. :type 'boolean
  125. :local t
  126. :group 'bible)
  127. (defcustom bible-red-letter-enabled
  128. t
  129. "Display words of Jesus in red when module has that information."
  130. :type 'boolean
  131. :local t
  132. :group 'bible)
  133. (defcustom bible-show-diatheke-exec
  134. t
  135. "Show the arguments by which diatheke is executed."
  136. :type 'boolean
  137. :local nil
  138. :group 'bible)
  139. ;;; variable defs
  140. (defconst bible--verse-regexp "\\(I \\|1 \\|II \\|2 \\|III \\|3 \\)??[a-zA-Z]+?[ \t\n][0-9]+[:][0-9]+")
  141. (defvar bible--modules (lazy-completion-table bible--modules bible--list-biblical-modules))
  142. ;; XXX I believe these chapter counts aren't the same for all modules, e.g. JPS.
  143. (defvar bible--books
  144. '(;; Old Testament
  145. ("Genesis" . 50) ("Exodus" . 40) ("Leviticus" . 27) ("Numbers" . 36)
  146. ("Deuteronomy" . 34) ("Joshua" . 24) ("Judges" . 21) ("Ruth" . 4)
  147. ("I Samuel" . 31) ("II Samuel" . 24) ("I Kings" . 22) ("II Kings" . 25)
  148. ("1 Samuel" . 31) ("2 Samuel" . 24) ("1 Kings" . 22) ("2 Kings" . 25)
  149. ("I Chronicles" . 29) ("II Chronicles" . 36) ("Ezra" . 10) ("Nehemiah" . 13)
  150. ("1 Chronicles" . 29) ("2 Chronicles" . 36)
  151. ("Ezra" . 10) ("Nehemiah" . 13)
  152. ("Esther" . 10) ("Job" . 42) ("Psalms" . 150) ("Proverbs" . 31)
  153. ("Ecclesiastes" . 12) ("Song of Solomon" . 8) ("Isaiah" . 66) ("Jeremiah" . 52)
  154. ("Lamentations" . 5) ("Ezekiel" . 48) ("Daniel" . 12) ("Hosea" . 14)
  155. ("Joel" . 3) ("Amos" . 9) ("Obadiah" . 1) ("Jonah" . 4)
  156. ("Micah" . 7) ("Nahum" . 3) ("Habakkuk" . 3) ("Zephaniah" . 3)
  157. ("Haggai" . 2) ("Zechariah" . 14) ("Malachi" . 4)
  158. ;; New Testament
  159. ("Matthew" . 28) ("Mark" . 16) ("Luke" . 24) ("John" . 21)
  160. ("Acts" . 28) ("Romans" . 16)
  161. ("I Corinthians" . 16) ("II Corinthians" . 13)
  162. ("1 Corinthians" . 16) ("2 Corinthians" . 13)
  163. ("Galatians" . 6) ("Ephesians" . 6) ("Philippians" . 4) ("Colossians" . 4)
  164. ("I Thessalonians" . 5) ("II Thessalonians" . 3) ("I Timothy" . 6) ("II Timothy" . 4)
  165. ("1 Thessalonians" . 5) ("2 Thessalonians" . 3) ("1 Timothy" . 6) ("2 Timothy" . 4)
  166. ("Titus" . 3) ("Philemon" . 1) ("Hebrews" . 13) ("James" . 5)
  167. ("I Peter" . 5) ("II Peter" . 3) ("I John" . 5) ("II John" . 1)
  168. ("1 Peter" . 5) ("2 Peter" . 3) ("1 John" . 5) ("2 John" . 1)
  169. ("III John" . 1) ("Jude" . 1) ("Revelation of John" . 22)
  170. ("3 John" . 1))
  171. "A-list of name / chapter count for Bible books.")
  172. (defvar bible--book-name-abbreviations-alist
  173. '(;; Old Testament
  174. ("Ge" . "Genesis") ("Ex" . "Exodus") ("Le" . "Leviticus") ("Nu" . "Numbers")
  175. ("De" . "Deuteronomy") ("Js" . "Joshua") ("Jg" . "Judges") ("Judg" . "Judges")
  176. ("Ru" . "Ruth") ("1 Samuel" . "I Samuel") ("I Sa" . "I Samuel") ("1 Sa" . "I Samuel")
  177. ("2 Samuel" . "II Samuel") ("II Sa" . "II Samuel") ("2 Sa" . "II Samuel") ("1 Kings" . "I Kings")
  178. ("I Ki" . "I Kings") ("1 Ki" . "I Kings") ("2 Kings" . "II Kings") ("II Ki" . "II Kings")
  179. ("2 Ki" . "II Kings") ("1 Chronicles" . "I Chronicles") ("I Ch" . "I Chronicles") ("1 Ch" . "I Chronicles")
  180. ("2 Chronicles" . "II Chronicles") ("II Ch" . "II Chronicles") ("2 Ch" . "II Chronicles")
  181. ("Ezr" . "Ezra") ("Ne" . "Nehemiah")
  182. ("Es" . "Esther") ("Jb" . "Job") ("Ps" . "Psalms") ("Pr" . "Proverbs")
  183. ("Ec" . "Ecclesiastes") ("So" . "Song of Solomon") ("Is" . "Isaiah") ("Je" . "Jeremiah")
  184. ("La" . "Lamentations") ("Ez" . "Ezekiel") ("Da" . "Daniel") ("Ho" . "Hosea")
  185. ("Joe" . "Joel") ("Am" . "Amos") ("Ob" . "Obadiah") ("Jon" . "Jonah")
  186. ("Mi" . "Micah") ("Na" . "Nahum") ("Ha" . "Habakkuk") ("Zep" . "Zephaniah")
  187. ("Hag" . "Haggai") ("Ze" . "Zechariah") ("Mal" . "Malachi")
  188. ;; New Testament
  189. ;; Added AbbottSmith lexicon abbreviations to allow proper following of cross references in lexicon buffers.
  190. ("Mt" . "Matthew") ("Matt" . "Matthew")
  191. ("Mk" . "Mark") ("Lk" . "Luke") ("Jo" . "John") ("Ac" . "Acts")
  192. ("Ro" . "Romans") ("Rom" . "Romans")
  193. ("1 Corintihans" . "I Corinthians") ("I Co" . "I Corinthians") ("1 Co" . "I Corinthians") ("ICor" . "I Corinthians")
  194. ("2 Corinthians" . "II Corinthians") ("II Co" . "II Corinthians") ("2 Co" . "II Corinthians") ("IICor" . "II Corinthians")
  195. ("Ga" . "Galatians") ("Gal" . "Galatians")
  196. ("Eph" . "Ephesians")
  197. ("Phl" . "Philippians") ("Phil" . "Philippians")
  198. ("Col" . "Colossians")
  199. ("1 Thessalonians" . "I Thessalonians") ("I Th" . "I Thessalonians") ("1 Th" . "I Thessalonians") ("IThess" . "I Thessalonians")
  200. ("2 Thessalonians" . "II Thessalonians") ("II Th" . "II Thessalonians") ("2 Th" . "II Thessalonians") ("IIThess" . "II Thessalonians")
  201. ("1 Timothy" . "I Timothy") ("I Ti" . "I Timothy") ("1 Ti" . "I Timothy") ("ITim" . "I Timothy")
  202. ("2 Timothy" . "II Timothy") ("II Ti" . "II Timothy") ("2 Ti" . "II Timothy") ("IITim" . "II Timothy")
  203. ("Tit" . "Titus")
  204. ("Phm" . "Philemon") ("Phlm" . "Philemon")
  205. ("He" . "Hebrews") ("Heb" . "Hebrews")
  206. ("Ja" . "James") ("Jas" . "James")
  207. ("1 Peter" . "I Peter") ("I Pe" . "I Peter") ("1 Pe" . "I Peter")
  208. ("2 Peter" . "II Peter") ("II Pe" . "II Peter") ("2 Pe" . "II Peter") ("IIPet" . "II Peter")
  209. ("1 John" . "I John") ("I Jo" . "I John") ("1 Jo" . "I John") ("IJohn" . "I John")
  210. ("2 John" . "II John") ("II Jo" . "II John") ("2 Jo" . "II John") ("IIJohn" . "II John")
  211. ("3 John" . "III John") ("III Jo" . "III John") ("3 Jo" . "III John") ("IIIJohn" . "III John")
  212. ("Ju" . "Jude")
  213. ("Re" . "Revelation of John") ("Rev" . "Revelation of John"))
  214. "A-list of abbreviations for Bible books.")
  215. ;;;; Book / chapter
  216. (defvar-local bible--current-book (assoc "Genesis" bible--books)
  217. "Current book data (name . chapter).")
  218. (defvar-local bible--current-book-name "Genesis"
  219. "Current book name.")
  220. (defvar-local bible--current-chapter 1
  221. "Current book chapter number.")
  222. (defvar-local bible-query nil
  223. "Search query associated with the buffer.")
  224. (defvar-local bible-search-mode "phrase"
  225. "Search mode: either `lucene', `phrase', `regex' or `multiword'.")
  226. (defvar bible-search-range nil)
  227. (defvar-local bible-has-lexemes nil
  228. "Set if the module being displayed has lexical entries availabile.")
  229. (defvar-local bible-has-morphology nil
  230. "Set if the module being displayed has morphology availabile.")
  231. ;;;; Keymaps
  232. ;;;; N.B. Bible menu items appear in reverse order of their
  233. ;;;; definition below
  234. (defconst bible-map (make-sparse-keymap)
  235. "Keymap for bible.")
  236. (define-key bible-map [menu-bar bible]
  237. (cons "Bible" (make-sparse-keymap "Bible")))
  238. (define-key bible-map
  239. [menu-bar bible toggle-debug]
  240. '("Toggle debug-on-error" . toggle-debug-on-error))
  241. (defun bible-toggle-display-diatheke ()
  242. "Toggle diatheke args display."
  243. (interactive)
  244. (setq bible-show-diatheke-exec (not bible-show-diatheke-exec)))
  245. (define-key bible-map
  246. [menu-bar bible display-diatheke]
  247. '("Toggle diatheke display" . bible-toggle-display-diatheke))
  248. (defun bible-toggle-display-xml ()
  249. "Toggle XML display."
  250. (interactive)
  251. (setq-local bible-debugme (not bible-debugme))
  252. (bible--display))
  253. (define-key bible-map "d" 'bible-toggle-display-xml)
  254. (define-key bible-map
  255. [menu-bar bible display-xml]
  256. '("Toggle XML Display" . bible-toggle-display-xml))
  257. (define-key bible-map
  258. [menu-bar bible sep]
  259. '(menu-item '"--"))
  260. ;;;;; Misc
  261. (define-key bible-map "m" 'bible-select-module)
  262. (define-key bible-map "w" 'bible-toggle-word-study)
  263. (define-key bible-map "l" 'bible-toggle-red-letter)
  264. (define-key bible-map "x" 'bible-split-display)
  265. (define-key bible-map
  266. [menu-bar bible split-display]
  267. '("Split Display" . bible-split-display))
  268. ;;;;; Search
  269. (define-key bible-map "/" 'bible-search)
  270. (define-key bible-map "s" 'bible-search)
  271. (define-key bible-map
  272. [menu-bar bible search]
  273. '("Search" . bible-search))
  274. (define-key bible-map "r" 'bible-set-search-range)
  275. (define-key bible-map
  276. [menu-bar bible range]
  277. '("Set Search Range" . bible-set-search-range))
  278. ;;;;; Navigation
  279. (define-key bible-map "p" 'bible-previous-chapter)
  280. (define-key bible-map
  281. [menu-bar bible previous-chapter]
  282. '("Previous Chapter" . bible-previous-chapter))
  283. (define-key bible-map "n" 'bible-next-chapter)
  284. (define-key bible-map
  285. [menu-bar bible next-chapter]
  286. '("Next Chapter" . bible-next-chapter))
  287. (define-key bible-map (kbd "TAB") 'bible-next-word)
  288. (define-key bible-map (kbd "M-<tab>") 'bible-previous-word)
  289. ;;;;; Direct jump
  290. (define-key bible-map "c" 'bible-select-chapter)
  291. (define-key bible-map
  292. [menu-bar bible select-chapter]
  293. '("Select Chapter" . bible-select-chapter))
  294. (define-key bible-map "b" 'bible-select-book)
  295. (define-key bible-map
  296. [menu-bar bible select-book]
  297. '("Select Book" . bible-select-book))
  298. (define-key bible-map
  299. [menu-bar bible sep]
  300. '(menu-item '"--"))
  301. ;;;;; Deal with visual-line-mode
  302. (define-key bible-map "\C-n" 'next-logical-line)
  303. (define-key bible-map "\C-p" 'previous-logical-line)
  304. (defun bible-next-search-item ()
  305. "Go to next item in list of found verses."
  306. (interactive)
  307. (search-forward-regexp bible--verse-regexp))
  308. (defun bible-previous-search-item ()
  309. "Go to previous item in list of found verses."
  310. (interactive)
  311. (search-backward-regexp bible--verse-regexp))
  312. (defconst bible-search-mode-map (make-keymap))
  313. (define-key bible-search-mode-map "s" 'bible-search)
  314. (define-key bible-search-mode-map "w" 'bible-toggle-word-study)
  315. (define-key bible-search-mode-map "n" 'bible-next-search-item)
  316. (define-key bible-search-mode-map "p" 'bible-previous-search-item)
  317. (define-key bible-search-mode-map (kbd "RET") 'bible-search-mode-follow-verse)
  318. (defconst bible-term-hebrew-mode-map (make-sparse-keymap))
  319. (defconst bible-term-greek-mode-map (make-sparse-keymap))
  320. (define-key bible-term-greek-mode-map [mouse-1] 'bible-search-mode-follow-xref)
  321. ;;;
  322. ;;; Menu bar items
  323. ;;;
  324. (defvar-local bible-text-direction 'left-to-right)
  325. (defun bible-toggle-text-direction ()
  326. "Switch between left-to-right and right-to-left text direction."
  327. (interactive)
  328. (if (eq bible-text-direction 'left-to-right)
  329. (setq-local bible-text-direction 'right-to-left)
  330. (setq-local bible-text-direction 'left-to-right))
  331. (setq-local bidi-paragraph-direction bible-text-direction))
  332. (defvar-local bible-debugme nil
  333. "Make text show up as XML when set.")
  334. (defvar-local bible-search-query nil
  335. "Query used in toggles (word study and red letter).")
  336. (defvar bible-use-tooltips t)
  337. (setq tooltip-delay 1)
  338. (setq tooltip-short-delay .5)
  339. (setq use-system-tooltips nil)
  340. (defun bible-toggle-tooltips ()
  341. "Toggle use of tooltips to display lexical/morphological items."
  342. (interactive)
  343. (setq bible-use-tooltips (not bible-use-tooltips))
  344. (tooltip-mode 'toggle)
  345. (setq tooltip-resize-echo-area bible-use-tooltips))
  346. (define-key bible-map
  347. [menu-bar bible sepp]
  348. '(menu-item '"--"))
  349. (define-key bible-map
  350. [menu-bar bible toggle-text-direction]
  351. '("Toggle text direction (for Hebrew display)" . bible-toggle-text-direction))
  352. (define-key bible-map
  353. [menu-bar bible toggle-tooltip-display]
  354. '("Toggle Tooltip Display" . bible-toggle-tooltips))
  355. (define-key bible-map
  356. [menu-bar bible sepp]
  357. '(menu-item '"--"))
  358. (define-key bible-map
  359. [menu-bar bible select-biblical-text]
  360. '("Select Module" . bible-display-available-modules))
  361. (defun bible--display-greek ()
  362. "Display Greek text.
  363. This command is run by clicking on text, not directly by the user."
  364. (interactive)
  365. (let ((item (car (split-string (get-text-property (point) 'strong)))))
  366. ;; Remove "strong:G" prefix
  367. (bible-term-greek (replace-regexp-in-string "strong:G" "" item))))
  368. (defconst bible-greek-keymap (make-sparse-keymap))
  369. (define-key bible-greek-keymap (kbd "RET") 'bible--display-greek)
  370. (define-key bible-greek-keymap [mouse-1] 'bible--display-greek)
  371. (defun bible--display-hebrew ()
  372. "Display Hebrew text.
  373. This command is run by clicking on text, not directly by the user."
  374. (interactive)
  375. (let ((item (car (split-string (get-text-property (point) 'strong)))))
  376. ;; Remove "strong:H" prefix and any alphabetic suffixes.
  377. (bible-term-hebrew (replace-regexp-in-string "strong:H" "" item))))
  378. (defconst bible-hebrew-keymap (make-sparse-keymap))
  379. (define-key bible-hebrew-keymap (kbd "RET") 'bible--display-hebrew)
  380. (define-key bible-hebrew-keymap [mouse-1] 'bible--display-hebrew)
  381. (defconst bible-lemma-keymap (make-sparse-keymap))
  382. (define-key bible-lemma-keymap (kbd "RET")
  383. (lambda ()
  384. (interactive)))
  385. ;; Not used. Not really sure what to do here or if it's useful to do anything.
  386. (defconst bible-morph-keymap (make-sparse-keymap))
  387. (define-key bible-morph-keymap (kbd "RET")
  388. (lambda ()
  389. (interactive)
  390. ;;; (let ((thing (thing-at-point 'word)))
  391. ;;; (message "thing at point: %s" thing)
  392. ;;; (message "morph property %s" (get-text-property 0 'field thing))
  393. ))
  394. ;;;; Modes
  395. (define-derived-mode bible special-mode "Bible"
  396. "Mode for reading the Bible.
  397. \\{bible-map}"
  398. (buffer-disable-undo)
  399. (font-lock-mode t)
  400. (use-local-map bible-map)
  401. (setq buffer-read-only t)
  402. (visual-line-mode t))
  403. (define-derived-mode bible-search-mode special-mode "Bible Search"
  404. "Mode for performing Bible searches.
  405. \\{bible-search-mode-map}"
  406. (buffer-disable-undo)
  407. (font-lock-mode t)
  408. (use-local-map bible-search-mode-map)
  409. (setq buffer-read-only t)
  410. (visual-line-mode t))
  411. (define-derived-mode bible-term-hebrew-mode special-mode "Bible Term (Hebrew)"
  412. "Mode for researching Hebrew terms in the Bible.
  413. \\{bible-term-hebrew-mode-map}"
  414. (buffer-disable-undo)
  415. (font-lock-mode t)
  416. (use-local-map bible-term-hebrew-mode-map)
  417. (setq buffer-read-only t)
  418. (visual-line-mode t))
  419. (define-derived-mode bible-term-greek-mode special-mode "Bible Term (Greek)"
  420. "Mode for researching Greek terms in the Bible.
  421. \\{bible-term-greek-mode-map}"
  422. (buffer-disable-undo)
  423. (font-lock-mode t)
  424. (use-local-map bible-term-greek-mode-map)
  425. (setq buffer-read-only t)
  426. (visual-line-mode t))
  427. (define-derived-mode bible-module-select-mode special-mode "Select Text Module"
  428. (buffer-disable-undo)
  429. (font-lock-mode t)
  430. (setq buffer-read-only t))
  431. ;;;; Functions
  432. ;;;;; Commands
  433. (defun bible-open (&optional book-name chapter verse)
  434. "Create and open a `bible' buffer with BOOK-NAME, CHAPTER and VERSE.
  435. Arguments BOOK-NAME, CHAPTER and VERSE, when supplied, give the starting
  436. verse reference for the buffer. If no optional arguments are supplied,
  437. Genesis 1:1 is used."
  438. (interactive)
  439. (with-current-buffer (get-buffer-create (generate-new-buffer-name (concat "*bible*")))
  440. (bible)
  441. (bible--set-location
  442. (or (assoc (or book-name "Genesis") bible--books) (list book-name))
  443. (or chapter 1)
  444. verse)
  445. (set-window-buffer (get-buffer-window (current-buffer)) (current-buffer))))
  446. (defun bible-next-chapter ()
  447. "Page to the next chapter for the active `bible' buffer."
  448. (interactive)
  449. (let* ((book-chapters (cdr bible--current-book))
  450. (chapter (min book-chapters (+ bible--current-chapter 1))))
  451. (bible--set-location bible--current-book chapter)))
  452. (defun bible-previous-chapter ()
  453. "Page to the previous chapter for the active `bible' buffer."
  454. (interactive)
  455. (bible--set-location bible--current-book (max 1 (- bible--current-chapter 1))))
  456. (defun bible-next-word ()
  457. "Move forward a word, taking into account the relevant text properties."
  458. (interactive)
  459. (unless (eobp)
  460. (let ((next-change (text-property-search-forward 'strong nil nil t)))
  461. (when next-change
  462. (goto-char (1- (prop-match-end next-change)))))))
  463. (defun bible-previous-word ()
  464. "Move back a word, taking into account the relevant text properties."
  465. (interactive)
  466. (unless (bobp)
  467. (let ((previous-change (text-property-search-backward 'strong)))
  468. (when previous-change
  469. (goto-char (prop-match-beginning previous-change))))))
  470. (defun bible-select-book ()
  471. "Ask user for a new book and chapter for the current `bible' buffer."
  472. (interactive)
  473. (let* ((completion-ignore-case t)
  474. (book-data (assoc (completing-read "Book: " bible--books nil t) bible--books))
  475. (book-data-string (car book-data))
  476. (chapter (string-to-number (completing-read "Chapter [1]: " (bible--list-number-range 1 (cdr book-data)) nil t nil nil "1"))))
  477. (pcase (aref book-data-string 0)
  478. (?1 (setq book-data (cons (concat "I" (substring book-data-string 1)) (cdr book-data))))
  479. (?2 (setq book-data (cons (concat "II" (substring book-data-string 1)) (cdr book-data))))
  480. (?3 (setq book-data (cons (concat "III" (substring book-data-string 1)) (cdr book-data)))))
  481. (setq-local bible--current-book book-data)
  482. (setq-local bible--current-book-name (car book-data))
  483. (setq-local bible--current-chapter chapter)
  484. (bible--display)))
  485. (defun bible-select-chapter ()
  486. "Ask user for a new chapter for the current `bible' buffer."
  487. (interactive)
  488. (let* ((book-chapters (cdr bible--current-book))
  489. (chapter (string-to-number (completing-read "Chapter [1]: " (bible--list-number-range 1 book-chapters) nil t nil nil "1"))))
  490. (when chapter
  491. (bible--set-location bible--current-book chapter))))
  492. (defun bible-set-search-range ()
  493. "Ask user for a new text module for the current `bible' buffer."
  494. (interactive)
  495. (let ((range (read-string "Range (<return> to clear): ")))
  496. (if (string-equal range "")
  497. (setq bible-search-range nil)
  498. (setq bible-search-range range))))
  499. (defun bible-select-module ()
  500. "Ask user for a new text module for the current `bible' buffer."
  501. (interactive)
  502. (setq-default bible-module (completing-read "Module: " bible--modules))
  503. (bible--display))
  504. (defun bible-toggle-word-study ()
  505. "Toggle the inclusion of word study for the active `bible' buffer."
  506. (interactive)
  507. (setq bible-word-study-enabled (not bible-word-study-enabled))
  508. (bible--display))
  509. (defun bible-toggle-red-letter ()
  510. "Toggle red letter mode for the active `bible' buffer."
  511. (interactive)
  512. (setq bible-red-letter-enabled (not bible-red-letter-enabled))
  513. (bible--display))
  514. (defun bible-split-display ()
  515. "Copy the active `bible' buffer into a new buffer in another window."
  516. (interactive)
  517. (split-window-right)
  518. (balance-windows)
  519. (other-window 1)
  520. (bible-open bible--current-book-name bible--current-chapter))
  521. (defun bible-search (query)
  522. "Search for a QUERY: a word or phrase.
  523. Asks the user for type of search: either `lucene', `phrase', `regex'
  524. or `multiword'. `lucene' is the default search.
  525. `lucene' mode requires an index to be built using the `mkfastmod' program."
  526. (interactive "sBible Search: ")
  527. (when (> (length query) 0)
  528. (let* ((bible-module (buffer-local-value 'bible-module (current-buffer)))
  529. (searchmode (completing-read "Search Mode: " '("lucene" "phrase" "regex" "multiword") nil t "lucene")))
  530. (bible--open-search query searchmode))))
  531. (defun bible-search-mode-follow-verse ()
  532. "Follow the hovered verse in a `bible-search-mode' buffer.
  533. Create a new `bible' buffer positioned at the selected verse."
  534. (interactive)
  535. (let* ((text (thing-at-point 'line t))
  536. book
  537. chapter
  538. verse)
  539. (string-match ".+ [0-9]?[0-9]?[0-9]?:[0-9]?[0-9]?[0-9]?:" text)
  540. (setq text (match-string 0 text))
  541. (string-match " [0-9]?[0-9]?[0-9]?:" text)
  542. (setq chapter (replace-regexp-in-string "[^0-9]" "" (match-string 0 text)))
  543. (string-match ":[0-9]?[0-9]?[0-9]?" text)
  544. (setq verse (replace-regexp-in-string "[^0-9]" "" (match-string 0 text)))
  545. (setq book (replace-regexp-in-string "[ ][0-9]?[0-9]?[0-9]?:[0-9]?[0-9]?[0-9]?:$" "" text))
  546. (bible-open (string-trim book) (string-to-number chapter) (string-to-number verse))))
  547. (defun bible-search-mode-follow-xref ()
  548. "Follow the hovered verse in a bible term buffer.
  549. Create a new `bible' buffer positioned at the specified verse.
  550. XXX We use the current module to avoid opening cans of worms regarding
  551. OT/NT etc. If that module doesn't have that verse...???
  552. Handle abbreviations from lexicon module (AbbottSmith)."
  553. (interactive)
  554. (let* ((xref (get-text-property (point) 'xref))
  555. (verse-ref (split-string xref))
  556. book-abbrev
  557. book
  558. chapter-verse
  559. chapter
  560. verse)
  561. (if (= (length verse-ref) 3) ; II Cor 3:17 or the like
  562. (setq book-abbrev (concat (car verse-ref) (cadr verse-ref))
  563. chapter-verse (split-string (caddr verse-ref) ":"))
  564. ;; Mat 5 or the like
  565. (setq book-abbrev (car verse-ref)
  566. chapter-verse (split-string (cadr verse-ref) ":")))
  567. (setq book (cdr (assoc book-abbrev bible--book-name-abbreviations-alist)))
  568. (unless book (setq book (car verse-ref))) ; Didn't find abbreviation
  569. (setq chapter (car chapter-verse)
  570. verse (cadr chapter-verse))
  571. (bible-open (string-trim book) (string-to-number chapter) (string-to-number verse))))
  572. ;;; These can be called interactively if you know the Strong's number
  573. ;;; you want to look up.
  574. (defun bible-term-hebrew (term)
  575. "Query user for a Strong's Hebrew Lexicon TERM."
  576. (interactive "sTerm: ")
  577. (bible--open-term-hebrew term))
  578. (defun bible-term-greek (term)
  579. "Query user for a Strong's Greek Lexicon TERM."
  580. (interactive "sTerm: ")
  581. (bible--open-term-greek term))
  582. ;;; Interactively insert a verse into an arbitrary current buffer.
  583. (defun bible-insert ()
  584. "Query user to select a verse for insertion into the current buffer."
  585. (interactive)
  586. (let* ((completion-ignore-case t)
  587. (book-data (assoc (completing-read "Book: " bible--books nil t) bible--books))
  588. (chapter (when book-data (completing-read "Chapter: " (bible--list-number-range 1 (cdr book-data)) nil t "1" nil "1")))
  589. (verse (when chapter (read-from-minibuffer "Verse: ")))
  590. (query (concat (car book-data) " " chapter ":" verse))
  591. (args (list bible-sword-query nil (current-buffer) t "-b" bible-module "-f" "plain" "-k" query)))
  592. (apply 'call-process args)))
  593. ;;;;; Support
  594. (defconst bible-diatheke-filter-options " avlnmw")
  595. ;;;; XXX
  596. ;;;; Can we avoid returning (buffer-string) and just return the buffer?
  597. ;;;;
  598. (defun bible--exec-diatheke (query &optional filter format module)
  599. "Execute `diatheke' with specified QUERY options, returning output
  600. buffer. FILTER is the Diatheke filter argument. FORMAT is either plain
  601. or the default of internal. MODULE is the text module to use."
  602. (let ((module (or module bible-module)))
  603. (with-temp-buffer
  604. (let ((args (list bible-sword-query nil (current-buffer) t "-b" module)))
  605. (if filter
  606. (setq filter (concat filter bible-diatheke-filter-options))
  607. (setq filter bible-diatheke-filter-options))
  608. (setq args (append args (list "-o" filter)))
  609. (setq args (append args (list "-f" (pcase format ("plain" "plain") (_ "internal")) "-k" query)))
  610. (when bible-show-diatheke-exec
  611. (message "%s" args))
  612. (apply 'call-process args))
  613. (buffer-string))))
  614. (defun bible--diatheke-search (query searchtype &optional format module)
  615. "Execute `diatheke' for searches. Requires the search query and the
  616. search type. Optional argument FORMAT is either plain or the default of
  617. internal. MODULE is the text module to use and defaults to the current
  618. module."
  619. (with-temp-buffer
  620. (let ((args (list bible-sword-query nil (current-buffer) t "-b" (or module bible-module))))
  621. (setq args (append args (list "-s" (pcase searchtype
  622. ("lucene" "lucene")
  623. ("phrase" "phrase")
  624. ("regex" "regex")
  625. ("multiword" "multiword")))))
  626. (when bible-search-range (setq args (append args (list "-r" bible-search-range))))
  627. (setq args (append args (list "-f" (pcase format ("plain" "plain") (_ "internal")) "-k" query)))
  628. (when bible-show-diatheke-exec
  629. (message "%s" args))
  630. (apply 'call-process args))
  631. (buffer-string)))
  632. ;;; XXX Bible chapter titles mostly appear in Psalms. This code works
  633. ;;; OK except for Psalm 119 which uses the chapter title as a heading
  634. ;;; for each verse of the psalm.
  635. ;;;
  636. ;;; Chapter titles seem to be part of each verse in the modules I saw.
  637. ;;;
  638. ;;; Fixing this issue would require keeping track of the current
  639. ;;; chapter title and emitting the title whenever it changed. Since
  640. ;;; there is (AFAIK) only one chapter in the Bible that has this
  641. ;;; issue, it doesn't seem like a high priority now.
  642. (defvar-local bible-chapter-title nil
  643. "Text preceding start of chapter.
  644. Mostly in Psalms, like `Of David' or the like.")
  645. ;;;
  646. ;;; Greek and Hebrew lexicon and morphology tooltip rendering.
  647. ;;;
  648. ;;; Hash tables for Lexical definitions.
  649. (defvar bible-hash-greek (make-hash-table :test 'equal :size 10000))
  650. (defvar bible-hash-hebrew (make-hash-table :test 'equal :size 10000))
  651. ;;; Hash tables for tooltips.
  652. (defvar lex-hash (make-hash-table :test 'equal :size 10000))
  653. (defvar morph-hash (make-hash-table :test 'equal :size 10000))
  654. ;;; Use HTMLHREF format with diatheke, post-process to render html.
  655. (defun bible--morph-query (query module)
  656. "Execute `diatheke' to do morph QUERY, using MODULE.
  657. Render HTML, return string. Do some tweaking specific to morphology."
  658. (with-temp-buffer
  659. (let ((args (list bible-sword-query nil (current-buffer) t "-b" module "-o" "m" "-f" "HTMLHREF" "-k" query)))
  660. (when bible-show-diatheke-exec
  661. (message "%s" args))
  662. (apply 'call-process args)
  663. (shr-render-region (point-min) (point-max))
  664. (format-replace-strings
  665. '(("\n:" . "") ; This makes the Packard morphology display look better.
  666. ("Part of Speech" . "")) ; This helps the Robinson display look better.
  667. nil (point-min) (point-max))
  668. (substring (buffer-string) (+ (length query) 1))) ; This tries to get rid of unnecessary query identifier.
  669. ))
  670. ;;; Use "plain" format with diatheke.
  671. (defun bible--lex-query (query module)
  672. "Execute `diatheke' for QUERY, using MODULE.
  673. Plain format, returns string."
  674. (bible--exec-diatheke query nil "plain" module))
  675. (defun bible--lookup-lemma-index (key)
  676. "Return the Greek lemma from lemma index with a strong's number as KEY."
  677. (string-trim
  678. (string-replace
  679. (concat "(" bible-lexicon-index) ""
  680. (bible--lex-query key bible-lexicon-index))))
  681. ;;;
  682. ;;; The Greek lexical definitions are done using the HTMLHREF output
  683. ;;; format so they come out looking nice and having clickable
  684. ;;; cross-references and/or Strong's references.
  685. (defun bible--process-href ()
  686. "Fix the XML so cross-references are in the right format.
  687. These cross-references get processed later when the term is displayed.
  688. First, find the links put in by diatheke's HTMLHREF output format.
  689. Replace the links with verse references that get changed to clickable
  690. cross-references when the term is displayed.
  691. The verse refs look like this: <bookname>.<chapter>.<verse>. We convert
  692. them to the <bookname> <chapter>:<verse> format."
  693. (goto-char (point-min))
  694. (while (re-search-forward "<a href=\"passagestudy.*?</a>" nil t) ; HTMLHREF cross references.
  695. (let ((match-text (match-string 0)))
  696. ;; Delete original link.
  697. (replace-match "" nil nil)
  698. ;; Get the verse reference from the string we saved. Put it in
  699. ;; good format, then insert it into buffer where href was.
  700. (when (string-match "value=.*?&" match-text)
  701. (let* ((value-string (match-string 0 match-text))
  702. ;; Strip off value= and trailing &.
  703. (verse-ref-string (substring value-string 6 (1- (length value-string))))
  704. (verse-ref-length (length verse-ref-string))
  705. period)
  706. ;; Convert periods
  707. ;; Substitute first period with space
  708. (when (setq period (cl-search "." verse-ref-string))
  709. (aset verse-ref-string period ? ))
  710. ;; Substitute second period with colon
  711. (when (setq period (cl-search "." verse-ref-string))
  712. (aset verse-ref-string period ?:))
  713. ;; Replace numbers (1, 2 or 3) with roman numerals (I, II, III) XXX Fix?
  714. (pcase (aref verse-ref-string 0)
  715. (?1 (setq verse-ref-string (concat "I" (substring verse-ref-string 1))))
  716. (?2 (setq verse-ref-string (concat "II" (substring verse-ref-string 1))))
  717. (?3 (setq verse-ref-string (concat "III" (substring verse-ref-string 1)))))
  718. (set-text-properties 0 verse-ref-length nil verse-ref-string) ; Clear unwanted properties (if any)
  719. (insert verse-ref-string))))))
  720. (defun bible--lookup-def-greek (key)
  721. "Execute `diatheke' to do query on KEY.
  722. Massage output so verse cross references are usable. Returns string."
  723. (with-temp-buffer
  724. (let ((args (list bible-sword-query nil (current-buffer) t "-b" bible-greek-lexicon "-o" "m" "-f" "plain" "-k" key)))
  725. (when bible-show-diatheke-exec
  726. (message "%s" args))
  727. (apply 'call-process args)
  728. (bible--cleanup-lex-text (string-replace (concat "(" bible-greek-lexicon ) "" (buffer-string))))))
  729. (defun bible--lookup-lemma-greek-indexed (key)
  730. "Lookup Greek lemma using Strong's number KEY.
  731. Then look up the definition of that lemma. Used when two-stage
  732. lexical definition is set for a particular lexicon."
  733. (let ((lemma-entry (bible--lookup-lemma-index key))) ; Get lemma from Strong's number
  734. (when lemma-entry
  735. (let ((lemma (caddr (split-string lemma-entry " "))))
  736. (bible--lookup-def-greek lemma)))))
  737. (defun bible--lookup-lemma-greek (key)
  738. "Lookup lexical definition using Strong's number KEY.
  739. 1. Check hash table first. If entry found, return.
  740. 2. Otherwise, if a lexicon is accessed by lemmas, do lookup using index method.
  741. 3. Otherwise just use the Strong's number method."
  742. (or (gethash key bible-hash-greek)
  743. (puthash key
  744. (if bible-use-index-for-lexicon
  745. (bible--lookup-lemma-greek-indexed key)
  746. (bible--lookup-def-greek key))
  747. bible-hash-greek)))
  748. (defun bible--lookup-def-hebrew (key)
  749. "Execute `diatheke' to do query on KEY.
  750. Massage output so various cross references are usable. Returns string."
  751. (with-temp-buffer
  752. (let ((args (list bible-sword-query nil (current-buffer) t "-b" bible-hebrew-lexicon "-f" "plain" "-k" key)))
  753. (when bible-show-diatheke-exec
  754. (message "%s" args))
  755. (apply 'call-process args)
  756. (bible--process-href)
  757. (bidi-string-mark-left-to-right
  758. (string-replace (concat "(" bible-hebrew-lexicon ) "" (substring (buffer-string) 7))))))
  759. (defun bible--lookup-lemma-hebrew (key)
  760. "Lookup lexical definition using Strong's number KEY.
  761. 1. Check hash table first. If entry found, return.
  762. 2. Otherwise, if a lexicon is accessed by lemmas, do lookup using index method.
  763. 3. Otherwise just use the Strong's number method."
  764. (or (gethash key bible-hash-hebrew)
  765. (puthash key
  766. (bible--lookup-def-hebrew key)
  767. bible-hash-hebrew)))
  768. ;;;
  769. ;;; We use the shorter lexicons for text in tooltips. We also cache
  770. ;;; the lex and morph strings, hoping to speed up tooltip rendering.
  771. ;;;
  772. (defun bible--lookup-lemma-greek-short (lemma)
  773. "Look up Greek lexical entry for LEX from short Greek lexicon."
  774. (when (string-match "[0-9]+" lemma)
  775. (bible--lex-query (match-string 0 lemma) bible-greek-lexicon-short)))
  776. (defun bible--lookup-lemma-hebrew-short (lemma)
  777. "Look up Hebrew lexical entry for LEX from short Hebrew
  778. lexicon (StrongsRealHebrew)."
  779. (when (string-match "[0-9]+" lemma)
  780. ;; Remove redundant stuff at the beginnning.
  781. (substring (bible--lex-query (concat (match-string 0 lemma)) bible-hebrew-lexicon-short) 7)))
  782. (defun bible--lookup-lex (lex)
  783. "Look up lexical item LEX. This is used for tooltips.
  784. Return hash table entry if present in lex-hash cache, else look up in
  785. database and stash in cache."
  786. (when lex
  787. (let* ((key (substring lex 7)) ; strip off "strong:" prefix.
  788. (lex-text (gethash key lex-hash)))
  789. ;; XXX Kludge alert! Emacs tooltips look really nice for Greek
  790. ;; terms, but Hebrew needs system tooltips because of direction
  791. ;; issues.
  792. (setq use-system-tooltips (if (string-prefix-p "G" key) nil t))
  793. (if lex-text
  794. lex-text
  795. (setq lex-text
  796. (cond ((string-prefix-p "G" key)
  797. (string-replace
  798. (concat "(" bible-greek-lexicon-short )
  799. ""
  800. (bible--lookup-lemma-greek-short key)))
  801. ((string-prefix-p "H" key)
  802. (bidi-string-mark-left-to-right
  803. (string-replace
  804. (concat "(" bible-hebrew-lexicon-short)
  805. ""
  806. (bible--lookup-lemma-hebrew-short key))))))
  807. (puthash key (string-fill (bible--cleanup-lex-text lex-text) 75) lex-hash)))))
  808. (defun bible--lookup-morph-entry (morph)
  809. "Look up entry for morphological item MORPH.
  810. Return hash table entry if present in morph-hash cache, else look up in
  811. database and stash in cache."
  812. (when morph
  813. (or (gethash morph morph-hash)
  814. (puthash morph
  815. (let (morph-module morph-key)
  816. (cond ((string-prefix-p "robinson:" morph)
  817. (setq morph-module "Robinson")
  818. (setq morph-key (substring morph (length "robinson:"))))
  819. ((string-prefix-p "packard:" morph)
  820. (setq morph-module "Packard")
  821. (setq morph-key (substring morph (length "packard:"))))
  822. ((string-prefix-p "oshm:" morph)
  823. (setq morph-module "OSHM")
  824. (setq morph-key (substring morph (length "oshm:")))))
  825. (string-replace (concat "(" morph-module )
  826. ""
  827. (bible--morph-query morph-key morph-module)))
  828. morph-hash))))
  829. ;; (defvar bible-outline-strings
  830. ;; '((". ." . ".")
  831. ;; (" I. ." . "\n I.")
  832. ;; (" II. ." . "\n II.")
  833. ;; (" III. ." . "\n III.")
  834. ;; (" IV. ." . "\n IV.")
  835. ;; (" V. ." . "\n V.")
  836. ;; ("1. ." . "\n 1.")
  837. ;; ("2. ." . "\n 2.")
  838. ;; ("3. ." . "\n 3.")
  839. ;; ("4. ." . "\n 4.")
  840. ;; ("5. ." . "\n 5.")
  841. ;; ("6. ." . "\n 6.")
  842. ;; ("7. ." . "\n 7.")
  843. ;; ("8. ." . "\n 8.")
  844. ;; ("9. ." . "\n 9.")
  845. ;; ("a. ." . "\n a.")
  846. ;; ("b. ." . "\n b.")
  847. ;; ("c. ." . "\n c.")
  848. ;; ("d. ." . "\n d.")
  849. ;; ("e. ." . "\n e.")
  850. ;; ("f. ." . "\n f.")
  851. ;; ("g. ." . "\n g.")
  852. ;; ("h. ." . "\n h.")
  853. ;; (" . " . ". ")))
  854. (defvar bible-outline-strings
  855. '(;;(". ." . ".")
  856. (" I. ." . "\nI.")
  857. (" II. ." . " II.")
  858. (" III. ." . " III.")
  859. (" IV. ." . " IV.")
  860. (" V. ." . " V.")
  861. ("1. ." . "\n 1.")
  862. ("2. ." . "2.")
  863. ("3. ." . "3.")
  864. ("4. ." . "4.")
  865. ("5. ." . "5.")
  866. ("6. ." . "6.")
  867. ("7. ." . "7.")
  868. ("8. ." . "8.")
  869. ("9. ." . "9.")
  870. ("a. ." . "\n a.")
  871. ("(a)." . "\n (a).")
  872. ("b. ." . " b.")
  873. ("c. ." . " c.")
  874. ("d. ." . " d.")
  875. ("e. ." . " e.")
  876. ("f. ." . " f.")
  877. ("g. ." . " g.")
  878. ("h. ." . " h.")
  879. (" . " . ". ")
  880. ("\n\n" . "\n")))
  881. (defun bible--cleanup-lex-text (lex-text)
  882. "Reformat tooltip text LEX-TEXT so tooltips look nice."
  883. (dolist (outline-string bible-outline-strings)
  884. (setq lex-text (string-replace (car outline-string) (cdr outline-string) lex-text)))
  885. lex-text)
  886. ;;;
  887. ;;; Get string for tooltip display
  888. ;;;
  889. (defun bible--show-lex-morph (_window object pos)
  890. "Get text for tooltip display for OBJECT at POS in WINDOW.
  891. Includes both lex and morph definitions if text module has
  892. both tags, otherwise just get lex definition."
  893. (let* ((lex (get-text-property pos 'strong object))
  894. (lex-text (bible--lookup-lex lex))
  895. (morph (get-text-property pos 'morph object))
  896. (morph-text (bible--lookup-morph-entry morph)))
  897. (when lex-text
  898. ;; This prevents bogus command substitutions in the tooltip by
  899. ;; removing backslashes. XXX I couldn't figure out a better way
  900. ;; to bypass command substitution in the tooltips.
  901. (subst-char-in-string
  902. ?\\
  903. ?
  904. (if morph-text
  905. (concat (string-trim lex-text) "\n" (string-trim morph-text))
  906. (string-trim lex-text))))))
  907. (defun bible-handle-divine-name (item)
  908. "When ITEM is divine name, display it as such."
  909. (insert "LORD")
  910. (let* ((refstart (- (point) (length "LORD")))
  911. (refend (point))
  912. (strongs (dom-attr item 'savlm)))
  913. (add-face-text-property refstart refend 'bold)
  914. (put-text-property refstart refend 'keymap bible-hebrew-keymap)
  915. (when (and strongs (string-match "strong:H" strongs))
  916. (put-text-property refstart refend 'help-echo 'bible--show-lex-morph)
  917. (put-text-property refstart refend 'strong (match-string 0 strongs)))))
  918. (defun bible--process-word (item iproperties)
  919. "Handle <w ...> fubar </w> tag in ITEM. Check IPROPERTIES for qualifiers.
  920. Add tooltips for definitions and morphology. Also insert lemmas in
  921. buffer if `word study' is turned on (must be done after item is inserted
  922. in buffer)."
  923. (let ((word (string-trim (dom-text item)))
  924. (morph (dom-attr item 'morph))
  925. (savlm (dom-attr item 'savlm))
  926. (lemma (dom-attr item 'lemma))
  927. (divinename (dom-by-tag item 'divinename)))
  928. (let ((refstart (point))
  929. (refend (+ (point) (length word))))
  930. (insert word)
  931. ;; Red letter (Yuck, some modules need this below)
  932. (when (plist-get iproperties 'jesus)
  933. (add-face-text-property refstart refend '(:foreground "red")))
  934. ;; Special case this. XXX Some modules do this differently.
  935. (when divinename
  936. (insert " ")
  937. (bible-handle-divine-name item))
  938. ;; lexical definitions
  939. (when (or lemma savlm)
  940. (let* ((matched nil)
  941. (lexemes (split-string (or lemma savlm)))
  942. ;; XXX KJV module conflates articles with lemmas. Deal with this.
  943. (lexeme (car (last lexemes))))
  944. ;; (message "Lexemes: %s" lexemes)
  945. (when (string-match "strong:.*" lexeme)
  946. (dolist (word (split-string (match-string 0 lexeme) " "))
  947. ;; (message "Word: %s" word)
  948. (cond ((string-match "strong:G.*" word) ; Greek
  949. (setq matched (match-string 0 lexeme))
  950. (put-text-property refstart refend 'keymap bible-greek-keymap))
  951. ((string-match "strong:H.*" lexeme) ; Hebrew
  952. (setq matched (match-string 0 lexeme))
  953. (put-text-property refstart refend 'keymap bible-hebrew-keymap))))
  954. ;; Add help-echo, strongs reference for tooltips if match.
  955. (when matched
  956. (setq bible-has-lexemes t)
  957. (put-text-property refstart refend 'help-echo 'bible--show-lex-morph)
  958. (put-text-property refstart refend 'strong matched)))))
  959. ;; morphology
  960. (when morph
  961. (let ((matched nil))
  962. (if (or
  963. (string-match "robinson:.*" morph) ; Robinson Greek morphology
  964. (string-match "packard:.*" morph) ; Packard Greek morphology --- LXX seems to use this
  965. (string-match "oshm:.*" morph)) ; OSHM Hebrew morphology
  966. (setq matched (match-string 0 morph))
  967. ;;(message "Unknown morphology %s" morph)
  968. )
  969. (when matched
  970. (setq bible-has-morphology t)
  971. (put-text-property refstart refend 'morph matched)
  972. (put-text-property refstart refend 'help-echo 'bible--show-lex-morph))))
  973. ;; Insert lemma into buffer. Lemma tag will be part of lemma/savelm item.
  974. ;; XXX Should I enable lexicon lookups on these lemmas? I don't use
  975. ;; this anyway....
  976. (when (and bible-word-study-enabled lemma (string-match "lemma.*:.*" lemma))
  977. (dolist (word (split-string (match-string 0 lemma) " "))
  978. (setq word (replace-regexp-in-string "[.:a-zA-Z0-9]+" "" word))
  979. (insert " " word)
  980. (let ((refstart (- (point) 1 (length word)))
  981. (refend (point)))
  982. (add-face-text-property refstart refend '(:foreground "blue"))
  983. (put-text-property refstart refend 'keymap bible-lemma-keymap)))))))
  984. (defun bible-new-line ()
  985. "Ensure beginning of line. Try to avoid redundant blank lines."
  986. (unless (= (current-column) 0)
  987. (insert "\n")))
  988. (defun bible--insert-domnode-recursive (node &optional iproperties notitle)
  989. "Recursively parse domnode NODE obtained from `libxml-parse-html-region'.
  990. Inserts resulting text into active buffer with properties specified in
  991. IPROPERTIES. If NOTITLE is true, don't render title headings.
  992. XXX In processing subnodes, each case will prepend a space if it needs it."
  993. (when (and bible-red-letter-enabled (equal (dom-attr node 'who) "Jesus"))
  994. ;; For red-letter display.
  995. (setq iproperties (plist-put iproperties 'jesus t)))
  996. (dolist (subnode (dom-children node))
  997. (cond ((null subnode) nil)
  998. ((stringp subnode)
  999. ;; Red letter
  1000. (when (plist-get iproperties 'jesus)
  1001. (add-face-text-property 0 (length subnode) '(:foreground "red") nil subnode))
  1002. (insert subnode))
  1003. ((consp subnode)
  1004. (let ((tag (dom-tag subnode)))
  1005. (pcase tag
  1006. ;; Maybe process these at some point? Include footnotes etc.
  1007. ;; ('node nil)
  1008. ;; ('lb nil)
  1009. ;; 'w --- Usual case.
  1010. ('w (insert " ") (bible--process-word subnode iproperties))
  1011. ;; Font tag should be ignored, treat as if 'w
  1012. ('font (insert " ") (bible--process-word subnode iproperties))
  1013. ('i ; Italic face
  1014. (let ((word (dom-text subnode)))
  1015. (insert " " word)
  1016. (put-text-property (- (point) (length word)) (point) 'face 'italic)))
  1017. ;; 'q is used for red letter.
  1018. ;; NASB Module uses 'seg to indicate OT quotations (and others?).
  1019. ((or 'body 'seg 'p 'q) (bible--insert-domnode-recursive subnode iproperties notitle))
  1020. ('title (when (not notitle) (setq bible-chapter-title subnode) (bible-new-line)))
  1021. ;; These tags appear in ESV modules (and maybe others?) XXX still not right
  1022. ('l
  1023. (let ((attributes (dom-attributes subnode)))
  1024. (cond ((equal (cdr (assoc 'type attributes)) "x-br")
  1025. (bible-new-line))
  1026. ((equal (cdr (assoc 'type attributes)) "x-indent")
  1027. (insert "\t"))
  1028. ((assoc 'level attributes)
  1029. (let ((indent (string-to-number (alist-get 'level attributes))))
  1030. (when (= indent 2) (insert "\n\t")))))))
  1031. ('divinename (bible-handle-divine-name subnode))
  1032. ;; Some modules use this for line breaks and such.
  1033. ('milestone (when (equal (dom-attr subnode 'type) "line") (bible-new-line)))
  1034. ;; ('br (bible-new-line))
  1035. ('div (when (equal (dom-attr subnode 'type) "paragraph") (bible-new-line)))
  1036. ;; Word inserted by translation, not in original, give visual indication.
  1037. ((or 'transchange 'hi)
  1038. (let ((word (dom-text subnode)))
  1039. (insert " " word)
  1040. (if (plist-get iproperties 'jesus)
  1041. (add-face-text-property (- (point) (length word)) (point) '(:foreground "salmon"))
  1042. (add-face-text-property (- (point) (length word)) (point) '(:foreground "gray50")))))))))))
  1043. (defun bible--display (&optional verse)
  1044. "Render text for `bible'. If VERSE is supplied, set cursor at verse."
  1045. ;; Display buffers can have different modules.
  1046. (setq-local bible-module (default-value 'bible-module))
  1047. ;; Clear buffer and insert the result of calling bible--exec-diatheke.
  1048. (let ((buffer-read-only nil)
  1049. (bible-chapter-title nil)
  1050. (bible-has-lexemes nil)
  1051. (bible-has-morphology nil))
  1052. (erase-buffer)
  1053. (insert (bible--exec-diatheke (concat bible--current-book-name ":" (number-to-string bible--current-chapter))))
  1054. ;; Parse the xml in the buffer into a DOM tree.
  1055. (let ((html-dom-tree (libxml-parse-html-region (point-min) (point-max))))
  1056. ;; Render the DOM tree into the buffer.
  1057. (unless bible-debugme
  1058. (erase-buffer)
  1059. ;; Looking for the "body" tag in the DOM node.
  1060. (bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body) nil nil)
  1061. (goto-char (point-min))))
  1062. (save-excursion
  1063. (let ((search-string (concat (car bible--current-book) " " (number-to-string bible--current-chapter) ":")))
  1064. ;; Delete <Book Ch:> (may be more than one)
  1065. (while (search-forward search-string nil t)
  1066. (replace-match ""))))
  1067. (save-excursion
  1068. ;; Highlight verse number(s)
  1069. (while (re-search-forward "^ *[0-9]+" nil t)
  1070. (add-face-text-property (match-beginning 0) (match-end 0) '(:foreground "purple") nil)))
  1071. (save-excursion
  1072. ;; Remove the module name from the buffer.
  1073. (while (re-search-forward (concat "^.*" bible-module ".*$") nil t)
  1074. ;; (message "Replacing %s" (concat "(" bible-module ")"))
  1075. (replace-match "" nil t)))
  1076. ;; Deal with chapter titles (i.e. in Psalms)
  1077. ;; N.B. This won't change a title inside a chapter, and so it
  1078. ;; doesn't work with Psalm 119 where the acrostic letters get
  1079. ;; printed as "titles".
  1080. (save-excursion
  1081. (when bible-chapter-title ; This gets set in bible-insert-domnode-recursive.
  1082. (let ((title-text (dom-texts bible-chapter-title))
  1083. (refstart (point-min))
  1084. refend)
  1085. (when (stringp title-text)
  1086. (setf title-text (replace-regexp-in-string "<.*?>" "" title-text))
  1087. (insert title-text "\n")
  1088. (setq refend (point))
  1089. (put-text-property refstart refend 'face 'bold))))
  1090. ;; Get rid of spurious spaces.
  1091. (format-replace-strings '(("." . ". ")
  1092. ("," . ", ")
  1093. (";" . "; ")
  1094. (":" . ": ")
  1095. ("?" . "? ")
  1096. ("!" . "! ")
  1097. (" ." . ". ")
  1098. (" ," . ", ")
  1099. (" ;" . "; ")
  1100. (" :" . ": ")
  1101. (" ?" . "? ")
  1102. (" !" . "! ")
  1103. ("“ " . "“")
  1104. ("‘ " . "‘")
  1105. (" ’" . "’")
  1106. (". ”" . ".”")
  1107. ("? ”" . "?”")
  1108. (" " . " ")
  1109. (" " . " "))
  1110. nil (point-min) (point-max)))
  1111. ;; Set the mode line of the biffer.
  1112. (setq mode-name (concat "Bible (" bible--current-book-name " " (number-to-string bible--current-chapter) ") "
  1113. bible-module
  1114. (when bible-has-lexemes " Lex")
  1115. (when bible-has-morphology " Morph")
  1116. ")")))
  1117. ;; If optional verse specification go to that verse.
  1118. (when verse
  1119. (re-search-forward (regexp-opt `(,(concat (number-to-string verse) ":"))) nil t)))
  1120. (defun bible--list-biblical-modules ()
  1121. "Return a list of accessible Biblical Text modules."
  1122. (let ((text (bible--exec-diatheke "modulelist" nil nil "system"))
  1123. modules)
  1124. (catch 'done
  1125. (dolist (line (split-string text "[\n\r]+"))
  1126. (when (equal line "Commentaries:")
  1127. (throw 'done nil))
  1128. (when (not (equal "Biblical Texts:" line))
  1129. (push (split-string line " : ") modules))))
  1130. modules))
  1131. (defun bible-pick-module ()
  1132. "Keymap action function---select module user chooses."
  1133. (interactive)
  1134. (let ((item (get-text-property (point) 'module)))
  1135. (setq-default bible-module item)
  1136. (bible-open)))
  1137. (defconst bible-module-map (make-keymap))
  1138. (define-key bible-module-map [mouse-1] 'bible-pick-module)
  1139. (define-key bible-module-map (kbd "RET") 'bible-pick-module)
  1140. (defun bible-display-available-modules ()
  1141. "Display available modules, allow user to select."
  1142. (interactive)
  1143. (with-current-buffer (get-buffer-create "Modules")
  1144. (bible-module-select-mode)
  1145. (let ((buffer-read-only nil))
  1146. (erase-buffer)
  1147. (setq-local tab-stop-list '(25))
  1148. (dolist (mod (bible--list-biblical-modules))
  1149. (let ((name (string-trim (car mod)))
  1150. (description (string-trim-left (cadr mod))))
  1151. (insert
  1152. (propertize (string-trim name)
  1153. 'face 'bold
  1154. 'module name
  1155. 'help-echo (concat "Select " name)
  1156. 'keymap bible-module-map))
  1157. (move-to-tab-stop)
  1158. (insert (format "%s\n" description)))))
  1159. (goto-char (point-min))
  1160. (pop-to-buffer (current-buffer) nil t)))
  1161. ;;;;; Bible Searching
  1162. (defun bible--open-search (query searchmode)
  1163. "Open a search buffer of QUERY using SEARCHMODE in module MOD."
  1164. (let ((results (string-trim (replace-regexp-in-string
  1165. "Entries .+?--" ""
  1166. (bible--diatheke-search query searchmode "plain" bible-module)))))
  1167. (if (equal results (concat "none (" bible-module ")"))
  1168. (message (concat
  1169. "No results found."
  1170. (when (equal searchmode "lucene")
  1171. " Verify index has been build with mkfastmod.")))
  1172. (with-current-buffer (get-buffer-create (concat "*bible-search-" (downcase bible-module) "-" query "*"))
  1173. (bible-search-mode)
  1174. (bible--display-search results)
  1175. (pop-to-buffer (current-buffer) nil t)))))
  1176. (defun bible--display-search (results)
  1177. "Render RESULTS of search query."
  1178. (let ((match 0)
  1179. (matchstr "")
  1180. (verses nil)
  1181. (query-verses "")
  1182. (buffer-read-only nil))
  1183. (erase-buffer)
  1184. (while match
  1185. (setq match (string-match ".+?:[0-9]?[0-9]?" results (+ match (length matchstr)))
  1186. matchstr (match-string 0 results))
  1187. (when match
  1188. (push
  1189. ;; Massage match to make it more sortable, get rid of some characters.
  1190. (string-replace
  1191. "I " "1"
  1192. (string-replace
  1193. "II " "2"
  1194. (string-replace
  1195. "III " "3"
  1196. (string-replace
  1197. ".+; " ""
  1198. matchstr))))
  1199. verses)))
  1200. (setq match 0)
  1201. (setq verses (sort verses))
  1202. (dolist (verse verses)
  1203. (if query-verses
  1204. (setq query-verses (concat query-verses ";" verse))
  1205. (setq query-verses verse)))
  1206. (let ((bible-show-diatheke-exec nil))
  1207. (insert (bible--exec-diatheke query-verses nil nil bible-module))
  1208. (let* ((html-dom-tree (libxml-parse-html-region (point-min) (point-max))))
  1209. (erase-buffer)
  1210. (bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body) nil nil)
  1211. (goto-char (point-min))
  1212. (while (search-forward (concat "(" bible-module ")") nil t)
  1213. (replace-match "")))
  1214. (setq mode-name (concat "Bible Search (" bible-module))
  1215. (when bible-search-range
  1216. (setq mode-name (concat mode-name " [" bible-search-range "]")))
  1217. (setq mode-name (concat mode-name ")"))
  1218. (goto-char (point-min)))))
  1219. ;;;;; Terms (lemmas, morphology)
  1220. ;;(defun bible-display-morphology (morph)
  1221. ;; ;; xxx Do something here?
  1222. ;; )
  1223. (defun bible--fixup-lexicon-display (termtype)
  1224. "Fixup the display of a lexical entry whose language is given by TERMTYPE."
  1225. (let ((buffer-read-only nil))
  1226. (goto-char (point-min))
  1227. ;; This enables clicking on Strong's numbers in some lexicon definitions.
  1228. (while (search-forward-regexp "[0-9]+" nil t)
  1229. (cond ((eq termtype 'hebrew)
  1230. (put-text-property (match-beginning 0) (match-end 0) 'strong (concat "strong:H" (match-string 0)))
  1231. (put-text-property (match-beginning 0) (match-end 0) 'keymap bible-hebrew-keymap)
  1232. (add-face-text-property (match-beginning 0) (match-end 0) `(:foreground "blue")))
  1233. ((eq termtype 'greek)
  1234. (put-text-property (match-beginning 0) (match-end 0) 'strong (concat "strong:G" (match-string 0)))
  1235. (put-text-property (match-beginning 0) (match-end 0) 'keymap bible-greek-keymap)
  1236. (add-face-text-property (match-beginning 0) (match-end 0) `(:foreground "blue")))))
  1237. (goto-char (point-min))
  1238. ;; This enables clicking on verse references.
  1239. (while (search-forward-regexp bible--verse-regexp nil t)
  1240. (put-text-property (match-beginning 0) (match-end 0) 'xref (match-string 0))
  1241. (put-text-property (match-beginning 0) (match-end 0) 'keymap bible-search-mode-map)
  1242. (put-text-property (match-beginning 0) (match-end 0) 'help-echo (concat "Go to " (match-string 0)))
  1243. (add-face-text-property (match-beginning 0) (match-end 0) '(:foreground "blue")))
  1244. (goto-char (point-min))
  1245. (while (search-forward "()" nil t)
  1246. (replace-match ""))
  1247. (goto-char (point-min))))
  1248. (defun bible--open-term-hebrew (term)
  1249. "Open a buffer of the Strong's Hebrew TERM's definition."
  1250. (with-current-buffer (get-buffer-create (concat "*bible-term-hebrew-" term "*"))
  1251. (bible-term-hebrew-mode)
  1252. (setq-local bidi-paragraph-direction 'left-to-right)
  1253. (bible--display-lemma-hebrew term)
  1254. (pop-to-buffer (current-buffer) nil t)
  1255. (fit-window-to-buffer)))
  1256. (defun bible--display-lemma-hebrew (lemma)
  1257. "Render the definition of the Strong's Hebrew LEMMA.
  1258. This code is customized for the BDBGlosses_Strongs lexicon."
  1259. (let ((buffer-read-only nil))
  1260. (erase-buffer)
  1261. ;; BDBGlosses_Strongs needs the prefixed `H'.
  1262. (insert (substring (bible--cleanup-lex-text (bible--lookup-lemma-hebrew (concat "H" lemma))) 7))
  1263. (bible--fixup-lexicon-display 'hebrew)))
  1264. (defun bible--open-term-greek (term)
  1265. "Open a buffer of the Strong's Greek TERM definition."
  1266. (with-current-buffer (get-buffer-create (concat "*bible-term-greek-" term "*"))
  1267. (bible-term-greek-mode)
  1268. (bible--display-lemma-greek term)
  1269. (pop-to-buffer (current-buffer) nil t)
  1270. (fit-window-to-buffer)))
  1271. (defun bible--display-lemma-greek (lemma)
  1272. "Render the definition of the Strong's Greek LEMMA."
  1273. (let ((buffer-read-only nil))
  1274. (erase-buffer)
  1275. (insert (bible--lookup-lemma-greek lemma))
  1276. (bible--fixup-lexicon-display 'greek)))
  1277. (defun bible--set-location (book chapter &optional verse)
  1278. "Set the BOOK, CHAPTER and optionally VERSE of the active `bible' buffer."
  1279. (setq-local bible-module (default-value 'bible-module))
  1280. (setq-local bible--current-book book)
  1281. (setq-local bible--current-book-name (car book))
  1282. (setq-local bible--current-chapter chapter)
  1283. (bible--display verse))
  1284. ;;;;; Utilities
  1285. (defun bible--list-number-range (min max &optional prefix)
  1286. "Returns a list containing entries for each integer between MIN and MAX.
  1287. If PREFIX is supplied, prepend PREFIX to the entries.
  1288. Used in tandem with `completing-read' for chapter selection."
  1289. (let ((range-list nil))
  1290. (dotimes (num (1+ max))
  1291. (when (>= num min)
  1292. (push (cons (concat prefix (number-to-string num)) num) range-list)))
  1293. (nreverse range-list)))
  1294. ;;; Provides
  1295. (provide 'bible)
  1296. ;;; bible.el ends here.
  1297. ;; Local Variables:
  1298. ;; End: