bible.el 82 KB

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