Mercurial > emacs
changeset 87697:e0467846347e
2008-01-10 Tassilo Horn <tassilo@member.fsf.org>
* doc-view.el (doc-view-buffer-file-name): New variable.
(doc-view-convert-current-doc, doc-view-search)
(doc-view-current-cache-dir, doc-view-initiate-display)
(doc-view-mode): Use it.
(doc-view-bookmark-make-cell): Use variable buffer-file-name
instead of function.
author | Tassilo Horn <tassilo@member.fsf.org> |
---|---|
date | Thu, 10 Jan 2008 15:08:10 +0000 |
parents | d5a92df16467 |
children | 2f6b9a1655ca |
files | lisp/doc-view.el |
diffstat | 1 files changed, 42 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/doc-view.el Thu Jan 10 14:18:23 2008 +0000 +++ b/lisp/doc-view.el Thu Jan 10 15:08:10 2008 +0000 @@ -135,7 +135,6 @@ (require 'dired) (require 'image-mode) (require 'jka-compr) -(require 'tramp) ;; would be better to make tramp-tramp-file-p autoloaded ;;;; Customization Options @@ -248,6 +247,14 @@ (defvar doc-view-previous-major-mode nil "Only used internally.") +(defvar doc-view-buffer-file-name nil + "Only used internally. +The file name used for conversion. Normally it's the same as +`buffer-file-name', but for remote files, compressed files and +files inside an archive it is a temporary copy of +the (uncompressed, extracted) file residing in +`doc-view-cache-directory'.") + ;;;; DocView Keymaps (defvar doc-view-mode-map @@ -451,12 +458,12 @@ (setq doc-view-current-cache-dir (file-name-as-directory (expand-file-name - (let ((doc buffer-file-name)) - (concat (file-name-nondirectory doc) - "-" - (with-temp-buffer - (insert-file-contents-literally doc) - (md5 (current-buffer))))) + (concat (file-name-nondirectory buffer-file-name) + "-" + (let ((file doc-view-buffer-file-name)) + (with-temp-buffer + (insert-file-contents-literally file) + (md5 (current-buffer))))) doc-view-cache-directory))))) (defun doc-view-remove-if (predicate list) @@ -621,7 +628,7 @@ (process-put doc-view-current-converter-process 'pdf-file pdf)) (defun doc-view-convert-current-doc () - "Convert `buffer-file-name' to a set of png files, one file per page. + "Convert `doc-view-buffer-file-name' to a set of png files, one file per page. Those files are saved in the directory given by the function `doc-view-current-cache-dir'." ;; Let stale files still display while we recompute the new ones, so only @@ -633,12 +640,12 @@ (let ((png-file (expand-file-name "page-%d.png" (doc-view-current-cache-dir)))) (make-directory (doc-view-current-cache-dir)) - (if (not (string= (file-name-extension buffer-file-name) "dvi")) + (if (not (string= (file-name-extension doc-view-buffer-file-name) "dvi")) ;; Convert to PNG images. - (doc-view-pdf/ps->png buffer-file-name png-file) + (doc-view-pdf/ps->png doc-view-buffer-file-name png-file) ;; DVI files have to be converted to PDF before Ghostscript can process ;; it. - (doc-view-dvi->pdf buffer-file-name + (doc-view-dvi->pdf doc-view-buffer-file-name (expand-file-name "doc.pdf" doc-view-current-cache-dir))))) @@ -848,15 +855,15 @@ ;; We must convert to TXT first! (if doc-view-current-converter-process (message "DocView: please wait till conversion finished.") - (let ((ext (file-name-extension buffer-file-name))) + (let ((ext (file-name-extension doc-view-buffer-file-name))) (cond ((string= ext "pdf") ;; Doc is a PDF, so convert it to TXT - (doc-view-pdf->txt buffer-file-name txt)) + (doc-view-pdf->txt doc-view-buffer-file-name txt)) ((string= ext "ps") ;; Doc is a PS, so convert it to PDF (which will be converted to ;; TXT thereafter). - (doc-view-ps->pdf buffer-file-name + (doc-view-ps->pdf doc-view-buffer-file-name (expand-file-name "doc.pdf" (doc-view-current-cache-dir)))) ((string= ext "dvi") @@ -901,7 +908,7 @@ (defun doc-view-initiate-display () ;; Switch to image display if possible - (if (doc-view-mode-p (intern (file-name-extension buffer-file-name))) + (if (doc-view-mode-p (intern (file-name-extension doc-view-buffer-file-name))) (progn (doc-view-buffer-message) (setq doc-view-current-page (or doc-view-current-page 1)) @@ -919,7 +926,7 @@ "%s" (substitute-command-keys (concat "No image (png) support available or some conversion utility for " - (file-name-extension buffer-file-name)" files is missing. " + (file-name-extension doc-view-buffer-file-name)" files is missing. " "Type \\[doc-view-toggle-display] to switch to an editing mode."))))) (defvar bookmark-make-cell-function) @@ -930,23 +937,6 @@ You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to toggle between displaying the document or editing it as text." (interactive) - ;; Handle compressed files, TRAMP files, files inside archives - (cond - (jka-compr-really-do-compress - (let ((file (expand-file-name - (file-name-nondirectory - (file-name-sans-extension buffer-file-name)) - doc-view-cache-directory))) - (write-region nil nil file) - (setq buffer-file-name file))) - ((or - (not (file-exists-p buffer-file-name)) - (tramp-tramp-file-p buffer-file-name)) - (let ((file (expand-file-name - (file-name-nondirectory buffer-file-name) - doc-view-cache-directory))) - (write-region nil nil file) - (setq buffer-file-name file)))) (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode) doc-view-previous-major-mode @@ -954,6 +944,24 @@ (kill-all-local-variables) (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) + ;; Handle compressed files, remote files, files inside archives + (set (make-local-variable 'doc-view-buffer-file-name) + (cond + (jka-compr-really-do-compress + (expand-file-name + (file-name-nondirectory + (file-name-sans-extension buffer-file-name)) + doc-view-cache-directory)) + ((or + (not (file-exists-p buffer-file-name)) + (file-remote-p buffer-file-name)) + (expand-file-name + (file-name-nondirectory buffer-file-name) + doc-view-cache-directory)) + (t buffer-file-name))) + (when (not (string= doc-view-buffer-file-name buffer-file-name)) + (write-region nil nil doc-view-buffer-file-name)) + (make-local-variable 'doc-view-current-files) (make-local-variable 'doc-view-current-image) (make-local-variable 'doc-view-current-page) @@ -1012,7 +1020,7 @@ (defun doc-view-bookmark-make-cell (annotation &rest args) (let ((the-record - `((filename . ,(buffer-file-name)) + `((filename . ,buffer-file-name) (page . ,doc-view-current-page) (handler . doc-view-bookmark-jump))))