# HG changeset patch # User Stefan Monnier # Date 1265048747 18000 # Node ID 3ce5dcdece397bf62fa1741b419ae80eda630665 # Parent 8d8e02bbef81f28c59ba4b0ec03f8f2e9c5bb8e9 (doc-view-new-window-function): Be a bit more defensive. (doc-view-revert-buffer): New command. (doc-view-mode-map): Use it. diff -r 8d8e02bbef81 -r 3ce5dcdece39 lisp/ChangeLog --- a/lisp/ChangeLog Sun Jan 31 20:58:35 2010 -0800 +++ b/lisp/ChangeLog Mon Feb 01 13:25:47 2010 -0500 @@ -1,3 +1,9 @@ +2010-02-01 Stefan Monnier + + * doc-view.el (doc-view-new-window-function): Be a bit more defensive. + (doc-view-revert-buffer): New command. + (doc-view-mode-map): Use it. + 2010-02-01 Dan Nicolaescu * vc-bzr.el (vc-bzr-dir-extra-headers): Add a header when a diff -r 8d8e02bbef81 -r 3ce5dcdece39 lisp/doc-view.el --- a/lisp/doc-view.el Sun Jan 31 20:58:35 2010 -0800 +++ b/lisp/doc-view.el Mon Feb 01 13:25:47 2010 -0500 @@ -235,8 +235,15 @@ (defun doc-view-new-window-function (winprops) (let ((ol (image-mode-window-get 'overlay winprops))) + (when (and ol (not (overlay-buffer ol))) + ;; I've seen `ol' be a dead overlay. I do not yet know how this + ;; happened, so maybe the bug is elsewhere, but in the mean time, + ;; this seems like a safe approach. + (setq ol nil)) (if ol - (setq ol (copy-overlay ol)) + (progn + (assert (eq (overlay-buffer ol) (current-buffer))) + (setq ol (copy-overlay ol))) (assert (not (get-char-property (point-min) 'display))) (setq ol (make-overlay (point-min) (point-max) nil t)) (overlay-put ol 'doc-view t)) @@ -323,12 +330,21 @@ (define-key map (kbd "C-c C-c") 'doc-view-toggle-display) ;; Open a new buffer with doc's text contents (define-key map (kbd "C-c C-t") 'doc-view-open-text) - ;; Reconvert the current document - (define-key map (kbd "g") 'revert-buffer) - (define-key map (kbd "r") 'revert-buffer) + ;; Reconvert the current document. Don't just use revert-buffer + ;; because that resets the scale factor, the page number, ... + (define-key map (kbd "g") 'doc-view-revert-buffer) + (define-key map (kbd "r") 'doc-view-revert-buffer) map) "Keymap used by `doc-view-mode' when displaying a doc as a set of images.") +(defun doc-view-revert-buffer (&optional ignore-auto noconfirm) + "Like `revert-buffer', but preserves the buffer's current modes." + ;; FIXME: this should probably be moved to files.el and used for + ;; most/all "g" bindings to revert-buffer. + (interactive (list (not current-prefix-arg))) + (revert-buffer ignore-auto noconfirm 'preserve-modes)) + + (easy-menu-define doc-view-menu doc-view-mode-map "Menu for Doc View mode." '("DocView"