3 Revize e5eb7b33a7 ... 788b9e1c2f

Autor SHA1 Zpráva Datum
  Fred Gilham 788b9e1c2f Fixed titles (ps 119 now works correctly) před 2 týdny
  Fred Gilham 3ff3fa135d Multiple titles in chapters mostly works. před 2 týdny
  Fred Gilham 565a0b4597 Start fix of chapter title issue for Psalm 119 před 3 týdny
2 změnil soubory, kde provedl 37 přidání a 28 odebrání
  1. 2 2
      TODO
  2. 35 26
      bible.el

+ 2 - 2
TODO

@@ -1,13 +1,13 @@
 #+COMMENT: -*- Mode: org -*-
-#+COMMENT: Time-stamp: <2026-03-09 14:00:52 fred>
+#+COMMENT: Time-stamp: <2026-03-17 07:24:20 fred>
 * TODO Add commentaries as module options.
 * TODO Fix cross-references from books/commentaries.
 * TODO Add customizations for font faces for different kinds of buffers (e.g. Greek, Hebrew, English etc.)
 * TODO Infer chapter counts from book data.
   - May not be easily possible
-* TODO Psalm 119 acrostic Hebrew letters doesn't work.
 * TODO Search should order references by OT books, then NT books, in alphabetical order
   - Search references currently works pretty well except for the above. Worth doing?
+* DONE Psalm 119 acrostic Hebrew letters doesn't work.
 * DONE It would be nice to be able to enter either I, II or III or 1, 2 or 3 when referencing books.
 * DONE XXX Using "bible-search-mode-follow-verse" function reverts to default (customized) module instead of current module.
 * DONE Add search ranges

+ 35 - 26
bible.el

@@ -1193,10 +1193,29 @@ in buffer)."
   (unless (= (current-column) 0)
     (insert "\n")))
 
-(defun bible--insert-domnode-recursive (node &optional iproperties notitle)
+(defun bible--insert-title (title-node)
+  "Insert the text in TITLE-NODE into buffer as a chapter title. 
+Since each verse will have a `title' tag, keep track and only emit a
+title when the new title in `title-node' is different from the one
+stored in `bible-chapter-title'."
+  (unless (equal bible-chapter-title title-node)
+;;    (unless bible-chapter-title
+;;      (goto-char (point-min)))
+    (setq-local bible-chapter-title title-node)
+    (let ((title-text (bible-dom-texts bible-chapter-title)))
+      (let ((refstart (point))
+	    refend)
+	(setf title-text (replace-regexp-in-string "<.*?>" "" title-text))
+	(bible-new-line)
+	(insert (bidi-string-mark-left-to-right title-text))
+	(bible-new-line)
+	(setq refend (point))
+	(put-text-property refstart refend 'face 'bold)))))
+
+(defun bible--insert-domnode-recursive (node &optional iproperties)
   "Recursively parse domnode NODE obtained from `libxml-parse-html-region'.
 Inserts resulting text into active buffer with properties specified in
-IPROPERTIES.  If NOTITLE is true, don't render title headings.
+IPROPERTIES.
 In processing subnodes, each case will prepend a space if it needs it."
   (when (and bible-red-letter-enabled (equal (dom-attr node 'who) "Jesus"))
     ;; For red-letter display.
@@ -1218,7 +1237,14 @@ In processing subnodes, each case will prepend a space if it needs it."
                ;; ('lb nil)
                ;; 'w is usual case.
                ('w (insert " ") (bible--process-word subnode iproperties))
-               ;; Font tag should be ignored, treat as if 'w
+	       ('title 
+		;; This mess is to deal with the possibility that the
+		;; title might change in the middle of the chapter. I'm
+		;; talking about YOU, Psalm 119.
+		(if bible-chapter-title 
+		    (bible--insert-title subnode) ; Middle of chapter.
+		  (save-excursion (goto-char (point-min)) (bible--insert-title subnode)))) ; Beginning of chapter.
+	       ;; Font tag should be ignored, treat as if 'w
                ('font (insert " ") (bible--process-word subnode iproperties))
                ('hi (when (equal (dom-attr subnode 'type) "bold")
                       (let ((word (bible-dom-text subnode)))
@@ -1231,8 +1257,7 @@ In processing subnodes, each case will prepend a space if it needs it."
                   (add-face-text-property (- (point) (length word)) (point) '(:foreground "orange"))))
                ;; 'q is used for red letter.
                ;; NASB Module uses 'seg to indicate OT quotations (and others?).
-               ((or 'body 'seg 'p 'q) (bible--insert-domnode-recursive subnode iproperties notitle))
-               ('title (unless notitle (setq bible-chapter-title subnode) (bible-new-line)))
+	       ((or 'body 'seg 'p 'q) (bible--insert-domnode-recursive subnode iproperties))
                ;; These tags appear in ESV modules (and maybe others?)
                ;; REVIEW: Is this right? (FMG 5-Mar-2026)
                ('l
@@ -1246,7 +1271,7 @@ In processing subnodes, each case will prepend a space if it needs it."
 			   ;; REVIEW: Some modules use `level' tag but
 			   ;; not in a consistent way. (FMG 7-Mar-2026)
                            (cond ((= indent 1) (insert " "))
-                                ((= indent 2) (bible-new-line) (insert "\t\t"))))))))
+                                 ((= indent 2) (bible-new-line) (insert "\t\t"))))))))
 	       ;; REVIEW: divine name handling doesn't seem to work the same
 	       ;;         with all modules.
 	       ('divinename (bible-handle-divine-name subnode))
@@ -1268,7 +1293,7 @@ In processing subnodes, each case will prepend a space if it needs it."
                       (put-text-property start end 'help-echo (concat "Go to " word " (doesn't work yet)"))
                       (add-face-text-property start end '(:foreground "blue"))))))
                ;; Various text properties---ignore for now
-               ((or 'b 'u) (bible--insert-domnode-recursive subnode iproperties notitle))
+               ((or 'b 'u) (bible--insert-domnode-recursive subnode iproperties))
                ;; Word inserted by translation, not in original, give visual indication.
                ('transchange
                 (let ((word (bible-dom-text subnode)))
@@ -1277,14 +1302,12 @@ In processing subnodes, each case will prepend a space if it needs it."
                       (add-face-text-property (- (point) (length word)) (point) '(:foreground "salmon"))
                     (add-face-text-property (- (point) (length word)) (point) '(:foreground "gray50")))))))))))
 
-
 (defun bible--display (&optional module verse)
   "Render a page of Bible text.
 If optional argument MODULE is supplied, use that module for display.
 If optional argument VERSE is supplied, set cursor at verse."
   (when module (setq-local bible-module module))
   (let ((buffer-read-only nil)
-        (bible-chapter-title nil)
         (bible-has-lexemes nil)
         (bible-has-morphemes nil))
     (erase-buffer)
@@ -1294,8 +1317,9 @@ If optional argument VERSE is supplied, set cursor at verse."
       ;; Render the DOM tree into the buffer.
       (unless bible-debugme        ; If this is true, display the XML.
         (erase-buffer)
+	(setq-local bible-chapter-title nil)
         ;; Looking for the "body" tag in the DOM node.
-        (bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body) nil nil)
+	(bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body) nil)
         (goto-char (point-min))))
     (save-excursion
       (let ((search-string (concat " *" (car bible--current-book) " " (number-to-string bible--current-chapter) ":")))
@@ -1318,21 +1342,6 @@ If optional argument VERSE is supplied, set cursor at verse."
 	(replace-match "LORD's")
 	(add-face-text-property (1- (point)) (- (point) 5) 'bold)))
     (save-excursion
-      ;; Deal with chapter titles (i.e. in Psalms)
-      ;; TODO: N.B. This won't change a title inside a chapter, and so
-      ;;       it doesn't work with Psalm 119 where the acrostic
-      ;;       letters get printed as titles. (FMG 5-Mar-2026)
-      (when bible-chapter-title ; This gets set in bible--insert-domnode-recursive.
-        (let ((title-text (bible-dom-texts bible-chapter-title))
-              (refstart (point-min))
-              refend)
-          (when (stringp title-text)
-            ;; Clear out XML stuff.
-            (setf title-text (replace-regexp-in-string "<.*?>" "" title-text))
-            (insert title-text "\n")
-            (setq refend (point))
-            (put-text-property refstart refend 'face 'bold))))
-      ;; Get rid of spurious spaces.
       (format-replace-strings '(("." . ". ")
                                 ("," . ", ")
                                 (";" . "; ")
@@ -1460,7 +1469,7 @@ If optional argument VERSE is supplied, set cursor at verse."
       (insert (bible--exec-diatheke query-verses nil nil module)))
     (let* ((html-dom-tree (libxml-parse-html-region (point-min) (point-max))))
       (erase-buffer)
-      (bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body) nil nil))
+      (bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body) nil))
     (goto-char (point-min))
     (save-excursion
       (while (re-search-forward (concat "^.*" module) nil t)