Mercurial > emacs
comparison lisp/doc-view.el @ 87842:3a98637489f5
(doc-view-pdf/ps->png): Make sure we a have a valid cwd.
(doc-view-insert-image): Do something if the image is missing.
(doc-view-mode): Don't use file-remote-p.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 18 Jan 2008 20:09:26 +0000 |
parents | e0467846347e |
children | dd673d4bceda |
comparison
equal
deleted
inserted
replaced
87841:f76850f6a776 | 87842:3a98637489f5 |
---|---|
98 ;; and modify them to your needs. | 98 ;; and modify them to your needs. |
99 | 99 |
100 ;;; Todo: | 100 ;;; Todo: |
101 | 101 |
102 ;; - better menu. | 102 ;; - better menu. |
103 ;; - don't use `find-file'. | |
104 ;; - Bind slicing to a drag event. | 103 ;; - Bind slicing to a drag event. |
105 ;; - doc-view-fit-doc-to-window and doc-view-fit-window-to-doc. | 104 ;; - doc-view-fit-doc-to-window and doc-view-fit-window-to-doc. |
106 ;; - zoom a the region around the cursor (like xdvi). | 105 ;; - zoom the region around the cursor (like xdvi). |
107 ;; - get rid of the silly arrow in the fringe. | 106 ;; - get rid of the silly arrow in the fringe. |
108 ;; - improve anti-aliasing (pdf-utils gets it better). | 107 ;; - improve anti-aliasing (pdf-utils gets it better). |
109 | 108 |
110 ;;;; About isearch support | 109 ;;;; About isearch support |
111 | 110 |
556 (doc-view-display buffer-file-name 'force)))) | 555 (doc-view-display buffer-file-name 'force)))) |
557 | 556 |
558 (defun doc-view-pdf/ps->png (pdf-ps png) | 557 (defun doc-view-pdf/ps->png (pdf-ps png) |
559 "Convert PDF-PS to PNG asynchronously." | 558 "Convert PDF-PS to PNG asynchronously." |
560 (setq doc-view-current-converter-process | 559 (setq doc-view-current-converter-process |
561 (apply 'start-process | 560 ;; Make sure the process is started in an existing directory, |
562 (append (list "pdf/ps->png" doc-view-conversion-buffer | 561 ;; (rather than some file-name-handler-managed dir, for example). |
563 doc-view-ghostscript-program) | 562 (let ((default-directory (file-name-directory pdf-ps))) |
564 doc-view-ghostscript-options | 563 (apply 'start-process |
565 (list (format "-r%d" (round doc-view-resolution))) | 564 (append (list "pdf/ps->png" doc-view-conversion-buffer |
566 (list (concat "-sOutputFile=" png)) | 565 doc-view-ghostscript-program) |
567 (list pdf-ps))) | 566 doc-view-ghostscript-options |
567 (list (format "-r%d" (round doc-view-resolution))) | |
568 (list (concat "-sOutputFile=" png)) | |
569 (list pdf-ps)))) | |
568 mode-line-process (list (format ":%s" doc-view-current-converter-process))) | 570 mode-line-process (list (format ":%s" doc-view-current-converter-process))) |
569 (process-put doc-view-current-converter-process | 571 (process-put doc-view-current-converter-process |
570 'buffer (current-buffer)) | 572 'buffer (current-buffer)) |
571 (set-process-sentinel doc-view-current-converter-process | 573 (set-process-sentinel doc-view-current-converter-process |
572 'doc-view-pdf/ps->png-sentinel) | 574 'doc-view-pdf/ps->png-sentinel) |
703 "Insert the given png FILE. | 705 "Insert the given png FILE. |
704 ARGS is a list of image descriptors." | 706 ARGS is a list of image descriptors." |
705 (when doc-view-pending-cache-flush | 707 (when doc-view-pending-cache-flush |
706 (clear-image-cache) | 708 (clear-image-cache) |
707 (setq doc-view-pending-cache-flush nil)) | 709 (setq doc-view-pending-cache-flush nil)) |
708 (let ((image (apply 'create-image file 'png nil args))) | 710 (if (null file) |
709 (setq doc-view-current-image image) | 711 ;; We're trying to display a page that doesn't exist. Typically happens |
710 (move-overlay doc-view-current-overlay (point-min) (point-max)) | 712 ;; if the conversion process somehow failed. Better not signal an |
711 (overlay-put doc-view-current-overlay 'display | 713 ;; error here because it could prevent a subsequent reconversion from |
712 (if doc-view-current-slice | 714 ;; fixing the problem. |
713 (list (cons 'slice doc-view-current-slice) image) | 715 (progn |
714 image)))) | 716 (setq doc-view-current-image nil) |
717 (move-overlay doc-view-current-overlay (point-min) (point-max)) | |
718 (overlay-put doc-view-current-overlay 'display | |
719 "Cannot display this page! Probably a conversion failure!")) | |
720 (let ((image (apply 'create-image file 'png nil args))) | |
721 (setq doc-view-current-image image) | |
722 (move-overlay doc-view-current-overlay (point-min) (point-max)) | |
723 (overlay-put doc-view-current-overlay 'display | |
724 (if doc-view-current-slice | |
725 (list (cons 'slice doc-view-current-slice) image) | |
726 image))))) | |
715 | 727 |
716 (defun doc-view-sort (a b) | 728 (defun doc-view-sort (a b) |
717 "Return non-nil if A should be sorted before B. | 729 "Return non-nil if A should be sorted before B. |
718 Predicate for sorting `doc-view-current-files'." | 730 Predicate for sorting `doc-view-current-files'." |
719 (or (< (length a) (length b)) | 731 (or (< (length a) (length b)) |
950 (jka-compr-really-do-compress | 962 (jka-compr-really-do-compress |
951 (expand-file-name | 963 (expand-file-name |
952 (file-name-nondirectory | 964 (file-name-nondirectory |
953 (file-name-sans-extension buffer-file-name)) | 965 (file-name-sans-extension buffer-file-name)) |
954 doc-view-cache-directory)) | 966 doc-view-cache-directory)) |
955 ((or | 967 ;; Is the file readable by local processes? |
956 (not (file-exists-p buffer-file-name)) | 968 ;; We used to use `file-remote-p' but it's unclear what it's |
957 (file-remote-p buffer-file-name)) | 969 ;; supposed to return nil for things like local files accessed via |
970 ;; `su' or via file://... | |
971 ((let ((file-name-handler-alist nil)) | |
972 (not (file-readable-p buffer-file-name))) | |
958 (expand-file-name | 973 (expand-file-name |
959 (file-name-nondirectory buffer-file-name) | 974 (file-name-nondirectory buffer-file-name) |
960 doc-view-cache-directory)) | 975 doc-view-cache-directory)) |
961 (t buffer-file-name))) | 976 (t buffer-file-name))) |
962 (when (not (string= doc-view-buffer-file-name buffer-file-name)) | 977 (when (not (string= doc-view-buffer-file-name buffer-file-name)) |