aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTassilo Horn2009-01-27 15:52:17 +0000
committerTassilo Horn2009-01-27 15:52:17 +0000
commit06a21f70a8b0973f28a30f0ea7afd85b572c8269 (patch)
treed9138c5d3e3ec6afa65ff7a8a3f9712cd93e6eb3
parent2efe61c06248ccc0753e0ac1bb331cd3782e4814 (diff)
downloademacs-06a21f70a8b0973f28a30f0ea7afd85b572c8269.tar.gz
emacs-06a21f70a8b0973f28a30f0ea7afd85b572c8269.zip
(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.)
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/doc-view.el186
2 files changed, 109 insertions, 85 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3e8a1200ec8..33076abb2f4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12009-01-27 Tassilo Horn <tassilo@member.fsf.org>
2
3 * doc-view.el (doc-view-mode): Enhance docstring and fallback to
4 fundamental-mode or ps-mode if the file is empty or doesn't exist
5 at all.
6 (doc-view-initiate-display): Better info message if doc-view-mode
7 cannot be used. (Missing utility or no png support/no X frame.)
8
12009-01-27 Glenn Morris <rgm@gnu.org> 92009-01-27 Glenn Morris <rgm@gnu.org>
2 10
3 * mail/rmail.el (rmail-copy-headers): Doc fix. Leave point at the end 11 * mail/rmail.el (rmail-copy-headers): Doc fix. Leave point at the end
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."
1049 (message 1049 (message
1050 "%s" 1050 "%s"
1051 (substitute-command-keys 1051 (substitute-command-keys
1052 (concat "No image (png) support available or some conversion utility for " 1052 (concat "No PNG support available or some conversion utility for "
1053 (file-name-extension doc-view-buffer-file-name)" files is missing. " 1053 (file-name-extension doc-view-buffer-file-name)" files is missing. "
1054 "Type \\[doc-view-toggle-display] to switch to an editing mode or " 1054 "Type \\[doc-view-toggle-display] to switch to "
1055 "\\[doc-view-open-text] to open a buffer showing the doc as text."))))) 1055 (if (eq doc-view-doc-type 'ps)
1056 "ps-mode"
1057 "fundamental-mode")
1058 ", \\[doc-view-open-text] to show the doc as text in a separate buffer "
1059 " or \\[doc-view-kill-proc-and-buffer] to kill this buffer.")))))
1056 1060
1057(defvar bookmark-make-record-function) 1061(defvar bookmark-make-record-function)
1058 1062
@@ -1078,93 +1082,105 @@ If BACKWARD is non-nil, jump to the previous match."
1078;;;###autoload 1082;;;###autoload
1079(defun doc-view-mode () 1083(defun doc-view-mode ()
1080 "Major mode in DocView buffers. 1084 "Major mode in DocView buffers.
1085
1086DocView Mode is an Emacs document viewer. It displays PDF, PS
1087and DVI files (as PNG images) in Emacs buffers.
1088
1081You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to 1089You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
1082toggle between displaying the document or editing it as text. 1090toggle between displaying the document or editing it as text.
1083\\{doc-view-mode-map}" 1091\\{doc-view-mode-map}"
1084 (interactive) 1092 (interactive)
1085 1093
1086 (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode) 1094 (if (or (not (file-exists-p buffer-file-name))
1087 doc-view-previous-major-mode 1095 (= (point-min) (point-max)))
1088 major-mode))) 1096 ;; The doc is empty or doesn't exist at all, so fallback to an
1089 (kill-all-local-variables) 1097 ;; editing mode.
1090 (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode)) 1098 (if (string-match "[eE]?[pP][sS]" (file-name-extension buffer-file-name) "")
1091 1099 (ps-mode)
1092 ;; Figure out the document type. 1100 (fundamental-mode)) ;;Should we activate d-v-minor-mode here?
1093 (let ((name-types 1101
1094 (when buffer-file-name 1102 (let* ((prev-major-mode (if (eq major-mode 'doc-view-mode)
1095 (cdr (assoc (file-name-extension buffer-file-name) 1103 doc-view-previous-major-mode
1096 '(("dvi" dvi) 1104 major-mode)))
1097 ("pdf" pdf) 1105 (kill-all-local-variables)
1098 ("epdf" pdf) 1106 (set (make-local-variable 'doc-view-previous-major-mode) prev-major-mode))
1099 ("ps" ps) 1107
1100 ("eps" ps)))))) 1108 ;; Figure out the document type.
1101 (content-types 1109 (let ((name-types
1102 (save-excursion 1110 (when buffer-file-name
1103 (goto-char (point-min)) 1111 (cdr (assoc (file-name-extension buffer-file-name)
1104 (cond 1112 '(("dvi" dvi)
1105 ((looking-at "%!") '(ps)) 1113 ("pdf" pdf)
1106 ((looking-at "%PDF") '(pdf)) 1114 ("epdf" pdf)
1107 ((looking-at "\367\002") '(dvi)))))) 1115 ("ps" ps)
1108 (set (make-local-variable 'doc-view-doc-type) 1116 ("eps" ps))))))
1109 (car (or (doc-view-intersection name-types content-types) 1117 (content-types
1110 (when (and name-types content-types) 1118 (save-excursion
1111 (error "Conflicting types: name says %s but content says %s" 1119 (goto-char (point-min))
1112 name-types content-types)) 1120 (cond
1113 name-types content-types 1121 ((looking-at "%!") '(ps))
1114 (error "Cannot determine the document type"))))) 1122 ((looking-at "%PDF") '(pdf))
1115 1123 ((looking-at "\367\002") '(dvi))))))
1116 (doc-view-make-safe-dir doc-view-cache-directory) 1124 (set (make-local-variable 'doc-view-doc-type)
1117 ;; Handle compressed files, remote files, files inside archives 1125 (car (or (doc-view-intersection name-types content-types)
1118 (set (make-local-variable 'doc-view-buffer-file-name) 1126 (when (and name-types content-types)
1119 (cond 1127 (error "Conflicting types: name says %s but content says %s"
1120 (jka-compr-really-do-compress 1128 name-types content-types))
1121 (expand-file-name 1129 name-types content-types
1122 (file-name-nondirectory 1130 (error "Cannot determine the document type")))))
1123 (file-name-sans-extension buffer-file-name)) 1131
1124 doc-view-cache-directory)) 1132 (doc-view-make-safe-dir doc-view-cache-directory)
1125 ;; Is the file readable by local processes? 1133 ;; Handle compressed files, remote files, files inside archives
1126 ;; We used to use `file-remote-p' but it's unclear what it's 1134 (set (make-local-variable 'doc-view-buffer-file-name)
1127 ;; supposed to return nil for things like local files accessed via 1135 (cond
1128 ;; `su' or via file://... 1136 (jka-compr-really-do-compress
1129 ((let ((file-name-handler-alist nil)) 1137 (expand-file-name
1130 (not (file-readable-p buffer-file-name))) 1138 (file-name-nondirectory
1131 (expand-file-name 1139 (file-name-sans-extension buffer-file-name))
1132 (file-name-nondirectory buffer-file-name) 1140 doc-view-cache-directory))
1133 doc-view-cache-directory)) 1141 ;; Is the file readable by local processes?
1134 (t buffer-file-name))) 1142 ;; We used to use `file-remote-p' but it's unclear what it's
1135 (when (not (string= doc-view-buffer-file-name buffer-file-name)) 1143 ;; supposed to return nil for things like local files accessed via
1136 (write-region nil nil doc-view-buffer-file-name)) 1144 ;; `su' or via file://...
1137 1145 ((let ((file-name-handler-alist nil))
1138 (add-hook 'change-major-mode-hook 1146 (not (file-readable-p buffer-file-name)))
1139 (lambda () 1147 (expand-file-name
1140 (doc-view-kill-proc) 1148 (file-name-nondirectory buffer-file-name)
1141 (remove-overlays (point-min) (point-max) 'doc-view t)) 1149 doc-view-cache-directory))
1142 nil t) 1150 (t buffer-file-name)))
1143 (add-hook 'clone-indirect-buffer-hook 'doc-view-clone-buffer-hook nil t) 1151 (when (not (string= doc-view-buffer-file-name buffer-file-name))
1144 (add-hook 'kill-buffer-hook 'doc-view-kill-proc nil t) 1152 (write-region nil nil doc-view-buffer-file-name))
1145 1153
1146 (remove-overlays (point-min) (point-max) 'doc-view t) ;Just in case. 1154 (add-hook 'change-major-mode-hook
1147 ;; Keep track of display info ([vh]scroll, page number, overlay, ...) 1155 (lambda ()
1148 ;; for each window in which this document is shown. 1156 (doc-view-kill-proc)
1149 (add-hook 'image-mode-new-window-functions 1157 (remove-overlays (point-min) (point-max) 'doc-view t))
1150 'doc-view-new-window-function nil t) 1158 nil t)
1151 (image-mode-setup-winprops) 1159 (add-hook 'clone-indirect-buffer-hook 'doc-view-clone-buffer-hook nil t)
1152 1160 (add-hook 'kill-buffer-hook 'doc-view-kill-proc nil t)
1153 (set (make-local-variable 'mode-line-position) 1161
1154 '(" P" (:eval (number-to-string (doc-view-current-page))) 1162 (remove-overlays (point-min) (point-max) 'doc-view t) ;Just in case.
1155 "/" (:eval (number-to-string (length doc-view-current-files))))) 1163 ;; Keep track of display info ([vh]scroll, page number, overlay,
1156 ;; Don't scroll unless the user specifically asked for it. 1164 ;; ...) for each window in which this document is shown.
1157 (set (make-local-variable 'auto-hscroll-mode) nil) 1165 (add-hook 'image-mode-new-window-functions
1158 (set (make-local-variable 'cursor-type) nil) 1166 'doc-view-new-window-function nil t)
1159 (use-local-map doc-view-mode-map) 1167 (image-mode-setup-winprops)
1160 (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc) 1168
1161 (set (make-local-variable 'bookmark-make-record-function) 1169 (set (make-local-variable 'mode-line-position)
1162 'doc-view-bookmark-make-record) 1170 '(" P" (:eval (number-to-string (doc-view-current-page)))
1163 (setq mode-name "DocView" 1171 "/" (:eval (number-to-string (length doc-view-current-files)))))
1164 buffer-read-only t 1172 ;; Don't scroll unless the user specifically asked for it.
1165 major-mode 'doc-view-mode) 1173 (set (make-local-variable 'auto-hscroll-mode) nil)
1166 (doc-view-initiate-display) 1174 (set (make-local-variable 'cursor-type) nil)
1167 (run-mode-hooks 'doc-view-mode-hook)) 1175 (use-local-map doc-view-mode-map)
1176 (set (make-local-variable 'after-revert-hook) 'doc-view-reconvert-doc)
1177 (set (make-local-variable 'bookmark-make-record-function)
1178 'doc-view-bookmark-make-record)
1179 (setq mode-name "DocView"
1180 buffer-read-only t
1181 major-mode 'doc-view-mode)
1182 (doc-view-initiate-display)
1183 (run-mode-hooks 'doc-view-mode-hook)))
1168 1184
1169;;;###autoload 1185;;;###autoload
1170(define-minor-mode doc-view-minor-mode 1186(define-minor-mode doc-view-minor-mode