From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: doc-view.el --- View PDF/PostScript/DVI files in Emacs Date: Fri, 24 Aug 2007 13:03:39 +0200 Message-ID: <87d4xd19f8.fsf@baldur.tsdh.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1187953449 6418 80.91.229.12 (24 Aug 2007 11:04:09 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 24 Aug 2007 11:04:09 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 24 13:04:06 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IOWxR-0004ee-TJ for ged-emacs-devel@m.gmane.org; Fri, 24 Aug 2007 13:04:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IOWxR-0000BM-5b for ged-emacs-devel@m.gmane.org; Fri, 24 Aug 2007 07:04:05 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IOWxN-000086-3h for emacs-devel@gnu.org; Fri, 24 Aug 2007 07:04:01 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IOWxL-0008W8-Ch for emacs-devel@gnu.org; Fri, 24 Aug 2007 07:04:00 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IOWxL-0008Vw-9R for emacs-devel@gnu.org; Fri, 24 Aug 2007 07:03:59 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IOWxK-00029Z-3S for emacs-devel@gnu.org; Fri, 24 Aug 2007 07:03:58 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IOWxE-0004uR-Pg for emacs-devel@gnu.org; Fri, 24 Aug 2007 13:03:52 +0200 Original-Received: from dslb-084-063-001-053.pools.arcor-ip.net ([84.63.1.53]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 24 Aug 2007 13:03:52 +0200 Original-Received: from tassilo by dslb-084-063-001-053.pools.arcor-ip.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 24 Aug 2007 13:03:52 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 352 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: dslb-084-063-001-053.pools.arcor-ip.net Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAD1BMVEW2mhnYvEn26qD+/vbC t5CEWCLiAAAACXBIWXMAAAsSAAALEgHS3X78AAAATnRFWHRSYXcgcHJvZmlsZSB0eXBlIGV4aWYA CmV4aWYKICAgICAgMjAKNDU3ODY5NjYwMDAwNGQ0ZDAwMmEwMDAwMDAwODAwMDAwMDAwMDAwMAqJ uBZbAAAACXZwQWcAAAAwAAAAMADO7oxXAAABkElEQVQ4y3WTDZLCIAyFQ08A6AFK0gNowgG6de9/ pn2Bau22ZRyF+ZKXX8lOjqZs1K9i+gUmStKAxmzTsjlECtwBEUfKb1CJKDvQkfwEWUFZCsD0shpi I8MbZAWoQWNI+KS3S2VhACaolwSAXzGkUD0ok7q4liwID4vFJAGEG1DIorDV4pGmXBCKka7GJPb0 ItwlIMHsHkJQMftlPKQQIVDA+wmAXgi70pg5pTyiGwC5t2SCw0LBOHNJ3oDH2sQf2CciETXNMLKx A82IhtCtbV6kQsJfT+aYuJB8+jtIA/OQiK3QNpDUgZeMtDYA7QZQl0fsUn6rK4heE+I36+WFvnMH paVobYJ6l5Ztr0M+IlgQr0vMvlKRPj0X5R1oDuXmXnICpDV9B6ooeugX//oCs2ry8dlzDyCASd2O HtNg2CC/jbwDMybYd24PoMSx8HugG3gMUoZtIhuYuRV3ANXX8XUCvIBRjkDjDStgR1CD/PuDrmDM dg7i6xwclVZQDkoriHwB7nYBlgugcgXsSurk/AEJvb3wF7X09QAAABp6VFh0anBlZzpjb2xvcnNw YWNlAAB42jMCAAAzADOJOCM1AAAAJnpUWHRqcGVnOnNhbXBsaW5nLWZhY3RvcgAAeNozqjDSMaww BGEAEYMC6T2XL08AAAAASUVORK5CYII= User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1.50 (gnu/linux) Cancel-Lock: sha1:s5nBZ4BNz38++T2B+KAuydlXvX0= X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:77090 Archived-At: --=-=-= Hi all, Richard and Stefan asked me to include my doc-view.el in the emacs distribution, so here it is together with a ChangeLog entry for lisp/ChangeLog. --8<---------------cut here---------------start------------->8--- Index: lisp/ChangeLog =================================================================== RCS file: /sources/emacs/emacs/lisp/ChangeLog,v retrieving revision 1.11619 diff -u -r1.11619 ChangeLog --- lisp/ChangeLog 24 Aug 2007 10:50:07 -0000 1.11619 +++ lisp/ChangeLog 24 Aug 2007 11:02:27 -0000 @@ -1,3 +1,7 @@ +2007-08-24 Tassilo Horn + + * doc-view.el: New file. A in-buffer PDF/PS/DVI viewer. + 2007-08-24 Thien-Thi Nguyen * progmodes/hideshow.el (hs-match-data): Delete alias. --8<---------------cut here---------------end--------------->8--- --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=doc-view.el Content-Transfer-Encoding: quoted-printable Content-Description: doc-view.el --- View PDF/PostScript/DVI files in Emacs ;;; doc-view.el --- View PDF/PostScript/DVI files in Emacs ;; Copyright (C) 2007 Free Software Foundation, Inc. ;; ;; Author: Tassilo Horn ;; Maintainer: Tassilo Horn ;; Keywords: files, pdf, ps, dvi ;; Version: <2007-08-23 Thu 11:48> ;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify it und= er ;; the terms of the GNU General Public License as published by the Free ;; Software Foundation; either version 3, or (at your option) any later ;; version. ;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT= ANY ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ;; details. ;; You should have received a copy of the GNU General Public License along = with ;; GNU Emacs; see the file COPYING. If not, write to the Free Software ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, ;; USA. ;;; Requirements: ;; I tested in on GNU Emacs 22, but maybe it works with older emacsen or ;; XEmacs, too. You need ImageMagick's `convert' tool. ;;; Commentary: ;; DocView is a document viewer for Emacs. It converts PDF, PS and DVI fil= es ;; to a set of PNG files, one PNG for each page, and displays the PNG images ;; inside an Emacs buffer. This buffer uses `doc-view-mode' which provides ;; convenient key bindings for browsing the document. ;; ;; To use it simply do ;; ;; M-x doc-view RET ;; ;; and you'll be queried for a document to open. ;; ;; Since conversion may take some time all the PNG images are cached in a ;; subdirectory of `doc-view-cache-directory' and reused when you want to v= iew ;; that file again. This reusing can be omitted if you provide a prefx ;; argument to `doc-view'. To delete all cached files use ;; `doc-view-clear-cache'. To open the cache with dired, so that you can t= idy ;; it out use `doc-view-dired-cache'. ;; ;; WARNING: The conversion process can make your computer unusable if the ;; document has many pages and `doc-view-display-size' is huge, because ;; `convert' grabs all your memory and the system will start swapping. You= can ;; restrict the resources ImageMagick uses with the environment variables, ;; MAGICK_AREA_LIMIT, MAGICK_DISK_LIMIT, MAGICK_FILE_LIMIT, MAGICK_MEMORY_L= IMIT ;; and MAGICK_MAP_LIMIT. See ;; http://www.imagemagick.org/script/resources.php#environment for their ;; meaning. If the limits are too low `convert' may fail. So you have to ;; fiddle a bit to get a good compromise between conversion speed and resou= rce ;; usage. ;; ;; The author uses the default values except for MAGICK_MEMORY_LIMIT (set to ;; 256) and MAGICK_MAP_LIMIT (set to 512) on his 1.7GHz Centrino Duo laptop ;; with 1GB of RAM. ;; ;; Other settings that influence the speed, memory usage and quality of the ;; resulting images are `doc-view-converter-image-settings' and ;; `doc-view-converter-image-operators'. If you find a combination that wo= rks ;; particulary well, please drop me a mail. ;;; Code: (require 'dired) (defgroup doc-view nil "In-buffer viewer for PDF, PostScript and DVI files." :link '(function-link doc-view) :version "22.2" :group 'applications :group 'multimedia :prefix "dac-view-") (defcustom doc-view-converter-program "convert" "Program to convert doc files to png." :type '(file) :group 'doc-view) (defcustom doc-view-converter-image-settings '("-density" "114") "A list of Image Settings. See http://www.imagemagick.org/script/command-line-processing.php#setting. The default is (\"-density\" \"114\") which determinates how big the resulting PNG images are. If the value is too small, reading might become hard. If it's too big, the images won't fit into an Emacs buffer. Fiddle with it!" :type '(string) :group 'doc-view) (defcustom doc-view-converter-image-operators '("-strip" "-trim") "A list of Image Operators. See http://www.imagemagick.org/script/command-line-processing.php#operator. The default is (\"-strip\" \"-trim\"). \"-strip\" removes all profiles or comments in the resulting png files. \"-trim\" cuts of the empty margins of the pages, so that display space is used as efficiently as possible." :type '(string) :group 'doc-view) (defcustom doc-view-cache-directory (concat temporary-file-directory "doc-v= iew") "The base directory, where the PNG images will be saved." :type '(directory) :group 'doc-view) (defcustom doc-view-display-margin 5 "The width of the margin put around the page's image." :type '(integer) :group 'doc-view) (defvar doc-view-current-files nil "Only used internally.") (defvar doc-view-current-page nil "Only used internally.") (defvar doc-view-current-file nil "Only used internally.") (defvar doc-view-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-v") 'doc-view-next-page) (define-key map (kbd "n") 'doc-view-next-page) (define-key map (kbd "") 'doc-view-next-page) (define-key map (kbd "SPC") 'doc-view-next-page) (define-key map (kbd "M-v") 'doc-view-previous-page) (define-key map (kbd "p") 'doc-view-previous-page) (define-key map (kbd "") 'doc-view-previous-page) (define-key map (kbd "M-<") 'doc-view-first-page) (define-key map (kbd "M->") 'doc-view-last-page) (define-key map (kbd "g") 'doc-view-goto-page) (define-key map (kbd "k") 'doc-view-kill-buffer) (define-key map (kbd "q") 'bury-buffer) (suppress-keymap map) map) "Keymap used by `doc-view-mode'.") (defun doc-view-kill-buffer () "Kill the current buffer." (interactive) (kill-buffer (current-buffer))) (defun doc-view-goto-page (page) "View the page given by ARG." (interactive "nPage: ") (if (< page 1) (setq page 1) (when (> page (length doc-view-current-files)) (setq page (length doc-view-current-files)))) (setq doc-view-current-page page) (doc-view-display-image (nth (1- page) doc-view-current-files))) (defun doc-view-next-page (arg) "Browse ARG pages forward." (interactive "p") (doc-view-goto-page (+ doc-view-current-page arg))) (defun doc-view-previous-page (arg) "Browse ARG pages backward." (interactive "p") (doc-view-goto-page (- doc-view-current-page arg))) (defun doc-view-first-page () "View the first page." (interactive) (doc-view-goto-page 1)) (defun doc-view-last-page () "View the last page." (interactive) (doc-view-goto-page (length doc-view-current-files))) (defun doc-view-file-name-to-directory-name (file) "Return the directory where the png files of FILE should be saved. It'a a subdirectory of `doc-view-cache-directory'." (concat (file-name-as-directory doc-view-cache-directory) (file-name-nondirectory file) "-" (md5 file))) (defun doc-view-convert-file (file) "Convert FILE to a set of png files, one file per page. Those files are saved in the directory given by `doc-view-file-name-to-directory-name'. Returns the converter process." (clear-image-cache) (let* ((dir (doc-view-file-name-to-directory-name file)) (png-file (concat dir "/" "page.png"))) (when (file-exists-p dir) (dired-delete-file dir 'always)) (make-directory dir t) (apply 'start-process (append (list "doc-view-convert" "*doc-view conversion output*" doc-view-converter-program) doc-view-converter-image-settings (list file) doc-view-converter-image-operators (list png-file))))) (defun doc-view-sort (a b) "Return non-nil if A should be sorted before B. Predicate for sorting `doc-view-current-files'." (if (< (length a) (length b)) t (if (> (length a) (length b)) nil (string< a b)))) (define-derived-mode doc-view-mode nil "DocView" "Major mode in DocView buffers. \\{doc-view-mode-map}" :group 'doc-view (setq buffer-read-only t) (make-local-variable 'doc-view-current-files) (make-local-variable 'doc-view-current-file) (make-local-variable 'doc-view-current-page)) (defun doc-view-display-image (file) "Display the given png FILE." (setq buffer-read-only nil) (erase-buffer) (let ((image (create-image file 'png nil :margin doc-view-display-margin :pointer 'hand))) (insert-image image)) (insert (propertize (format "\nPage %d of %d." doc-view-current-page (length doc-vie= w-current-files)) 'face 'bold)) (goto-char (point-min)) (forward-char) (setq buffer-read-only t)) (defun doc-view-display (file) "Start viewing the document FILE." (let ((buffer (get-buffer-create (format "*DocView: %s*" file))) (dir (doc-view-file-name-to-directory-name file))) (switch-to-buffer buffer) (doc-view-mode) (setq doc-view-current-files (sort (directory-files dir t "page-[0-9]+\\.png" t) 'doc-view-sort) doc-view-current-file file) (doc-view-goto-page 1))) (defun doc-view (no-cache) "Query for a document, convert it to png and start viewing it. If this file is still in the cache, don't convert and use the existing page files. With prefix arg NO-CACHE, don't use the cached files and convert anew." (interactive "P") (if (not (and (image-type-available-p 'png) (display-images-p))) (message "DocView: your emacs or display doesn't support png images.") (setq doc-view-current-file (expand-file-name (read-file-name "File: " nil nil t))) (if (and (file-exists-p (doc-view-file-name-to-directory-name doc-view-current-file)) (not no-cache)) (progn (message "DocView: using cached files!") (doc-view-display doc-view-current-file)) (message "DocView: starting conversion!") (set-process-sentinel (doc-view-convert-file doc-view-current-file) '(lambda (proc event) (message "DocView: finished conversion!") (doc-view-display doc-view-current-file)))))) (defun doc-view-clear-cache () "Delete the whole cache (`doc-view-cache-directory')." (interactive) (dired-delete-file doc-view-cache-directory 'always) (make-directory doc-view-cache-directory)) (defun doc-view-dired-cache () "Open `dired' in `doc-view-cache-directory'.." (interactive) (dired doc-view-cache-directory)) (provide 'doc-view) ;;; doc-view.el ends here --=-=-= Bye, Tassilo -- Chuck Norris' roundhouse kick is so powerful, it can be seen from outer space by the naked eye. --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--