Fred Gilham 6 дней назад
Родитель
Сommit
36e3743622
1 измененных файлов с 38 добавлено и 22 удалено
  1. 38 22
      bible.el

+ 38 - 22
bible.el

@@ -481,6 +481,10 @@ See `bible--display-lemma-hebrew'."
 (defvar bible--commentary-buffers nil
 (defvar bible--commentary-buffers nil
   "List of commentary buffers.")
   "List of commentary buffers.")
 
 
+(defvar-local associated-buffer nil
+  "Buffer associated with a given commentary buffer---used for 
+chasing cross-references.")
+
 (defvar bible--synced-buffers nil
 (defvar bible--synced-buffers nil
   "List of buffers that are synchronized so that navigation in one applies 
   "List of buffers that are synchronized so that navigation in one applies 
 to all of them.")
 to all of them.")
@@ -702,6 +706,10 @@ Mostly in Psalms, like `Of David' or the like.")
 (defvar-local bible-search-range-this-query nil)
 (defvar-local bible-search-range-this-query nil)
 (defvar-local bible-search-matches 0)
 (defvar-local bible-search-matches 0)
 
 
+;;;;; Variables used in constructing cross-references.
+(defvar-local bible-current-xref-book nil)
+(defvar-local bible-current-xref-chapter nil)
+
 
 
 ;;;; Functions
 ;;;; Functions
 
 
@@ -756,7 +764,7 @@ starting verse reference for the buffer. If no optional location
 arguments are supplied, Genesis 1:1 is used. Optional argument MODULE
 arguments are supplied, Genesis 1:1 is used. Optional argument MODULE
 specifies the module to use."
 specifies the module to use."
   (interactive)
   (interactive)
-  (with-current-buffer (or buffer (get-buffer-create (generate-new-buffer-name "*bible*")))
+  (with-current-buffer (or buffer (get-buffer-create "*bible*"))
     (bible)
     (bible)
     (when module (setq-default bible-text module))
     (when module (setq-default bible-text module))
     (setq-local bible-text (default-value 'bible-text))
     (setq-local bible-text (default-value 'bible-text))
@@ -768,8 +776,7 @@ specifies the module to use."
     (cl-pushnew (current-buffer) bible--text-buffers)
     (cl-pushnew (current-buffer) bible--text-buffers)
     (set-window-buffer (get-buffer-window (current-buffer)) (current-buffer))))
     (set-window-buffer (get-buffer-window (current-buffer)) (current-buffer))))
 
 
-(defvar-local associated-buffer nil)
-(defun commentary-open (&optional module book-name chapter verse)
+(defun commentary-open (&optional buffer book-name chapter verse module)
   "Create and open a `commentary' buffer.
   "Create and open a `commentary' buffer.
 Optional argument MODULE specifies the commentary module to use.
 Optional argument MODULE specifies the commentary module to use.
 Optional arguments BOOK-NAME, CHAPTER and VERSE, when supplied, give the
 Optional arguments BOOK-NAME, CHAPTER and VERSE, when supplied, give the
@@ -777,7 +784,7 @@ starting verse reference for the buffer. If no optional location
 arguments are supplied, Genesis 1:1 is used."
 arguments are supplied, Genesis 1:1 is used."
   (interactive)
   (interactive)
   (let ((old-buffer (current-buffer)))
   (let ((old-buffer (current-buffer)))
-    (with-current-buffer (get-buffer-create (generate-new-buffer-name "*commentary*"))
+    (with-current-buffer (or buffer (get-buffer-create "*commentary*"))
       (bible)
       (bible)
       (when module (setq-default bible-commentary module))
       (when module (setq-default bible-commentary module))
       (setq-local associated-buffer old-buffer)
       (setq-local associated-buffer old-buffer)
@@ -871,11 +878,11 @@ for any synchronized buffers."
 ;;;;;; Select modules
 ;;;;;; Select modules
 
 
 ;; Choose a module.
 ;; Choose a module.
-(defun bible-pick-text ()
+(defun bible-pick-text (&optional module)
   "Keymap action function---select text that the user chooses."
   "Keymap action function---select text that the user chooses."
   (interactive)
   (interactive)
-  (let ((item (get-text-property (point) 'module)))
-    (bible-open nil bible--current-book-name bible--current-chapter 1 item)))
+  (let ((item (or module (get-text-property (point) 'module))))
+    (bible-open (current-buffer) bible--current-book-name bible--current-chapter 1 item)))
 
 
 (defun bible-pick-commentary (&optional module)
 (defun bible-pick-commentary (&optional module)
   "Keymap action function---select commentary that the user chooses.
   "Keymap action function---select commentary that the user chooses.
@@ -883,7 +890,7 @@ Use optional argument MODULE as commentary if given."
   (interactive)
   (interactive)
   (let ((item (or module (get-text-property (point) 'module))))
   (let ((item (or module (get-text-property (point) 'module))))
     (setq-local bible-commentary item)
     (setq-local bible-commentary item)
-    (commentary-open item bible--current-book-name bible--current-chapter 1)))
+    (commentary-open nil bible--current-book-name bible--current-chapter 1 item)))
 
 
 (defun bible-select-text ()
 (defun bible-select-text ()
   "Ask user for a new text module for the current `bible' buffer."
   "Ask user for a new text module for the current `bible' buffer."
@@ -892,7 +899,7 @@ Use optional argument MODULE as commentary if given."
     (unless (string= text "")
     (unless (string= text "")
       (setq-default bible-text text)
       (setq-default bible-text text)
       (setq-local bible-text text)
       (setq-local bible-text text)
-      (bible--display))))
+      (bible-pick-text bible-text))))
 
 
 (defun bible-select-commentary ()
 (defun bible-select-commentary ()
   "Ask user for a new commentary module for the current `bible' buffer."
   "Ask user for a new commentary module for the current `bible' buffer."
@@ -935,7 +942,7 @@ Use optional argument MODULE as commentary if given."
   (split-window-right)
   (split-window-right)
   (balance-windows)
   (balance-windows)
   (other-window 1)
   (other-window 1)
-  (bible-open nil bible--current-book-name bible--current-chapter 1 bible-text))
+  (bible-open (generate-new-buffer "*bible*") bible--current-book-name bible--current-chapter 1 bible-text))
 
 
 ;;;;;; Search helpers
 ;;;;;; Search helpers
 
 
@@ -1420,8 +1427,6 @@ stored in `bible-chapter-title'."
            (newline)
            (newline)
            (delete-blank-lines)))))
            (delete-blank-lines)))))
 
 
-(defvar-local bible-current-xref-book nil)
-(defvar-local bible-current-xref-chapter nil)
 (defun bible--insert-xref (node)
 (defun bible--insert-xref (node)
   "Insert a cross reference specified by NODE.
   "Insert a cross reference specified by NODE.
 This format is used by the NETnote module."
 This format is used by the NETnote module."
@@ -1438,13 +1443,24 @@ This format is used by the NETnote module."
           ;; <verse> (or maybe <verse>-<verse>)
           ;; <verse> (or maybe <verse>-<verse>)
           ;; Books may look like this: <1 Cor> or <Gal> so we have to deal with the possible space.
           ;; Books may look like this: <1 Cor> or <Gal> so we have to deal with the possible space.
           ;; We ignore verse ranges and hope for the best (it seems to do the right thing).
           ;; We ignore verse ranges and hope for the best (it seems to do the right thing).
-          (let ((set-chapter-p nil))
+          (let ((chapter-set-p nil))
+            ;; See if we've got a book name. Use greedy regexp to make
+            ;; sure we get the whole name. If the name is not found,
+            ;; there will be a default (for this xref) name in
+            ;; bible-current-xref-book. (We hope. This depends on the module.)
             (when (string-match ".* " b-ref)
             (when (string-match ".* " b-ref)
               (setq-local bible-current-xref-book (match-string 0 b-ref)))
               (setq-local bible-current-xref-book (match-string 0 b-ref)))
+            ;; See if we've got a chapter. Note this regexp will skip
+            ;; the book name if present.
             (when (string-match "[0-9]*:" b-ref)
             (when (string-match "[0-9]*:" b-ref)
-              (setq-local bible-current-xref-chapter (string-trim (substring (match-string 0 b-ref) 0 (1- (length (match-string 0 b-ref))))))
-              (setq set-chapter-p t))
-            (let* ((match (string-match "[0-9]*" b-ref (if set-chapter-p (match-end 0) 0)))
+              (setq-local bible-current-xref-chapter 
+                          (string-trim 
+                           (substring 
+                            (match-string 0 b-ref)
+                            0
+                            (1- (length (match-string 0 b-ref))))))
+              (setq chapter-set-p t))
+            (let* ((match (string-match "[0-9]*" b-ref (if chapter-set-p (match-end 0) 0)))
                    (verse (string-trim (substring b-ref match (match-end 0)))))
                    (verse (string-trim (substring b-ref match (match-end 0)))))
               (just-one-space)
               (just-one-space)
               (let ((start (point))
               (let ((start (point))
@@ -1532,9 +1548,9 @@ In processing subnodes, each case will prepend a space if it needs it."
                ;; Some modules use this for line breaks and such.
                ;; Some modules use this for line breaks and such.
                ('milestone
                ('milestone
                 (pcase (dom-attr subnode 'type)
                 (pcase (dom-attr subnode 'type)
-                ("line" (bible-new-line))
-;;              ("x-PN" (bible-new-line)) ; REVIEW: Don't yet understand this one. (FMG 26-Mar-2026)
-                ("x-p" (insert (dom-attr subnode 'marker) " "))))
+                  ("line" (bible-new-line))
+;;                ("x-PN" (bible-new-line)) ; REVIEW: Don't yet understand this one. (FMG 26-Mar-2026)
+                  ("x-p" (insert (dom-attr subnode 'marker) " "))))
                ('br (bible-new-line))
                ('br (bible-new-line))
                ('lb (when (equal (dom-attr subnode 'type) "x-begin-paragraph") (bible-new-line)))
                ('lb (when (equal (dom-attr subnode 'type) "x-begin-paragraph") (bible-new-line)))
                ('div (when (or (equal (dom-attr subnode 'type) "paragraph")
                ('div (when (or (equal (dom-attr subnode 'type) "paragraph")
@@ -1741,7 +1757,7 @@ If optional argument VERSE is supplied, set cursor at verse."
                   "No results found."
                   "No results found."
                   (when (equal searchmode "lucene")
                   (when (equal searchmode "lucene")
                     " Verify index has been build with mkfastmod.")))
                     " Verify index has been build with mkfastmod.")))
-      (with-current-buffer (get-buffer-create (generate-new-buffer-name (concat "*bible-search*")))
+      (with-current-buffer (generate-new-buffer-name "*bible-search*")
         (bible-search-mode)
         (bible-search-mode)
         (bible--display-search results module)
         (bible--display-search results module)
         (setq-local bible-search-word-this-query query
         (setq-local bible-search-word-this-query query
@@ -1856,7 +1872,7 @@ This command is run by clicking on text, not directly by the user."
 
 
 (defun bible--open-term-hebrew (term)
 (defun bible--open-term-hebrew (term)
   "Open a buffer of the Strong's Hebrew TERM's definition."
   "Open a buffer of the Strong's Hebrew TERM's definition."
-  (with-current-buffer (get-buffer-create (generate-new-buffer-name "*bible-term*"))
+  (with-current-buffer (generate-new-buffer "*bible-term*")
     (bible-term-hebrew-mode)
     (bible-term-hebrew-mode)
     (setq-local bidi-paragraph-direction 'left-to-right)
     (setq-local bidi-paragraph-direction 'left-to-right)
     (setq-local mode-name (concat (bible--get-lemma 'hebrew term) " Term (Hebrew)"))
     (setq-local mode-name (concat (bible--get-lemma 'hebrew term) " Term (Hebrew)"))
@@ -1875,7 +1891,7 @@ This code is customized for the BDBGlosses_Strongs lexicon."
 
 
 (defun bible--open-term-greek (term)
 (defun bible--open-term-greek (term)
   "Open a buffer of the Strong's Greek TERM definition."
   "Open a buffer of the Strong's Greek TERM definition."
-  (with-current-buffer (get-buffer-create (generate-new-buffer-name "*bible-term*"))
+  (with-current-buffer (generate-new-buffer "*bible-term*")
     (bible-term-greek-mode)
     (bible-term-greek-mode)
     (setq-local mode-name (concat (bible--get-lemma 'greek term) " Term (Greek)"))
     (setq-local mode-name (concat (bible--get-lemma 'greek term) " Term (Greek)"))
     (bible--display-lemma-greek term)
     (bible--display-lemma-greek term)