bible.el 59 KB

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