Browse Source

More buffer management hacking

Fred Gilham 3 days ago
parent
commit
0cac348794
1 changed files with 58 additions and 23 deletions
  1. 58 23
      bible.el

+ 58 - 23
bible.el

@@ -255,7 +255,8 @@ See `bible--display-lemma-hebrew'."
   (buffer-disable-undo)
   (font-lock-mode t)
   (use-local-map bible-map)
-  (setq-local mode-line-format bible-mode-line-format)
+  (setq-local mode-line-format bible-mode-line-format
+              bible-buffer-type 'text)
   (setq buffer-read-only t)
   (visual-line-mode t))
  
@@ -265,7 +266,8 @@ See `bible--display-lemma-hebrew'."
   (buffer-disable-undo)
   (font-lock-mode t)
   (use-local-map bible-search-mode-map)
-  (setq-local mode-line-format bible-search-mode-line-format)
+  (setq-local mode-line-format bible-search-mode-line-format
+              bible-buffer-type 'search)
   (setq buffer-read-only t)
   (visual-line-mode t))
 
@@ -275,7 +277,8 @@ See `bible--display-lemma-hebrew'."
   (buffer-disable-undo)
   (font-lock-mode t)
   (use-local-map bible-term-mode-map)
-  (setq-local mode-line-format bible-term-mode-line-format)
+  (setq-local mode-line-format bible-term-mode-line-format
+              bible-buffer-type 'term)
   (setq buffer-read-only t)
   (visual-line-mode t))
 
@@ -478,7 +481,7 @@ See `bible--display-lemma-hebrew'."
   "List of commentary buffers.")
 
 (defvar bible-buffer-type nil
-  "One of `bible', `commentary', `term', `select' or `search'. Identifies
+  "One of `text', `commentary', `term', `select' or `search'. Identifies
 the type of buffer.")
   
 
@@ -789,7 +792,6 @@ specifies the module to use."
   (interactive)
   (with-current-buffer (or buffer (get-buffer-create "*bible*"))
     (bible)
-    (setq-local bible-buffer-type 'bible)
     (when module (setq-default bible-text module))
     (setq-local bible-text (default-value 'bible-text))
     (setq-local mode-name (concat "Text " bible-text))
@@ -813,7 +815,8 @@ arguments are supplied, Genesis 1:1 is used."
       (bible)
       (setq-local bible-buffer-type 'commentary)
       (when module (setq-default bible-commentary module))
-      (setq-local bible-associated-buffer old-buffer)
+      ;; Should we open a new text buffer here?
+      (setq-local bible-associated-buffer (cl-first bible--text-buffers))
       (setq-local bible-text (default-value 'bible-commentary))
       (setq-local mode-name (concat "Commentary " bible-text))
       (bible--set-location
@@ -917,7 +920,10 @@ for any synchronized buffers."
 
 ;; Choose a module.
 (defun bible-pick-text (&optional module buffer)
-  "Keymap action function---select text that the user chooses."
+  "Keymap action function---select text that the user chooses.
+If optional argument MODULE is supplied, use that as the module;
+otherwise use module text property. Will open a new buffer unless
+optional argument BUFFER is given."
   (interactive)
   (let ((item (or module (get-text-property (point) 'module))))
     (bible-open
@@ -929,30 +935,50 @@ for any synchronized buffers."
 
 (defun bible-pick-commentary (&optional module buffer)
   "Keymap action function---select commentary that the user chooses.
-Use optional argument MODULE as commentary if given."
+If optional argument MODULE is supplied, use that as the module;
+otherwise use module text property. Will open a new buffer unless
+optional argument BUFFER is given."
   (interactive)
-  (let ((item (or module (get-text-property (point) 'module)))
-        (buffer (or buffer (generate-new-buffer "*comm*"))))
-    (setq-local bible-commentary item)
-    (setq-local bible-buffer-type 'commentary)
+  (when (eq bible-buffer-type 'text)
     (split-window-right)
     (balance-windows)
-    (other-window 1)
-    (commentary-open 
-     buffer
-     bible--current-book-name 
-     bible--current-chapter 
-     1
-     item)))
+    (other-window 1))
+  (with-current-buffer (or buffer (current-buffer))
+    (rename-buffer "*comm*" t)
+    (let ((item (or module (get-text-property (point) 'module))))
+      (setq-local bible-commentary item)
+      (setq-local bible-buffer-type 'commentary)
+      (commentary-open 
+       (or buffer (current-buffer))
+       bible--current-book-name 
+       bible--current-chapter 
+       1
+       item))))
 
 (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.
+Replaces current text in buffer."
   (interactive)
   (let ((text (completing-read "Text: " bible--texts)))
     (unless (string= text "")
       (setq-default bible-text text)
       (setq-local bible-text text)
-      (bible-pick-text bible-text (when (eq bible-buffer-type 'bible) (current-buffer))))))
+      (bible-pick-text
+       bible-text 
+       (when (eq bible-buffer-type 'text)
+         (current-buffer))))))
+
+;;;(defun bible-select-commentary ()
+;;;  "Ask user for a new commentary module for the current `bible' buffer."
+;;;  (interactive)
+;;;  (let ((commentary (completing-read "Commentary: " bible--commentaries)))
+;;;    (unless (string= commentary "")
+;;;      (setq-local bible-commentary commentary)
+;;;      (bible-pick-commentary 
+;;;       bible-commentary 
+;;;       (if (eq bible-buffer-type 'commentary)
+;;;           (current-buffer)
+;;;         (generate-new-buffer "*comm*"))))))
 
 (defun bible-select-commentary ()
   "Ask user for a new commentary module for the current `bible' buffer."
@@ -960,7 +986,11 @@ Use optional argument MODULE as commentary if given."
   (let ((commentary (completing-read "Commentary: " bible--commentaries)))
     (unless (string= commentary "")
       (setq-local bible-commentary commentary)
-      (bible-pick-commentary bible-commentary (when (eq bible-buffer-type 'commentary) (current-buffer))))))
+      (bible-pick-commentary 
+       bible-commentary 
+       (if (eq bible-buffer-type 'commentary)
+           (current-buffer)
+         (generate-new-buffer "*comm*"))))))
 
 ;;;;;; Toggles
 
@@ -995,7 +1025,12 @@ Use optional argument MODULE as commentary if given."
   (split-window-right)
   (balance-windows)
   (other-window 1)
-  (bible-open (generate-new-buffer "*bible*") 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