bible.el 60 KB

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