From 57b9823ec7c0d3d15b0f452e07757163368a8b59 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Fri, 24 May 2013 12:54:20 +0200 Subject: [PATCH] * 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 handler. (doc-view-mode): Set `doc-view-desktop-save-buffer' as custom `desktop-save-buffer' function. --- lisp/ChangeLog | 11 +++++++++++ lisp/doc-view.el | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e93950e97d2..17d17698936 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +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 + handler. + (doc-view-mode): Set `doc-view-desktop-save-buffer' as custom + `desktop-save-buffer' function. + 2013-05-24 Michael Albinus * net/tramp-gvfs.el (tramp-gvfs-enabled): New defconst. diff --git a/lisp/doc-view.el b/lisp/doc-view.el index 272bb580ec5..d7476114fcb 100644 --- a/lisp/doc-view.el +++ b/lisp/doc-view.el @@ -1649,6 +1649,25 @@ If BACKWARD is non-nil, jump to the previous match." (setq-local doc-view--image-type type) (setq-local doc-view--image-file-pattern (concat "page-%s." extension)))) +;; desktop.el integration + +(defun doc-view-desktop-save-buffer (desktop-dirname) + `((page . ,(doc-view-current-page)) + (slice . ,(doc-view-current-slice)))) + +(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)) + (with-selected-window (or (get-buffer-window (current-buffer) 0) + (selected-window)) + (doc-view-goto-page page) + (when slice (apply 'doc-view-set-slice slice))))) + +(setq desktop-buffer-mode-handlers + (cons '(doc-view-mode . doc-view-restore-desktop-buffer) + desktop-buffer-mode-handlers)) + ;;;###autoload (defun doc-view-mode () "Major mode in DocView buffers. @@ -1715,6 +1734,9 @@ toggle between displaying the document or editing it as text. nil t) (add-hook 'clone-indirect-buffer-hook 'doc-view-clone-buffer-hook nil t) (add-hook 'kill-buffer-hook 'doc-view-kill-proc nil t) + (when (and (boundp 'desktop-save-mode) + desktop-save-mode) + (setq-local desktop-save-buffer 'doc-view-desktop-save-buffer)) (remove-overlays (point-min) (point-max) 'doc-view t) ;Just in case. ;; Keep track of display info ([vh]scroll, page number, overlay, -- 2.39.2