Browse Source

Work on synchronizing buffers

Fred Gilham 1 week ago
parent
commit
df76f0604a
1 changed files with 48 additions and 14 deletions
  1. 48 14
      bible.el

+ 48 - 14
bible.el

@@ -210,6 +210,17 @@ See `bible--display-lemma-hebrew'."
 
 ;;;; Variable definitions
 
+(defvar bible--text-buffers nil
+  "List of Bible text buffers.")
+
+(defvar bible--commentary-buffers nil
+  "List of commentary buffers.")
+
+(defvar bible--synced-buffers nil
+  "List of buffers that are synchronized so that navigation in one applies 
+to all of them.")
+
+
 (defvar bible-mode-line-format
   '("%e" mode-line-front-space
     mode-line-frame-identification mode-line-buffer-identification "   "
@@ -219,7 +230,6 @@ See `bible--display-lemma-hebrew'."
     mode-line-end-spaces)
   "Mode line format for bible buffers.")
 
-
 (defconst bible--verse-regexp "\\(I \\|1 \\|II \\|2 \\|III \\|3 \\)??[a-zA-Z]+?[ \t\n][0-9]+[:][0-9]+")
 
 (defvar bible--texts (lazy-completion-table bible--texts bible--list-biblical-texts))
@@ -413,6 +423,8 @@ See `bible--display-lemma-hebrew'."
             [menu-bar bible split-display]
             '("Split Display" . bible-split-display))
 
+(define-key bible-map "S" 'bible-synchronize-display)
+
 ;;;;; Navigation
 
 (define-key bible-map "p" 'bible-previous-chapter)
@@ -659,20 +671,40 @@ specifies the module to use."
      (assoc (or book-name "Genesis") bible--books)
      (or chapter 1)
      verse)
+    (cl-pushnew (current-buffer) bible--text-buffers)
     (set-window-buffer (get-buffer-window (current-buffer)) (current-buffer))))
 
-(defun bible-next-chapter ()
-  "Page to the next chapter for the active `bible' buffer."
-  (interactive)
+(defun bible--navigate-to-next-chapter ()
   (let* ((book-chapters (cdr bible--current-book))
          (chapter (min book-chapters (1+ bible--current-chapter))))
     (bible--set-location bible--current-book chapter)))
 
-(defun bible-previous-chapter ()
+(defun bible-next-chapter ()
+  "Page to the next chapter for the active `bible' buffer."
+  (interactive)
+  (bible--navigate-to-next-chapter)
+  (when bible--synced-buffers
+    (save-excursion
+      (dolist (buffer bible--synced-buffers)
+	(unless (eq buffer (current-buffer))
+	  (with-current-buffer buffer (bible--navigate-to-next-chapter)))))))
+
+(defun bible--navigate-to-previous-chapter ()
   "Page to the previous chapter for the active `bible' buffer."
   (interactive)
   (bible--set-location bible--current-book (max 1 (1- bible--current-chapter))))
 
+(defun bible-previous-chapter ()
+  "Page to the previous chapter for the active `bible' buffer."
+  (interactive)
+  (bible--navigate-to-previous-chapter)
+  (when bible--synced-buffers
+    (save-excursion
+      (dolist (buffer bible--synced-buffers)
+	(unless (eq buffer (current-buffer))
+	  (with-current-buffer buffer 
+	    (bible--set-location bible--current-book (max 1 (1- bible--current-chapter)))))))))
+
 (defun bible-next-word ()
   "Move forward a word, taking into account the relevant text properties."
   (interactive)
@@ -764,6 +796,11 @@ specifies the module to use."
   (other-window 1)
   (bible-open bible--current-book-name bible--current-chapter 1 bible-text))
 
+(defun bible-synchronize-display ()
+  "Copy the active `bible' buffer into a new buffer in another window."
+  (interactive)
+  (cl-pushnew (current-buffer) bible--synced-buffers))
+
 (defun bible-search (query)
   "Search for a QUERY: a word or phrase.
 Asks the user for type of search: either `lucene', `phrase', `regex'
@@ -805,10 +842,7 @@ Handle abbreviations from lexicon module (AbbottSmith)."
   (let* ((xref (get-text-property (point) 'xref))
          (verse-ref (split-string xref))
          book-abbrev
-         chapter-verse
-         book
-         chapter
-         verse)
+         chapter-verse)
 ;;    (message "Trying to follow %s" xref)
     (cond ((= (length verse-ref) 2) ; Mat 5 or the like
            (setq book-abbrev (car verse-ref)
@@ -817,10 +851,10 @@ Handle abbreviations from lexicon module (AbbottSmith)."
            (setq book-abbrev (concat (car verse-ref) " " (cadr verse-ref))
                  chapter-verse (split-string (caddr verse-ref) ":"))))
     ;; Use book abbreviation if present or try whatever is in verse-ref.
-    (setq book (or (alist-get book-abbrev bible--book-name-abbreviations nil nil #'string-equal-ignore-case) (car verse-ref))
-          chapter (car chapter-verse)
-          verse (cadr chapter-verse))
-    (bible-open (string-trim book) (string-to-number chapter) (string-to-number verse) (default-value 'bible-text))))
+    (let ((book (or (alist-get book-abbrev bible--book-name-abbreviations nil nil #'string-equal-ignore-case) (car verse-ref)))
+	  (chapter (car chapter-verse))
+          (verse (cadr chapter-verse)))
+      (bible-open (string-trim book) (string-to-number chapter) (string-to-number verse) (default-value 'bible-text)))))
 
 ;; These can be called interactively if you know the Strong's number
 ;; you want to look up.
@@ -856,7 +890,7 @@ Handle abbreviations from lexicon module (AbbottSmith)."
 
 ;;;; Support (internal)
 
-(defconst bible-diatheke-filter-options " avlnmw")
+(defconst bible-diatheke-filter-options " afilmnsvw")
 
 (defun bible--exec-diatheke (query &optional filter format module)
   "Execute `diatheke' with specified QUERY options.