summaryrefslogtreecommitdiff
path: root/lisp/doc-view.el
diff options
context:
space:
mode:
authorTassilo Horn <tassilo@member.fsf.org>2009-01-27 15:52:17 +0000
committerTassilo Horn <tassilo@member.fsf.org>2009-01-27 15:52:17 +0000
commit06a21f70a8b0973f28a30f0ea7afd85b572c8269 (patch)
treed9138c5d3e3ec6afa65ff7a8a3f9712cd93e6eb3 /lisp/doc-view.el
parent2efe61c06248ccc0753e0ac1bb331cd3782e4814 (diff)
downloademacs-06a21f70a8b0973f28a30f0ea7afd85b572c8269.tar.gz
(doc-view-mode): Enhance docstring and fallback to
fundamental-mode or ps-mode if the file is empty or doesn't exist at all. (doc-view-initiate-display): Better info message if doc-view-mode cannot be used. (Missing utility or no png support/no X frame.)
Diffstat (limited to 'lisp/doc-view.el')
-rw-r--r--lisp/doc-view.el186
1 files changed, 101 insertions, 85 deletions
diff --git a/lisp/doc-view.el b/lisp/doc-view.el
index 8f0dbb33a66..2507b864470 100644
--- a/lisp/doc-view.el
+++ b/lisp/doc-view.el
@@ -1049,10 +1049,14 @@ If BACKWARD is non-nil, jump to the previous match."
(message
"%s"
(substitute-command-keys
- (concat "No image (png) support available or some conversion utility for "
+ (concat "No PNG support available or some conversion utility for "
(file-name-extension doc-view-buffer-file-name)" files is missing. "
- "Type \\[doc-view-toggle-display] to switch to an editing mode or "
- "\\[doc-view-open-text] to open a buffer showing the doc as text.")))))
+ "Type \\[doc-view-toggle-display] to switch to "
+ (if (eq doc-view-doc-type 'ps)
+ "ps-mode"
+ "fundamental-mode")
+ ", \\[doc-view-open-text] to show the doc as text in a separate buffer "
+ " or \\[doc-view-kill-proc-and-buffer] to kill this buffer.")))))
(defvar bookmark-make-record-function)
@@ -1078,93 +1082,105 @@ If BACKWARD is non-nil, jump to the previous match."
;;;###autoload
(defun doc-view-mode ()
"Major mode in DocView buffers.
+
+DocView Mode is an Emacs document viewer. It displays PDF, PS
+and DVI files (as PNG images) in Emacs buffers.
+
You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
toggle between displaying the document or editing it as text.
\\{doc-view-mode-map}"
(interactive)
- (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode)
- doc-view-previous-major-mode
- major-mode)))
- (kill-all-local-variables)
- (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode))
-
- ;; Figure out the document type.
- (let ((name-types
- (when buffer-file-name
- (cdr (assoc (file-name-extension buffer-file-name)
- '(("dvi" dvi)
- ("pdf" pdf)
- ("epdf" pdf)
- ("ps" ps)
- ("eps" ps))))))
- (content-types
- (save-excursion
- (goto-char (point-min))
- (cond
- ((looking-at "%!") '(ps))
- ((looking-at "%PDF") '(pdf))
- ((looking-at "\367\002") '(dvi))))))
- (set (make-local-variable 'doc-view-doc-type)
- (car (or (doc-view-intersection name-types content-types)
- (when (and name-types content-types)
- (error "Conflicting types: name says %s but content says %s"
- name-types content-types))
- name-types content-types
- (error "Cannot determine the document type")))))
-
- (doc-view-make-safe-dir doc-view-cache-directory)
- ;; 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))
- ;; Is the file readable by local processes?
- ;; We used to use `file-remote-p' but it's unclear what it's
- ;; supposed to return nil for things like local files accessed via
- ;; `su' or via file://...
- ((let ((file-name-handler-alist nil))
- (not (file-readable-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))
-
- (add-hook 'change-major-mode-hook
- (lambda ()
- (doc-view-kill-proc)
- (remove-overlays (point-min) (point-max) 'doc-view t))
- 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)
-
- (remove-overlays (point-min) (point-max) 'doc-view t) ;Just in case.
- ;; Keep track of display info ([vh]scroll, page number, overlay, ...)
- ;; for each window in which this document is shown.
- (add-hook 'image-mode-new-window-functions
- 'doc-view-new-window-function nil t)
- (image-mode-setup-winprops)
-
- (set (make-local-variable 'mode-line-position)
- '(" P" (:eval (number-to-string (doc-view-current-page)))
- "/" (:eval (number-to-string (length doc-view-current-files)))))
- ;; Don't scroll unless the user specifically asked for it.
- (set (make-local-variable 'auto-hscroll-mode) nil)
- (set (make-local-variable 'cursor-type) nil)
- (use-local-map doc-view-mode-map)
- (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc)
- (set (make-local-variable 'bookmark-make-record-function)
- 'doc-view-bookmark-make-record)
- (setq mode-name "DocView"
- buffer-read-only t
- major-mode 'doc-view-mode)
- (doc-view-initiate-display)
- (run-mode-hooks 'doc-view-mode-hook))
+ (if (or (not (file-exists-p buffer-file-name))
+ (= (point-min) (point-max)))
+ ;; The doc is empty or doesn't exist at all, so fallback to an
+ ;; editing mode.
+ (if (string-match "[eE]?[pP][sS]" (file-name-extension buffer-file-name) "")
+ (ps-mode)
+ (fundamental-mode)) ;;Should we activate d-v-minor-mode here?
+
+ (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode)
+ doc-view-previous-major-mode
+ major-mode)))
+ (kill-all-local-variables)
+ (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode))
+
+ ;; Figure out the document type.
+ (let ((name-types
+ (when buffer-file-name
+ (cdr (assoc (file-name-extension buffer-file-name)
+ '(("dvi" dvi)
+ ("pdf" pdf)
+ ("epdf" pdf)
+ ("ps" ps)
+ ("eps" ps))))))
+ (content-types
+ (save-excursion
+ (goto-char (point-min))
+ (cond
+ ((looking-at "%!") '(ps))
+ ((looking-at "%PDF") '(pdf))
+ ((looking-at "\367\002") '(dvi))))))
+ (set (make-local-variable 'doc-view-doc-type)
+ (car (or (doc-view-intersection name-types content-types)
+ (when (and name-types content-types)
+ (error "Conflicting types: name says %s but content says %s"
+ name-types content-types))
+ name-types content-types
+ (error "Cannot determine the document type")))))
+
+ (doc-view-make-safe-dir doc-view-cache-directory)
+ ;; 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))
+ ;; Is the file readable by local processes?
+ ;; We used to use `file-remote-p' but it's unclear what it's
+ ;; supposed to return nil for things like local files accessed via
+ ;; `su' or via file://...
+ ((let ((file-name-handler-alist nil))
+ (not (file-readable-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))
+
+ (add-hook 'change-major-mode-hook
+ (lambda ()
+ (doc-view-kill-proc)
+ (remove-overlays (point-min) (point-max) 'doc-view t))
+ 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)
+
+ (remove-overlays (point-min) (point-max) 'doc-view t) ;Just in case.
+ ;; Keep track of display info ([vh]scroll, page number, overlay,
+ ;; ...) for each window in which this document is shown.
+ (add-hook 'image-mode-new-window-functions
+ 'doc-view-new-window-function nil t)
+ (image-mode-setup-winprops)
+
+ (set (make-local-variable 'mode-line-position)
+ '(" P" (:eval (number-to-string (doc-view-current-page)))
+ "/" (:eval (number-to-string (length doc-view-current-files)))))
+ ;; Don't scroll unless the user specifically asked for it.
+ (set (make-local-variable 'auto-hscroll-mode) nil)
+ (set (make-local-variable 'cursor-type) nil)
+ (use-local-map doc-view-mode-map)
+ (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc)
+ (set (make-local-variable 'bookmark-make-record-function)
+ 'doc-view-bookmark-make-record)
+ (setq mode-name "DocView"
+ buffer-read-only t
+ major-mode 'doc-view-mode)
+ (doc-view-initiate-display)
+ (run-mode-hooks 'doc-view-mode-hook)))
;;;###autoload
(define-minor-mode doc-view-minor-mode