bible.el 57 KB

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