From 5010583555fce883d83e7a50e26d9d34f9e108ce Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 24 May 2013 13:42:23 -0400 Subject: [PATCH] * lisp/image-mode.el (image-mode-winprops): Add winprops to image-mode-winprops-alist before running image-mode-new-window-functions. * lisp/doc-view.el (doc-view-new-window-function): Don't delay doc-view-goto-page via timers. Fixes: debbugs:14435 --- lisp/ChangeLog | 12 ++++++++++-- lisp/doc-view.el | 34 ++++++++++++++-------------------- lisp/image-mode.el | 12 ++++++++---- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 17d17698936..8dd3ef277b0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,10 +1,18 @@ +2013-05-24 Stefan Monnier + + * image-mode.el (image-mode-winprops): Add winprops to + image-mode-winprops-alist before running + image-mode-new-window-functions. + * doc-view.el (doc-view-new-window-function): Don't delay + doc-view-goto-page via timers (bug#14435). + 2013-05-24 Tassilo Horn * doc-view.el: Integrate with desktop.el. (Bug#14435) (doc-view-desktop-save-buffer): New function. (doc-view-restore-desktop-buffer): New function. - (desktop-buffer-mode-handlers): Add - `doc-view-restore-desktop-buffer' as desktop.el buffer mode + (desktop-buffer-mode-handlers): + Add `doc-view-restore-desktop-buffer' as desktop.el buffer mode handler. (doc-view-mode): Set `doc-view-desktop-save-buffer' as custom `desktop-save-buffer' function. diff --git a/lisp/doc-view.el b/lisp/doc-view.el index d7476114fcb..3a4a8138237 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -328,24 +328,15 @@ of the page moves to the previous page." (cl-assert (eq t (car winprops))) (delete-overlay ol)) (image-mode-window-put 'overlay ol winprops) - (when (windowp (car winprops)) - (if (stringp (overlay-get ol 'display)) - ;; We're not already displaying an image, so this is the - ;; initial window showing the document. - (run-with-timer nil nil - (lambda () - ;; In case a conversion is running, the - ;; refresh will happen as defined by - ;; `doc-view-conversion-refresh-interval'. - (unless doc-view-current-converter-processes - (with-selected-window (car winprops) - (doc-view-goto-page 1))))) - ;; We've split the window showing the document. All we need - ;; to do is selecting the new window to cause a redisplay to - ;; make the image appear there, too. - (run-with-timer nil nil - (lambda () - (with-selected-window (car winprops)))))))) + (when (and (windowp (car winprops)) + (stringp (overlay-get ol 'display)) + (null doc-view-current-converter-processes)) + ;; We're not displaying an image yet, so let's do so. This happens when + ;; the buffer is displayed for the first time. + ;; Don't do it if there's a conversion is running, since in that case, it + ;; will be done later. + (with-selected-window (car winprops) + (doc-view-goto-page 1))))) (defvar doc-view-current-files nil "Only used internally.") @@ -1651,14 +1642,17 @@ If BACKWARD is non-nil, jump to the previous match." ;; desktop.el integration -(defun doc-view-desktop-save-buffer (desktop-dirname) +(defun doc-view-desktop-save-buffer (_desktop-dirname) `((page . ,(doc-view-current-page)) (slice . ,(doc-view-current-slice)))) +(declare-function desktop-restore-file-buffer "desktop" + (buffer-filename buffer-name buffer-misc)) + (defun doc-view-restore-desktop-buffer (file name misc) (let ((page (cdr (assq 'page misc))) (slice (cdr (assq 'slice misc)))) - (prog1 (desktop-restore-file-buffer file name misc)) + (desktop-restore-file-buffer file name misc) (with-selected-window (or (get-buffer-window (current-buffer) 0) (selected-window)) (doc-view-goto-page page) diff --git a/lisp/image-mode.el b/lisp/image-mode.el index ac090f020b3..909e2fa247f 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -69,13 +69,17 @@ otherwise it defaults to t, used for times when the buffer is not displayed." image-mode-winprops-alist)))) (let ((winprops (assq window image-mode-winprops-alist))) ;; For new windows, set defaults from the latest. - (unless winprops + (if winprops + ;; Move window to front. + (setq image-mode-winprops-alist + (cons winprops (delq winprops image-mode-winprops-alist))) (setq winprops (cons window (copy-alist (cdar image-mode-winprops-alist)))) + ;; Add winprops before running the hook, to avoid inf-loops if the hook + ;; triggers window-configuration-change-hook. + (setq image-mode-winprops-alist + (cons winprops image-mode-winprops-alist)) (run-hook-with-args 'image-mode-new-window-functions winprops)) - ;; Move window to front. - (setq image-mode-winprops-alist - (cons winprops (delq winprops image-mode-winprops-alist))) winprops)) (defun image-mode-window-get (prop &optional winprops) -- 2.39.2