changeset 91789:0048d198c131

(doc-view-display): Change file arg to buffer arg, so it works also for buffers w/o buffer-file-name. Update callers. (doc-view-clone-buffer-hook): New fun. (doc-view-mode): Use it for indirect clones. Mark the overlays with the `doc-view' property so they can be recognized.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 12 Feb 2008 02:41:55 +0000
parents 14206a515e37
children c568e49dbbc5
files lisp/ChangeLog lisp/doc-view.el
diffstat 2 files changed, 34 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Feb 12 02:25:10 2008 +0000
+++ b/lisp/ChangeLog	Tue Feb 12 02:41:55 2008 +0000
@@ -1,5 +1,11 @@
 2008-02-12  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* doc-view.el (doc-view-display): Change file arg to buffer arg, so it
+	works also for buffers w/o buffer-file-name.  Update callers.
+	(doc-view-clone-buffer-hook): New fun.
+	(doc-view-mode): Use it for indirect clones.
+	Mark the overlays with the `doc-view' property so they can be recognized.
+
 	* simple.el (clone-indirect-buffer-hook): New hook.
 	(clone-indirect-buffer): Run it.
 
--- a/lisp/doc-view.el	Tue Feb 12 02:25:10 2008 +0000
+++ b/lisp/doc-view.el	Tue Feb 12 02:41:55 2008 +0000
@@ -551,7 +551,7 @@
         (cancel-timer doc-view-current-timer)
         (setq doc-view-current-timer nil))
       ;; Yippie, finished.  Update the display!
-      (doc-view-display buffer-file-name 'force))))
+      (doc-view-display (current-buffer) 'force))))
 
 (defun doc-view-pdf/ps->png (pdf-ps png)
   "Convert PDF-PS to PNG asynchronously."
@@ -575,7 +575,7 @@
     (setq doc-view-current-timer
 	  (run-at-time "1 secs" doc-view-conversion-refresh-interval
 		       'doc-view-display
-		       buffer-file-name))))
+		       (current-buffer)))))
 
 (defun doc-view-pdf->txt-sentinel (proc event)
   (if (not (string-match "finished" event))
@@ -731,11 +731,11 @@
       (and (= (length a) (length b))
            (string< a b))))
 
-(defun doc-view-display (doc &optional force)
-  "Start viewing the document DOC.
+(defun doc-view-display (buffer &optional force)
+  "Start viewing the document in BUFFER.
 If FORCE is non-nil, start viewing even if the document does not
 have the page we want to view."
-  (with-current-buffer (get-file-buffer doc)
+  (with-current-buffer buffer
     (setq doc-view-current-files
           (sort (directory-files (doc-view-current-cache-dir) t
                                  "page-[0-9]+\\.png" t)
@@ -778,7 +778,7 @@
       (progn
 	(doc-view-kill-proc)
 	(setq buffer-read-only nil)
-        (delete-overlay doc-view-current-overlay)
+        (remove-overlays (point-min) (point-max) 'doc-view)
 	;; Switch to the previously used major mode or fall back to fundamental
 	;; mode.
 	(if doc-view-previous-major-mode
@@ -926,7 +926,7 @@
 	(if (file-exists-p (doc-view-current-cache-dir))
 	    (progn
 	      (message "DocView: using cached files!")
-	      (doc-view-display buffer-file-name 'force))
+	      (doc-view-display (current-buffer) 'force))
 	  (doc-view-convert-current-doc))
 	(message
 	 "%s"
@@ -942,6 +942,24 @@
 
 (defvar bookmark-make-cell-function)
 
+(defun doc-view-clone-buffer-hook ()
+  ;; FIXME: There are several potential problems linked with reconversion
+  ;; and auto-revert when we have indirect buffers because they share their
+  ;; /tmp cache directory.  This sharing is good (you'd rather not reconvert
+  ;; for each clone), but that means that clones need to collaborate a bit.
+  ;; I guess it mostly means: detect when a reconversion process is already
+  ;; running, and run the sentinel in all clones.
+  ;; Not sure how important it is to fix it: a better target would be to
+  ;; allow a single buffer (without cloning) to display different pages in
+  ;; different windows.
+  ;; Maybe then the clones should really have a separate /tmp directory
+  ;; so they could have a different resolution and you could use clones
+  ;; for zooming.
+  (dolist (ol (overlays-in (point-min) (point-max)))
+    ;; The overlay was copied by the cloning, so we just need to find it
+    ;; and put it in doc-view-current-overlay.
+    (if (overlay-get ol 'doc-view) (setq doc-view-current-overlay ol))))
+
 ;;;###autoload
 (defun doc-view-mode ()
   "Major mode in DocView buffers.
@@ -988,9 +1006,11 @@
   (make-local-variable 'doc-view-current-search-matches)
   (set (make-local-variable 'doc-view-current-overlay)
        (make-overlay (point-min) (point-max) nil t))
+  (overlay-put doc-view-current-overlay 'doc-view t)
   (add-hook 'change-major-mode-hook
-	    (lambda () (delete-overlay doc-view-current-overlay))
+	    (lambda () (remove-overlays (point-min) (point-max) 'doc-view))
 	    nil t)
+  (add-hook 'clone-indirect-buffer-hook 'doc-view-clone-buffer-hook nil t)
 
   ;; Keep track of [vh]scroll when switching buffers
   (make-local-variable 'image-mode-current-hscroll)