GNU bug report logs - #12876
24.3.50; DocView problem with cached files

Previous Next

Package: emacs;

Reported by: Stephen Berman <stephen.berman <at> gmx.net>

Date: Tue, 13 Nov 2012 11:14:02 UTC

Severity: normal

Tags: moreinfo

Found in versions 24.2.50, 24.3.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 12876 <at> debbugs.gnu.org (full text, mbox):

From: Tassilo Horn <tsdh <at> gnu.org>
To: Stephen Berman <stephen.berman <at> gmx.net>
Cc: 12876 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#12876: 24.3.50; DocView problem with cached files
Date: Tue, 13 Nov 2012 21:28:44 +0100
Hi Stephen & Stefan,

the following patch fixes the issue for me, but I'm not sure if it's the
right thing to do.  Stefan, could you please check?

Basically, the difference between finding a not yet converted doc and a
doc that's already cached is that in the former case
`doc-view-goto-page' runs with the selected window displaying the doc's
buffer.  AFAIKS, that's a must for the image-mode winprops stuff to
work, so in the latter case, the patch defers running
`doc-view-goto-page' a bit into the future when the window showing the
doc buffer is hopefully there.

--8<---------------cut here---------------start------------->8---
=== modified file 'lisp/doc-view.el'
--- lisp/doc-view.el	2012-09-28 10:05:46 +0000
+++ lisp/doc-view.el	2012-11-13 20:25:53 +0000
@@ -419,57 +419,63 @@
 (defun doc-view-goto-page (page)
   "View the page given by PAGE."
   (interactive "nPage: ")
-  (let ((len (doc-view-last-page-number))
-	(hscroll (window-hscroll)))
-    (if (< page 1)
-	(setq page 1)
-      (when (and (> page len)
-                 ;; As long as the converter is running, we don't know
-                 ;; how many pages will be available.
-                 (null doc-view-current-converter-processes))
-	(setq page len)))
-    (setf (doc-view-current-page) page
-	  (doc-view-current-info)
-	  (concat
-	   (propertize
-	    (format "Page %d of %d." page len) 'face 'bold)
-	   ;; Tell user if converting isn't finished yet
-	   (if doc-view-current-converter-processes
-	       " (still converting...)\n"
-	     "\n")
-	   ;; Display context infos if this page matches the last search
-	   (when (and doc-view-current-search-matches
-		      (assq page doc-view-current-search-matches))
-	     (concat (propertize "Search matches:\n" 'face 'bold)
-		     (let ((contexts ""))
-		       (dolist (m (cdr (assq page
-					     doc-view-current-search-matches)))
-			 (setq contexts (concat contexts "  - \"" m "\"\n")))
-		       contexts)))))
-    ;; Update the buffer
-    ;; We used to find the file name from doc-view-current-files but
-    ;; that's not right if the pages are not generated sequentially
-    ;; or if the page isn't in doc-view-current-files yet.
-    (let ((file (expand-file-name (format "page-%d.png" page)
-                                  (doc-view-current-cache-dir))))
-      (doc-view-insert-image file :pointer 'arrow)
-      (set-window-hscroll (selected-window) hscroll)
-      (when (and (not (file-exists-p file))
-                 doc-view-current-converter-processes)
-        ;; The PNG file hasn't been generated yet.
-        (doc-view-pdf->png-1 doc-view-buffer-file-name file page
-                             (let ((win (selected-window)))
-                               (lambda ()
-                                 (and (eq (current-buffer) (window-buffer win))
-                                      ;; If we changed page in the mean
-                                      ;; time, don't mess things up.
-                                      (eq (doc-view-current-page win) page)
-                                      ;; Make sure we don't infloop.
-                                      (file-readable-p file)
-                                      (with-selected-window win
-							    (doc-view-goto-page page))))))))
-    (overlay-put (doc-view-current-overlay)
-                 'help-echo (doc-view-current-info))))
+  (if (null (get-buffer-window))
+      ;; The document buffer isn't displayed in any window yet.  This
+      ;; happens when using cached PNG files.  The buffer will be
+      ;; displayed after `doc-view-mode' has returned, so try again a
+      ;; bit later.
+      (run-with-timer 0.1 nil #'doc-view-goto-page page)
+    (let ((len (doc-view-last-page-number))
+	  (hscroll (window-hscroll)))
+      (if (< page 1)
+	  (setq page 1)
+	(when (and (> page len)
+		   ;; As long as the converter is running, we don't know
+		   ;; how many pages will be available.
+		   (null doc-view-current-converter-processes))
+	  (setq page len)))
+      (setf (doc-view-current-page) page
+	    (doc-view-current-info)
+	    (concat
+	     (propertize
+	      (format "Page %d of %d." page len) 'face 'bold)
+	     ;; Tell user if converting isn't finished yet
+	     (if doc-view-current-converter-processes
+		 " (still converting...)\n"
+	       "\n")
+	     ;; Display context infos if this page matches the last search
+	     (when (and doc-view-current-search-matches
+			(assq page doc-view-current-search-matches))
+	       (concat (propertize "Search matches:\n" 'face 'bold)
+		       (let ((contexts ""))
+			 (dolist (m (cdr (assq page
+					       doc-view-current-search-matches)))
+			   (setq contexts (concat contexts "  - \"" m "\"\n")))
+			 contexts)))))
+      ;; Update the buffer
+      ;; We used to find the file name from doc-view-current-files but
+      ;; that's not right if the pages are not generated sequentially
+      ;; or if the page isn't in doc-view-current-files yet.
+      (let ((file (expand-file-name (format "page-%d.png" page)
+				    (doc-view-current-cache-dir))))
+	(doc-view-insert-image file :pointer 'arrow)
+	(set-window-hscroll (selected-window) hscroll)
+	(when (and (not (file-exists-p file))
+		   doc-view-current-converter-processes)
+	  ;; The PNG file hasn't been generated yet.
+	  (doc-view-pdf->png-1 doc-view-buffer-file-name file page
+			       (let ((win (selected-window)))
+				 (lambda ()
+				   (and (eq (current-buffer) (window-buffer win))
+					;; If we changed page in the mean
+					;; time, don't mess things up.
+					(eq (doc-view-current-page win) page)
+					;; Make sure we don't infloop.
+					(file-readable-p file)
+					(with-selected-window win
+					  (doc-view-goto-page page))))))))
+      (overlay-put (doc-view-current-overlay)
+		   'help-echo (doc-view-current-info)))))
 
 (defun doc-view-next-page (&optional arg)
   "Browse ARG pages forward."

--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo




This bug report was last modified 4 years and 312 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.