bible.el 83 KB

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