Sfoglia il codice sorgente

Fix search to work with new code that uses buffers more

Fred Gilham 1 mese fa
parent
commit
8b12dad81b
1 ha cambiato i file con 30 aggiunte e 22 eliminazioni
  1. 30 22
      bible.el

+ 30 - 22
bible.el

@@ -278,8 +278,8 @@ which are of the form
 (defvar-local bible-has-lexemes nil
   "Set if the module being displayed has lexical entries availabile.")
 
-(defvar-local bible-has-morphology nil
-  "Set if the module being displayed has morphology availabile.")
+(defvar-local bible-has-morphemes nil
+  "Set if the module being displayed has morphemes availabile.")
 
 ;;;; Keymaps
 
@@ -665,13 +665,19 @@ Create a new `bible' buffer positioned at the selected verse."
          book
          chapter
          verse)
-    (string-match ".+ [0-9]?[0-9]?[0-9]?:[0-9]?[0-9]?[0-9]?:" text)
+    (string-match bible--verse-regexp text)
     (setq text (match-string 0 text))
-    (string-match " [0-9]?[0-9]?[0-9]?:" text)
-    (setq chapter (replace-regexp-in-string "[^0-9]" "" (match-string 0 text)))
+    (message "Following verse result: %s" text)
+    (string-match "I?I?I? ?[A-Z]?[a-z]* " text)
+    (setq book (match-string 0 text))
+    (message "Book: %s" book)
+    (message "Following %s" text)
+    (string-match "[0-9]?[0-9]?:" text)
+    (setq chapter (substring (match-string 0 text) 0 (1- (length (match-string 0 text)))))
+    (message "Chapter: %s" chapter)
     (string-match ":[0-9]?[0-9]?[0-9]?" text)
-    (setq verse (replace-regexp-in-string "[^0-9]" "" (match-string 0 text)))
-    (setq book (replace-regexp-in-string "[ ][0-9]?[0-9]?[0-9]?:[0-9]?[0-9]?[0-9]?:$" "" text))
+    (setq verse (substring (match-string 0 text) 1))
+    (message "Verse: %s" verse)
     (bible-open (string-trim book) (string-to-number chapter) (string-to-number verse))))
 
 (defun bible-search-mode-follow-xref ()
@@ -790,7 +796,7 @@ Mostly in Psalms, like `Of David' or the like.")
 
 
 ;;;
-;;; Greek and Hebrew lexicon and morphology tooltip rendering.
+;;; Greek and Hebrew lexicon and morphemes tooltip rendering.
 ;;;
 
 ;;; Hash tables for Lexical definitions.
@@ -1128,7 +1134,8 @@ in buffer)."
 	       (lexeme (car (last lexemes))))
 ;;	  (message "Lexemes: %s" lexemes)
 	  (when (string-match "strong:.*" lexeme)
-	    (dolist (word (split-string (match-string 0 lexeme) " "))
+;;	    (message "Matched %s" (match-string 0 lexeme))
+	    (dolist (word (split-string (match-string 0 lexeme)))
 ;;	      (message "Word: %s" word)
 	      (cond ((string-match "strong:G.*" word) ; Greek
 		     (setq matched (match-string 0 lexeme))
@@ -1153,7 +1160,7 @@ in buffer)."
 	    ;;(message "Unknown morphology %s" morph)
 	    )
 	  (when matched
-	    (setq bible-has-morphology t)
+	    (setq bible-has-morphemes t)
 	    (put-text-property refstart refend 'morph matched)
 	    (put-text-property refstart refend 'help-echo 'bible--show-lex-morph))))
 
@@ -1244,7 +1251,7 @@ XXX In processing subnodes, each case will prepend a space if it needs it."
   (let ((buffer-read-only nil)
 	(bible-chapter-title nil)
 	(bible-has-lexemes nil)
-	(bible-has-morphology nil))
+	(bible-has-morphemes nil))
     (erase-buffer)
     (insert (bible--exec-diatheke (concat bible--current-book-name ":" (number-to-string bible--current-chapter))))
     ;; Parse the xml in the buffer into a DOM tree.
@@ -1272,7 +1279,7 @@ XXX In processing subnodes, each case will prepend a space if it needs it."
 	(replace-match "" nil t)))
 
     ;; Deal with chapter titles (i.e. in Psalms)
-    ;; N.B. This won't change a title inside a chapter, and so it
+    ;; XXX 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".
     (save-excursion
@@ -1312,12 +1319,12 @@ XXX In processing subnodes, each case will prepend a space if it needs it."
     (setq mode-name (concat "Bible (" bible--current-book-name " " (number-to-string bible--current-chapter) ") "
 			    bible-module
 			    (when bible-has-lexemes " Lex")
-			    (when bible-has-morphology " Morph")
+			    (when bible-has-morphemes " Morph")
 			    ")")))
 
   ;; If optional verse specification go to that verse.
   (when verse
-    (re-search-forward (regexp-opt `(,(concat (number-to-string verse) ":"))) nil t)))
+    (re-search-forward (concat " ?" (number-to-string verse)) nil t)))
 
 
 (defun bible--list-biblical-modules ()
@@ -1401,19 +1408,20 @@ XXX In processing subnodes, each case will prepend a space if it needs it."
       (when match
 	(push
 	 ;; Massage match to make it more sortable, get rid of some characters.
-	 (string-replace 
-	  "I " "1"
+	 (replace-regexp-in-string
+	  ".+; " "" 
 	  (string-replace
-	   "II " "2"
+	   "I " "1"
 	   (string-replace
-	    "III " "3"
+	    "II " "2"
 	    (string-replace
-	     ".+; " "" 
+	     "III " "3"
 	     matchstr))))
 	 verses)))
 
     (setq match 0)
-    (setq verses (sort verses))
+    (setq verses (sort verses :key nil :lessp #'(lambda (s1 s2) (string-version-lessp s1 s2))))
+;;    (message "Verses: %s" verses)
     (dolist (verse verses)
       (if query-verses
 	  (setq query-verses (concat query-verses ";" verse))
@@ -1425,7 +1433,7 @@ XXX In processing subnodes, each case will prepend a space if it needs it."
 	(erase-buffer)
 	(bible--insert-domnode-recursive (dom-by-tag html-dom-tree 'body) nil nil)
 	(goto-char (point-min))
-	(while (search-forward (concat "(" bible-module ")") nil t)
+	(while (re-search-forward (concat "^.*" bible-module ".*$") nil t)
 	  (replace-match "")))
 
       (setq mode-name (concat "Bible Search (" bible-module))
@@ -1434,7 +1442,7 @@ XXX In processing subnodes, each case will prepend a space if it needs it."
       (setq mode-name (concat mode-name ")"))
       (goto-char (point-min)))))
 
-;;;;; Terms (lemmas, morphology)
+;;;;; Terms (lemmas, morphemes)
 
 
 ;;(defun bible-display-morphology (morph)