bible.el 58 KB

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