bible.el 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  1. ;;; bible.el --- A Bible browsing application -*- lexical-binding: t; mode: EMACS-LISP; indent-tabs-mode: nil -*-
  2. ;; Copyright (c) 2025-2026 Fred Gilham
  3. ;; Author: Fred Gilham <fmgilham@gmail.com>
  4. ;; Version: 1.2.0
  5. ;; Keywords: files, text, hypermedia
  6. ;; Package-Requires: ((emacs "29.1") cl-lib dom shr)
  7. ;; URL: https://gitbot.homedns.org/fred/bible
  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-text' to set a default browsing module, as
  32. ;; well as `bible-word-study-enabled' to enable word study by default.
  33. ;; NB: Currently this just shows the lemmas in the original language
  34. ;; if present. Tooltips will display whenever there are strongs
  35. ;; numbers in the module.
  36. ;;;; Design
  37. ;; The idea here is to use the diatheke program to lookup text from
  38. ;; modules (biblical texts), then insert this text into buffers. The
  39. ;; main bible display uses diatheke's internal XML format. The whole
  40. ;; buffer gets parsed by `libxml-parse-html-region' to create a dom
  41. ;; tree. This gets parsed by `bible--insert-domnode-recursive' to render
  42. ;; the text into reading format.
  43. ;; The text is then decorated using information from the dom format as
  44. ;; necessary along with regular expressions to identify the verse
  45. ;; references. This is for red letters, purple highlighting of the
  46. ;; verse numbers, bold face of the divine name in the OT and so on.
  47. ;; If Strongs tags and/or morphological tags are present, they are
  48. ;; looked up in appropriate lexical and morphological modules and used
  49. ;; to add tooltips to the text so that hovering over words will bring
  50. ;; up a tooltip with information about the word. Clicking on a word
  51. ;; with lexical information will display that information in a "term"
  52. ;; buffer.
  53. ;;; Code:
  54. ;;;; Environment stuff
  55. ;; Turn off modes because we are greedy for pixels....
  56. (tool-bar-mode -1)
  57. (scroll-bar-mode -1)
  58. ;; eldoc isn't meaningful in this program, and this saves space in the
  59. ;; mode line.
  60. (global-eldoc-mode -1)
  61. ;;;; Requirements
  62. (require 'cl-lib)
  63. (require 'dom)
  64. (require 'shr)
  65. (require 'menu+ nil t) ; If you have it, it looks nice.
  66. ;;;; Aliases for obsolete functions
  67. ;; dom-text and dom-texts declared obsolescent in Emacs 31. Check for
  68. ;; new function, retain backward compatibility.
  69. ;; Note that the following is the simplest way I found to avoid compile warnings.
  70. (defalias 'bible-dom-text (if (fboundp 'dom-inner-text) 'dom-inner-text 'dom-text))
  71. (defalias 'bible-dom-texts (if (fboundp 'dom-inner-texts) 'dom-inner-text 'dom-texts))
  72. ;;;; Customization Variables
  73. (defgroup bible nil
  74. "Settings for `bible'."
  75. :group 'tools
  76. :link '(url-link "https://gitbot.homedns.org/fred/bible-mode"))
  77. (defcustom bible-text
  78. "KJV"
  79. "Customize default bible text module for Diatheke to query.
  80. \(For full list of installed modules, run `diatheke -b system -l bibliography'\)"
  81. :type '(choice (const :tag "None" nil)
  82. (string :tag "Bible text (e.g. \"KJV\")"))
  83. :local nil
  84. :group 'bible)
  85. (defcustom bible-commentary
  86. "Clarke"
  87. "Customize default commentary module for Diatheke to query.
  88. \(For full list of installed modules, run `diatheke -b system -l bibliography'\)"
  89. :type '(choice (const :tag "None" nil)
  90. (string :tag "Commentary (e.g. \"Clarke\")"))
  91. :local nil
  92. :group 'bible)
  93. ;; TODO: Not implememted yet (FMG 5-Mar-2026)
  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. "Specify program used to query sword modules.
  103. Must be some version of the sword 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."
  120. :type 'boolean
  121. :local nil
  122. :group 'bible)
  123. (defcustom bible-lexicon-index "AbbottSmithStrongs"
  124. "A module that consists of an index mapping Strong's numbers to Greek lemmas.
  125. The code is written to use the entries in AbbottSmithStrongs
  126. which are of the form
  127. <strong's number>: @LINK <greek lemma>"
  128. :type '(string :tag "Lexicon index.")
  129. :local nil
  130. :group 'bible)
  131. (defcustom bible-greek-lexicon-short
  132. "StrongsRealGreek"
  133. "Lexicon used for displaying definitions of Greek words in tooltips."
  134. :type '(string :tag "Lexicon module (e.g. \"StrongsRealGreek\").")
  135. :local nil
  136. :group 'bible)
  137. ;; HACK: The Hebrew lexicons differ on whether they accept keys of the
  138. ;; form `Hnnnn' or `nnnn'. The code does not yet handle this
  139. ;; correctly, so stick with the following. (FMG 5-Mar-2026)
  140. (defcustom bible-hebrew-lexicon
  141. "BDBGlosses_Strongs" ; This seems to work
  142. "Specify Lexicon used to display definitions of Hebrew words.
  143. Note that changing this may require changing some code.
  144. See `bible--display-lemma-hebrew'."
  145. :type '(string :tag "Lexicon module (e.g. \"BDBGlosses_Strongs\")")
  146. :local nil
  147. :group 'bible)
  148. (defcustom bible-hebrew-lexicon-short
  149. "StrongsRealHebrew"
  150. ;; "StrongsHebrew"
  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. \(KJV New Testament has this.\)"
  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. nil
  170. "Show the arguments by which diatheke is executed (mostly for debugging)."
  171. :type 'boolean
  172. :local nil
  173. :group 'bible)
  174. ;;;; Mode line formats for different kinds of buffers.
  175. (defvar bible-mode-line-format
  176. '("%e" mode-line-front-space
  177. mode-line-frame-identification mode-line-buffer-identification " "
  178. bible--current-book-name
  179. " " (:eval (number-to-string bible--current-chapter))
  180. " " (:eval (if bible--synced-p "Sync" ""))
  181. (:eval (when bible-search-range (concat " <" bible-search-range ">")))
  182. " " mode-line-modes mode-line-misc-info
  183. mode-line-end-spaces)
  184. "Mode line format for bible buffers.")
  185. (defvar bible-search-mode-line-format
  186. '("%e" mode-line-front-space
  187. mode-line-frame-identification mode-line-buffer-identification " "
  188. bible-search-text-this-query " " bible-search-word-this-query " "
  189. (:eval (when bible-search-range-this-query (concat "<" bible-search-range-this-query "> ")))
  190. (:eval (number-to-string bible-search-matches)) " matches"
  191. " " mode-line-modes mode-line-misc-info
  192. mode-line-end-spaces)
  193. "Mode line format for bible search buffers.")
  194. (defvar bible-term-mode-line-format
  195. '("%e" mode-line-front-space
  196. mode-line-frame-identification mode-line-buffer-identification " "
  197. mode-line-modes mode-line-misc-info
  198. mode-line-end-spaces)
  199. "Mode line format for bible term buffers.")
  200. ;;;; Modes
  201. (define-derived-mode bible special-mode "Bible"
  202. "Mode for reading the Bible.
  203. \\{bible-map}"
  204. (buffer-disable-undo)
  205. (font-lock-mode t)
  206. (use-local-map bible-map)
  207. (setq-local mode-line-format bible-mode-line-format)
  208. (setq buffer-read-only t)
  209. (visual-line-mode t))
  210. (define-derived-mode bible-search-mode special-mode "Bible Search"
  211. "Mode for performing Bible searches.
  212. \\{bible-search-mode-map}"
  213. (buffer-disable-undo)
  214. (font-lock-mode t)
  215. (use-local-map bible-search-mode-map)
  216. (setq-local mode-line-format bible-search-mode-line-format)
  217. (setq buffer-read-only t)
  218. (visual-line-mode t))
  219. (define-derived-mode bible-term-mode special-mode "Bible Term"
  220. "Mode for researching terms in the Bible.
  221. \\{bible-term-mode-map}"
  222. (buffer-disable-undo)
  223. (font-lock-mode t)
  224. (use-local-map bible-term-mode-map)
  225. (setq-local mode-line-format bible-term-mode-line-format)
  226. (setq buffer-read-only t)
  227. (visual-line-mode t))
  228. (define-derived-mode bible-term-hebrew-mode bible-term-mode "Bible Term"
  229. "Mode for researching Hebrew terms in the Bible.
  230. \\{bible-term-hebrew-mode-map}"
  231. (setq-local bible-term-language "Hebrew"))
  232. (define-derived-mode bible-term-greek-mode bible-term-mode "Bible Term"
  233. "Mode for researching Greek terms in the Bible.
  234. \\{bible-term-greek-mode-map}"
  235. (setq-local bible-term-language "Greek"))
  236. (define-derived-mode bible-text-select-mode special-mode "Select Module"
  237. (buffer-disable-undo)
  238. (font-lock-mode t)
  239. (setq buffer-read-only t))
  240. ;;;; Keymaps
  241. ;; N.B. Bible Menu items appear in reverse order of their definition
  242. ;; below
  243. (defconst bible-map (make-sparse-keymap)
  244. "Keymap for bible.")
  245. (define-key bible-map [menu-bar bible]
  246. (cons "Bible" (make-sparse-keymap "Bible")))
  247. (define-key bible-map
  248. [menu-bar bible toggle-debug]
  249. '("Toggle debug-on-error" . toggle-debug-on-error))
  250. (define-key bible-map
  251. [menu-bar bible display-diatheke]
  252. '("Toggle diatheke display" . bible-toggle-display-diatheke))
  253. (define-key bible-map "d" 'bible-toggle-display-xml)
  254. (define-key bible-map
  255. [menu-bar bible display-xml]
  256. '("Toggle XML Display" . bible-toggle-display-xml))
  257. (define-key bible-map
  258. [menu-bar bible toggle-text-direction]
  259. '("Toggle text direction (for Hebrew display)" . bible-toggle-text-direction))
  260. (define-key bible-map
  261. [menu-bar bible toggle-tooltip-display]
  262. '("Toggle Tooltip Display" . bible-toggle-tooltips))
  263. (define-key bible-map
  264. [menu-bar bible sep]
  265. '(menu-item '"--"))
  266. ;;;;; Misc key bindings
  267. (define-key bible-map "T" 'bible-select-text)
  268. (define-key bible-map "C" 'bible-select-commentary)
  269. (define-key bible-map "w" 'bible-toggle-word-study)
  270. (define-key bible-map "l" 'bible-toggle-red-letter)
  271. (define-key bible-map "z" 'text-scale-adjust)
  272. (define-key bible-map
  273. [menu-bar bible zoom-text]
  274. '("Zoom Text" . text-scale-adjust))
  275. (define-key bible-map "x" 'bible-split-display)
  276. (define-key bible-map
  277. [menu-bar bible split-display]
  278. '("Split Display" . bible-split-display))
  279. (define-key bible-map "S" 'bible-toggle-buffer-sync)
  280. (define-key bible-map [menu-bar bible sync]
  281. '("Toggle Synchronize Buffer" . bible-toggle-buffer-sync))
  282. ;;;;; Navigation
  283. (define-key bible-map "p" 'bible-previous-chapter)
  284. (define-key bible-map
  285. [menu-bar bible previous-chapter]
  286. '("Previous Chapter" . bible-previous-chapter))
  287. (define-key bible-map "n" 'bible-next-chapter)
  288. (define-key bible-map
  289. [menu-bar bible next-chapter]
  290. '("Next Chapter" . bible-next-chapter))
  291. (define-key bible-map (kbd "TAB") 'bible-next-word)
  292. (define-key bible-map (kbd "M-<tab>") 'bible-previous-word)
  293. ;;;;; Direct jump
  294. (define-key bible-map "c" 'bible-select-chapter)
  295. (define-key bible-map
  296. [menu-bar bible select-chapter]
  297. '("Select Chapter" . bible-select-chapter))
  298. (define-key bible-map "b" 'bible-select-book)
  299. (define-key bible-map
  300. [menu-bar bible select-book]
  301. '("Select Book" . bible-select-book))
  302. (define-key bible-map
  303. [menu-bar bible sep]
  304. '(menu-item '"--"))
  305. ;; Deal with visual-line-mode navigation.
  306. (define-key bible-map "\C-n" 'next-logical-line)
  307. (define-key bible-map "\C-p" 'previous-logical-line)
  308. ;;;;; Search
  309. (define-key bible-map "/" 'bible-search)
  310. (define-key bible-map "s" 'bible-search)
  311. (define-key bible-map
  312. [menu-bar bible search]
  313. '("Search" . bible-search))
  314. (define-key bible-map "r" 'bible-set-search-range)
  315. (define-key bible-map
  316. [menu-bar bible range]
  317. '("Set Search Range" . bible-set-search-range))
  318. (define-key bible-map
  319. [menu-bar bible sepp]
  320. '(menu-item '"--"))
  321. (define-key bible-map
  322. [menu-bar bible sepp]
  323. '(menu-item '"--"))
  324. (define-key bible-map
  325. [menu-bar bible select-biblical-commentary]
  326. '("Select Commentary" . bible-display-available-commentaries))
  327. (define-key bible-map
  328. [menu-bar bible select-biblical-text]
  329. '("Select Text" . bible-display-available-texts))
  330. (defconst bible-search-mode-map (make-keymap))
  331. (define-key bible-search-mode-map "s" 'bible-search)
  332. (define-key bible-search-mode-map "w" 'bible-toggle-word-study)
  333. (define-key bible-search-mode-map "n" 'bible-next-search-item)
  334. (define-key bible-search-mode-map "p" 'bible-previous-search-item)
  335. (define-key bible-search-mode-map (kbd "RET") 'bible-follow-verse)
  336. (define-key bible-search-mode-map [mouse-1] 'bible-follow-verse)
  337. ;;;;; Term mode keymaps
  338. (defconst bible-term-mode-map (make-sparse-keymap))
  339. (define-key bible-term-mode-map "z" 'text-scale-adjust)
  340. (define-key bible-term-mode-map [mouse-1] 'bible-follow-xref)
  341. (defconst bible-greek-keymap (make-sparse-keymap))
  342. (define-key bible-greek-keymap (kbd "RET") 'bible--display-greek)
  343. (define-key bible-greek-keymap [mouse-1] 'bible--display-greek)
  344. (defconst bible-hebrew-keymap (make-sparse-keymap))
  345. (define-key bible-hebrew-keymap (kbd "RET") 'bible--display-hebrew)
  346. (define-key bible-hebrew-keymap [mouse-1] 'bible--display-hebrew)
  347. (defconst bible-lemma-keymap (make-sparse-keymap))
  348. (define-key bible-lemma-keymap (kbd "RET")
  349. (lambda ()
  350. (interactive)))
  351. ;; Not used. Not really sure what to do here or if it's useful to do anything.
  352. (defconst bible-morph-keymap (make-sparse-keymap))
  353. (define-key bible-morph-keymap (kbd "RET")
  354. (lambda ()
  355. (interactive)
  356. ;; (let ((thing (thing-at-point 'word)))
  357. ;; (message "thing at point: %s" thing)
  358. ;; (message "morph property %s" (get-text-property 0 'field thing))
  359. ))
  360. ;;;;; Module choice keymaps.
  361. (defconst bible-text-map (make-keymap))
  362. (define-key bible-text-map [mouse-1] 'bible-pick-text)
  363. (define-key bible-text-map (kbd "RET") 'bible-pick-text)
  364. (defconst bible-commentary-map (make-keymap))
  365. (define-key bible-commentary-map [mouse-1] 'bible-pick-commentary)
  366. (define-key bible-commentary-map (kbd "RET") 'bible-pick-commentary)
  367. ;;;; Variable definitions
  368. (defconst bible--verse-regexp "\\(I \\|1 \\|II \\|2 \\|III \\|3 \\)??[a-zA-Z]+?[ \t\n][0-9]+[:][0-9]+")
  369. ;; Don't know how to get footnotes and scripture cross references yet.
  370. ;;(defconst bible-diatheke-filter-options " afilmnsvw")
  371. (defconst bible-diatheke-filter-options " almnvw")
  372. (defvar bible--text-buffers nil
  373. "List of Bible text buffers.")
  374. (defvar bible--commentary-buffers nil
  375. "List of commentary buffers.")
  376. (defvar bible-buffer-type nil
  377. "One of `bible', `commentary', `term', `select' or `search'. Identifies
  378. the type of buffer.")
  379. (defvar-local bible-associated-buffer nil
  380. "Buffer associated with a given commentary buffer---used for
  381. chasing cross-references.")
  382. (defvar bible--synced-buffers nil
  383. "List of buffers that are synchronized so that navigation in one applies
  384. to all of them.")
  385. (defvar-local bible--synced-p nil
  386. "Is this buffer syncronized?")
  387. (defvar bible--texts (lazy-completion-table bible--texts bible--list-biblical-texts))
  388. (defvar bible--commentaries (lazy-completion-table bible--commentaries bible--list-biblical-commentaries))
  389. ;; REVIEW: I believe these chapter counts aren't the same for all modules, e.g. JPS. (FMG 5-Mar-2026)
  390. (defvar bible--books
  391. '(;; Old Testament
  392. ("Genesis" . 50) ("Exodus" . 40) ("Leviticus" . 27) ("Numbers" . 36)
  393. ("Deuteronomy" . 34) ("Joshua" . 24) ("Judges" . 21) ("Ruth" . 4)
  394. ("I Samuel" . 31) ("II Samuel" . 24) ("I Kings" . 22) ("II Kings" . 25)
  395. ("1 Samuel" . 31) ("2 Samuel" . 24) ("1 Kings" . 22) ("2 Kings" . 25)
  396. ("I Chronicles" . 29) ("II Chronicles" . 36) ("Ezra" . 10) ("Nehemiah" . 13)
  397. ("1 Chronicles" . 29) ("2 Chronicles" . 36)
  398. ("Ezra" . 10) ("Nehemiah" . 13)
  399. ("Esther" . 10) ("Job" . 42) ("Psalms" . 150) ("Proverbs" . 31)
  400. ("Ecclesiastes" . 12) ("Song of Solomon" . 8) ("Isaiah" . 66) ("Jeremiah" . 52)
  401. ("Lamentations" . 5) ("Ezekiel" . 48) ("Daniel" . 12) ("Hosea" . 14)
  402. ("Joel" . 3) ("Amos" . 9) ("Obadiah" . 1) ("Jonah" . 4)
  403. ("Micah" . 7) ("Nahum" . 3) ("Habakkuk" . 3) ("Zephaniah" . 3)
  404. ("Haggai" . 2) ("Zechariah" . 14) ("Malachi" . 4)
  405. ;; New Testament
  406. ("Matthew" . 28) ("Mark" . 16) ("Luke" . 24) ("John" . 21)
  407. ("Acts" . 28) ("Romans" . 16)
  408. ("I Corinthians" . 16) ("II Corinthians" . 13)
  409. ("1 Corinthians" . 16) ("2 Corinthians" . 13)
  410. ("Galatians" . 6) ("Ephesians" . 6) ("Philippians" . 4) ("Colossians" . 4)
  411. ("I Thessalonians" . 5) ("II Thessalonians" . 3) ("I Timothy" . 6) ("II Timothy" . 4)
  412. ("1 Thessalonians" . 5) ("2 Thessalonians" . 3) ("1 Timothy" . 6) ("2 Timothy" . 4)
  413. ("Titus" . 3) ("Philemon" . 1) ("Hebrews" . 13) ("James" . 5)
  414. ("I Peter" . 5) ("II Peter" . 3) ("I John" . 5) ("II John" . 1)
  415. ("1 Peter" . 5) ("2 Peter" . 3) ("1 John" . 5) ("2 John" . 1)
  416. ("III John" . 1) ("Jude" . 1) ("Revelation of John" . 22)
  417. ("3 John" . 1))
  418. "A-list of name / chapter count for Bible books.")
  419. ;; These abbreviations are used to follow cross-references in commentaries and lexicons.
  420. ;; Abbreviations from NETnote module and Clarke module (commentaries).
  421. ;; Abbreviations from some lexicons.
  422. ;; Standard abbreviations come first.
  423. (defvar bible--book-name-abbreviations
  424. '(;; Old Testament
  425. ("Gen" . "Genesis") ("Ge" . "Genesis")
  426. ("Exod" . "Exodus") ("Ex" . "Exodus") ("Exo" . "Exodus")
  427. ("Lev" . "Leviticus") ("Le" . "Leviticus")
  428. ("Num" . "Numbers") ("Nu" . "Numbers")
  429. ("Deut" . "Deuteronomy") ("De" . "Deuteronomy") ("Deu" . "Deuteronomy")
  430. ("Josh" . "Joshua") ("Js" . "Joshua") ("Jos" . "Joshua")
  431. ("Judg" . "Judges") ("Jg" . "Judges") ("Jdg" . "Judges")
  432. ("Ru" . "Ruth") ("Rut" . "Ruth")
  433. ("1 Sam" . "I Samuel") ("1 Samuel" . "I Samuel") ("I Sa" . "I Samuel")
  434. ("1 Sa" . "I Samuel") ("1Sam" . "I Samuel")
  435. ("2 Sam" . "II Samuel") ("2 Samuel" . "II Samuel") ("II Sa" . "II Samuel")
  436. ("2 Sa" . "II Samuel") ("2Sam" . "II Samuel")
  437. ("1 Kgs" . "I Kings") ("1 Kings" . "I Kings") ("I Ki" . "I Kings")
  438. ("1 Ki" . "I Kings") ("1Ki" . "I Kings")
  439. ("2 Kgs" . "II Kings") ("2 Kings" . "II Kings") ("II Ki" . "II Kings")
  440. ("2 Ki" . "II Kings") ("2Ki" . "II Kings")
  441. ("1 Chr" . "I Chronicles") ("1 Chronicles" . "I Chronicles")
  442. ("I Ch" . "I Chronicles") ("1 Ch" . "I Chronicles")
  443. ("2 Chr" . "II Chronicles") ("2 Chronicles" . "II Chronicles")
  444. ("II Ch" . "II Chronicles") ("2 Ch" . "II Chronicles")
  445. ("Ezr" . "Ezra")
  446. ("Neh" . "Nehemiah") ("Ne" . "Nehemiah")
  447. ("Esth" . "Esther") ("Es" . "Esther") ("Est" . "Esther")
  448. ("Jb" . "Job")
  449. ("Ps" . "Psalms") ("Psa" . "Psalms")
  450. ("Prov" . "Proverbs") ("Pr" . "Proverbs") ("Pro" . "Proverbs")
  451. ("Eccl" . "Ecclesiastes") ("Ec" . "Ecclesiastes")
  452. ("Ecc" . "Ecclesiastes")
  453. ("Song" . "Song of Solomon") ("So" . "Song of Solomon")
  454. ("Sol" . "Song of Solomon")
  455. ("Isa" . "Isaiah") ("Is" . "Isaiah")
  456. ("Jer" . "Jeremiah") ("Je" . "Jeremiah")
  457. ("Lam" . "Lamentations") ("La" . "Lamentations")
  458. ("Ezek" . "Ezekiel") ("Ez" . "Ezekiel") ("Eze" . "Ezekiel")
  459. ("Dan" . "Daniel") ("Da" . "Daniel")
  460. ("Hos" . "Hosea") ("Ho" . "Hosea")
  461. ("Joe" . "Joel")
  462. ("Am" . "Amos") ("Amo" . "Amos")
  463. ("Obad" . "Obadiah") ("Ob" . "Obadiah") ("Oba" . "Obadiah")
  464. ("Jon" . "Jonah")
  465. ("Mic" . "Micah") ("Mi" . "Micah")
  466. ("Nah" . "Nahum") ("Na" . "Nahum")
  467. ("Hab" . "Habakkuk") ("Ha" . "Habakkuk")
  468. ("Zeph" . "Zephaniah") ("Zep" . "Zephaniah")
  469. ("Hag" . "Haggai")
  470. ("Zech" . "Zechariah") ("Ze" . "Zechariah")
  471. ("Zac" . "Zechariah") ; Is this one correct??
  472. ("Mal" . "Malachi")
  473. ;; New Testament
  474. ("Mt" . "Matthew") ("Mat" . "Matthew") ("Matt" . "Matthew")
  475. ("Mk" . "Mark") ("Mar" . "Mark")
  476. ("Lk" . "Luke") ("Luk" . "Luke")
  477. ("Jn" . "John") ("Jo" . "John") ("Joh" . "John")
  478. ("Ac" . "Acts") ("Act" . "Acts")
  479. ("Rom" . "Romans") ("Ro" . "Romans")
  480. ("1 Cor" . "I Corinthians") ("1 Corintihans" . "I Corinthians")
  481. ("I Co" . "I Corinthians") ("1 Co" . "I Corinthians")
  482. ("ICor" . "I Corinthians") ("1Cor" . "I Corinthians")
  483. ("2 Cor" . "II Corinthians") ("2 Corinthians" . "II Corinthians")
  484. ("II Co" . "II Corinthians") ("2 Co" . "II Corinthians")
  485. ("IICor" . "II Corinthians") ("2Cor" . "II Corinthians")
  486. ("Gal" . "Galatians") ("Ga" . "Galatians")
  487. ("Eph" . "Ephesians")
  488. ("Phil" . "Philippians") ("Phl" . "Philippians")
  489. ("Col" . "Colossians")
  490. ("1 Thess" . "I Thessalonians") ("1 Thessalonians" . "I Thessalonians")
  491. ("I Th" . "I Thessalonians") ("1 Th" . "I Thessalonians")
  492. ("IThess" . "I Thessalonians") ("1Thes" . "I Thessalonians")
  493. ("1Thess" . "I Thessalonians")
  494. ("2 Thess" . "II Thessalonians") ("2 Thessalonians" . "II Thessalonians")
  495. ("II Th" . "II Thessalonians") ("2 Th" . "II Thessalonians")
  496. ("IIThess" . "II Thessalonians") ("2Thes" . "II Thessalonians")
  497. ("2Thess" . "II Thessalonians")
  498. ("1 Tim" . "I Timothy") ("1 Timothy" . "I Timothy")
  499. ("I Ti" . "I Timothy") ("1 Ti" . "I Timothy") ("ITim" . "I Timothy")
  500. ("1Tim" . "I Timothy")
  501. ("2 Tim" . "II Timothy") ("2 Timothy" . "II Timothy")
  502. ("II Ti" . "II Timothy") ("2 Ti" . "II Timothy") ("IITim" . "II Timothy")
  503. ("2Tim" . "II Timothy")
  504. ("Tit" . "Titus")
  505. ("Phlm" . "Philemon") ("Phm" . "Philemon") ("Plm" . "Philemon")
  506. ("Heb" . "Hebrews") ("He" . "Hebrews")
  507. ("Jas" . "James") ("Ja" . "James") ("Jam" . "James")
  508. ("1 Pet" . "I Peter") ("1 Peter" . "I Peter") ("I Pe" . "I Peter")
  509. ("1 Pe" . "I Peter") ("IPet" . "I Peter") ("1Pet" . "I Peter")
  510. ("2 Pet" . "II Peter") ("2 Peter" . "II Peter") ("II Pe" . "II Peter")
  511. ("2 Pe" . "II Peter") ("IIPet" . "II Peter") ("2Pet" . "II Peter")
  512. ("1 Jn" . "I John") ("1 John" . "I John") ("I Jo" . "I John")
  513. ("1 Jo" . "I John") ("IJohn" . "I John") ("1Jn" . "I John")
  514. ("2 Jn" . "II John") ("2 John" . "II John") ("II Jo" . "II John")
  515. ("2 Jo" . "II John") ("IIJohn" . "II John") ("2Jn" . "II John")
  516. ("3 Jn" . "III John") ("3 John" . "III John") ("III Jo" . "III John")
  517. ("3 Jo" . "III John") ("IIIJohn" . "III John") ("3Jn" . "III John")
  518. ("Ju" . "Jude") ("Jde" . "Jude")
  519. ("Rev" . "Revelation of John") ("Re" . "Revelation of John"))
  520. "A-list of abbreviations for Bible books.")
  521. ;;;;; Book / chapter
  522. (defvar-local bible--current-book (assoc "Genesis" bible--books)
  523. "Current book data (name . chapter).")
  524. (defvar-local bible--current-book-name "Genesis"
  525. "Current book name.")
  526. (defvar-local bible--current-chapter 1
  527. "Current book chapter number.")
  528. ;;;;; Search / query
  529. (defvar-local bible-query nil
  530. "Search query associated with the buffer.")
  531. (defvar-local bible-search-mode "phrase"
  532. "Search mode: either `lucene', `phrase', `regex' or `multiword'.")
  533. (defvar bible-search-range nil)
  534. ;;;;; Lexemes / morphemes
  535. (defvar-local bible-term-language nil
  536. "Displaying terms of this language.")
  537. (defvar-local bible-term-lemma nil
  538. "Lemma for term mode line.")
  539. (defvar-local bible-has-lexemes nil
  540. "Set if the module being displayed has lexical entries availabile.")
  541. (defvar-local bible-has-morphemes nil
  542. "Set if the module being displayed has morphemes availabile.")
  543. (defvar-local bible-text-direction 'left-to-right)
  544. (defvar-local bible-debugme nil
  545. "Make text show up as XML when set.")
  546. (defvar bible-use-tooltips t)
  547. (setq tooltip-delay 1)
  548. (setq tooltip-short-delay .5)
  549. (setq use-system-tooltips nil)
  550. (defvar-local bible-search-query nil
  551. "Query used in toggles (word study and red letter).")
  552. (defvar-local bible-chapter-title nil
  553. "Text preceding start of chapter.
  554. Mostly in Psalms, like `Of David' or the like.")
  555. (defvar-local bible-level "0"
  556. "Used by some modules for indentation and line breaks.")
  557. ;;;; Greek and Hebrew lexeme and morpheme tooltip rendering.
  558. ;;;;; Hash tables for Lexical definitions.
  559. (defvar bible-hash-greek (make-hash-table :test 'equal :size 10000))
  560. (defvar bible-hash-hebrew (make-hash-table :test 'equal :size 10000))
  561. ;;;;; Hash tables for tooltips.
  562. (defvar lex-hash (make-hash-table :test 'equal :size 10000))
  563. (defvar morph-hash (make-hash-table :test 'equal :size 10000))
  564. (defvar bible-outline-strings
  565. '(;;(". ." . ".")
  566. (" I. ." . "\nI.")
  567. (" II. ." . " II.")
  568. (" III. ." . " III.")
  569. (" IV. ." . " IV.")
  570. (" V. ." . " V.")
  571. ("1. ." . "\n 1.")
  572. ("2. ." . "2.")
  573. ("3. ." . "3.")
  574. ("4. ." . "4.")
  575. ("5. ." . "5.")
  576. ("6. ." . "6.")
  577. ("7. ." . "7.")
  578. ("8. ." . "8.")
  579. ("9. ." . "9.")
  580. ("a. ." . "\n a.")
  581. ("(a)." . "\n (a).")
  582. ("b. ." . " b.")
  583. ("c. ." . " c.")
  584. ("d. ." . " d.")
  585. ("e. ." . " e.")
  586. ("f. ." . " f.")
  587. ("g. ." . " g.")
  588. ("h. ." . " h.")
  589. (" . " . ". ")
  590. ("\n\n" . "\n")))
  591. ;;;;; Variables for mode-line-format for search buffers.
  592. (defvar-local bible-search-word-this-query "")
  593. (defvar-local bible-search-text-this-query "")
  594. (defvar-local bible-search-range-this-query nil)
  595. (defvar-local bible-search-matches 0)
  596. ;;;;; Variables used in constructing cross-references.
  597. (defvar-local bible-current-xref-book nil)
  598. (defvar-local bible-current-xref-chapter nil)
  599. ;;;; Functions
  600. ;;;;; Keymap helpers
  601. (defun bible-toggle-display-diatheke ()
  602. "Toggle diatheke args display."
  603. (interactive)
  604. (setq bible-show-diatheke-exec (not bible-show-diatheke-exec))
  605. (message ""))
  606. (defun bible-next-search-item ()
  607. "Go to next item in list of found verses."
  608. (interactive)
  609. (search-forward-regexp bible--verse-regexp))
  610. (defun bible-previous-search-item ()
  611. "Go to previous item in list of found verses."
  612. (interactive)
  613. (search-backward-regexp bible--verse-regexp))
  614. (defun bible-toggle-display-xml ()
  615. "Toggle XML display."
  616. (interactive)
  617. (setq-local bible-debugme (not bible-debugme))
  618. (bible--display))
  619. (defun bible-toggle-text-direction ()
  620. "Switch between left-to-right and right-to-left text direction."
  621. (interactive)
  622. (if (eq bible-text-direction 'left-to-right)
  623. (setq-local bible-text-direction 'right-to-left)
  624. (setq-local bible-text-direction 'left-to-right))
  625. (setq-local bidi-paragraph-direction bible-text-direction))
  626. (defun bible-toggle-tooltips ()
  627. "Toggle use of tooltips to display lexical/morphological items."
  628. (interactive)
  629. (setq bible-use-tooltips (not bible-use-tooltips))
  630. (tooltip-mode 'toggle)
  631. (setq tooltip-resize-echo-area (not bible-use-tooltips))
  632. (setq bible-show-diatheke-exec (and bible-show-diatheke-exec bible-use-tooltips)) ; Don't conflict with echo area
  633. (message ""))
  634. ;;;;; Commands (interactive)
  635. (defun bible-open (&optional buffer book-name chapter verse module)
  636. "Create and open a `bible' buffer.
  637. Optional arguments BOOK-NAME, CHAPTER and VERSE, when supplied, give the
  638. starting verse reference for the buffer. If no optional location
  639. arguments are supplied, Genesis 1:1 is used. Optional argument MODULE
  640. specifies the module to use."
  641. (interactive)
  642. (with-current-buffer (or buffer (get-buffer-create "*bible*"))
  643. (bible)
  644. (setq-local bible-buffer-type 'bible)
  645. (when module (setq-default bible-text module))
  646. (setq-local bible-text (default-value 'bible-text))
  647. (setq-local mode-name (concat "Text " bible-text))
  648. (bible--set-location
  649. (assoc (or book-name "Genesis") bible--books)
  650. (or chapter 1)
  651. verse)
  652. (cl-pushnew (current-buffer) bible--text-buffers)
  653. (set-window-buffer (get-buffer-window (current-buffer)) (current-buffer))))
  654. (defun commentary-open (&optional buffer book-name chapter verse module)
  655. "Create and open a `commentary' buffer.
  656. Optional argument MODULE specifies the commentary module to use.
  657. Optional arguments BOOK-NAME, CHAPTER and VERSE, when supplied, give the
  658. starting verse reference for the buffer. If no optional location
  659. arguments are supplied, Genesis 1:1 is used."
  660. (interactive)
  661. (let ((old-buffer (current-buffer)))
  662. (unless old-buffer (error "No current buffer! How did this happen!"))
  663. (with-current-buffer (or buffer (get-buffer-create "*comm*"))
  664. (bible)
  665. (setq-local bible-buffer-type 'commentary)
  666. (when module (setq-default bible-commentary module))
  667. (setq-local bible-associated-buffer old-buffer)
  668. (setq-local bible-text (default-value 'bible-commentary))
  669. (setq-local mode-name (concat "Commentary " bible-text))
  670. (bible--set-location
  671. (assoc (or book-name "Genesis") bible--books)
  672. (or chapter 1)
  673. verse)
  674. (cl-pushnew (current-buffer) bible--commentary-buffers)
  675. (set-window-buffer (get-buffer-window (current-buffer)) (current-buffer)))))
  676. ;;;;;; Navigation
  677. (defun bible--do-set-location (book chapter &optional verse)
  678. (setq-local bible--current-book book)
  679. (setq-local bible--current-book-name (car book))
  680. (setq-local bible--current-chapter chapter)
  681. (bible--display verse))
  682. (defun bible--set-location (book chapter &optional verse)
  683. "Set the BOOK, CHAPTER and optionally VERSE of the active `bible' buffer."
  684. (let ((buffer (current-buffer)))
  685. (bible--do-set-location book chapter verse)
  686. (when (cl-find buffer bible--synced-buffers)
  687. (save-excursion
  688. (dolist (buf bible--synced-buffers)
  689. (unless (eq buf buffer)
  690. (with-current-buffer buf
  691. (bible--do-set-location book chapter verse))))))))
  692. (defun bible-next-chapter ()
  693. "Page to the next chapter for the active `bible' buffer and
  694. for any synchronized buffers."
  695. (interactive)
  696. (let* ((book-chapters (cdr bible--current-book))
  697. (chapter (min book-chapters (1+ bible--current-chapter))))
  698. (bible--set-location bible--current-book chapter)))
  699. (defun bible-previous-chapter ()
  700. "Page to the previous chapter for the active `bible' buffer and
  701. for any synchronized buffers."
  702. (interactive)
  703. (bible--set-location bible--current-book (max 1 (1- bible--current-chapter))))
  704. (defun bible-next-word ()
  705. "Move forward a word, taking into account the relevant text properties."
  706. (interactive)
  707. (unless (eobp)
  708. (let ((next-change (text-property-search-forward 'strong nil nil t)))
  709. (when next-change
  710. (goto-char (1- (prop-match-end next-change)))))))
  711. (defun bible-previous-word ()
  712. "Move back a word, taking into account the relevant text properties."
  713. (interactive)
  714. (unless (bobp)
  715. (let ((previous-change (text-property-search-backward 'strong)))
  716. (when previous-change
  717. (goto-char (prop-match-beginning previous-change))))))
  718. ;;;;;; Select Location
  719. (defun bible-select-book ()
  720. "Ask user for a new book and chapter for the current `bible' buffer."
  721. (interactive)
  722. (let* ((completion-ignore-case t)
  723. (book-data (assoc (completing-read "Book: " bible--books nil t) bible--books))
  724. (book-data-string (car book-data))
  725. (chapter (string-to-number
  726. (completing-read
  727. "Chapter [1]: "
  728. (bible--list-number-range 1 (cdr book-data)) nil t nil nil "1"))))
  729. (pcase (aref book-data-string 0)
  730. (?1 (setq book-data (cons (concat "I" (substring book-data-string 1)) (cdr book-data))))
  731. (?2 (setq book-data (cons (concat "II" (substring book-data-string 1)) (cdr book-data))))
  732. (?3 (setq book-data (cons (concat "III" (substring book-data-string 1)) (cdr book-data)))))
  733. (bible--set-location book-data chapter)))
  734. (defun bible-select-chapter ()
  735. "Ask user for a new chapter for the current `bible' buffer."
  736. (interactive)
  737. (let* ((book-chapters (cdr bible--current-book))
  738. (chapter (string-to-number
  739. (completing-read
  740. "Chapter [1]: "
  741. (bible--list-number-range 1 book-chapters) nil t nil nil "1"))))
  742. (when chapter
  743. (bible--set-location bible--current-book chapter))))
  744. ;;;;;; Select modules
  745. ;; REVIEW: Need to re-visit which of the following is called in which
  746. ;; mode. `bible-select-<xxxx>' should be called in <xxxx> mode
  747. ;; (i.e. text or commentary). It should be used for replacing
  748. ;; the current text/commentary and should not create a new
  749. ;; buffer. `bible-select-<xxxx>' uses the interface for
  750. ;; choosing texts or commentaries and should be available in
  751. ;; either mode. It will create a new buffer with the chosen
  752. ;; module in it. Commentaries have an `associated buffer'
  753. ;; against which its cross-references work and so I guess
  754. ;; there will have to be an identified current bible text
  755. ;; buffer to set this association. (FMG 31-Mar-2026)
  756. ;; Choose a module.
  757. (defun bible-pick-text (&optional module buffer)
  758. "Keymap action function---select text that the user chooses."
  759. (interactive)
  760. (let ((item (or module (get-text-property (point) 'module))))
  761. (bible-open
  762. (or buffer (generate-new-buffer "*bible*"))
  763. bible--current-book-name
  764. bible--current-chapter
  765. 1
  766. item)))
  767. (defun bible-pick-commentary (&optional module buffer)
  768. "Keymap action function---select commentary that the user chooses.
  769. Use optional argument MODULE as commentary if given."
  770. (interactive)
  771. (let ((item (or module (get-text-property (point) 'module)))
  772. (buffer (or buffer (generate-new-buffer "*comm*"))))
  773. (setq-local bible-commentary item)
  774. (setq-local bible-buffer-type 'commentary)
  775. (split-window-right)
  776. (balance-windows)
  777. (other-window 1)
  778. (commentary-open
  779. buffer
  780. bible--current-book-name
  781. bible--current-chapter
  782. 1
  783. item)))
  784. (defun bible-select-text ()
  785. "Ask user for a new text module for the current `bible' buffer."
  786. (interactive)
  787. (let ((text (completing-read "Text: " bible--texts)))
  788. (unless (string= text "")
  789. (setq-default bible-text text)
  790. (setq-local bible-text text)
  791. (bible-pick-text bible-text (when (eq bible-buffer-type 'bible) (current-buffer))))))
  792. (defun bible-select-commentary ()
  793. "Ask user for a new commentary module for the current `bible' buffer."
  794. (interactive)
  795. (let ((commentary (completing-read "Commentary: " bible--commentaries)))
  796. (unless (string= commentary "")
  797. (setq-local bible-commentary commentary)
  798. (bible-pick-commentary bible-commentary (when (eq bible-buffer-type 'commentary) (current-buffer))))))
  799. ;;;;;; Toggles
  800. (defun bible-toggle-word-study ()
  801. "Toggle the inclusion of word study for the active `bible' buffer."
  802. (interactive)
  803. (setq bible-word-study-enabled (not bible-word-study-enabled))
  804. (bible--display))
  805. (defun bible-toggle-red-letter ()
  806. "Toggle red letter mode for the active `bible' buffer."
  807. (interactive)
  808. (setq bible-red-letter-enabled (not bible-red-letter-enabled))
  809. (bible--display))
  810. (defun bible-toggle-buffer-sync ()
  811. "Either add or remove the current buffer from the
  812. `bible--synced-buffers' list."
  813. (interactive)
  814. (let ((buffer (current-buffer)))
  815. (if bible--synced-p
  816. (progn
  817. (setq bible--synced-buffers (cl-delete buffer bible--synced-buffers))
  818. (setq-local bible--synced-p nil))
  819. (cl-pushnew buffer bible--synced-buffers)
  820. (setq-local bible--synced-p t))
  821. (force-mode-line-update)))
  822. (defun bible-split-display ()
  823. "Copy the active `bible' buffer into a new buffer in another window."
  824. (interactive)
  825. (split-window-right)
  826. (balance-windows)
  827. (other-window 1)
  828. (bible-open (generate-new-buffer "*bible*") bible--current-book-name bible--current-chapter 1 bible-text))
  829. ;;;;;; Search helpers
  830. (defun bible-set-search-range ()
  831. "Ask user for a new text module for the current `bible' buffer."
  832. (interactive)
  833. (let ((range (read-string "Range (<return> to clear): ")))
  834. (if (string-equal range "")
  835. (setq bible-search-range nil)
  836. (setq bible-search-range range))))
  837. (defun bible-search (query)
  838. "Search for a QUERY: a word or phrase.
  839. Asks the user for type of search: either `lucene', `phrase', `regex'
  840. or `multiword'. `lucene' is the default search.
  841. `lucene' mode requires an index to be built using the `mkfastmod' program."
  842. (interactive "sBible Search: ")
  843. (when (> (length query) 0)
  844. (let ((searchmode (completing-read "Search Mode: " '("lucene" "phrase" "regex" "multiword") nil t "lucene")))
  845. (bible--open-search query searchmode (buffer-local-value 'bible-text (current-buffer))))))
  846. (defvar-local bible-search-reference-buffer nil)
  847. (defun bible-follow-verse ()
  848. "Follow the hovered verse in a bible search mode buffer.
  849. Create a new `bible' buffer positioned at the selected verse."
  850. (interactive)
  851. (let* ((text (thing-at-point 'line t))
  852. book
  853. chapter
  854. verse)
  855. (when (string-match bible--verse-regexp text)
  856. (setq text (match-string 0 text))
  857. (string-match "I?I?I? ?[A-Z]?[a-z]* " text)
  858. (setq book (match-string 0 text))
  859. (string-match "[0-9]?[0-9]?[0-9]?:" text)
  860. (setq chapter (substring (match-string 0 text) 0 (1- (length (match-string 0 text)))))
  861. (string-match ":[0-9]?[0-9]?[0-9]?" text)
  862. (setq verse (substring (match-string 0 text) 1))
  863. (unless bible-search-reference-buffer
  864. (setq-local bible-search-reference-buffer (generate-new-buffer "*bible*")))
  865. (bible-open bible-search-reference-buffer
  866. (string-trim book)
  867. (string-to-number chapter)
  868. (string-to-number verse)
  869. bible-text))))
  870. (defun bible-follow-xref ()
  871. "Follow the hovered verse in a bible term or commentary buffer.
  872. Create a new `bible' buffer positioned at the specified verse.
  873. Handle abbreviations."
  874. (interactive)
  875. (let ((xref (get-text-property (point) 'xref)))
  876. (when xref
  877. (let ((verse-ref (split-string xref))
  878. book-abbrev
  879. chapter-verse)
  880. (cond ((= (length verse-ref) 2) ; Mat 5 or the like
  881. (setq book-abbrev (car verse-ref)
  882. chapter-verse (split-string (cadr verse-ref) ":")))
  883. ((= (length verse-ref) 3) ; II Cor 3:17 or the like
  884. (setq book-abbrev (concat (car verse-ref) " " (cadr verse-ref))
  885. chapter-verse (split-string (caddr verse-ref) ":"))))
  886. ;; Use book abbreviation if present or try whatever is in verse-ref.
  887. (let ((book (or (alist-get book-abbrev
  888. bible--book-name-abbreviations
  889. nil
  890. nil
  891. #'string-equal-ignore-case)
  892. (car verse-ref)))
  893. (chapter (car chapter-verse))
  894. (verse (cadr chapter-verse)))
  895. (bible-open bible-associated-buffer
  896. (string-trim book)
  897. (string-to-number chapter)
  898. (string-to-number verse)
  899. (default-value 'bible-text)))))))
  900. ;;;;;; User visible actions.
  901. ;; These can be called interactively if you know the Strong's number
  902. ;; you want to look up.
  903. (defun bible-term-hebrew (term)
  904. "Query user for a Strong's Hebrew Lexicon TERM."
  905. (interactive "sTerm: ")
  906. (bible--open-term-hebrew term))
  907. (defun bible-term-greek (term)
  908. "Query user for a Strong's Greek Lexicon TERM."
  909. (interactive "sTerm: ")
  910. (bible--open-term-greek term))
  911. ;; Interactively insert a verse into an arbitrary current buffer.
  912. (defun bible-insert ()
  913. "Query user to select a verse for insertion into the current buffer."
  914. (interactive)
  915. (let* ((completion-ignore-case t)
  916. (book-data (assoc (completing-read "Book: " bible--books nil t) bible--books))
  917. (chapter (when book-data (completing-read "Chapter: " (bible--list-number-range 1 (cdr book-data)) nil t "1" nil "1")))
  918. (verse (when chapter (read-from-minibuffer "Verse: ")))
  919. (query (concat (car book-data) " " chapter ":" verse))
  920. (args (list bible-sword-query nil (current-buffer) t "-b" bible-text "-f" "plain" "-k" query)))
  921. (apply #'call-process args)))
  922. ;;;;;; Support (internal)
  923. ;;;;;;; Diatheke interface
  924. (defun bible--exec-diatheke (query &optional filter format module)
  925. "Execute `diatheke' with specified QUERY options.
  926. FILTER is the Diatheke filter argument. FORMAT is either plain or
  927. the default of internal. MODULE is the text module to use. Returns
  928. string containing query result."
  929. (let ((module (or module bible-text)))
  930. (with-temp-buffer
  931. (let ((args (list bible-sword-query nil (current-buffer) t "-b" module)))
  932. (if filter
  933. (setq filter (concat filter bible-diatheke-filter-options))
  934. (setq filter bible-diatheke-filter-options))
  935. (setq args (append args (list "-o" filter)))
  936. (setq args (append args (list "-f" (pcase format ("plain" "plain") (_ "internal")) "-k" query)))
  937. (when bible-show-diatheke-exec
  938. (message "%s" args))
  939. (apply #'call-process args))
  940. (buffer-string))))
  941. (defun bible--diatheke-search (query searchtype &optional format module)
  942. "Execute `diatheke' on QUERY with SEARCHTYPE.
  943. Optional argument FORMAT is either plain or the default of internal.
  944. MODULE is the text module to use and defaults to the current module."
  945. (with-temp-buffer
  946. (let ((args (list bible-sword-query nil (current-buffer) t "-b" (or module bible-text))))
  947. (setq args (append args (list "-s" (pcase searchtype
  948. ("lucene" "lucene")
  949. ("phrase" "phrase")
  950. ("regex" "regex")
  951. ("multiword" "multiword")))))
  952. (when bible-search-range (setq args (append args (list "-r" bible-search-range))))
  953. (setq args (append args (list "-f" (pcase format ("plain" "plain") (_ "internal")) "-k" query)))
  954. (when bible-show-diatheke-exec
  955. (message "%s" args))
  956. (apply #'call-process args))
  957. (buffer-string)))
  958. ;; Use HTMLHREF format with diatheke, post-process to render html.
  959. (defun bible--morph-query (query module)
  960. "Execute `diatheke' to do morph QUERY, using MODULE.
  961. Render HTML, return string. Do some tweaking specific to morphology."
  962. (with-temp-buffer
  963. (let ((args (list bible-sword-query nil (current-buffer) t "-b" module "-o" "m" "-f" "HTMLHREF" "-k" query)))
  964. (when bible-show-diatheke-exec
  965. (message "%s" args))
  966. (apply #'call-process args)
  967. (shr-render-region (point-min) (point-max))
  968. (format-replace-strings
  969. '(("\n:" . "") ; This makes the Packard morphology display look better.
  970. ("Part of Speech" . "")) ; This helps the Robinson display look better.
  971. nil (point-min) (point-max))
  972. (substring (buffer-string) (1+ (length query)))))) ; This tries to get rid of unnecessary query identifier.
  973. ;; Use "plain" format with diatheke.
  974. (defun bible--lex-query (query module)
  975. "Execute `diatheke' for QUERY, using MODULE.
  976. Plain format, returns string."
  977. (bible--exec-diatheke query nil "plain" module))
  978. ;;;;;; Lexicon processing
  979. ;; The Greek lexical definitions are done using the HTMLHREF output
  980. ;; format so they come out looking nice and having clickable
  981. ;; cross-references and/or Strong's references.
  982. (defun bible--process-href ()
  983. "Fix the XML so cross-references are in the right format.
  984. These cross-references get processed later when the term is displayed.
  985. First, find the links put in by diatheke's HTMLHREF output format.
  986. Replace the links with verse references that get changed to clickable
  987. cross-references when the term is displayed.
  988. The verse refs look like this: <bookname>.<chapter>.<verse>. We convert
  989. them to the <bookname> <chapter>:<verse> format."
  990. (goto-char (point-min))
  991. (while (re-search-forward "<a href=\"passagestudy.*?</a>" nil t) ; HTMLHREF cross references.
  992. (let ((match-text (match-string 0)))
  993. ;; Delete original link.
  994. (replace-match "" nil nil)
  995. ;; Get the verse reference from the string we saved. Put it in
  996. ;; good format, then insert it into buffer where href was.
  997. (when (string-match "value=.*?&" match-text)
  998. (let* ((value-string (match-string 0 match-text))
  999. ;; Strip off value= and trailing &.
  1000. (verse-ref-string (substring value-string 6 (1- (length value-string))))
  1001. (verse-ref-length (length verse-ref-string))
  1002. period)
  1003. ;; Convert periods
  1004. ;; Substitute first period with space
  1005. (when (setq period (cl-search "." verse-ref-string))
  1006. (aset verse-ref-string period ? ))
  1007. ;; Substitute second period with colon
  1008. (when (setq period (cl-search "." verse-ref-string))
  1009. (aset verse-ref-string period ?:))
  1010. ;; Replace numbers (1, 2 or 3) with roman numerals (I, II, III).
  1011. (pcase (aref verse-ref-string 0)
  1012. (?1 (setq verse-ref-string (concat "I" (substring verse-ref-string 1))))
  1013. (?2 (setq verse-ref-string (concat "II" (substring verse-ref-string 1))))
  1014. (?3 (setq verse-ref-string (concat "III" (substring verse-ref-string 1)))))
  1015. (set-text-properties 0 verse-ref-length nil verse-ref-string) ; Clear unwanted properties (if any)
  1016. (insert verse-ref-string))))))
  1017. (defun bible--cleanup-lex-text (lex-text)
  1018. "Reformat tooltip text LEX-TEXT so tooltips look nice."
  1019. (dolist (outline-string bible-outline-strings)
  1020. (setq lex-text (string-replace (car outline-string) (cdr outline-string) lex-text)))
  1021. lex-text)
  1022. (defun bible--lookup-def-greek (key)
  1023. "Execute `diatheke' to do query on KEY.
  1024. Massage output so verse cross references are usable. Returns string."
  1025. (with-temp-buffer
  1026. (let ((args (list bible-sword-query nil (current-buffer) t "-b" bible-greek-lexicon "-o" "m" "-f" "plain" "-k" key)))
  1027. (when bible-show-diatheke-exec
  1028. (message "%s" args))
  1029. (apply #'call-process args)
  1030. (bible--cleanup-lex-text (bible--remove-module-name bible-greek-lexicon (buffer-string))))))
  1031. (defun bible--lookup-lemma-index (key)
  1032. "Return the Greek lemma from lemma index with a strong's number as KEY."
  1033. (string-trim
  1034. (bible--remove-module-name bible-lexicon-index (bible--lex-query key bible-lexicon-index))))
  1035. (defun bible--lookup-lemma-greek-indexed (key)
  1036. "Lookup Greek lemma using Strong's number KEY.
  1037. Then look up the definition of that lemma. Used when two-stage
  1038. lexical definition is set for a particular lexicon."
  1039. (let ((lemma-entry (bible--lookup-lemma-index key))) ; Get lemma from Strong's number
  1040. (when lemma-entry
  1041. (let ((lemma (caddr (split-string lemma-entry " "))))
  1042. (bible--lookup-def-greek lemma)))))
  1043. (defun bible--lookup-lemma-greek (key)
  1044. "Lookup lexical definition using Strong's number KEY.
  1045. 1. Check hash table first. If entry found, return.
  1046. 2. Otherwise, if a lexicon is accessed by lemmas, do lookup using index method.
  1047. 3. Otherwise just use the Strong's number method."
  1048. (or (gethash key bible-hash-greek)
  1049. (puthash key
  1050. (if bible-use-index-for-lexicon
  1051. (bible--lookup-lemma-greek-indexed key)
  1052. (bible--lookup-def-greek key))
  1053. bible-hash-greek)))
  1054. (defun bible--lookup-def-hebrew (key)
  1055. "Execute `diatheke' to do query on KEY.
  1056. Massage output so various cross references are usable. Returns string."
  1057. (with-temp-buffer
  1058. (let ((args (list bible-sword-query nil (current-buffer) t "-b" bible-hebrew-lexicon "-f" "plain" "-k" key)))
  1059. (when bible-show-diatheke-exec
  1060. (message "%s" args))
  1061. (apply #'call-process args)
  1062. (bible--process-href)
  1063. (concat (string ?\x200e)
  1064. (bible--remove-module-name bible-hebrew-lexicon (substring (buffer-string) 7))))))
  1065. (defun bible--lookup-lemma-hebrew (key)
  1066. "Lookup lexical definition using Strong's number KEY.
  1067. 1. Check hash table first. If entry found, return.
  1068. 2. Otherwise, if a lexicon is accessed by lemmas, do lookup using index method.
  1069. 3. Otherwise just use the Strong's number method."
  1070. (or (gethash key bible-hash-hebrew)
  1071. (puthash key
  1072. (bible--lookup-def-hebrew key)
  1073. bible-hash-hebrew)))
  1074. ;; We use the shorter lexicons for text in tooltips. We also cache the
  1075. ;; lex and morph strings, hoping to speed up tooltip rendering.
  1076. (defun bible--lookup-lemma-short (lemma lexicon)
  1077. "Look up lexical entry for LEMMA in short LEXICON.
  1078. Returns a string that is intended to be displayed in a tooltip.
  1079. Uses short lexicon (e.g. StrongsRealHebrew or StrongsRealGreek)."
  1080. (when (string-match "[0-9]+" lemma)
  1081. (bible--remove-module-name
  1082. lexicon
  1083. ;; Get rid of unnecessary strongs codes at the beginning.
  1084. (replace-regexp-in-string
  1085. ".*[0-9]+ [0-9]+ " ""
  1086. (bible--lex-query (concat (match-string 0 lemma)) lexicon)))))
  1087. (defun bible--lookup-lex (lex)
  1088. "Look up lexical item LEX. This is used for tooltips.
  1089. Return hash table entry if present in `lex-hash' cache, else look up in
  1090. database and stash in cache."
  1091. (when lex
  1092. (let* ((key (substring lex 7)) ; strip off "strong:" prefix.
  1093. (lex-text (gethash key lex-hash)))
  1094. (if lex-text
  1095. lex-text
  1096. (setq lex-text
  1097. (cond ((string-prefix-p "G" key)
  1098. (bible--lookup-lemma-short key bible-greek-lexicon-short))
  1099. ((string-prefix-p "H" key)
  1100. (concat (string ?\x200e)
  1101. (bible--lookup-lemma-short key bible-hebrew-lexicon-short)))))
  1102. (puthash key (string-fill (bible--cleanup-lex-text lex-text) 75) lex-hash)))))
  1103. (defun bible--lookup-morph-entry (morph)
  1104. "Look up entry for morphological item MORPH.
  1105. Return hash table entry if present in `morph-hash' cache, else look up in
  1106. database and stash in cache."
  1107. (when morph
  1108. (or (gethash morph morph-hash)
  1109. (puthash morph
  1110. (let (morph-module morph-key)
  1111. ;; We know about these modules. (Assume they're installed.)
  1112. (cond ((string-prefix-p "robinson:" morph)
  1113. (setq morph-module "Robinson")
  1114. (setq morph-key (substring morph (length "robinson:"))))
  1115. ((string-prefix-p "packard:" morph)
  1116. (setq morph-module "Packard")
  1117. (setq morph-key (substring morph (length "packard:"))))
  1118. ((string-prefix-p "oshm:" morph)
  1119. (setq morph-module "OSHM")
  1120. (setq morph-key (substring morph (length "oshm:")))))
  1121. (bible--remove-module-name morph-module (bible--morph-query morph-key morph-module)))
  1122. morph-hash))))
  1123. ;; Get string for tooltip display
  1124. (defun bible--show-lex-morph (_window object pos)
  1125. "Get text for tooltip display for OBJECT at POS in WINDOW.
  1126. Includes both lex and morph definitions if text module has
  1127. both tags, otherwise just get lex definition."
  1128. (let* ((lex (get-text-property pos 'strong object))
  1129. (lex-text (bible--lookup-lex lex))
  1130. (morph (get-text-property pos 'morph object))
  1131. (morph-text (bible--lookup-morph-entry morph)))
  1132. (when lex-text
  1133. ;; This removes backslashes to prevent bogus command
  1134. ;; substitutions (that is, Emacs mistakenly filling in a key
  1135. ;; binding for some command---see Info doc on Substituting Key
  1136. ;; Bindings) in the tooltip.
  1137. ;; REVIEW: I couldn't figure out a better way to bypass command
  1138. ;; substitution in the tooltips. (FMG 5-Mar-2026)
  1139. (subst-char-in-string
  1140. ?\\
  1141. ?
  1142. (if morph-text
  1143. (concat (string-trim lex-text) "\n" (string-trim morph-text))
  1144. (string-trim lex-text))))))
  1145. ;;;; Display module text
  1146. (defun bible-handle-divine-name (item)
  1147. "When ITEM is divine name, display it as such."
  1148. (let ((start (point))
  1149. (strongs (dom-attr item 'savlm)))
  1150. (insert "LORD")
  1151. (let ((end (point)))
  1152. (add-face-text-property start end 'bold)
  1153. (put-text-property start end 'keymap bible-hebrew-keymap)
  1154. (when (and strongs (string-match "strong:H" strongs))
  1155. (put-text-property start end 'help-echo 'bible--show-lex-morph)
  1156. (put-text-property start end 'strong (match-string 0 strongs))))))
  1157. (defun bible--process-word (item iproperties)
  1158. "Handle <w ...> fubar </w> tag in ITEM. Check IPROPERTIES for qualifiers.
  1159. Add tooltips for definitions and morphology. Also insert lemmas in
  1160. buffer if `word study' is turned on (must be done after item is inserted
  1161. in buffer)."
  1162. (let ((word (string-trim (bible-dom-text item)))
  1163. (morph (dom-attr item 'morph))
  1164. (savlm (dom-attr item 'savlm))
  1165. (lemma (dom-attr item 'lemma))
  1166. (divinename (dom-by-tag item 'divinename)))
  1167. (let ((start (point))
  1168. (end (+ (point) (length word))))
  1169. (insert word)
  1170. ;; REVIEW: Special case this. Some modules do this differently.
  1171. ;; (FMG 5-Mar-2026)
  1172. (when divinename
  1173. (just-one-space)
  1174. (bible-handle-divine-name item)
  1175. (just-one-space))
  1176. ;; Red letter.
  1177. (when (plist-get iproperties 'jesus)
  1178. (add-face-text-property start end '(:foreground "red")))
  1179. ;; lexical definitions
  1180. ;; N.B. There are some severe issues with Strongs numbers in some modules.
  1181. (when (or savlm lemma)
  1182. (let* ((matched nil)
  1183. (lexemes (split-string (or savlm lemma)))
  1184. (lexeme
  1185. ;; HACK: Kludge alert. KJV module conflates Greek
  1186. ;; articles with nouns. Deal with this.
  1187. ;; (FMG 5-Mar-2026)
  1188. (let ((lexeme-list
  1189. (if (string= bible-text "KJV")
  1190. (reverse lexemes) ; Use the last `strong:' entry.
  1191. lexemes)))
  1192. (catch 'loop
  1193. (dolist (item lexeme-list)
  1194. (when (string-prefix-p "strong:" item)
  1195. (throw 'loop item)))))))
  1196. (when lexeme
  1197. (cond ((string-match "strong:G.*" lexeme) ; Greek
  1198. (setq matched (match-string 0 lexeme))
  1199. (put-text-property start end 'keymap bible-greek-keymap))
  1200. ((string-match "strong:H.*" lexeme) ; Hebrew
  1201. (setq matched (match-string 0 lexeme))
  1202. (put-text-property start end 'keymap bible-hebrew-keymap)))
  1203. ;; Add help-echo, strongs reference for tooltips if match.
  1204. (when matched
  1205. (setq bible-has-lexemes " Lex")
  1206. (put-text-property start end 'help-echo 'bible--show-lex-morph)
  1207. (put-text-property start end 'strong matched))))
  1208. ;; morphology
  1209. (when morph
  1210. (let* ((matched nil)
  1211. (morphemes (split-string morph))
  1212. (morpheme (car (last morphemes)))) ; KJV kludge as above
  1213. (if (or
  1214. (string-match "robinson:.*" morpheme) ; Robinson Greek morphology
  1215. (string-match "packard:.*" morpheme) ; Packard Greek morphology --- LXX seems to use this
  1216. (string-match "oshm:.*" morpheme)) ; OSHM Hebrew morphology
  1217. (setq matched (match-string 0 morpheme)))
  1218. (when matched
  1219. (setq bible-has-morphemes " Morph")
  1220. (put-text-property start end 'morph matched)
  1221. (put-text-property start end 'help-echo 'bible--show-lex-morph))))
  1222. ;; Insert lemma into buffer. Lemma tag will be part of lemma/savelm item.
  1223. ;; TODO: Should I enable lexicon lookups on these lemmas? I
  1224. ;; don't use this anyway.... (FMG 5-Mar-2026)
  1225. (when (and bible-word-study-enabled lemma (string-match "lemma.*:.*" lemma))
  1226. (dolist (word (split-string (match-string 0 lemma) " "))
  1227. (setq word (replace-regexp-in-string "[.:a-zA-Z0-9]+" "" word))
  1228. (just-one-space)
  1229. (let ((refstart (point)))
  1230. (insert word)
  1231. (add-face-text-property refstart (point) '(:foreground "blue"))
  1232. (put-text-property refstart (point) 'keymap bible-lemma-keymap))))))))
  1233. (defun bible--insert-title (title-node)
  1234. "Insert the text in TITLE-NODE into buffer as a chapter title.
  1235. Since each verse will have a `title' tag, keep track and only emit a
  1236. title when the new title in `title-node' is different from the one
  1237. stored in `bible-chapter-title'."
  1238. (unless (equal bible-chapter-title title-node)
  1239. (setq-local bible-chapter-title title-node)
  1240. (let ((title-text
  1241. (replace-regexp-in-string ; Clear out XML.
  1242. "<.*?>" ""
  1243. (bible-dom-texts bible-chapter-title)))
  1244. (start (point)))
  1245. (bible-new-line)
  1246. ;; Insert the LRM character to make the text render left-to-right.
  1247. ;; This is necessary in the KJV module when displaying psalm 119.
  1248. (insert (string ?\x200e) title-text)
  1249. (put-text-property start (point) 'face 'bold)
  1250. (newline)
  1251. (delete-blank-lines))))
  1252. ;; These tags appear in ESV modules (and maybe others?)
  1253. ;; REVIEW: Is this right? (FMG 5-Mar-2026)
  1254. (defun bible--level-tag (node)
  1255. "Indent or break line as dictated by NODE."
  1256. (let ((type (dom-attr node 'type))
  1257. (level (dom-attr node 'level)))
  1258. (cond ((and type (string-equal-ignore-case type "x-br"))
  1259. (newline))
  1260. ((and type (string-equal-ignore-case type "x-indent"))
  1261. (insert "\t"))
  1262. ;; REVIEW: Some modules use `level' tag but
  1263. ;; not in a consistent way. (FMG 7-Mar-2026)
  1264. ((equal level "1")
  1265. (just-one-space))
  1266. ((equal level "2")
  1267. (newline)
  1268. (delete-blank-lines)))))
  1269. (defun bible--insert-xref (node)
  1270. "Insert a cross reference specified by NODE.
  1271. This format is used by the NETnote module."
  1272. ;; HACK: What a mess! There are still some broken edge cases! (FMG 29-Mar-2026)
  1273. (let* ((refs-text (bible-dom-text node))
  1274. (refs (split-string refs-text "," t " ")))
  1275. ;; Fix: each reference will have a book name. There are three
  1276. ;; different kinds of reference entries:
  1277. ;;
  1278. ;; 1. The reference entry will have a single book with possibly
  1279. ;; multiple references to that book. Make sure the book is carried
  1280. ;; along to all the other references until another book name
  1281. ;; appears. E.g. Mark 2:3 4 8:17 all refer to the book of Mark.
  1282. ;;
  1283. ;; 2. The reference entry has multiple book names. Mark 2:3 8 Luke
  1284. ;; 8:17 is three references, two to Mark and one to Luke. Make
  1285. ;; sure the book names are updated appropriately.
  1286. ;;
  1287. ;; 3. If the reference entry has no book at all, use the current
  1288. ;; module's book name. We set it here as a default; it will get
  1289. ;; replaced if a book name appears in the reference entry.
  1290. (setq-local bible-current-xref-book (concat bible--current-book-name " "))
  1291. (dolist (ref refs)
  1292. (let ((a-ref (split-string ref ";" t " ")))
  1293. (dolist (b-ref a-ref)
  1294. ;; b-ref is an individual reference.
  1295. ;; At this point b-ref will, we hope, look like one of the following:
  1296. ;; <book> <chapter>:<verse> (or maybe <book> <chapter>)
  1297. ;; <chapter>:verse
  1298. ;; <verse> (or maybe <verse>-<verse>)
  1299. ;; Books may look like this: <1 Cor> or <Gal> so we have to deal with the possible space.
  1300. ;; We ignore verse ranges and hope for the best (it seems to do the right thing).
  1301. (let ((chapter-set-p nil))
  1302. ;; See if we've got a book name. Use greedy regexp to make
  1303. ;; sure we get the whole name. If the name is not found,
  1304. ;; there will be a default (for this xref) name in
  1305. ;; bible-current-xref-book.
  1306. (when (string-match ".* " b-ref)
  1307. (setq-local bible-current-xref-book (match-string 0 b-ref)))
  1308. ;; See if we've got a chapter. Note this regexp will skip
  1309. ;; the book name if present.
  1310. (when (string-match "[0-9]*:" b-ref)
  1311. (setq-local bible-current-xref-chapter
  1312. (string-trim
  1313. (substring
  1314. (match-string 0 b-ref)
  1315. 0
  1316. (1- (length (match-string 0 b-ref))))))
  1317. (setq chapter-set-p t))
  1318. (let* ((match (string-match "[0-9]*" b-ref (if chapter-set-p (match-end 0) 0)))
  1319. (verse (string-trim (substring b-ref match (match-end 0)))))
  1320. (just-one-space)
  1321. (let ((start (point))
  1322. (the-ref (concat bible-current-xref-book bible-current-xref-chapter)))
  1323. (when verse (setq the-ref (concat the-ref ":" verse)))
  1324. (insert b-ref)
  1325. (put-text-property start (point) 'xref the-ref)
  1326. (put-text-property start (point) 'keymap bible-term-mode-map)
  1327. (put-text-property start (point) 'help-echo (concat "Go to " the-ref))
  1328. (add-face-text-property start (point) '(:foreground "blue"))))))))))
  1329. (defun bible--insert-osis-xref (node)
  1330. "Insert a cross reference specified by NODE.
  1331. The node should have the `osisref' attribute."
  1332. (let* ((ref-text (bible-dom-text node))
  1333. (ref-ref (dom-attr node 'osisref))
  1334. (ref-split (split-string ref-ref "[.]" t " "))
  1335. (ref-book (cl-first ref-split))
  1336. (ref-chapter (cl-second ref-split))
  1337. (ref-verse (cl-third ref-split))
  1338. (the-ref (concat ref-book " " ref-chapter ":" ref-verse)))
  1339. (just-one-space)
  1340. (let ((start (point)))
  1341. (insert ref-text)
  1342. (put-text-property start (point) 'xref the-ref)
  1343. (put-text-property start (point) 'keymap bible-term-mode-map)
  1344. (put-text-property start (point) 'help-echo (concat "Go to " the-ref))
  1345. (add-face-text-property start (point) '(:foreground "blue")))))
  1346. (defun bible--insert-domnode-recursive (node &optional iproperties)
  1347. "Recursively parse domnode NODE obtained from `libxml-parse-html-region'.
  1348. Inserts resulting text into active buffer with properties specified in
  1349. IPROPERTIES.
  1350. In processing subnodes, each case will prepend a space if it needs it."
  1351. (when (and bible-red-letter-enabled (equal (dom-attr node 'who) "Jesus"))
  1352. ;; For red-letter display.
  1353. (setq iproperties (plist-put iproperties 'jesus t)))
  1354. (dolist (subnode (dom-children node))
  1355. (cond ((null subnode) nil)
  1356. ((stringp subnode)
  1357. ;; Red letter
  1358. (when (plist-get iproperties 'jesus)
  1359. (add-face-text-property 0 (length subnode) '(:foreground "red") nil subnode))
  1360. (insert subnode))
  1361. ((consp subnode)
  1362. (let ((tag (dom-tag subnode)))
  1363. (pcase tag
  1364. ;; TODO: There are lots of tags we don't handle, especially in commentaries.
  1365. ;; Maybe process these at some point? Include footnotes etc.
  1366. ;; (FMG 5-Mar-2026)
  1367. ;; 'w is usual case.
  1368. ('w (insert " ") (bible--process-word subnode iproperties))
  1369. ('title
  1370. ;; This mess is to deal with the possibility that the
  1371. ;; title might change in the middle of the chapter. I'm
  1372. ;; talking about YOU, Psalm 119.
  1373. (if bible-chapter-title
  1374. (bible--insert-title subnode) ; Middle of chapter.
  1375. (save-excursion ; Beginning of chapter.
  1376. (goto-char (point-min))
  1377. (bible--insert-title subnode))))
  1378. ;; Font tag ignored for now, treat as if 'w.
  1379. ('font (insert " ") (bible--process-word subnode iproperties))
  1380. ('hi (when (equal (dom-attr subnode 'type) "bold")
  1381. (just-one-space)
  1382. (let ((word (bible-dom-text subnode))
  1383. (start (point)))
  1384. (insert word)
  1385. (put-text-property start (point) 'face 'bold))))
  1386. ;; Italic face (special case for certain module)
  1387. ('i
  1388. (just-one-space)
  1389. (let ((word (bible-dom-text subnode))
  1390. (start (point)))
  1391. (insert word)
  1392. (put-text-property start (point) 'face 'bold)
  1393. (add-face-text-property start (point) '(:foreground "orange"))))
  1394. ;; 'q is used for quotations (red letter and non-specific).
  1395. ;; NASB Module uses 'seg to indicate OT quotations (and others?).
  1396. ((or 'body 'seg 'p 'q)
  1397. ;; Some modules use `marker' to indicate quotation marks.
  1398. (when (dom-attr subnode 'marker) (insert (dom-attr subnode 'marker)))
  1399. (bible--insert-domnode-recursive subnode iproperties))
  1400. ('l (bible--level-tag subnode))
  1401. ;; REVIEW: divine name handling doesn't seem to work the same
  1402. ;; with all modules. (FMG 26-Mar-2026)
  1403. ('divinename (bible-handle-divine-name subnode))
  1404. ;; Some modules use this for line breaks and such.
  1405. ('milestone
  1406. (pcase (dom-attr subnode 'type)
  1407. ("line" (bible-new-line))
  1408. ;; ("x-PN" (bible-new-line)) ; REVIEW: Don't yet understand this one. (FMG 26-Mar-2026)
  1409. ("x-p" (insert (dom-attr subnode 'marker) " "))))
  1410. ('br (bible-new-line))
  1411. ('lb (when (equal (dom-attr subnode 'type) "x-begin-paragraph") (bible-new-line)))
  1412. ('div (when (or (equal (dom-attr subnode 'type) "paragraph")
  1413. (equal (dom-attr subnode 'type) "x-p"))
  1414. (bible-new-line)))
  1415. ;; For commentaries and the like.
  1416. ;; This is used by the NETnote module.
  1417. ('scripref (bible--insert-xref subnode))
  1418. ;; This is used by many commentaries.
  1419. ('reference (bible--insert-osis-xref subnode))
  1420. ;; Various text properties---ignore for now. REVIEW: (FMG 26-Mar-2026)
  1421. ((or 'b 'u) (bible--insert-domnode-recursive subnode iproperties))
  1422. ;; Word inserted by translation, not in original, give visual indication.
  1423. ('transchange
  1424. (insert " ")
  1425. (let ((word (bible-dom-text subnode))
  1426. (start (point))
  1427. (face (if (plist-get iproperties 'jesus) '(:foreground "salmon") '(:foreground "gray50"))))
  1428. (insert word)
  1429. (add-face-text-property start (point) face)))))))))
  1430. (defun bible--display (&optional verse)
  1431. "Render a page (chapter) of a Bible module.
  1432. Defaults to using `bible-text'.
  1433. If optional argument VERSE is supplied, set cursor at verse."
  1434. (let ((buffer-read-only nil)
  1435. (bible-has-lexemes nil)
  1436. (bible-has-morphemes nil))
  1437. (erase-buffer)
  1438. (insert (bible--exec-diatheke (concat bible--current-book-name ":" (number-to-string bible--current-chapter))))
  1439. ;; Parse the xml in the buffer into a DOM tree.
  1440. (let ((html-dom-tree (libxml-parse-html-region (point-min) (point-max))))
  1441. ;; Render the DOM tree into the buffer.
  1442. (unless bible-debugme ; If this is true, display the XML.
  1443. (erase-buffer)
  1444. (setq-local bible-chapter-title nil)
  1445. ;; Looking for the "body" tag in the DOM node.
  1446. (bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body))
  1447. (goto-char (point-min))))
  1448. (save-excursion
  1449. (let ((search-string (concat " *" (car bible--current-book) " " (number-to-string bible--current-chapter) ":")))
  1450. ;; Delete <Book Ch:> at beginning of verse, just leave verse number.
  1451. (while (re-search-forward search-string nil t)
  1452. (replace-match "")
  1453. (bible-new-line)
  1454. ;; Highlight verse number
  1455. (when (re-search-forward " *[0-9]+:" nil t 1)
  1456. (add-face-text-property (match-beginning 0) (match-end 0) '(:foreground "purple"))))))
  1457. (save-excursion
  1458. ;; Fix divine name lossage.
  1459. (while (re-search-forward "Lord LORD" nil t)
  1460. (replace-match "LORD")
  1461. (add-face-text-property (point) (- (point) 4) 'bold))
  1462. (while (re-search-forward "Lord.+s LORD" nil t -1)
  1463. (replace-match "LORD's")
  1464. (add-face-text-property (1- (point)) (- (point) 5) 'bold))
  1465. ;; Remove the module name from the buffer.
  1466. (while (re-search-forward (concat "^.*" bible-text ".*$") nil t)
  1467. (replace-match ""))
  1468. (delete-blank-lines))
  1469. (save-excursion
  1470. (format-replace-strings '(("." . ". ")
  1471. ("," . ", ")
  1472. (";" . "; ")
  1473. (":" . ": ")
  1474. ("?" . "? ")
  1475. ("!" . "! ")
  1476. (" ." . ". ")
  1477. (" ," . ", ")
  1478. (" ;" . "; ")
  1479. (" :" . ": ")
  1480. (" ?" . "? ")
  1481. (" !" . "! ")
  1482. ("“ " . "“")
  1483. ("‘ " . "‘")
  1484. (" ’" . "’")
  1485. (". ”" . ".”")
  1486. ("? ”" . "?”"))
  1487. nil (point-min) (point-max)))
  1488. ;; Get rid of multiple consecutive spaces.
  1489. (save-excursion
  1490. (while (re-search-forward " *" nil t) ; More than one space in a row
  1491. (just-one-space)))
  1492. ;; Set the mode line of the biffer.
  1493. (if bible-has-lexemes
  1494. (unless (string-match " Lex" mode-name) (setq mode-name (concat mode-name " Lex")))
  1495. (setq mode-name (replace-regexp-in-string " Lex" "" mode-name)))
  1496. (if bible-has-morphemes
  1497. (unless (string-match " Morph" mode-name) (setq mode-name (concat mode-name " Morph")))
  1498. (setq mode-name (replace-regexp-in-string " Morph" "" mode-name)))
  1499. (force-mode-line-update))
  1500. ;; If optional verse specification go to that verse.
  1501. (when verse
  1502. (re-search-forward (concat " ?" (number-to-string verse)) nil t)))
  1503. ;;;; Modules (Bible texts, commentaries)
  1504. (defun compare-module-names (n1 n2)
  1505. "Compare N1 and N2, ignoring case, using collation order."
  1506. (string-collate-lessp n1 n2 nil t))
  1507. (defun bible--get-biblical-modules ()
  1508. "Populate `bible--texts' and `bible--commentaries' lists."
  1509. (let ((lines
  1510. (split-string
  1511. (bible--exec-diatheke "modulelist" nil "plain" "system")
  1512. "[\n\r]+"))
  1513. (texts nil)
  1514. (commentaries nil)
  1515. (doing-texts nil)
  1516. (doing-commentaries nil))
  1517. (setq bible--texts nil)
  1518. (setq bible--commentaries nil)
  1519. (catch 'done
  1520. (dolist (line lines)
  1521. (when doing-texts
  1522. (push (split-string line " : ") texts))
  1523. (when doing-commentaries
  1524. (push (split-string line " : ") commentaries))
  1525. (when (string-equal line "Biblical Texts:")
  1526. (setq doing-texts t))
  1527. (when (string-equal line "Commentaries:")
  1528. (setq doing-texts nil)
  1529. (pop texts) ; Remove `Commentaries:' line from `bible--texts'.
  1530. (setq doing-commentaries t))
  1531. (when (string-equal line "Lexicons / Dictionaries:")
  1532. (pop commentaries) ; Remove `Lexicons / Dictionaries:' line
  1533. ; from bible--commentaries.
  1534. (throw 'done nil))))
  1535. (setq bible--texts (cl-sort texts #'compare-module-names :key #'car))
  1536. (setq bible--commentaries (cl-sort commentaries #'compare-module-names :key #'car)))
  1537. nil)
  1538. (defun bible--list-biblical-texts ()
  1539. "Return a list of accessible Biblical Text modules."
  1540. (bible--get-biblical-modules) ; Make sure the lists are fresh.
  1541. bible--texts)
  1542. (defun bible--list-biblical-commentaries ()
  1543. "Return a list of accessible Biblical Text modules."
  1544. (bible--get-biblical-modules) ; Make sure the lists are fresh.
  1545. bible--commentaries)
  1546. (defun bible-display-available-texts ()
  1547. "Display available modules, allow user to select."
  1548. (interactive)
  1549. (bible--get-biblical-modules) ; Make sure lists are fresh.
  1550. (with-current-buffer (get-buffer-create "Texts")
  1551. (bible-text-select-mode)
  1552. (let ((buffer-read-only nil))
  1553. (erase-buffer)
  1554. (setq-local tab-stop-list '(25))
  1555. (dolist (text bible--texts)
  1556. (let ((name (string-trim (car text)))
  1557. (description (string-trim-left (cadr text))))
  1558. (insert
  1559. (propertize (string-trim name)
  1560. 'face 'bold
  1561. 'module name
  1562. 'help-echo (concat "Select " name)
  1563. 'keymap bible-text-map))
  1564. (move-to-tab-stop)
  1565. (insert (format "%s\n" description)))))
  1566. (goto-char (point-min))
  1567. (pop-to-buffer (current-buffer) nil t)))
  1568. (defun bible-display-available-commentaries ()
  1569. "Display available modules, allow user to select."
  1570. (interactive)
  1571. (bible--get-biblical-modules) ; Make sure lists are fresh.
  1572. (with-current-buffer (get-buffer-create "Commentaries")
  1573. (bible-text-select-mode)
  1574. (let ((buffer-read-only nil))
  1575. (erase-buffer)
  1576. (setq-local tab-stop-list '(25))
  1577. (dolist (commentary bible--commentaries)
  1578. (let ((name (string-trim (car commentary)))
  1579. (description (string-trim-left (cadr commentary))))
  1580. (insert
  1581. (propertize (string-trim name)
  1582. 'face 'bold
  1583. 'module name
  1584. 'help-echo (concat "Select " name)
  1585. 'keymap bible-commentary-map))
  1586. (move-to-tab-stop)
  1587. (insert (format "%s\n" description)))))
  1588. (goto-char (point-min))
  1589. (pop-to-buffer (current-buffer) nil t)))
  1590. ;;;; Bible Searching
  1591. (defun bible--open-search (query searchmode module)
  1592. "Open a search buffer of QUERY using SEARCHMODE in module MODULE."
  1593. (let ((results (string-trim (replace-regexp-in-string
  1594. "Entries .+?--" ""
  1595. (bible--diatheke-search query searchmode "plain" module)))))
  1596. (if (equal results (concat "none (" module ")"))
  1597. (message (concat
  1598. "No results found."
  1599. (when (equal searchmode "lucene")
  1600. " Verify index has been build with mkfastmod.")))
  1601. (with-current-buffer (generate-new-buffer "*bible-search*")
  1602. (bible-search-mode)
  1603. (bible--display-search results module)
  1604. (setq-local bible-search-word-this-query query
  1605. bible-search-text-this-query module
  1606. bible-search-range-this-query bible-search-range)
  1607. (pop-to-buffer (current-buffer) nil t)))))
  1608. (defun bible--display-search (results module)
  1609. "Render RESULTS of search query with MODULE."
  1610. (let ((match 0)
  1611. (matchstr "")
  1612. (verses nil)
  1613. (query-verses "")
  1614. (buffer-read-only nil))
  1615. ;; (message "display-search %s" module)
  1616. (setq-default bible-text module)
  1617. (erase-buffer)
  1618. (while match
  1619. (setq match (string-match ".+?:[0-9]?[0-9]?" results (+ match (length matchstr)))
  1620. matchstr (match-string 0 results))
  1621. (when match
  1622. (push
  1623. ;; Massage match to make it more sortable, get rid of some characters.
  1624. (replace-regexp-in-string
  1625. ".+; " ""
  1626. (string-replace
  1627. "I " "1"
  1628. (string-replace
  1629. "II " "2"
  1630. (string-replace
  1631. "III " "3"
  1632. matchstr))))
  1633. verses)))
  1634. (setq verses (cl-sort verses #'string-version-lessp))
  1635. (dolist (verse verses)
  1636. (if query-verses
  1637. (setq query-verses (concat query-verses ";" verse))
  1638. (setq query-verses verse)))
  1639. (let ((bible-show-diatheke-exec nil))
  1640. (insert (bible--exec-diatheke query-verses nil nil module)))
  1641. (let* ((html-dom-tree (libxml-parse-html-region (point-min) (point-max))))
  1642. (erase-buffer)
  1643. (bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body)))
  1644. (goto-char (point-min))
  1645. (save-excursion
  1646. ;; Remove module name from buffer.
  1647. (while (re-search-forward (concat "^.*" module ".*$") nil t)
  1648. (replace-match ""))
  1649. (delete-blank-lines))
  1650. (setq mode-name "Bible Search ")
  1651. (setq-local bible-search-matches (length verses))))
  1652. ;;;; Terms (lemmas, morphemes)
  1653. (defun bible--get-lemma (language strongs)
  1654. "Get the lemma from lexicon for LANGUAGE for strong's term STRONGS.
  1655. Used to display lemmas in mode lines. Assumes that StrongsHebrew
  1656. and StrongsGreek lexicons have been installed."
  1657. (let ((lemma-entry
  1658. (pcase language
  1659. ('hebrew
  1660. ;; Use Strong's Hebrew lexicon to look up Hebrew lemma.
  1661. (bible--lex-query strongs "StrongsHebrew" ))
  1662. ('greek
  1663. ;; Use Strong's Greek lexicon to look up Greek lemma.
  1664. (bible--lex-query strongs "StrongsGreek")))))
  1665. (unless (equal lemma-entry "")
  1666. ;; Entry will look like <num>: <num>. <lemma> <definition>. Get
  1667. ;; rid of everything before and after <lemma>.
  1668. (let* ((lemma-line (split-string lemma-entry))
  1669. (lemma (caddr lemma-line)))
  1670. lemma))))
  1671. (defun bible--display-greek ()
  1672. "Display Greek term.
  1673. This command is run by clicking on text, not directly by the user."
  1674. (interactive)
  1675. (let ((item (car (split-string (get-text-property (point) 'strong)))))
  1676. ;; Remove "strong:G" prefix
  1677. (bible--open-term-greek (replace-regexp-in-string "strong:G" "" item))))
  1678. (defun bible--display-hebrew ()
  1679. "Display Hebrew term.
  1680. This command is run by clicking on text, not directly by the user."
  1681. (interactive)
  1682. (let ((item (car (split-string (get-text-property (point) 'strong)))))
  1683. ;; Remove "strong:H" prefix and any alphabetic suffixes.
  1684. (bible--open-term-hebrew (replace-regexp-in-string "strong:H" "" item))))
  1685. ;;(defun bible-display-morphology (morph)
  1686. ;; ;; REVIEW: Do something here? (FMG 5-Mar-2026)
  1687. ;; )
  1688. (defun bible--fixup-lexicon-display (_termtype)
  1689. "Fixup the display of a lexical entry whose language is given by TERMTYPE."
  1690. (let ((buffer-read-only nil))
  1691. (goto-char (point-min))
  1692. ;; This enables clicking on verse references.
  1693. (save-excursion
  1694. (while (search-forward-regexp bible--verse-regexp nil t)
  1695. (let ((match (match-string 0))
  1696. (start (match-beginning 0))
  1697. (end (match-end 0)))
  1698. (put-text-property start end 'xref match)
  1699. (put-text-property start end 'keymap bible-term-mode-map)
  1700. (put-text-property start end 'help-echo (concat "Go to " (substring-no-properties match)))
  1701. (add-face-text-property start end '(:foreground "blue")))))
  1702. (save-excursion
  1703. (while (search-forward "()" nil t)
  1704. (replace-match ""))
  1705. (delete-blank-lines))))
  1706. (defun bible--open-term-hebrew (term)
  1707. "Open a buffer of the Strong's Hebrew TERM's definition."
  1708. (with-current-buffer (generate-new-buffer "*bible-term*")
  1709. (bible-term-hebrew-mode)
  1710. (setq-local bidi-paragraph-direction 'left-to-right)
  1711. (setq-local mode-name (concat (bible--get-lemma 'hebrew term) " Term (Hebrew)"))
  1712. (bible--display-lemma-hebrew term)
  1713. (pop-to-buffer (current-buffer) nil t)
  1714. (fit-window-to-buffer)))
  1715. (defun bible--display-lemma-hebrew (lemma)
  1716. "Render the definition of the Strong's Hebrew LEMMA.
  1717. This code is customized for the BDBGlosses_Strongs lexicon."
  1718. (let ((buffer-read-only nil))
  1719. (erase-buffer)
  1720. ;; BDBGlosses_Strongs needs the prefixed `H'.
  1721. (insert (substring (bible--cleanup-lex-text (bible--lookup-lemma-hebrew (concat "H" lemma))) 7))
  1722. (bible--fixup-lexicon-display 'hebrew)))
  1723. (defun bible--open-term-greek (term)
  1724. "Open a buffer of the Strong's Greek TERM definition."
  1725. (with-current-buffer (generate-new-buffer "*bible-term*")
  1726. (bible-term-greek-mode)
  1727. (setq-local mode-name (concat (bible--get-lemma 'greek term) " Term (Greek)"))
  1728. (bible--display-lemma-greek term)
  1729. (pop-to-buffer (current-buffer) nil t)
  1730. (fit-window-to-buffer)))
  1731. (defun bible--display-lemma-greek (lemma)
  1732. "Render the definition of the Strong's Greek LEMMA."
  1733. (let ((buffer-read-only nil))
  1734. (erase-buffer)
  1735. (insert (bible--lookup-lemma-greek lemma))
  1736. (bible--fixup-lexicon-display 'greek)))
  1737. ;;;; Utilities
  1738. (defun bible-new-line ()
  1739. "Ensure beginning of line. Try to avoid redundant blank lines."
  1740. (unless (bolp)
  1741. (newline)))
  1742. (defun bible--remove-module-name (module-name string)
  1743. "Remove parenthesized MODULE-NAME from STRING.
  1744. Also deals with bug where some versions of diatheke return string that
  1745. is missing close parenthesis."
  1746. (replace-regexp-in-string (concat "^(" module-name ".*$") "" string))
  1747. (defun bible--list-number-range (min max &optional prefix)
  1748. "Returns a list containing entries for each integer between MIN and MAX.
  1749. If PREFIX is supplied, prepend PREFIX to the entries.
  1750. Used in tandem with `completing-read' for chapter selection."
  1751. (let ((range-list nil))
  1752. (dotimes (num (1+ max))
  1753. (when (>= num min)
  1754. (push (cons (concat prefix (number-to-string num)) num) range-list)))
  1755. (nreverse range-list)))
  1756. ;;; Provides
  1757. (provide 'bible)
  1758. ;;; bible.el ends here.