all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Please install: Some improvements to doc-view.el
@ 2007-10-02  9:15 Tassilo Horn
  2007-10-02 13:04 ` Davis Herring
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-10-02  9:15 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 601 bytes --]

Hi all,

would someone with write access please install this patch for me?  It
includes the following improvements:

1. When doing `M-x doc-view' the filename completion doesn't hide pdf,
   ps, and dvi files anymore.

2. I added a simple around advice to `view-file' that asks to use
   `doc-view' instead of `view-file' if file is a pdf, ps or dvi file.
   This enables users to use the normal `v' command in dired to open
   document files.

The patch is a bit large because the current version was indented with
spaces, this one uses both spaces and tabs (width 8) as it's the default
for emacs.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: doc-view.patch --]
[-- Type: text/x-patch, Size: 24922 bytes --]

Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.2
diff -u -r1.2 doc-view.el
--- lisp/doc-view.el	10 Sep 2007 11:53:00 -0000	1.2
+++ lisp/doc-view.el	2 Oct 2007 09:06:13 -0000
@@ -5,7 +5,7 @@
 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
 ;; Keywords: files, pdf, ps, dvi
-;; Version: <2007-09-07 Fri 15:28>
+;; Version: <2007-10-02 Tue 10:40>
 
 ;; This file is part of GNU Emacs.
 
@@ -67,8 +67,6 @@
 ;; bottom-right corner of the desired slice.  To reset the slice use
 ;; `doc-view-reset-slice' (bound to `s r').
 ;;
-;; Dired users should have a look at `doc-view-dired'.
-;;
 ;; You can also search within the document.  The command `doc-view-search'
 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
 ;; matching pages and messages how many match-pages were found.  After that you
@@ -80,6 +78,10 @@
 ;; conversion.  When that finishes and you're still viewing the document
 ;; (i.e. you didn't switch to another buffer) you're queried for the regexp
 ;; then.
+;;
+;; Dired users can simply hit `v' on a document file.  If it's a PS, PDF or DVI
+;; file you're asked to open it with `doc-view' instead of `view-file'.
+;;
 
 ;;; Configuration:
 
@@ -150,7 +152,7 @@
   :group 'doc-view)
 
 (defcustom doc-view-cache-directory (concat temporary-file-directory
-                                            "doc-view")
+					    "doc-view")
   "The base directory, where the PNG images will be saved."
   :type '(directory)
   :group 'doc-view)
@@ -246,36 +248,36 @@
   (interactive "nPage: ")
   (let ((len (length doc-view-current-files)))
     (if (< page 1)
-        (setq page 1)
+	(setq page 1)
       (when (> page len)
-        (setq page len)))
+	(setq page len)))
     (setq doc-view-current-page page
-          doc-view-current-info
-          (concat
-           (propertize
-            (format "Page %d of %d."
-                    doc-view-current-page
-                    len) 'face 'bold)
-           ;; Tell user if converting isn't finished yet
-           (if doc-view-current-converter-process
-               " (still converting...)\n"
-             "\n")
-           ;; Display context infos if this page matches the last search
-           (when (and doc-view-current-search-matches
-                      (assq doc-view-current-page
-                            doc-view-current-search-matches))
-             (concat (propertize "Search matches:\n" 'face 'bold)
-                     (let ((contexts ""))
-                       (dolist (m (cdr (assq doc-view-current-page
-                                             doc-view-current-search-matches)))
-                         (setq contexts (concat contexts "  - \"" m "\"\n")))
-                       contexts)))))
+	  doc-view-current-info
+	  (concat
+	   (propertize
+	    (format "Page %d of %d."
+		    doc-view-current-page
+		    len) 'face 'bold)
+	   ;; Tell user if converting isn't finished yet
+	   (if doc-view-current-converter-process
+	       " (still converting...)\n"
+	     "\n")
+	   ;; Display context infos if this page matches the last search
+	   (when (and doc-view-current-search-matches
+		      (assq doc-view-current-page
+			    doc-view-current-search-matches))
+	     (concat (propertize "Search matches:\n" 'face 'bold)
+		     (let ((contexts ""))
+		       (dolist (m (cdr (assq doc-view-current-page
+					     doc-view-current-search-matches)))
+			 (setq contexts (concat contexts "  - \"" m "\"\n")))
+		       contexts)))))
     ;; Update the buffer
     (setq inhibit-read-only t)
     (erase-buffer)
     (let ((beg (point)))
       (doc-view-insert-image (nth (1- page) doc-view-current-files)
-                             :pointer 'arrow)
+			     :pointer 'arrow)
       (put-text-property beg (point) 'help-echo doc-view-current-info))
     (insert "\n" doc-view-current-info)
     (goto-char (point-min))
@@ -315,7 +317,7 @@
   (condition-case nil
       (scroll-down)
     (error (doc-view-previous-page)
-           (goto-char (point-max)))))
+	   (goto-char (point-max)))))
 
 (defun doc-view-kill-proc-and-buffer ()
   "Kill the current converter process and buffer."
@@ -338,13 +340,13 @@
       doc-view-current-cache-dir
     (file-name-as-directory
      (concat (file-name-as-directory doc-view-cache-directory)
-             (with-temp-buffer
-               (insert-file-contents-literally file)
-               (md5 (current-buffer)))))))
+	     (with-temp-buffer
+	       (insert-file-contents-literally file)
+	       (md5 (current-buffer)))))))
 
 (defun doc-view-dvi->pdf-sentinel (proc event)
   "If DVI->PDF conversion was successful, convert the PDF to PNG
-now."
+ now."
   (if (not (string-match "finished" event))
       (message "DocView: dvi->pdf process changed status to %s." event)
     (set-buffer (process-get proc 'buffer))
@@ -352,20 +354,20 @@
     (message "DocView: finished conversion from DVI to PDF!")
     ;; Now go on converting this PDF to a set of PNG files.
     (let* ((pdf (process-get proc 'pdf-file))
-           (png (concat (doc-view-file-name-to-directory-name
-                         doc-view-current-doc)
-                        "page-%d.png")))
+	   (png (concat (doc-view-file-name-to-directory-name
+			 doc-view-current-doc)
+			"page-%d.png")))
       (doc-view-pdf/ps->png pdf png))))
 
 (defun doc-view-dvi->pdf (dvi pdf)
   "Convert DVI to PDF asynchrounously."
   (message "DocView: converting DVI to PDF now!")
   (setq doc-view-current-converter-process
-        (start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
-                       doc-view-dvipdfm-program
-                       "-o" pdf dvi))
+	(start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
+		       doc-view-dvipdfm-program
+		       "-o" pdf dvi))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-dvi->pdf-sentinel)
+			'doc-view-dvi->pdf-sentinel)
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
   (process-put doc-view-current-converter-process 'pdf-file pdf))
 
@@ -386,44 +388,44 @@
   "Convert PDF-PS to PNG asynchrounously."
   (message "DocView: converting PDF or PS to PNG now!")
   (setq doc-view-current-converter-process
-        (apply 'start-process
-               (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
-                             doc-view-ghostscript-program)
-                       doc-view-ghostscript-options
-                       (list (concat "-sOutputFile=" png))
-                       (list pdf-ps))))
+	(apply 'start-process
+	       (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
+			     doc-view-ghostscript-program)
+		       doc-view-ghostscript-options
+		       (list (concat "-sOutputFile=" png))
+		       (list pdf-ps))))
   (process-put doc-view-current-converter-process
-               'buffer (current-buffer))
+	       'buffer (current-buffer))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-pdf/ps->png-sentinel)
+			'doc-view-pdf/ps->png-sentinel)
   (when doc-view-conversion-refresh-interval
     (setq doc-view-current-timer
-          (run-at-time "1 secs" doc-view-conversion-refresh-interval
-                       'doc-view-display
-                       doc-view-current-doc))))
+	  (run-at-time "1 secs" doc-view-conversion-refresh-interval
+		       'doc-view-display
+		       doc-view-current-doc))))
 
 (defun doc-view-pdf->txt-sentinel (proc event)
   (if (not (string-match "finished" event))
       (message "DocView: converter process changed status to %s." event)
     (let ((current-buffer (current-buffer))
-          (proc-buffer    (process-get proc 'buffer)))
+	  (proc-buffer    (process-get proc 'buffer)))
       (set-buffer proc-buffer)
       (setq doc-view-current-converter-process nil)
       (message "DocView: finished conversion from PDF to TXT!")
       ;; If the user looks at the DocView buffer where the conversion was
       ;; performed, search anew.  This time it will be queried for a regexp.
       (when (eq current-buffer proc-buffer)
-        (doc-view-search)))))
+	(doc-view-search)))))
 
 (defun doc-view-pdf->txt (pdf txt)
   "Convert PDF to TXT asynchrounously."
   (message "DocView: converting PDF to TXT now!")
   (setq doc-view-current-converter-process
-        (start-process "doc-view-pdf->txt" doc-view-conversion-buffer
-                       doc-view-pdftotext-program "-raw"
-                       pdf txt))
+	(start-process "doc-view-pdf->txt" doc-view-conversion-buffer
+		       doc-view-pdftotext-program "-raw"
+		       pdf txt))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-pdf->txt-sentinel)
+			'doc-view-pdf->txt-sentinel)
   (process-put doc-view-current-converter-process 'buffer (current-buffer)))
 
 (defun doc-view-ps->pdf-sentinel (proc event)
@@ -434,19 +436,19 @@
     (message "DocView: finished conversion from PS to PDF!")
     ;; Now we can transform to plain text.
     (doc-view-pdf->txt (process-get proc 'pdf-file)
-                       (concat (doc-view-file-name-to-directory-name
-                                doc-view-current-doc)
-                               "doc.txt"))))
+		       (concat (doc-view-file-name-to-directory-name
+				doc-view-current-doc)
+			       "doc.txt"))))
 
 (defun doc-view-ps->pdf (ps pdf)
   "Convert PS to PDF asynchronously."
   (message "DocView: converting PS to PDF now!")
   (setq doc-view-current-converter-process
-        (start-process "doc-view-ps->pdf" doc-view-conversion-buffer
-                       doc-view-ps2pdf-program
-                       ps pdf))
+	(start-process "doc-view-ps->pdf" doc-view-conversion-buffer
+		       doc-view-ps2pdf-program
+		       ps pdf))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-ps->pdf-sentinel)
+			'doc-view-ps->pdf-sentinel)
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
   (process-put doc-view-current-converter-process 'pdf-file pdf))
 
@@ -457,18 +459,18 @@
 `doc-view-file-name-to-directory-name'."
   (clear-image-cache)
   (let* ((dir (doc-view-file-name-to-directory-name doc))
-         (png-file (concat (file-name-as-directory dir) "page-%d.png")))
+	 (png-file (concat (file-name-as-directory dir) "page-%d.png")))
     (when (file-exists-p dir)
       (dired-delete-file dir 'always))
     (make-directory dir t)
     (if (not (string= (file-name-extension doc) "dvi"))
-        ;; Convert to PNG images.
-        (doc-view-pdf/ps->png doc png-file)
+	;; Convert to PNG images.
+	(doc-view-pdf/ps->png doc png-file)
       ;; DVI files have to be converted to PDF before GhostScript can process
       ;; it.
       (doc-view-dvi->pdf doc
-                         (concat (file-name-as-directory dir)
-                                 "doc.pdf")))))
+			 (concat (file-name-as-directory dir)
+				 "doc.pdf")))))
 
 ;;;; DocView Mode
 
@@ -501,10 +503,10 @@
 do that.  To reset the slice use `doc-view-reset-slice'."
   (interactive
    (let* ((size (image-size doc-view-current-image t))
-          (a (read-number (format "Top-left X (0..%d): " (car size))))
-          (b (read-number (format "Top-left Y (0..%d): " (cdr size))))
-          (c (read-number (format "Width (0..%d): " (- (car size) a))))
-          (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
+	  (a (read-number (format "Top-left X (0..%d): " (car size))))
+	  (b (read-number (format "Top-left Y (0..%d): " (cdr size))))
+	  (c (read-number (format "Width (0..%d): " (- (car size) a))))
+	  (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
      (list a b c d)))
   (setq doc-view-current-slice (list x y width height))
   ;; Redisplay
@@ -519,14 +521,14 @@
   (let (x y w h done)
     (while (not done)
       (let ((e (read-event
-                (concat "Press mouse-1 at the top-left corner and "
-                        "drag it to the bottom-right corner!"))))
-        (when (eq (car e) 'drag-mouse-1)
-          (setq x (car (posn-object-x-y (event-start e))))
-          (setq y (cdr (posn-object-x-y (event-start e))))
-          (setq w (- (car (posn-object-x-y (event-end e))) x))
-          (setq h (- (cdr (posn-object-x-y (event-end e))) y))
-          (setq done t))))
+		(concat "Press mouse-1 at the top-left corner and "
+			"drag it to the bottom-right corner!"))))
+	(when (eq (car e) 'drag-mouse-1)
+	  (setq x (car (posn-object-x-y (event-start e))))
+	  (setq y (cdr (posn-object-x-y (event-start e))))
+	  (setq w (- (car (posn-object-x-y (event-end e))) x))
+	  (setq h (- (cdr (posn-object-x-y (event-end e))) y))
+	  (setq done t))))
     (doc-view-set-slice x y w h)))
 
 (defun doc-view-reset-slice ()
@@ -553,7 +555,7 @@
   (if (< (length a) (length b))
       t
     (if (> (length a) (length b))
-        nil
+	nil
       (string< a b))))
 
 (defun doc-view-display (doc)
@@ -561,8 +563,8 @@
   (let ((dir (doc-view-file-name-to-directory-name doc)))
     (set-buffer (format "*DocView: %s*" doc))
     (setq doc-view-current-files
-          (sort (directory-files dir t "page-[0-9]+\\.png" t)
-                'doc-view-sort))
+	  (sort (directory-files dir t "page-[0-9]+\\.png" t)
+		'doc-view-sort))
     (when (> (length doc-view-current-files) 0)
       (doc-view-goto-page doc-view-current-page))))
 
@@ -570,8 +572,8 @@
   (setq inhibit-read-only t)
   (erase-buffer)
   (insert (propertize "Welcome to DocView!" 'face 'bold)
-          "\n"
-          "
+	  "\n"
+	  "
 If you  see this buffer  it means that  the document you  want to
 view gets  converted to PNG now  and the conversion  of the first
 page           hasn't          finished           yet          or
@@ -579,8 +581,8 @@
 
 For now these keys are useful:
 
-    `q' : Bury this buffer.  Conversion will go on in background.
-    `k' : Kill the conversion process and this buffer.\n")
+`q' : Bury this buffer.  Conversion will go on in background.
+`k' : Kill the conversion process and this buffer.\n")
   (setq inhibit-read-only nil))
 
 (defun doc-view-show-tooltip ()
@@ -591,39 +593,35 @@
 
 (defun doc-view-search-internal (regexp file)
   "Return a list of FILE's pages that contain text matching REGEXP.
-The value is an alist of the form
-
-    (PAGE CONTEXTS)
-
-where PAGE is the pagenumber and CONTEXTS are the lines
-containing the match."
+The value is an alist of the form (PAGE CONTEXTS) where PAGE is
+the pagenumber and CONTEXTS are all lines of text containing a match."
   (with-temp-buffer
     (insert-file-contents file)
     (let ((page 1)
-          (lastpage 1)
-          matches)
+	  (lastpage 1)
+	  matches)
       (while (re-search-forward (concat "\\(?:\\([\f]\\)\\|\\("
-                                        regexp "\\)\\)") nil t)
-        (when (match-string 1) (incf page))
-        (when (match-string 2)
-          (if (/= page lastpage)
-              (setq matches (push (cons page
-                                        (list (buffer-substring
-                                               (line-beginning-position)
-                                               (line-end-position))))
-                                  matches))
-            (setq matches (cons
-                           (append
-                            (or
-                             ;; This page already is a match.
-                             (car matches)
-                             ;; This is the first match on page.
-                             (list page))
-                            (list (buffer-substring
-                                   (line-beginning-position)
-                                   (line-end-position))))
-                           (cdr matches))))
-          (setq lastpage page)))
+					regexp "\\)\\)") nil t)
+	(when (match-string 1) (incf page))
+	(when (match-string 2)
+	  (if (/= page lastpage)
+	      (setq matches (push (cons page
+					(list (buffer-substring
+					       (line-beginning-position)
+					       (line-end-position))))
+				  matches))
+	    (setq matches (cons
+			   (append
+			    (or
+			     ;; This page already is a match.
+			     (car matches)
+			     ;; This is the first match on page.
+			     (list page))
+			    (list (buffer-substring
+				   (line-beginning-position)
+				   (line-end-position))))
+			   (cdr matches))))
+	  (setq lastpage page)))
       (nreverse matches))))
 
 (defun doc-view-search-no-of-matches (list)
@@ -642,66 +640,66 @@
   ;; New search, so forget the old results.
   (setq doc-view-current-search-matches nil)
   (let ((txt (concat (doc-view-file-name-to-directory-name
-                      doc-view-current-doc)
-                     "doc.txt")))
+		      doc-view-current-doc)
+		     "doc.txt")))
     (if (file-readable-p txt)
-        (progn
-          (setq doc-view-current-search-matches
-                (doc-view-search-internal
-                 (read-from-minibuffer "Regexp: ")
-                 txt))
-          (message "DocView: search yielded %d matches."
-                   (doc-view-search-no-of-matches
-                    doc-view-current-search-matches)))
+	(progn
+	  (setq doc-view-current-search-matches
+		(doc-view-search-internal
+		 (read-from-minibuffer "Regexp: ")
+		 txt))
+	  (message "DocView: search yielded %d matches."
+		   (doc-view-search-no-of-matches
+		    doc-view-current-search-matches)))
       ;; We must convert to TXT first!
       (if doc-view-current-converter-process
-          (message "DocView: please wait till conversion finished.")
-        (let ((ext (file-name-extension doc-view-current-doc)))
-          (cond
-           ((string= ext "pdf")
-            ;; Doc is a PDF, so convert it to TXT
-            (doc-view-pdf->txt doc-view-current-doc txt))
-           ((string= ext "ps")
-            ;; Doc is a PS, so convert it to PDF (which will be converted to
-            ;; TXT thereafter).
-            (doc-view-ps->pdf doc-view-current-doc
-                              (concat (doc-view-file-name-to-directory-name
-                                       doc-view-current-doc)
-                                      "doc.pdf")))
-           ((string= ext "dvi")
-            ;; Doc is a DVI.  This means that a doc.pdf already exists in its
-            ;; cache subdirectory.
-            (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
-                                        doc-view-current-doc)
-                                       "doc.pdf")
-                               txt))
-           (t (error "DocView doesn't know what to do"))))))))
+	  (message "DocView: please wait till conversion finished.")
+	(let ((ext (file-name-extension doc-view-current-doc)))
+	  (cond
+	   ((string= ext "pdf")
+	    ;; Doc is a PDF, so convert it to TXT
+	    (doc-view-pdf->txt doc-view-current-doc txt))
+	   ((string= ext "ps")
+	    ;; Doc is a PS, so convert it to PDF (which will be converted to
+	    ;; TXT thereafter).
+	    (doc-view-ps->pdf doc-view-current-doc
+			      (concat (doc-view-file-name-to-directory-name
+				       doc-view-current-doc)
+				      "doc.pdf")))
+	   ((string= ext "dvi")
+	    ;; Doc is a DVI.  This means that a doc.pdf already exists in its
+	    ;; cache subdirectory.
+	    (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
+					doc-view-current-doc)
+				       "doc.pdf")
+			       txt))
+	   (t (error "DocView doesn't know what to do"))))))))
 
 (defun doc-view-search-next-match (arg)
   "Go to the ARGth next matching page."
   (interactive "p")
   (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page))
-                                doc-view-current-search-matches))
-         (page (car (nth (1- arg) next-pages))))
+				doc-view-current-search-matches))
+	 (page (car (nth (1- arg) next-pages))))
     (if page
-        (doc-view-goto-page page)
+	(doc-view-goto-page page)
       (when (and
-             doc-view-current-search-matches
-             (y-or-n-p "No more matches after current page.  Wrap to first match? "))
-        (doc-view-goto-page (caar doc-view-current-search-matches))))))
+	     doc-view-current-search-matches
+	     (y-or-n-p "No more matches after current page.  Wrap to first match? "))
+	(doc-view-goto-page (caar doc-view-current-search-matches))))))
 
 (defun doc-view-search-previous-match (arg)
   "Go to the ARGth previous matching page."
   (interactive "p")
   (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page))
-                                doc-view-current-search-matches))
-         (page (car (nth (1- arg) (nreverse prev-pages)))))
+				doc-view-current-search-matches))
+	 (page (car (nth (1- arg) (nreverse prev-pages)))))
     (if page
-        (doc-view-goto-page page)
+	(doc-view-goto-page page)
       (when (and
-             doc-view-current-search-matches
-             (y-or-n-p "No more matches before current page.  Wrap to last match? "))
-        (doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
+	     doc-view-current-search-matches
+	     (y-or-n-p "No more matches before current page.  Wrap to last match? "))
+	(doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
 
 ;;;; User Interface Commands
 
@@ -713,24 +711,31 @@
 cached files and convert anew."
   (interactive "P")
   (if (not (and (image-type-available-p 'png)
-                (display-images-p)))
+		(display-images-p)))
       (message "DocView: your emacs or display doesn't support png images.")
     (let* ((doc (or file
-                    (expand-file-name (read-file-name "File: " nil nil t))))
-           (buffer (get-buffer-create (format "*DocView: %s*" doc)))
-           (dir (doc-view-file-name-to-directory-name doc)))
+		    (expand-file-name
+		     (let ((completion-ignored-extensions
+			    ;; Don't hide files doc-view can display
+			    (remove-if (lambda (str)
+					 (string-match "\\.\\(ps\\|pdf\\|dvi\\)$"
+						       str))
+				       completion-ignored-extensions)))
+		       (read-file-name "File: " nil nil t)))))
+	   (buffer (get-buffer-create (format "*DocView: %s*" doc)))
+	   (dir (doc-view-file-name-to-directory-name doc)))
       (switch-to-buffer buffer)
       (doc-view-buffer-message)
       (doc-view-mode)
       (setq doc-view-current-doc doc)
       (setq doc-view-current-page 1)
       (if (not (and (file-exists-p dir)
-                    (not no-cache)))
-          (progn
-            (setq doc-view-current-cache-dir nil)
-            (doc-view-convert-doc doc-view-current-doc))
-        (message "DocView: using cached files!")
-        (doc-view-display doc-view-current-doc)))))
+		    (not no-cache)))
+	  (progn
+	    (setq doc-view-current-cache-dir nil)
+	    (doc-view-convert-doc doc-view-current-doc))
+	(message "DocView: using cached files!")
+	(doc-view-display doc-view-current-doc)))))
 
 (defun doc-view-dired (no-cache)
   "View the current dired file with doc-view.
@@ -738,10 +743,23 @@
 
 You might want to bind this command to a dired key, e.g.
 
-    (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)"
+  (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)
+
+This function is now OBSOLETE because of a more general solution:
+There's an advice to `view-file' which asks to open the file with
+`doc-view' if it's a PS, PDF or DVI file. Simply hit `v' on a
+file in dired to view it."
   (interactive "P")
   (doc-view no-cache (dired-get-file-for-visit)))
 
+(defadvice view-file (around doc-view-file (file) activate)
+  "View FILE with doc-view if it is a PostScript, a PDF or a DVI file.
+Use the the cached image files if possible."
+  (if (and (string-match "\\.\\(ps\\|pdf\\|dvi\\)$" file)
+	   (y-or-n-p "Open with `doc-view' instead of `view-file'? "))
+      (doc-view nil file)
+    ad-do-it))
+
 (defun doc-view-clear-cache ()
   "Delete the whole cache (`doc-view-cache-directory')."
   (interactive)
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.11854
diff -u -r1.11854 ChangeLog
--- lisp/ChangeLog	2 Oct 2007 02:05:46 -0000	1.11854
+++ lisp/ChangeLog	2 Oct 2007 09:06:19 -0000
@@ -1,3 +1,11 @@
+2007-10-02  Tassilo Horn  <tassilo@member.fsf.org>
+
+	* doc-view.el (doc-view): Don't hide document files (pdf, dvi, ps)
+	in the filename completion.
+	(doc-view-dired): Mark as obsolete.
+	(view-file): New advise: Offer to open with doc-view instead of
+	view-file for pdf, ps and dvi files.
+
 2007-10-02  Richard Stallman  <rms@gnu.org>
 
 	* frame.el (cursor-in-non-selected-windows): Doc fix.

[-- Attachment #3: Type: text/plain, Size: 71 bytes --]


The patch includes the ChangeLog entry, too.

Bye and thanks,
Tassilo

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-02  9:15 Please install: Some improvements to doc-view.el Tassilo Horn
@ 2007-10-02 13:04 ` Davis Herring
  2007-10-02 14:42   ` Tassilo Horn
  2007-10-02 16:49   ` Tassilo Horn
  0 siblings, 2 replies; 98+ messages in thread
From: Davis Herring @ 2007-10-02 13:04 UTC (permalink / raw)
  To: emacs-devel

> 2. I added a simple around advice to `view-file' that asks to use
>    `doc-view' instead of `view-file' if file is a pdf, ps or dvi file.
>    This enables users to use the normal `v' command in dired to open
>    document files.

We would prefer this implemented without advice -- perhaps just by
rebinding v in Dired to a new, simple function `view-or-doc-view-file', or
by modifying `view-mode' itself to recognize such files and change to
doc-view-mode.  ("Such files" should of course be a user option; you may
have it so already.)

> The patch is a bit large because the current version was indented with
> spaces, this one uses both spaces and tabs (width 8) as it's the default
> for emacs.

That makes your patch quite hard to read, and causes CVS conflicts with
everyone who has unchecked-in changes to the file.  There's nothing wrong,
I don't think, with fixing the indentation on lines that you change, but
otherwise it's best to leave it alone.  (This is why I'm not sure whether
your patch makes the set of doc-viewable file types a user option.)

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-02 13:04 ` Davis Herring
@ 2007-10-02 14:42   ` Tassilo Horn
  2007-10-02 16:49   ` Tassilo Horn
  1 sibling, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-02 14:42 UTC (permalink / raw)
  To: emacs-devel

"Davis Herring" <herring@lanl.gov> writes:

Hi Davis,

>> 2. I added a simple around advice to `view-file' that asks to use
>>    `doc-view' instead of `view-file' if file is a pdf, ps or dvi file.
>>    This enables users to use the normal `v' command in dired to open
>>    document files.
>
> We would prefer this implemented without advice -- perhaps just by
> rebinding v in Dired to a new, simple function
> `view-or-doc-view-file',

If I rebind this key in doc-view.el then the documentation has to be
extended to tell the user that (require 'doc-view) re-binds it.

I could change that in dired, too, but there may be users that want to
use dired but not doc-view.

Maybe the right thing to do is to add an autoload cookie for doc-view
and change `dired-view-file' to recognize pdf, ps and dvi files.  What
do you think?

>> The patch is a bit large because the current version was indented
>> with spaces, this one uses both spaces and tabs (width 8) as it's the
>> default for emacs.
>
> That makes your patch quite hard to read, and causes CVS conflicts
> with everyone who has unchecked-in changes to the file.  There's
> nothing wrong, I don't think, with fixing the indentation on lines
> that you change, but otherwise it's best to leave it alone.

Oh, too bad.  But now I think I cannot revert the whitespace changes...

> (This is why I'm not sure whether your patch makes the set of
> doc-viewable file types a user option.)

No, that's no user option.  For all doc-view supported file-types (pdf,
ps and dvi) the user will be queried to open the file with doc-view
instead of view-file.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-02 13:04 ` Davis Herring
  2007-10-02 14:42   ` Tassilo Horn
@ 2007-10-02 16:49   ` Tassilo Horn
  2007-10-02 17:33     ` Andreas Schwab
  2007-10-03 18:37     ` Richard Stallman
  1 sibling, 2 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-02 16:49 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 658 bytes --]

"Davis Herring" <herring@lanl.gov> writes:

Hi!

> We would prefer this implemented without advice -- perhaps just by
> rebinding v in Dired to a new, simple function
> `view-or-doc-view-file', or by modifying `view-mode' itself to
> recognize such files and change to doc-view-mode.

I changed `dired-view-file' so that it asks the user to use doc-view for
pdf, ps and dvi files instead of `view-file'.

The only non-whitespace changes are those in doc-view.el at @@ -713,34
+712,31 @@ and those in dired.el and ChangeLog.  The rest are only
whitespace changes and minor changes in comments.

If this patch is ok, would you please install it?

Bye,
Tassilo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: some doc-view changes --]
[-- Type: text/x-patch, Size: 25622 bytes --]

Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.2
diff -u -r1.2 doc-view.el
--- lisp/doc-view.el	10 Sep 2007 11:53:00 -0000	1.2
+++ lisp/doc-view.el	2 Oct 2007 16:42:13 -0000
@@ -5,7 +5,7 @@
 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
 ;; Keywords: files, pdf, ps, dvi
-;; Version: <2007-09-07 Fri 15:28>
+;; Version: <2007-10-02 Tue 18:21>
 
 ;; This file is part of GNU Emacs.
 
@@ -67,8 +67,6 @@
 ;; bottom-right corner of the desired slice.  To reset the slice use
 ;; `doc-view-reset-slice' (bound to `s r').
 ;;
-;; Dired users should have a look at `doc-view-dired'.
-;;
 ;; You can also search within the document.  The command `doc-view-search'
 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
 ;; matching pages and messages how many match-pages were found.  After that you
@@ -80,6 +78,10 @@
 ;; conversion.  When that finishes and you're still viewing the document
 ;; (i.e. you didn't switch to another buffer) you're queried for the regexp
 ;; then.
+;;
+;; Dired users can simply hit `v' on a document file.  If it's a PS, PDF or DVI
+;; file you're asked to open it with `doc-view' instead of `view-file'.
+;;
 
 ;;; Configuration:
 
@@ -150,7 +152,7 @@
   :group 'doc-view)
 
 (defcustom doc-view-cache-directory (concat temporary-file-directory
-                                            "doc-view")
+					    "doc-view")
   "The base directory, where the PNG images will be saved."
   :type '(directory)
   :group 'doc-view)
@@ -246,36 +248,36 @@
   (interactive "nPage: ")
   (let ((len (length doc-view-current-files)))
     (if (< page 1)
-        (setq page 1)
+	(setq page 1)
       (when (> page len)
-        (setq page len)))
+	(setq page len)))
     (setq doc-view-current-page page
-          doc-view-current-info
-          (concat
-           (propertize
-            (format "Page %d of %d."
-                    doc-view-current-page
-                    len) 'face 'bold)
-           ;; Tell user if converting isn't finished yet
-           (if doc-view-current-converter-process
-               " (still converting...)\n"
-             "\n")
-           ;; Display context infos if this page matches the last search
-           (when (and doc-view-current-search-matches
-                      (assq doc-view-current-page
-                            doc-view-current-search-matches))
-             (concat (propertize "Search matches:\n" 'face 'bold)
-                     (let ((contexts ""))
-                       (dolist (m (cdr (assq doc-view-current-page
-                                             doc-view-current-search-matches)))
-                         (setq contexts (concat contexts "  - \"" m "\"\n")))
-                       contexts)))))
+	  doc-view-current-info
+	  (concat
+	   (propertize
+	    (format "Page %d of %d."
+		    doc-view-current-page
+		    len) 'face 'bold)
+	   ;; Tell user if converting isn't finished yet
+	   (if doc-view-current-converter-process
+	       " (still converting...)\n"
+	     "\n")
+	   ;; Display context infos if this page matches the last search
+	   (when (and doc-view-current-search-matches
+		      (assq doc-view-current-page
+			    doc-view-current-search-matches))
+	     (concat (propertize "Search matches:\n" 'face 'bold)
+		     (let ((contexts ""))
+		       (dolist (m (cdr (assq doc-view-current-page
+					     doc-view-current-search-matches)))
+			 (setq contexts (concat contexts "  - \"" m "\"\n")))
+		       contexts)))))
     ;; Update the buffer
     (setq inhibit-read-only t)
     (erase-buffer)
     (let ((beg (point)))
       (doc-view-insert-image (nth (1- page) doc-view-current-files)
-                             :pointer 'arrow)
+			     :pointer 'arrow)
       (put-text-property beg (point) 'help-echo doc-view-current-info))
     (insert "\n" doc-view-current-info)
     (goto-char (point-min))
@@ -315,7 +317,7 @@
   (condition-case nil
       (scroll-down)
     (error (doc-view-previous-page)
-           (goto-char (point-max)))))
+	   (goto-char (point-max)))))
 
 (defun doc-view-kill-proc-and-buffer ()
   "Kill the current converter process and buffer."
@@ -338,13 +340,13 @@
       doc-view-current-cache-dir
     (file-name-as-directory
      (concat (file-name-as-directory doc-view-cache-directory)
-             (with-temp-buffer
-               (insert-file-contents-literally file)
-               (md5 (current-buffer)))))))
+	     (with-temp-buffer
+	       (insert-file-contents-literally file)
+	       (md5 (current-buffer)))))))
 
 (defun doc-view-dvi->pdf-sentinel (proc event)
   "If DVI->PDF conversion was successful, convert the PDF to PNG
-now."
+ now."
   (if (not (string-match "finished" event))
       (message "DocView: dvi->pdf process changed status to %s." event)
     (set-buffer (process-get proc 'buffer))
@@ -352,20 +354,20 @@
     (message "DocView: finished conversion from DVI to PDF!")
     ;; Now go on converting this PDF to a set of PNG files.
     (let* ((pdf (process-get proc 'pdf-file))
-           (png (concat (doc-view-file-name-to-directory-name
-                         doc-view-current-doc)
-                        "page-%d.png")))
+	   (png (concat (doc-view-file-name-to-directory-name
+			 doc-view-current-doc)
+			"page-%d.png")))
       (doc-view-pdf/ps->png pdf png))))
 
 (defun doc-view-dvi->pdf (dvi pdf)
   "Convert DVI to PDF asynchrounously."
   (message "DocView: converting DVI to PDF now!")
   (setq doc-view-current-converter-process
-        (start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
-                       doc-view-dvipdfm-program
-                       "-o" pdf dvi))
+	(start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
+		       doc-view-dvipdfm-program
+		       "-o" pdf dvi))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-dvi->pdf-sentinel)
+			'doc-view-dvi->pdf-sentinel)
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
   (process-put doc-view-current-converter-process 'pdf-file pdf))
 
@@ -386,44 +388,44 @@
   "Convert PDF-PS to PNG asynchrounously."
   (message "DocView: converting PDF or PS to PNG now!")
   (setq doc-view-current-converter-process
-        (apply 'start-process
-               (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
-                             doc-view-ghostscript-program)
-                       doc-view-ghostscript-options
-                       (list (concat "-sOutputFile=" png))
-                       (list pdf-ps))))
+	(apply 'start-process
+	       (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
+			     doc-view-ghostscript-program)
+		       doc-view-ghostscript-options
+		       (list (concat "-sOutputFile=" png))
+		       (list pdf-ps))))
   (process-put doc-view-current-converter-process
-               'buffer (current-buffer))
+	       'buffer (current-buffer))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-pdf/ps->png-sentinel)
+			'doc-view-pdf/ps->png-sentinel)
   (when doc-view-conversion-refresh-interval
     (setq doc-view-current-timer
-          (run-at-time "1 secs" doc-view-conversion-refresh-interval
-                       'doc-view-display
-                       doc-view-current-doc))))
+	  (run-at-time "1 secs" doc-view-conversion-refresh-interval
+		       'doc-view-display
+		       doc-view-current-doc))))
 
 (defun doc-view-pdf->txt-sentinel (proc event)
   (if (not (string-match "finished" event))
       (message "DocView: converter process changed status to %s." event)
     (let ((current-buffer (current-buffer))
-          (proc-buffer    (process-get proc 'buffer)))
+	  (proc-buffer    (process-get proc 'buffer)))
       (set-buffer proc-buffer)
       (setq doc-view-current-converter-process nil)
       (message "DocView: finished conversion from PDF to TXT!")
       ;; If the user looks at the DocView buffer where the conversion was
       ;; performed, search anew.  This time it will be queried for a regexp.
       (when (eq current-buffer proc-buffer)
-        (doc-view-search)))))
+	(doc-view-search)))))
 
 (defun doc-view-pdf->txt (pdf txt)
   "Convert PDF to TXT asynchrounously."
   (message "DocView: converting PDF to TXT now!")
   (setq doc-view-current-converter-process
-        (start-process "doc-view-pdf->txt" doc-view-conversion-buffer
-                       doc-view-pdftotext-program "-raw"
-                       pdf txt))
+	(start-process "doc-view-pdf->txt" doc-view-conversion-buffer
+		       doc-view-pdftotext-program "-raw"
+		       pdf txt))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-pdf->txt-sentinel)
+			'doc-view-pdf->txt-sentinel)
   (process-put doc-view-current-converter-process 'buffer (current-buffer)))
 
 (defun doc-view-ps->pdf-sentinel (proc event)
@@ -434,19 +436,19 @@
     (message "DocView: finished conversion from PS to PDF!")
     ;; Now we can transform to plain text.
     (doc-view-pdf->txt (process-get proc 'pdf-file)
-                       (concat (doc-view-file-name-to-directory-name
-                                doc-view-current-doc)
-                               "doc.txt"))))
+		       (concat (doc-view-file-name-to-directory-name
+				doc-view-current-doc)
+			       "doc.txt"))))
 
 (defun doc-view-ps->pdf (ps pdf)
   "Convert PS to PDF asynchronously."
   (message "DocView: converting PS to PDF now!")
   (setq doc-view-current-converter-process
-        (start-process "doc-view-ps->pdf" doc-view-conversion-buffer
-                       doc-view-ps2pdf-program
-                       ps pdf))
+	(start-process "doc-view-ps->pdf" doc-view-conversion-buffer
+		       doc-view-ps2pdf-program
+		       ps pdf))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-ps->pdf-sentinel)
+			'doc-view-ps->pdf-sentinel)
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
   (process-put doc-view-current-converter-process 'pdf-file pdf))
 
@@ -457,18 +459,18 @@
 `doc-view-file-name-to-directory-name'."
   (clear-image-cache)
   (let* ((dir (doc-view-file-name-to-directory-name doc))
-         (png-file (concat (file-name-as-directory dir) "page-%d.png")))
+	 (png-file (concat (file-name-as-directory dir) "page-%d.png")))
     (when (file-exists-p dir)
       (dired-delete-file dir 'always))
     (make-directory dir t)
     (if (not (string= (file-name-extension doc) "dvi"))
-        ;; Convert to PNG images.
-        (doc-view-pdf/ps->png doc png-file)
+	;; Convert to PNG images.
+	(doc-view-pdf/ps->png doc png-file)
       ;; DVI files have to be converted to PDF before GhostScript can process
       ;; it.
       (doc-view-dvi->pdf doc
-                         (concat (file-name-as-directory dir)
-                                 "doc.pdf")))))
+			 (concat (file-name-as-directory dir)
+				 "doc.pdf")))))
 
 ;;;; DocView Mode
 
@@ -501,10 +503,10 @@
 do that.  To reset the slice use `doc-view-reset-slice'."
   (interactive
    (let* ((size (image-size doc-view-current-image t))
-          (a (read-number (format "Top-left X (0..%d): " (car size))))
-          (b (read-number (format "Top-left Y (0..%d): " (cdr size))))
-          (c (read-number (format "Width (0..%d): " (- (car size) a))))
-          (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
+	  (a (read-number (format "Top-left X (0..%d): " (car size))))
+	  (b (read-number (format "Top-left Y (0..%d): " (cdr size))))
+	  (c (read-number (format "Width (0..%d): " (- (car size) a))))
+	  (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
      (list a b c d)))
   (setq doc-view-current-slice (list x y width height))
   ;; Redisplay
@@ -519,14 +521,14 @@
   (let (x y w h done)
     (while (not done)
       (let ((e (read-event
-                (concat "Press mouse-1 at the top-left corner and "
-                        "drag it to the bottom-right corner!"))))
-        (when (eq (car e) 'drag-mouse-1)
-          (setq x (car (posn-object-x-y (event-start e))))
-          (setq y (cdr (posn-object-x-y (event-start e))))
-          (setq w (- (car (posn-object-x-y (event-end e))) x))
-          (setq h (- (cdr (posn-object-x-y (event-end e))) y))
-          (setq done t))))
+		(concat "Press mouse-1 at the top-left corner and "
+			"drag it to the bottom-right corner!"))))
+	(when (eq (car e) 'drag-mouse-1)
+	  (setq x (car (posn-object-x-y (event-start e))))
+	  (setq y (cdr (posn-object-x-y (event-start e))))
+	  (setq w (- (car (posn-object-x-y (event-end e))) x))
+	  (setq h (- (cdr (posn-object-x-y (event-end e))) y))
+	  (setq done t))))
     (doc-view-set-slice x y w h)))
 
 (defun doc-view-reset-slice ()
@@ -553,7 +555,7 @@
   (if (< (length a) (length b))
       t
     (if (> (length a) (length b))
-        nil
+	nil
       (string< a b))))
 
 (defun doc-view-display (doc)
@@ -561,8 +563,8 @@
   (let ((dir (doc-view-file-name-to-directory-name doc)))
     (set-buffer (format "*DocView: %s*" doc))
     (setq doc-view-current-files
-          (sort (directory-files dir t "page-[0-9]+\\.png" t)
-                'doc-view-sort))
+	  (sort (directory-files dir t "page-[0-9]+\\.png" t)
+		'doc-view-sort))
     (when (> (length doc-view-current-files) 0)
       (doc-view-goto-page doc-view-current-page))))
 
@@ -570,8 +572,8 @@
   (setq inhibit-read-only t)
   (erase-buffer)
   (insert (propertize "Welcome to DocView!" 'face 'bold)
-          "\n"
-          "
+	  "\n"
+	  "
 If you  see this buffer  it means that  the document you  want to
 view gets  converted to PNG now  and the conversion  of the first
 page           hasn't          finished           yet          or
@@ -579,8 +581,8 @@
 
 For now these keys are useful:
 
-    `q' : Bury this buffer.  Conversion will go on in background.
-    `k' : Kill the conversion process and this buffer.\n")
+`q' : Bury this buffer.  Conversion will go on in background.
+`k' : Kill the conversion process and this buffer.\n")
   (setq inhibit-read-only nil))
 
 (defun doc-view-show-tooltip ()
@@ -591,39 +593,35 @@
 
 (defun doc-view-search-internal (regexp file)
   "Return a list of FILE's pages that contain text matching REGEXP.
-The value is an alist of the form
-
-    (PAGE CONTEXTS)
-
-where PAGE is the pagenumber and CONTEXTS are the lines
-containing the match."
+The value is an alist of the form (PAGE CONTEXTS) where PAGE is
+the pagenumber and CONTEXTS are all lines of text containing a match."
   (with-temp-buffer
     (insert-file-contents file)
     (let ((page 1)
-          (lastpage 1)
-          matches)
+	  (lastpage 1)
+	  matches)
       (while (re-search-forward (concat "\\(?:\\([\f]\\)\\|\\("
-                                        regexp "\\)\\)") nil t)
-        (when (match-string 1) (incf page))
-        (when (match-string 2)
-          (if (/= page lastpage)
-              (setq matches (push (cons page
-                                        (list (buffer-substring
-                                               (line-beginning-position)
-                                               (line-end-position))))
-                                  matches))
-            (setq matches (cons
-                           (append
-                            (or
-                             ;; This page already is a match.
-                             (car matches)
-                             ;; This is the first match on page.
-                             (list page))
-                            (list (buffer-substring
-                                   (line-beginning-position)
-                                   (line-end-position))))
-                           (cdr matches))))
-          (setq lastpage page)))
+					regexp "\\)\\)") nil t)
+	(when (match-string 1) (incf page))
+	(when (match-string 2)
+	  (if (/= page lastpage)
+	      (setq matches (push (cons page
+					(list (buffer-substring
+					       (line-beginning-position)
+					       (line-end-position))))
+				  matches))
+	    (setq matches (cons
+			   (append
+			    (or
+			     ;; This page already is a match.
+			     (car matches)
+			     ;; This is the first match on page.
+			     (list page))
+			    (list (buffer-substring
+				   (line-beginning-position)
+				   (line-end-position))))
+			   (cdr matches))))
+	  (setq lastpage page)))
       (nreverse matches))))
 
 (defun doc-view-search-no-of-matches (list)
@@ -642,69 +640,70 @@
   ;; New search, so forget the old results.
   (setq doc-view-current-search-matches nil)
   (let ((txt (concat (doc-view-file-name-to-directory-name
-                      doc-view-current-doc)
-                     "doc.txt")))
+		      doc-view-current-doc)
+		     "doc.txt")))
     (if (file-readable-p txt)
-        (progn
-          (setq doc-view-current-search-matches
-                (doc-view-search-internal
-                 (read-from-minibuffer "Regexp: ")
-                 txt))
-          (message "DocView: search yielded %d matches."
-                   (doc-view-search-no-of-matches
-                    doc-view-current-search-matches)))
+	(progn
+	  (setq doc-view-current-search-matches
+		(doc-view-search-internal
+		 (read-from-minibuffer "Regexp: ")
+		 txt))
+	  (message "DocView: search yielded %d matches."
+		   (doc-view-search-no-of-matches
+		    doc-view-current-search-matches)))
       ;; We must convert to TXT first!
       (if doc-view-current-converter-process
-          (message "DocView: please wait till conversion finished.")
-        (let ((ext (file-name-extension doc-view-current-doc)))
-          (cond
-           ((string= ext "pdf")
-            ;; Doc is a PDF, so convert it to TXT
-            (doc-view-pdf->txt doc-view-current-doc txt))
-           ((string= ext "ps")
-            ;; Doc is a PS, so convert it to PDF (which will be converted to
-            ;; TXT thereafter).
-            (doc-view-ps->pdf doc-view-current-doc
-                              (concat (doc-view-file-name-to-directory-name
-                                       doc-view-current-doc)
-                                      "doc.pdf")))
-           ((string= ext "dvi")
-            ;; Doc is a DVI.  This means that a doc.pdf already exists in its
-            ;; cache subdirectory.
-            (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
-                                        doc-view-current-doc)
-                                       "doc.pdf")
-                               txt))
-           (t (error "DocView doesn't know what to do"))))))))
+	  (message "DocView: please wait till conversion finished.")
+	(let ((ext (file-name-extension doc-view-current-doc)))
+	  (cond
+	   ((string= ext "pdf")
+	    ;; Doc is a PDF, so convert it to TXT
+	    (doc-view-pdf->txt doc-view-current-doc txt))
+	   ((string= ext "ps")
+	    ;; Doc is a PS, so convert it to PDF (which will be converted to
+	    ;; TXT thereafter).
+	    (doc-view-ps->pdf doc-view-current-doc
+			      (concat (doc-view-file-name-to-directory-name
+				       doc-view-current-doc)
+				      "doc.pdf")))
+	   ((string= ext "dvi")
+	    ;; Doc is a DVI.  This means that a doc.pdf already exists in its
+	    ;; cache subdirectory.
+	    (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
+					doc-view-current-doc)
+				       "doc.pdf")
+			       txt))
+	   (t (error "DocView doesn't know what to do"))))))))
 
 (defun doc-view-search-next-match (arg)
   "Go to the ARGth next matching page."
   (interactive "p")
   (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page))
-                                doc-view-current-search-matches))
-         (page (car (nth (1- arg) next-pages))))
+				doc-view-current-search-matches))
+	 (page (car (nth (1- arg) next-pages))))
     (if page
-        (doc-view-goto-page page)
+	(doc-view-goto-page page)
       (when (and
-             doc-view-current-search-matches
-             (y-or-n-p "No more matches after current page.  Wrap to first match? "))
-        (doc-view-goto-page (caar doc-view-current-search-matches))))))
+	     doc-view-current-search-matches
+	     (y-or-n-p "No more matches after current page.  Wrap to first match? "))
+	(doc-view-goto-page (caar doc-view-current-search-matches))))))
 
 (defun doc-view-search-previous-match (arg)
   "Go to the ARGth previous matching page."
   (interactive "p")
   (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page))
-                                doc-view-current-search-matches))
-         (page (car (nth (1- arg) (nreverse prev-pages)))))
+				doc-view-current-search-matches))
+	 (page (car (nth (1- arg) (nreverse prev-pages)))))
     (if page
-        (doc-view-goto-page page)
+	(doc-view-goto-page page)
       (when (and
-             doc-view-current-search-matches
-             (y-or-n-p "No more matches before current page.  Wrap to last match? "))
-        (doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
+	     doc-view-current-search-matches
+	     (y-or-n-p "No more matches before current page.  Wrap to last match? "))
+	(doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
 
 ;;;; User Interface Commands
 
+;;;###autoload
 (defun doc-view (no-cache &optional file)
   "Convert FILE to png and start viewing it.
 If no FILE is given, query for on.
@@ -713,34 +712,31 @@
 cached files and convert anew."
   (interactive "P")
   (if (not (and (image-type-available-p 'png)
-                (display-images-p)))
+		(display-images-p)))
       (message "DocView: your emacs or display doesn't support png images.")
     (let* ((doc (or file
-                    (expand-file-name (read-file-name "File: " nil nil t))))
-           (buffer (get-buffer-create (format "*DocView: %s*" doc)))
-           (dir (doc-view-file-name-to-directory-name doc)))
+		    (expand-file-name
+		     (let ((completion-ignored-extensions
+			    ;; Don't hide files doc-view can display
+			    (remove-if (lambda (str)
+					 (string-match "\\.\\(ps\\|pdf\\|dvi\\)$"
+						       str))
+				       completion-ignored-extensions)))
+		       (read-file-name "File: " nil nil t)))))
+	   (buffer (get-buffer-create (format "*DocView: %s*" doc)))
+	   (dir (doc-view-file-name-to-directory-name doc)))
       (switch-to-buffer buffer)
       (doc-view-buffer-message)
       (doc-view-mode)
       (setq doc-view-current-doc doc)
       (setq doc-view-current-page 1)
       (if (not (and (file-exists-p dir)
-                    (not no-cache)))
-          (progn
-            (setq doc-view-current-cache-dir nil)
-            (doc-view-convert-doc doc-view-current-doc))
-        (message "DocView: using cached files!")
-        (doc-view-display doc-view-current-doc)))))
-
-(defun doc-view-dired (no-cache)
-  "View the current dired file with doc-view.
-NO-CACHE is the same as in `doc-view'.
-
-You might want to bind this command to a dired key, e.g.
-
-    (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)"
-  (interactive "P")
-  (doc-view no-cache (dired-get-file-for-visit)))
+		    (not no-cache)))
+	  (progn
+	    (setq doc-view-current-cache-dir nil)
+	    (doc-view-convert-doc doc-view-current-doc))
+	(message "DocView: using cached files!")
+	(doc-view-display doc-view-current-doc)))))
 
 (defun doc-view-clear-cache ()
   "Delete the whole cache (`doc-view-cache-directory')."
Index: lisp/dired.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired.el,v
retrieving revision 1.369
diff -u -r1.369 dired.el
--- lisp/dired.el	25 Sep 2007 10:45:04 -0000	1.369
+++ lisp/dired.el	2 Oct 2007 16:42:16 -0000
@@ -1771,15 +1771,19 @@
 
 (defun dired-view-file ()
   "In Dired, examine a file in view mode, returning to Dired when done.
-When file is a directory, show it in this buffer if it is inserted.
-Otherwise, display it in another buffer."
+When file is a directory, show it in this buffer if it is
+inserted.  Otherwise, display it in another buffer."
   (interactive)
   (let ((file (dired-get-file-for-visit)))
     (if (file-directory-p file)
 	(or (and (cdr dired-subdir-alist)
 		 (dired-goto-subdir file))
 	    (dired file))
-      (view-file file))))
+      ;; for pdf, ps and dvi files doc-view is an appropriate viewer
+      (if (and (string-match "\\.\\(pdf\\|ps\\|dvi\\)$" file)
+	       (y-or-n-p "Open the file with `doc-view' instead of `view-file'? "))
+	  (doc-view (y-or-n-p "Use cached PNG files if possible? ") file)
+	(view-file file)))))
 
 (defun dired-find-file-other-window ()
   "In Dired, visit this file or directory in another window."
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.11854
diff -u -r1.11854 ChangeLog
--- lisp/ChangeLog	2 Oct 2007 02:05:46 -0000	1.11854
+++ lisp/ChangeLog	2 Oct 2007 16:42:22 -0000
@@ -1,3 +1,11 @@
+2007-10-02  Tassilo Horn  <tassilo@member.fsf.org>
+
+	* doc-view.el (doc-view): Don't ignore pdf and dvi files when
+	completing filename.
+
+	* dired.el (dired-view-file): Ask to use doc-view instead of
+	view-file for pdf, ps and dvi files.
+
 2007-10-02  Richard Stallman  <rms@gnu.org>
 
 	* frame.el (cursor-in-non-selected-windows): Doc fix.

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-02 16:49   ` Tassilo Horn
@ 2007-10-02 17:33     ` Andreas Schwab
  2007-10-02 18:19       ` Tassilo Horn
  2007-10-03 18:37     ` Richard Stallman
  1 sibling, 1 reply; 98+ messages in thread
From: Andreas Schwab @ 2007-10-02 17:33 UTC (permalink / raw)
  To: emacs-devel

Tassilo Horn <tassilo@member.fsf.org> writes:

>  (defun doc-view-dvi->pdf-sentinel (proc event)
>    "If DVI->PDF conversion was successful, convert the PDF to PNG
> -now."
> + now."

This is wrong.  The first line of the doc string should always be a full
sentence.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-02 17:33     ` Andreas Schwab
@ 2007-10-02 18:19       ` Tassilo Horn
  0 siblings, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-02 18:19 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 301 bytes --]

Andreas Schwab <schwab@suse.de> writes:

Hi Andreas,

>>  (defun doc-view-dvi->pdf-sentinel (proc event)
>>    "If DVI->PDF conversion was successful, convert the PDF to PNG
>> -now."
>> + now."
>
> This is wrong.  The first line of the doc string should always be a
> full sentence.

Fixed, thanks.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fixed patch --]
[-- Type: text/x-patch, Size: 26454 bytes --]

Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.2
diff -u -r1.2 doc-view.el
--- lisp/doc-view.el	10 Sep 2007 11:53:00 -0000	1.2
+++ lisp/doc-view.el	2 Oct 2007 18:17:37 -0000
@@ -5,7 +5,7 @@
 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
 ;; Keywords: files, pdf, ps, dvi
-;; Version: <2007-09-07 Fri 15:28>
+;; Version: <2007-10-02 Tue 18:21>
 
 ;; This file is part of GNU Emacs.
 
@@ -67,8 +67,6 @@
 ;; bottom-right corner of the desired slice.  To reset the slice use
 ;; `doc-view-reset-slice' (bound to `s r').
 ;;
-;; Dired users should have a look at `doc-view-dired'.
-;;
 ;; You can also search within the document.  The command `doc-view-search'
 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
 ;; matching pages and messages how many match-pages were found.  After that you
@@ -80,6 +78,10 @@
 ;; conversion.  When that finishes and you're still viewing the document
 ;; (i.e. you didn't switch to another buffer) you're queried for the regexp
 ;; then.
+;;
+;; Dired users can simply hit `v' on a document file.  If it's a PS, PDF or DVI
+;; file you're asked to open it with `doc-view' instead of `view-file'.
+;;
 
 ;;; Configuration:
 
@@ -150,7 +152,7 @@
   :group 'doc-view)
 
 (defcustom doc-view-cache-directory (concat temporary-file-directory
-                                            "doc-view")
+					    "doc-view")
   "The base directory, where the PNG images will be saved."
   :type '(directory)
   :group 'doc-view)
@@ -246,36 +248,36 @@
   (interactive "nPage: ")
   (let ((len (length doc-view-current-files)))
     (if (< page 1)
-        (setq page 1)
+	(setq page 1)
       (when (> page len)
-        (setq page len)))
+	(setq page len)))
     (setq doc-view-current-page page
-          doc-view-current-info
-          (concat
-           (propertize
-            (format "Page %d of %d."
-                    doc-view-current-page
-                    len) 'face 'bold)
-           ;; Tell user if converting isn't finished yet
-           (if doc-view-current-converter-process
-               " (still converting...)\n"
-             "\n")
-           ;; Display context infos if this page matches the last search
-           (when (and doc-view-current-search-matches
-                      (assq doc-view-current-page
-                            doc-view-current-search-matches))
-             (concat (propertize "Search matches:\n" 'face 'bold)
-                     (let ((contexts ""))
-                       (dolist (m (cdr (assq doc-view-current-page
-                                             doc-view-current-search-matches)))
-                         (setq contexts (concat contexts "  - \"" m "\"\n")))
-                       contexts)))))
+	  doc-view-current-info
+	  (concat
+	   (propertize
+	    (format "Page %d of %d."
+		    doc-view-current-page
+		    len) 'face 'bold)
+	   ;; Tell user if converting isn't finished yet
+	   (if doc-view-current-converter-process
+	       " (still converting...)\n"
+	     "\n")
+	   ;; Display context infos if this page matches the last search
+	   (when (and doc-view-current-search-matches
+		      (assq doc-view-current-page
+			    doc-view-current-search-matches))
+	     (concat (propertize "Search matches:\n" 'face 'bold)
+		     (let ((contexts ""))
+		       (dolist (m (cdr (assq doc-view-current-page
+					     doc-view-current-search-matches)))
+			 (setq contexts (concat contexts "  - \"" m "\"\n")))
+		       contexts)))))
     ;; Update the buffer
     (setq inhibit-read-only t)
     (erase-buffer)
     (let ((beg (point)))
       (doc-view-insert-image (nth (1- page) doc-view-current-files)
-                             :pointer 'arrow)
+			     :pointer 'arrow)
       (put-text-property beg (point) 'help-echo doc-view-current-info))
     (insert "\n" doc-view-current-info)
     (goto-char (point-min))
@@ -315,7 +317,7 @@
   (condition-case nil
       (scroll-down)
     (error (doc-view-previous-page)
-           (goto-char (point-max)))))
+	   (goto-char (point-max)))))
 
 (defun doc-view-kill-proc-and-buffer ()
   "Kill the current converter process and buffer."
@@ -332,19 +334,17 @@
 
 (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'."
+It's a subdirectory of `doc-view-cache-directory'."
   (if doc-view-current-cache-dir
       doc-view-current-cache-dir
     (file-name-as-directory
      (concat (file-name-as-directory doc-view-cache-directory)
-             (with-temp-buffer
-               (insert-file-contents-literally file)
-               (md5 (current-buffer)))))))
+	     (with-temp-buffer
+	       (insert-file-contents-literally file)
+	       (md5 (current-buffer)))))))
 
 (defun doc-view-dvi->pdf-sentinel (proc event)
-  "If DVI->PDF conversion was successful, convert the PDF to PNG
-now."
+  "If DVI->PDF conversion was successful, convert the PDF to PNG now."
   (if (not (string-match "finished" event))
       (message "DocView: dvi->pdf process changed status to %s." event)
     (set-buffer (process-get proc 'buffer))
@@ -352,20 +352,20 @@
     (message "DocView: finished conversion from DVI to PDF!")
     ;; Now go on converting this PDF to a set of PNG files.
     (let* ((pdf (process-get proc 'pdf-file))
-           (png (concat (doc-view-file-name-to-directory-name
-                         doc-view-current-doc)
-                        "page-%d.png")))
+	   (png (concat (doc-view-file-name-to-directory-name
+			 doc-view-current-doc)
+			"page-%d.png")))
       (doc-view-pdf/ps->png pdf png))))
 
 (defun doc-view-dvi->pdf (dvi pdf)
   "Convert DVI to PDF asynchrounously."
   (message "DocView: converting DVI to PDF now!")
   (setq doc-view-current-converter-process
-        (start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
-                       doc-view-dvipdfm-program
-                       "-o" pdf dvi))
+	(start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
+		       doc-view-dvipdfm-program
+		       "-o" pdf dvi))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-dvi->pdf-sentinel)
+			'doc-view-dvi->pdf-sentinel)
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
   (process-put doc-view-current-converter-process 'pdf-file pdf))
 
@@ -386,44 +386,44 @@
   "Convert PDF-PS to PNG asynchrounously."
   (message "DocView: converting PDF or PS to PNG now!")
   (setq doc-view-current-converter-process
-        (apply 'start-process
-               (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
-                             doc-view-ghostscript-program)
-                       doc-view-ghostscript-options
-                       (list (concat "-sOutputFile=" png))
-                       (list pdf-ps))))
+	(apply 'start-process
+	       (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
+			     doc-view-ghostscript-program)
+		       doc-view-ghostscript-options
+		       (list (concat "-sOutputFile=" png))
+		       (list pdf-ps))))
   (process-put doc-view-current-converter-process
-               'buffer (current-buffer))
+	       'buffer (current-buffer))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-pdf/ps->png-sentinel)
+			'doc-view-pdf/ps->png-sentinel)
   (when doc-view-conversion-refresh-interval
     (setq doc-view-current-timer
-          (run-at-time "1 secs" doc-view-conversion-refresh-interval
-                       'doc-view-display
-                       doc-view-current-doc))))
+	  (run-at-time "1 secs" doc-view-conversion-refresh-interval
+		       'doc-view-display
+		       doc-view-current-doc))))
 
 (defun doc-view-pdf->txt-sentinel (proc event)
   (if (not (string-match "finished" event))
       (message "DocView: converter process changed status to %s." event)
     (let ((current-buffer (current-buffer))
-          (proc-buffer    (process-get proc 'buffer)))
+	  (proc-buffer    (process-get proc 'buffer)))
       (set-buffer proc-buffer)
       (setq doc-view-current-converter-process nil)
       (message "DocView: finished conversion from PDF to TXT!")
       ;; If the user looks at the DocView buffer where the conversion was
       ;; performed, search anew.  This time it will be queried for a regexp.
       (when (eq current-buffer proc-buffer)
-        (doc-view-search)))))
+	(doc-view-search)))))
 
 (defun doc-view-pdf->txt (pdf txt)
   "Convert PDF to TXT asynchrounously."
   (message "DocView: converting PDF to TXT now!")
   (setq doc-view-current-converter-process
-        (start-process "doc-view-pdf->txt" doc-view-conversion-buffer
-                       doc-view-pdftotext-program "-raw"
-                       pdf txt))
+	(start-process "doc-view-pdf->txt" doc-view-conversion-buffer
+		       doc-view-pdftotext-program "-raw"
+		       pdf txt))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-pdf->txt-sentinel)
+			'doc-view-pdf->txt-sentinel)
   (process-put doc-view-current-converter-process 'buffer (current-buffer)))
 
 (defun doc-view-ps->pdf-sentinel (proc event)
@@ -434,19 +434,19 @@
     (message "DocView: finished conversion from PS to PDF!")
     ;; Now we can transform to plain text.
     (doc-view-pdf->txt (process-get proc 'pdf-file)
-                       (concat (doc-view-file-name-to-directory-name
-                                doc-view-current-doc)
-                               "doc.txt"))))
+		       (concat (doc-view-file-name-to-directory-name
+				doc-view-current-doc)
+			       "doc.txt"))))
 
 (defun doc-view-ps->pdf (ps pdf)
   "Convert PS to PDF asynchronously."
   (message "DocView: converting PS to PDF now!")
   (setq doc-view-current-converter-process
-        (start-process "doc-view-ps->pdf" doc-view-conversion-buffer
-                       doc-view-ps2pdf-program
-                       ps pdf))
+	(start-process "doc-view-ps->pdf" doc-view-conversion-buffer
+		       doc-view-ps2pdf-program
+		       ps pdf))
   (set-process-sentinel doc-view-current-converter-process
-                        'doc-view-ps->pdf-sentinel)
+			'doc-view-ps->pdf-sentinel)
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
   (process-put doc-view-current-converter-process 'pdf-file pdf))
 
@@ -457,18 +457,18 @@
 `doc-view-file-name-to-directory-name'."
   (clear-image-cache)
   (let* ((dir (doc-view-file-name-to-directory-name doc))
-         (png-file (concat (file-name-as-directory dir) "page-%d.png")))
+	 (png-file (concat (file-name-as-directory dir) "page-%d.png")))
     (when (file-exists-p dir)
       (dired-delete-file dir 'always))
     (make-directory dir t)
     (if (not (string= (file-name-extension doc) "dvi"))
-        ;; Convert to PNG images.
-        (doc-view-pdf/ps->png doc png-file)
+	;; Convert to PNG images.
+	(doc-view-pdf/ps->png doc png-file)
       ;; DVI files have to be converted to PDF before GhostScript can process
       ;; it.
       (doc-view-dvi->pdf doc
-                         (concat (file-name-as-directory dir)
-                                 "doc.pdf")))))
+			 (concat (file-name-as-directory dir)
+				 "doc.pdf")))))
 
 ;;;; DocView Mode
 
@@ -501,10 +501,10 @@
 do that.  To reset the slice use `doc-view-reset-slice'."
   (interactive
    (let* ((size (image-size doc-view-current-image t))
-          (a (read-number (format "Top-left X (0..%d): " (car size))))
-          (b (read-number (format "Top-left Y (0..%d): " (cdr size))))
-          (c (read-number (format "Width (0..%d): " (- (car size) a))))
-          (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
+	  (a (read-number (format "Top-left X (0..%d): " (car size))))
+	  (b (read-number (format "Top-left Y (0..%d): " (cdr size))))
+	  (c (read-number (format "Width (0..%d): " (- (car size) a))))
+	  (d (read-number (format "Height (0..%d): " (- (cdr size) b)))))
      (list a b c d)))
   (setq doc-view-current-slice (list x y width height))
   ;; Redisplay
@@ -519,18 +519,18 @@
   (let (x y w h done)
     (while (not done)
       (let ((e (read-event
-                (concat "Press mouse-1 at the top-left corner and "
-                        "drag it to the bottom-right corner!"))))
-        (when (eq (car e) 'drag-mouse-1)
-          (setq x (car (posn-object-x-y (event-start e))))
-          (setq y (cdr (posn-object-x-y (event-start e))))
-          (setq w (- (car (posn-object-x-y (event-end e))) x))
-          (setq h (- (cdr (posn-object-x-y (event-end e))) y))
-          (setq done t))))
+		(concat "Press mouse-1 at the top-left corner and "
+			"drag it to the bottom-right corner!"))))
+	(when (eq (car e) 'drag-mouse-1)
+	  (setq x (car (posn-object-x-y (event-start e))))
+	  (setq y (cdr (posn-object-x-y (event-start e))))
+	  (setq w (- (car (posn-object-x-y (event-end e))) x))
+	  (setq h (- (cdr (posn-object-x-y (event-end e))) y))
+	  (setq done t))))
     (doc-view-set-slice x y w h)))
 
 (defun doc-view-reset-slice ()
-  "Resets the current slice.
+  "Reset the current slice.
 After calling this function the whole pages will be visible
 again."
   (interactive)
@@ -542,7 +542,7 @@
 
 (defun doc-view-insert-image (file &rest args)
   "Insert the given png FILE.
-ARGs is a list of image descriptors."
+ARGS is a list of image descriptors."
   (let ((image (apply 'create-image file 'png nil args)))
     (setq doc-view-current-image image)
     (insert-image image (concat "[" file "]") nil doc-view-current-slice)))
@@ -553,7 +553,7 @@
   (if (< (length a) (length b))
       t
     (if (> (length a) (length b))
-        nil
+	nil
       (string< a b))))
 
 (defun doc-view-display (doc)
@@ -561,8 +561,8 @@
   (let ((dir (doc-view-file-name-to-directory-name doc)))
     (set-buffer (format "*DocView: %s*" doc))
     (setq doc-view-current-files
-          (sort (directory-files dir t "page-[0-9]+\\.png" t)
-                'doc-view-sort))
+	  (sort (directory-files dir t "page-[0-9]+\\.png" t)
+		'doc-view-sort))
     (when (> (length doc-view-current-files) 0)
       (doc-view-goto-page doc-view-current-page))))
 
@@ -570,8 +570,8 @@
   (setq inhibit-read-only t)
   (erase-buffer)
   (insert (propertize "Welcome to DocView!" 'face 'bold)
-          "\n"
-          "
+	  "\n"
+	  "
 If you  see this buffer  it means that  the document you  want to
 view gets  converted to PNG now  and the conversion  of the first
 page           hasn't          finished           yet          or
@@ -579,8 +579,8 @@
 
 For now these keys are useful:
 
-    `q' : Bury this buffer.  Conversion will go on in background.
-    `k' : Kill the conversion process and this buffer.\n")
+`q' : Bury this buffer.  Conversion will go on in background.
+`k' : Kill the conversion process and this buffer.\n")
   (setq inhibit-read-only nil))
 
 (defun doc-view-show-tooltip ()
@@ -591,39 +591,35 @@
 
 (defun doc-view-search-internal (regexp file)
   "Return a list of FILE's pages that contain text matching REGEXP.
-The value is an alist of the form
-
-    (PAGE CONTEXTS)
-
-where PAGE is the pagenumber and CONTEXTS are the lines
-containing the match."
+The value is an alist of the form (PAGE CONTEXTS) where PAGE is
+the pagenumber and CONTEXTS are all lines of text containing a match."
   (with-temp-buffer
     (insert-file-contents file)
     (let ((page 1)
-          (lastpage 1)
-          matches)
+	  (lastpage 1)
+	  matches)
       (while (re-search-forward (concat "\\(?:\\([\f]\\)\\|\\("
-                                        regexp "\\)\\)") nil t)
-        (when (match-string 1) (incf page))
-        (when (match-string 2)
-          (if (/= page lastpage)
-              (setq matches (push (cons page
-                                        (list (buffer-substring
-                                               (line-beginning-position)
-                                               (line-end-position))))
-                                  matches))
-            (setq matches (cons
-                           (append
-                            (or
-                             ;; This page already is a match.
-                             (car matches)
-                             ;; This is the first match on page.
-                             (list page))
-                            (list (buffer-substring
-                                   (line-beginning-position)
-                                   (line-end-position))))
-                           (cdr matches))))
-          (setq lastpage page)))
+					regexp "\\)\\)") nil t)
+	(when (match-string 1) (incf page))
+	(when (match-string 2)
+	  (if (/= page lastpage)
+	      (setq matches (push (cons page
+					(list (buffer-substring
+					       (line-beginning-position)
+					       (line-end-position))))
+				  matches))
+	    (setq matches (cons
+			   (append
+			    (or
+			     ;; This page already is a match.
+			     (car matches)
+			     ;; This is the first match on page.
+			     (list page))
+			    (list (buffer-substring
+				   (line-beginning-position)
+				   (line-end-position))))
+			   (cdr matches))))
+	  (setq lastpage page)))
       (nreverse matches))))
 
 (defun doc-view-search-no-of-matches (list)
@@ -642,69 +638,70 @@
   ;; New search, so forget the old results.
   (setq doc-view-current-search-matches nil)
   (let ((txt (concat (doc-view-file-name-to-directory-name
-                      doc-view-current-doc)
-                     "doc.txt")))
+		      doc-view-current-doc)
+		     "doc.txt")))
     (if (file-readable-p txt)
-        (progn
-          (setq doc-view-current-search-matches
-                (doc-view-search-internal
-                 (read-from-minibuffer "Regexp: ")
-                 txt))
-          (message "DocView: search yielded %d matches."
-                   (doc-view-search-no-of-matches
-                    doc-view-current-search-matches)))
+	(progn
+	  (setq doc-view-current-search-matches
+		(doc-view-search-internal
+		 (read-from-minibuffer "Regexp: ")
+		 txt))
+	  (message "DocView: search yielded %d matches."
+		   (doc-view-search-no-of-matches
+		    doc-view-current-search-matches)))
       ;; We must convert to TXT first!
       (if doc-view-current-converter-process
-          (message "DocView: please wait till conversion finished.")
-        (let ((ext (file-name-extension doc-view-current-doc)))
-          (cond
-           ((string= ext "pdf")
-            ;; Doc is a PDF, so convert it to TXT
-            (doc-view-pdf->txt doc-view-current-doc txt))
-           ((string= ext "ps")
-            ;; Doc is a PS, so convert it to PDF (which will be converted to
-            ;; TXT thereafter).
-            (doc-view-ps->pdf doc-view-current-doc
-                              (concat (doc-view-file-name-to-directory-name
-                                       doc-view-current-doc)
-                                      "doc.pdf")))
-           ((string= ext "dvi")
-            ;; Doc is a DVI.  This means that a doc.pdf already exists in its
-            ;; cache subdirectory.
-            (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
-                                        doc-view-current-doc)
-                                       "doc.pdf")
-                               txt))
-           (t (error "DocView doesn't know what to do"))))))))
+	  (message "DocView: please wait till conversion finished.")
+	(let ((ext (file-name-extension doc-view-current-doc)))
+	  (cond
+	   ((string= ext "pdf")
+	    ;; Doc is a PDF, so convert it to TXT
+	    (doc-view-pdf->txt doc-view-current-doc txt))
+	   ((string= ext "ps")
+	    ;; Doc is a PS, so convert it to PDF (which will be converted to
+	    ;; TXT thereafter).
+	    (doc-view-ps->pdf doc-view-current-doc
+			      (concat (doc-view-file-name-to-directory-name
+				       doc-view-current-doc)
+				      "doc.pdf")))
+	   ((string= ext "dvi")
+	    ;; Doc is a DVI.  This means that a doc.pdf already exists in its
+	    ;; cache subdirectory.
+	    (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
+					doc-view-current-doc)
+				       "doc.pdf")
+			       txt))
+	   (t (error "DocView doesn't know what to do"))))))))
 
 (defun doc-view-search-next-match (arg)
   "Go to the ARGth next matching page."
   (interactive "p")
   (let* ((next-pages (remove-if (lambda (i) (<= (car i) doc-view-current-page))
-                                doc-view-current-search-matches))
-         (page (car (nth (1- arg) next-pages))))
+				doc-view-current-search-matches))
+	 (page (car (nth (1- arg) next-pages))))
     (if page
-        (doc-view-goto-page page)
+	(doc-view-goto-page page)
       (when (and
-             doc-view-current-search-matches
-             (y-or-n-p "No more matches after current page.  Wrap to first match? "))
-        (doc-view-goto-page (caar doc-view-current-search-matches))))))
+	     doc-view-current-search-matches
+	     (y-or-n-p "No more matches after current page.  Wrap to first match? "))
+	(doc-view-goto-page (caar doc-view-current-search-matches))))))
 
 (defun doc-view-search-previous-match (arg)
   "Go to the ARGth previous matching page."
   (interactive "p")
   (let* ((prev-pages (remove-if (lambda (i) (>= (car i) doc-view-current-page))
-                                doc-view-current-search-matches))
-         (page (car (nth (1- arg) (nreverse prev-pages)))))
+				doc-view-current-search-matches))
+	 (page (car (nth (1- arg) (nreverse prev-pages)))))
     (if page
-        (doc-view-goto-page page)
+	(doc-view-goto-page page)
       (when (and
-             doc-view-current-search-matches
-             (y-or-n-p "No more matches before current page.  Wrap to last match? "))
-        (doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
+	     doc-view-current-search-matches
+	     (y-or-n-p "No more matches before current page.  Wrap to last match? "))
+	(doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
 
 ;;;; User Interface Commands
 
+;;;###autoload
 (defun doc-view (no-cache &optional file)
   "Convert FILE to png and start viewing it.
 If no FILE is given, query for on.
@@ -713,34 +710,31 @@
 cached files and convert anew."
   (interactive "P")
   (if (not (and (image-type-available-p 'png)
-                (display-images-p)))
+		(display-images-p)))
       (message "DocView: your emacs or display doesn't support png images.")
     (let* ((doc (or file
-                    (expand-file-name (read-file-name "File: " nil nil t))))
-           (buffer (get-buffer-create (format "*DocView: %s*" doc)))
-           (dir (doc-view-file-name-to-directory-name doc)))
+		    (expand-file-name
+		     (let ((completion-ignored-extensions
+			    ;; Don't hide files doc-view can display
+			    (remove-if (lambda (str)
+					 (string-match "\\.\\(ps\\|pdf\\|dvi\\)$"
+						       str))
+				       completion-ignored-extensions)))
+		       (read-file-name "File: " nil nil t)))))
+	   (buffer (get-buffer-create (format "*DocView: %s*" doc)))
+	   (dir (doc-view-file-name-to-directory-name doc)))
       (switch-to-buffer buffer)
       (doc-view-buffer-message)
       (doc-view-mode)
       (setq doc-view-current-doc doc)
       (setq doc-view-current-page 1)
       (if (not (and (file-exists-p dir)
-                    (not no-cache)))
-          (progn
-            (setq doc-view-current-cache-dir nil)
-            (doc-view-convert-doc doc-view-current-doc))
-        (message "DocView: using cached files!")
-        (doc-view-display doc-view-current-doc)))))
-
-(defun doc-view-dired (no-cache)
-  "View the current dired file with doc-view.
-NO-CACHE is the same as in `doc-view'.
-
-You might want to bind this command to a dired key, e.g.
-
-    (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)"
-  (interactive "P")
-  (doc-view no-cache (dired-get-file-for-visit)))
+		    (not no-cache)))
+	  (progn
+	    (setq doc-view-current-cache-dir nil)
+	    (doc-view-convert-doc doc-view-current-doc))
+	(message "DocView: using cached files!")
+	(doc-view-display doc-view-current-doc)))))
 
 (defun doc-view-clear-cache ()
   "Delete the whole cache (`doc-view-cache-directory')."
Index: lisp/dired.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired.el,v
retrieving revision 1.369
diff -u -r1.369 dired.el
--- lisp/dired.el	25 Sep 2007 10:45:04 -0000	1.369
+++ lisp/dired.el	2 Oct 2007 18:17:40 -0000
@@ -1771,15 +1771,19 @@
 
 (defun dired-view-file ()
   "In Dired, examine a file in view mode, returning to Dired when done.
-When file is a directory, show it in this buffer if it is inserted.
-Otherwise, display it in another buffer."
+When file is a directory, show it in this buffer if it is
+inserted.  Otherwise, display it in another buffer."
   (interactive)
   (let ((file (dired-get-file-for-visit)))
     (if (file-directory-p file)
 	(or (and (cdr dired-subdir-alist)
 		 (dired-goto-subdir file))
 	    (dired file))
-      (view-file file))))
+      ;; for pdf, ps and dvi files doc-view is an appropriate viewer
+      (if (and (string-match "\\.\\(pdf\\|ps\\|dvi\\)$" file)
+	       (y-or-n-p "Open the file with `doc-view' instead of `view-file'? "))
+	  (doc-view (y-or-n-p "Use cached PNG files if possible? ") file)
+	(view-file file)))))
 
 (defun dired-find-file-other-window ()
   "In Dired, visit this file or directory in another window."
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.11854
diff -u -r1.11854 ChangeLog
--- lisp/ChangeLog	2 Oct 2007 02:05:46 -0000	1.11854
+++ lisp/ChangeLog	2 Oct 2007 18:17:46 -0000
@@ -1,3 +1,11 @@
+2007-10-02  Tassilo Horn  <tassilo@member.fsf.org>
+
+	* doc-view.el (doc-view): Don't ignore pdf and dvi files when
+	completing filename.
+
+	* dired.el (dired-view-file): Ask to use doc-view instead of
+	view-file for pdf, ps and dvi files.
+
 2007-10-02  Richard Stallman  <rms@gnu.org>
 
 	* frame.el (cursor-in-non-selected-windows): Doc fix.

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


Bye,
Tassilo

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-02 16:49   ` Tassilo Horn
  2007-10-02 17:33     ` Andreas Schwab
@ 2007-10-03 18:37     ` Richard Stallman
  2007-10-03 23:29       ` Michaël Cadilhac
  2007-10-04  7:53       ` Tassilo Horn
  1 sibling, 2 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-03 18:37 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

    I changed `dired-view-file' so that it asks the user to use doc-view for
    pdf, ps and dvi files instead of `view-file'.

The change in Dired is similar to a change I installed in 2004, which
was removed in 2005.  The code worked but there was some sort of
drawback to the idea.  I don't remember what it was, but before we
install a similar feature now, someone should check on this list for
discussion of `dired-view-file' in Dec 2004 and make sure that the
arguments there don't apply against this change.

As for the changes in doc-view.el itself, would someone please install
them?

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-03 18:37     ` Richard Stallman
@ 2007-10-03 23:29       ` Michaël Cadilhac
  2007-10-04  7:53       ` Tassilo Horn
  1 sibling, 0 replies; 98+ messages in thread
From: Michaël Cadilhac @ 2007-10-03 23:29 UTC (permalink / raw)
  To: rms; +Cc: Tassilo Horn, emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 1147 bytes --]

Richard Stallman <rms@gnu.org> writes:

>     I changed `dired-view-file' so that it asks the user to use doc-view for
>     pdf, ps and dvi files instead of `view-file'.
>
> The change in Dired is similar to a change I installed in 2004, which
> was removed in 2005.  The code worked but there was some sort of
> drawback to the idea.  I don't remember what it was, but before we
> install a similar feature now, someone should check on this list for
> discussion of `dired-view-file' in Dec 2004 and make sure that the
> arguments there don't apply against this change.
>
> As for the changes in doc-view.el itself, would someone please install
> them?

Installed.  But Tassilo, please not that the « Version » field of your
file should be updated again when dired-related things will be
integrated.

-- 
 |   Michaël `Micha' Cadilhac       |  Fenouil                               |
 |   http://michael.cadilhac.name   |                                        |
 |   JID/MSN:                       |    -- Poème de François Le Lionnais    |
 `----  michael.cadilhac@gmail.com  |                                   -  --'

[-- Attachment #1.2: Type: application/pgp-signature, Size: 188 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-03 18:37     ` Richard Stallman
  2007-10-03 23:29       ` Michaël Cadilhac
@ 2007-10-04  7:53       ` Tassilo Horn
  2007-10-05 16:13         ` Richard Stallman
  1 sibling, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-10-04  7:53 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

Hi Richard,

>     I changed `dired-view-file' so that it asks the user to use
>     doc-view for pdf, ps and dvi files instead of `view-file'.
>
> The change in Dired is similar to a change I installed in 2004, which
> was removed in 2005.  The code worked but there was some sort of
> drawback to the idea.  I don't remember what it was, but before we
> install a similar feature now, someone should check on this list for
> discussion of `dired-view-file' in Dec 2004 and make sure that the
> arguments there don't apply against this change.

I searched through the archives of this list and I think the change you
mean was the introduction of the variable `dired-view-command-alist'.
The list had the form (REGEXP . SHELL-COMMAND) where SHELL-COMMAND was
an external viewer for files matching REGEXP.  So I think that the
problem with that was that calling external programs (which might not be
available) is generally not a good idea.  Since `doc-view' is an emacs
command and the user is asked if he wants to view the document with
`doc-view' instead of `view-file', I think my change is safe.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-04  7:53       ` Tassilo Horn
@ 2007-10-05 16:13         ` Richard Stallman
  2007-10-05 16:43           ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-05 16:13 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

      So I think that the
    problem with that was that calling external programs (which might not be
    available) is generally not a good idea.

Is it just a matter that they may not be available?  Or is it also risky?

					      Since `doc-view' is an emacs
    command and the user is asked if he wants to view the document with
    `doc-view' instead of `view-file', I think my change is safe.

If I understand correctly, `doc-view' also works by calling an
external program.  Why don't the same arguments apply?

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-05 16:13         ` Richard Stallman
@ 2007-10-05 16:43           ` Tassilo Horn
  2007-10-06 14:16             ` Tassilo Horn
                               ` (2 more replies)
  0 siblings, 3 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-05 16:43 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     So I think that the problem with that was that calling external
>     programs (which might not be available) is generally not a good
>     idea.
>
> Is it just a matter that they may not be available?

No, probably not.  It was only a wild guess from my side why that
feature was taken out.  I could only find the messages which discussed
its inclusion, but not the ones that discussed why it was taken out
again.  I'll try to find them tomorrow if time allows it.

> Or is it also risky?

Not really, I think.

>     Since `doc-view' is an emacs command and the user is asked if he
>     wants to view the document with `doc-view' instead of `view-file',
>     I think my change is safe.
>
> If I understand correctly, `doc-view' also works by calling an
> external program.  Why don't the same arguments apply?

Indeed.  The only difference is that doc-view uses only external
commands for the conversion whereas the dired change we're talking about
called viewers and thus gave the focus to other applications.

But what if we use my change in `dired-view-file' and add an additional
test for (featurep 'doc-view)?  Then users would only be asked if
doc-view should be used for pdf/ps/dvi files if they required it
explicitly.  If they do so, we can be sure that they have the needed
external programs installed.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-05 16:43           ` Tassilo Horn
@ 2007-10-06 14:16             ` Tassilo Horn
  2007-10-06 23:54               ` Juri Linkov
  2007-10-07 13:10               ` Please install: Some improvements to doc-view.el Richard Stallman
  2007-10-06 21:47             ` Stefan Monnier
  2007-10-07  0:30             ` Richard Stallman
  2 siblings, 2 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-06 14:16 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1284 bytes --]

Tassilo Horn <tassilo@member.fsf.org> writes:

> Richard Stallman <rms@gnu.org> writes:
>
>>     So I think that the problem with that was that calling external
>>     programs (which might not be available) is generally not a good
>>     idea.
>>
>> Is it just a matter that they may not be available?
>
> No, probably not.  It was only a wild guess from my side why that
> feature was taken out.  I could only find the messages which discussed
> its inclusion, but not the ones that discussed why it was taken out
> again.  I'll try to find them tomorrow if time allows it.

Ok, this is the thread:

  http://thread.gmane.org/gmane.emacs.devel/31757/focus=31861

It was taken out because the mechanism for invoking external viewers
should be replaced by the one that Gnus already uses.  Unfortunately
that didn't happen and no real discussion followed.

> But what if we use my change in `dired-view-file' and add an
> additional test for (featurep 'doc-view)?  Then users would only be
> asked if doc-view should be used for pdf/ps/dvi files if they required
> it explicitly.  If they do so, we can be sure that they have the
> needed external programs installed.

So I'd say the solution I proposed in the paragraph above is ok.  If you
agree, here's a patch that implements it.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: doc-view.patch --]
[-- Type: text/x-patch, Size: 4178 bytes --]

Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.4
diff -u -r1.4 doc-view.el
--- lisp/doc-view.el	3 Oct 2007 23:39:58 -0000	1.4
+++ lisp/doc-view.el	6 Oct 2007 14:14:39 -0000
@@ -5,7 +5,7 @@
 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
 ;; Keywords: files, pdf, ps, dvi
-;; Version: <2007-10-02 Tue 18:21>
+;; Version: <2007-10-06 Sat 16:14>
 
 ;; This file is part of GNU Emacs.
 
@@ -67,8 +67,6 @@
 ;; bottom-right corner of the desired slice.  To reset the slice use
 ;; `doc-view-reset-slice' (bound to `s r').
 ;;
-;; Dired users should have a look at `doc-view-dired'.
-;;
 ;; You can also search within the document.  The command `doc-view-search'
 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
 ;; matching pages and messages how many match-pages were found.  After that you
@@ -80,6 +78,10 @@
 ;; conversion.  When that finishes and you're still viewing the document
 ;; (i.e. you didn't switch to another buffer) you're queried for the regexp
 ;; then.
+;;
+;; Dired users can simply hit `v' on a document file.  If it's a PS, PDF or DVI
+;; file you're asked to open it with `doc-view' instead of `view-file'.
+;;
 
 ;;; Configuration:
 
@@ -332,8 +334,7 @@
 
 (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'."
+It's a subdirectory of `doc-view-cache-directory'."
   (if doc-view-current-cache-dir
       doc-view-current-cache-dir
     (file-name-as-directory
@@ -735,16 +736,6 @@
 	(message "DocView: using cached files!")
 	(doc-view-display doc-view-current-doc)))))
 
-(defun doc-view-dired (no-cache)
-  "View the current dired file with doc-view.
-NO-CACHE is the same as in `doc-view'.
-
-You might want to bind this command to a dired key, e.g.
-
-    (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)"
-  (interactive "P")
-  (doc-view no-cache (dired-get-file-for-visit)))
-
 (defun doc-view-clear-cache ()
   "Delete the whole cache (`doc-view-cache-directory')."
   (interactive)
Index: lisp/dired.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired.el,v
retrieving revision 1.369
diff -u -r1.369 dired.el
--- lisp/dired.el	25 Sep 2007 10:45:04 -0000	1.369
+++ lisp/dired.el	6 Oct 2007 14:14:42 -0000
@@ -1771,15 +1771,20 @@
 
 (defun dired-view-file ()
   "In Dired, examine a file in view mode, returning to Dired when done.
-When file is a directory, show it in this buffer if it is inserted.
-Otherwise, display it in another buffer."
+When file is a directory, show it in this buffer if it is
+inserted.  Otherwise, display it in another buffer."
   (interactive)
   (let ((file (dired-get-file-for-visit)))
     (if (file-directory-p file)
 	(or (and (cdr dired-subdir-alist)
 		 (dired-goto-subdir file))
 	    (dired file))
-      (view-file file))))
+      ;; for pdf, ps and dvi files doc-view is an appropriate viewer
+      (if (and (featurep 'doc-view)
+	       (string-match "\\.\\(pdf\\|ps\\|dvi\\)$" file)
+	       (y-or-n-p "Open the file with `doc-view' instead of `view-file'? "))
+	  (doc-view (y-or-n-p "Use cached PNG files if possible? ") file)
+	(view-file file)))))
 
 (defun dired-find-file-other-window ()
   "In Dired, visit this file or directory in another window."
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.11865
diff -u -r1.11865 ChangeLog
--- lisp/ChangeLog	6 Oct 2007 12:00:40 -0000	1.11865
+++ lisp/ChangeLog	6 Oct 2007 14:14:48 -0000
@@ -1,3 +1,10 @@
+2007-10-06  Tassilo Horn  <tassilo@member.fsf.org>
+
+	* dired.el (dired-view-file): Ask to use doc-view if file is a
+	pdf/dvi/ps file and doc-view was required by the user.
+
+	* doc-view.el (doc-view-dired): Delete function.
+
 2007-10-06  Michael Albinus  <michael.albinus@gmx.de>
 
 	* net/tramp.el (top): Move loading of tramp-util.el and

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


Bye,
Tassilo

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-05 16:43           ` Tassilo Horn
  2007-10-06 14:16             ` Tassilo Horn
@ 2007-10-06 21:47             ` Stefan Monnier
  2007-10-07 13:10               ` Richard Stallman
  2007-10-07  0:30             ` Richard Stallman
  2 siblings, 1 reply; 98+ messages in thread
From: Stefan Monnier @ 2007-10-06 21:47 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

> But what if we use my change in `dired-view-file' and add an additional
> test for (featurep 'doc-view)?  Then users would only be asked if
> doc-view should be used for pdf/ps/dvi files if they required it
> explicitly.  If they do so, we can be sure that they have the needed
> external programs installed.

But this would mean that merely loading doc-view.el changes the behavior of
dired-view-file.  Since loading a package should not change the behavior of
Emacs (because the load may take place for all kinds of reasons), I think
it's not a good solution,


        Stefan

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-06 14:16             ` Tassilo Horn
@ 2007-10-06 23:54               ` Juri Linkov
  2007-10-08 15:26                 ` Sascha Wilde
  2007-10-07 13:10               ` Please install: Some improvements to doc-view.el Richard Stallman
  1 sibling, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-10-06 23:54 UTC (permalink / raw)
  To: emacs-devel

> Ok, this is the thread:
>
>   http://thread.gmane.org/gmane.emacs.devel/31757/focus=31861
>
> It was taken out because the mechanism for invoking external viewers
> should be replaced by the one that Gnus already uses.  Unfortunately
> that didn't happen and no real discussion followed.

A plan was to use mailcap-related functions from Gnus with the dired-x
command-guessing user interface.  But it is unclear how to use code from
Gnus in dired.  Perhaps, by loading the `mailcap' library since it is in the
Emacs source tree.  Is adding (require 'mailcap) to dired.el a good thing?

>> But what if we use my change in `dired-view-file' and add an
>> additional test for (featurep 'doc-view)?  Then users would only be
>> asked if doc-view should be used for pdf/ps/dvi files if they required
>> it explicitly.  If they do so, we can be sure that they have the
>> needed external programs installed.
>
> So I'd say the solution I proposed in the paragraph above is ok.  If you
> agree, here's a patch that implements it.

I think asking a question before visiting a file is very bad thing to do.

Since doc-view-mode doesn't call an external viewer, but instead renders
the file as an image inside the Emacs buffer, I think a good solution
would be to use the same user interface as is implemented by image-mode:
by default, visiting a pdf/dvi file could display a rendered image
(which is more preferable for most users than editing them, I guess).
But if the user still wants to edit the source file or to view it as text,
then the user could type `C-c C-c'.  You could also implement
`doc-view-minor-mode' because the main mode for PS files is `ps-mode',
so this requires a minor view mode (like `image-minor-mode' for text-based
image formats).

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-05 16:43           ` Tassilo Horn
  2007-10-06 14:16             ` Tassilo Horn
  2007-10-06 21:47             ` Stefan Monnier
@ 2007-10-07  0:30             ` Richard Stallman
  2 siblings, 0 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-07  0:30 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

    Indeed.  The only difference is that doc-view uses only external
    commands for the conversion whereas the dired change we're talking about
    called viewers and thus gave the focus to other applications.

Maybe that makes a big difference.  Please check the reasons why I
took the other feature out, so we can see whether they do apply here.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-06 21:47             ` Stefan Monnier
@ 2007-10-07 13:10               ` Richard Stallman
  0 siblings, 0 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-07 13:10 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

    > But what if we use my change in `dired-view-file' and add an additional
    > test for (featurep 'doc-view)?  Then users would only be asked if
    > doc-view should be used for pdf/ps/dvi files if they required it
    > explicitly.  If they do so, we can be sure that they have the needed
    > external programs installed.

    But this would mean that merely loading doc-view.el changes the behavior of
    dired-view-file.  Since loading a package should not change the behavior of
    Emacs (because the load may take place for all kinds of reasons), I think
    it's not a good solution,

You are right, but this is easily fixed.  The right way to control
whether to use doc-view is with a variable (if we don't enable it
unconditionally).

The real question is whether to use doc-view or the Gnus mechanism.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-06 14:16             ` Tassilo Horn
  2007-10-06 23:54               ` Juri Linkov
@ 2007-10-07 13:10               ` Richard Stallman
  2007-10-08 19:42                 ` Juri Linkov
  1 sibling, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-07 13:10 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

    It was taken out because the mechanism for invoking external viewers
    should be replaced by the one that Gnus already uses.  Unfortunately
    that didn't happen and no real discussion followed.

It would be a good thing to have just one such mechanism: either
the one Gnus uses, or doc-view.  If we choose doc-view, then we
should make Gnus use it.

What are the arguments in favor of doc-view?

Does someone want to argue in favor of the mechanism that Gnus uses?

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-06 23:54               ` Juri Linkov
@ 2007-10-08 15:26                 ` Sascha Wilde
  2007-10-08 15:51                   ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Sascha Wilde @ 2007-10-08 15:26 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

Juri Linkov <juri@jurta.org> wrote:

> Since doc-view-mode doesn't call an external viewer, but instead renders
> the file as an image inside the Emacs buffer, I think a good solution
> would be to use the same user interface as is implemented by image-mode:
> by default, visiting a pdf/dvi file could display a rendered image
> (which is more preferable for most users than editing them, I guess).
> But if the user still wants to edit the source file or to view it as text,
> then the user could type `C-c C-c'.

+1

sascha
-- 
Sascha Wilde

I've always figured UNIX is a utility to be run under emacs.
	-- Charles R. Martin

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-08 15:26                 ` Sascha Wilde
@ 2007-10-08 15:51                   ` Tassilo Horn
  2007-10-08 19:34                     ` Juri Linkov
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-10-08 15:51 UTC (permalink / raw)
  To: emacs-devel

Sascha Wilde <wilde@sha-bang.de> writes:

Hi Sascha,

>> Since doc-view-mode doesn't call an external viewer, but instead
>> renders the file as an image inside the Emacs buffer, I think a good
>> solution would be to use the same user interface as is implemented by
>> image-mode: by default, visiting a pdf/dvi file could display a
>> rendered image (which is more preferable for most users than editing
>> them, I guess).  But if the user still wants to edit the source file
>> or to view it as text, then the user could type `C-c C-c'.
>
> +1

Would be ok for me, but I'll wait for a decision for the doc-view
vs. Gnus mechanism before implementing it.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-08 15:51                   ` Tassilo Horn
@ 2007-10-08 19:34                     ` Juri Linkov
  2007-10-09  9:02                       ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-10-08 19:34 UTC (permalink / raw)
  To: emacs-devel

>>> Since doc-view-mode doesn't call an external viewer, but instead
>>> renders the file as an image inside the Emacs buffer, I think a good
>>> solution would be to use the same user interface as is implemented by
>>> image-mode: by default, visiting a pdf/dvi file could display a
>>> rendered image (which is more preferable for most users than editing
>>> them, I guess).  But if the user still wants to edit the source file
>>> or to view it as text, then the user could type `C-c C-c'.
>>
>> +1
>
> Would be ok for me, but I'll wait for a decision for the doc-view
> vs. Gnus mechanism before implementing it.

I think Gnus mechanism is irrelevant to doc-view.  Gnus uses mailcap
mechanisms to find the appropriate mailcap entry and run an external
program in a separate process.  doc-view displays the rendered image
in the Emacs buffer.  So it could work exactly as image-mode for
pdf/ps/dvi files.

As for the mailcap feature, I recall there was a proposal to put
programs from the mailcap entry to the default value of the ! command
(`dired-do-shell-command').

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-07 13:10               ` Please install: Some improvements to doc-view.el Richard Stallman
@ 2007-10-08 19:42                 ` Juri Linkov
  2007-10-09 20:03                   ` Richard Stallman
  0 siblings, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-10-08 19:42 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

> It would be a good thing to have just one such mechanism: either
> the one Gnus uses, or doc-view.  If we choose doc-view, then we
> should make Gnus use it.
>
> What are the arguments in favor of doc-view?
>
> Does someone want to argue in favor of the mechanism that Gnus uses?

DocView and the Gnus mailcap mechanism are unrelated features.
Mailcap finds an appropriate external program to start in a separate
process.  DocView converts PDF/PS/DVI files to PNG files and displays
them in the Emacs buffer.  Perhaps this confusion was caused by the
name of the package doc-view?  What would be a better name?

BTW, the same package could be used to display other multi-image formats
in the same Emacs buffer, like e.g. a sequence of images from animated GIF.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-08 19:34                     ` Juri Linkov
@ 2007-10-09  9:02                       ` Tassilo Horn
  2007-10-09 21:55                         ` Juri Linkov
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-10-09  9:02 UTC (permalink / raw)
  To: emacs-devel; +Cc: Richard Stallman

Juri Linkov <juri@jurta.org> writes:

>>>> Since doc-view-mode doesn't call an external viewer, but instead
>>>> renders the file as an image inside the Emacs buffer, I think a
>>>> good solution would be to use the same user interface as is
>>>> implemented by image-mode: by default, visiting a pdf/dvi file
>>>> could display a rendered image (which is more preferable for most
>>>> users than editing them, I guess).  But if the user still wants to
>>>> edit the source file or to view it as text, then the user could
>>>> type `C-c C-c'.
>>>
>>> +1
>>
>> Would be ok for me, but I'll wait for a decision for the doc-view
>> vs. Gnus mechanism before implementing it.
>
> I think Gnus mechanism is irrelevant to doc-view.  Gnus uses mailcap
> mechanisms to find the appropriate mailcap entry and run an external
> program in a separate process.  doc-view displays the rendered image
> in the Emacs buffer.  So it could work exactly as image-mode for
> pdf/ps/dvi files.

Ok, that sounds reasonable to me and I'm willing to implement it.  If I
understand correctly, I have to add entries to `auto-mode-alist' and
change `doc-view-mode' so that it calls `doc-view' for the current
`buffer-file-name' plus a binding `C-c C-c' to toggle between the
rendered image presentation and the text representation.  Is that
correct?

One problem I see: Should `doc-view' called with NO-CACHE set to t?
Personally I prefer calling (doc-view nil file) and adding a binding to
the mode to reconvert the document.

> As for the mailcap feature, I recall there was a proposal to put
> programs from the mailcap entry to the default value of the ! command
> (`dired-do-shell-command').

I'd second that.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-08 19:42                 ` Juri Linkov
@ 2007-10-09 20:03                   ` Richard Stallman
  2007-10-09 21:30                     ` Tassilo Horn
  2007-10-09 21:54                     ` Please install: Some improvements to doc-view.el Juri Linkov
  0 siblings, 2 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-09 20:03 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

    DocView and the Gnus mailcap mechanism are unrelated features.

They are related because they do the same job: display non-textual
formats for Emacs.  They work in different ways, but each can still
substitute for the other.  If you have a PDF or PS or DVI file, you
can display it either with doc-view or with the Gnus mailcap
mechanism.  

So do we really want both methods?  If so, when should each
method be used?  Or how should the user choose?

The current code chooses the mailcap mechanism when in Gnus,
and now we have a proposal for Dired to use the doc-view mechanism.
But is there any reason to think those are the right choices?
I have tried to start a discussion of this question,
but nobody else has addressed it.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-09 20:03                   ` Richard Stallman
@ 2007-10-09 21:30                     ` Tassilo Horn
  2007-10-15 18:31                       ` Richard Stallman
  2007-10-09 21:54                     ` Please install: Some improvements to doc-view.el Juri Linkov
  1 sibling, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-10-09 21:30 UTC (permalink / raw)
  To: rms; +Cc: Juri Linkov, emacs-devel

Richard Stallman <rms@gnu.org> writes:

Hi Richard,

>     DocView and the Gnus mailcap mechanism are unrelated features.
>
> They are related because they do the same job: display non-textual
> formats for Emacs.  They work in different ways, but each can still
> substitute for the other.  If you have a PDF or PS or DVI file, you
> can display it either with doc-view or with the Gnus mailcap
> mechanism.
>
> So do we really want both methods?  If so, when should each method be
> used?

Personally I think a solution which doesn't give the focus to another
application is preferable and thus should be the default.  Gnus cannot
use doc-view since that depends on GNU Emacs whereas Gnus wants to run
on all Emacsen.

> Or how should the user choose?

Juri proposed a very good solution in <87ve9jhifi.fsf@jurta.org> and
<87ir5h4cz1.fsf@jurta.org>.

In summary:

1. He proposed to make doc-view the standard viewer for pdf/dvi/ps files
   and add a binding `C-c C-c' which would toggle between the rendered
   image representation and the text representation just like image-mode
   does.  This way `v' in dired would use doc-view by default and `C-c
   C-c' in doc-view-mode would switch to the text representation you get
   when you hit `v' on a doc nowadays.

2. The Gnus mailcap mechanism could be used for the default command for
   `dired-do-shell-command' (bound to `!' in dired).

I think this is a very good solution and I'm willing to implement point
1 if we agree on it.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-09 20:03                   ` Richard Stallman
  2007-10-09 21:30                     ` Tassilo Horn
@ 2007-10-09 21:54                     ` Juri Linkov
  2007-10-09 22:17                       ` mailcap viewers in dired; gnus-dired.el, mailcap.el (was: Please install: Some improvements to doc-view.el) Reiner Steib
  2007-10-15  1:37                       ` Please install: Some improvements to doc-view.el Richard Stallman
  1 sibling, 2 replies; 98+ messages in thread
From: Juri Linkov @ 2007-10-09 21:54 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

>     DocView and the Gnus mailcap mechanism are unrelated features.
>
> They are related because they do the same job: display non-textual
> formats for Emacs.  They work in different ways, but each can still
> substitute for the other.  If you have a PDF or PS or DVI file, you
> can display it either with doc-view or with the Gnus mailcap
> mechanism.
>
> So do we really want both methods?  If so, when should each
> method be used?  Or how should the user choose?

I think both methods are very useful.

The Gnus mailcap mechanism provides several alternatives of external
programs to run.  There are many different file types associated with
programs in the mailcap file, not only documents supported by doc-view.
But OTOH, doc-view provides more convenient way of viewing supported
file types (PDF/PS/DVI) inside Emacs, not in external programs.

> The current code chooses the mailcap mechanism when in Gnus,
> and now we have a proposal for Dired to use the doc-view mechanism.

There is already a file lisp/gnus/gnus-dired.el that binds `C-c C-m C-l'
in Dired to the command that runs the program found in the mailcap file.

But I think a better way would be to allow the user to select the
preferred program, inspect the command line and be able to edit the
command line before running a command.  This can be achieved by putting
program names found by the Gnus mailcap mechanism to the default value
in the minibuffer activated after typing !  in Dired.

A for doc-view, since it displays rendered images inside Emacs buffers,
there is no need to activate it only from Dired.  Visiting a PDF/PS/DVI
file in any way including `C-x C-f' could put it in doc-view mode.
And if the user want to see its source text, then the user can type
`C-c C-c' just like in image-mode.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-09  9:02                       ` Tassilo Horn
@ 2007-10-09 21:55                         ` Juri Linkov
  2007-10-11  1:28                           ` Doc-view as default viewer for pdf, ps and dvi files (was: Please install: Some improvements to doc-view.el) Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-10-09 21:55 UTC (permalink / raw)
  To: emacs-devel; +Cc: Richard Stallman

>> I think Gnus mechanism is irrelevant to doc-view.  Gnus uses mailcap
>> mechanisms to find the appropriate mailcap entry and run an external
>> program in a separate process.  doc-view displays the rendered image
>> in the Emacs buffer.  So it could work exactly as image-mode for
>> pdf/ps/dvi files.
>
> Ok, that sounds reasonable to me and I'm willing to implement it.  If I
> understand correctly, I have to add entries to `auto-mode-alist' and
> change `doc-view-mode' so that it calls `doc-view' for the current
> `buffer-file-name' plus a binding `C-c C-c' to toggle between the
> rendered image presentation and the text representation.  Is that
> correct?

Yes, this seems to be correct.  And also please don't forget to display
a message in the echo area saying how the user can switch to text-only
mode, something like:

Type C-c C-c to view the document as source text.

> One problem I see: Should `doc-view' called with NO-CACHE set to t?
> Personally I prefer calling (doc-view nil file) and adding a binding to
> the mode to reconvert the document.

Maybe, adding a binding like `g' (usually used to revert/refresh the buffer)
will help doing this.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* mailcap viewers in dired; gnus-dired.el, mailcap.el (was: Please install: Some improvements to doc-view.el)
  2007-10-09 21:54                     ` Please install: Some improvements to doc-view.el Juri Linkov
@ 2007-10-09 22:17                       ` Reiner Steib
  2007-10-09 22:47                         ` Juri Linkov
  2007-10-15  1:37                       ` Please install: Some improvements to doc-view.el Richard Stallman
  1 sibling, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-10-09 22:17 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

On Tue, Oct 09 2007, Juri Linkov wrote:

>> The current code chooses the mailcap mechanism when in Gnus,
>> and now we have a proposal for Dired to use the doc-view mechanism.
>
> There is already a file lisp/gnus/gnus-dired.el that binds `C-c C-m C-l'
> in Dired to the command that runs the program found in the mailcap file.

The current versions of `mailcap.el' and `gnus-dired.el' have some
dependencies on Gnus.  I'm working on reducing these dependencies so
that it should possible to use them in other parts of Emacs without
loading significant parts of Gnus (probably `gnus-dired.el' should be
renamed, e.g. to `dired-mime.el').

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: mailcap viewers in dired; gnus-dired.el, mailcap.el (was: Please install: Some improvements to doc-view.el)
  2007-10-09 22:17                       ` mailcap viewers in dired; gnus-dired.el, mailcap.el (was: Please install: Some improvements to doc-view.el) Reiner Steib
@ 2007-10-09 22:47                         ` Juri Linkov
  2007-10-10 21:20                           ` mailcap viewers in dired; gnus-dired.el, mailcap.el Reiner Steib
  0 siblings, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-10-09 22:47 UTC (permalink / raw)
  To: emacs-devel

>> There is already a file lisp/gnus/gnus-dired.el that binds `C-c C-m C-l'
>> in Dired to the command that runs the program found in the mailcap file.
>
> The current versions of `mailcap.el' and `gnus-dired.el' have some
> dependencies on Gnus.  I'm working on reducing these dependencies so
> that it should possible to use them in other parts of Emacs without
> loading significant parts of Gnus

Thanks.  Do you see any problems with this?

> (probably `gnus-dired.el' should be renamed, e.g. to `dired-mime.el').

gnus-dired.el has a function `gnus-dired-attach' that is Gnus-specific.
So I think it would be better to leave gnus-dired.el alone, and implement
new commands in dired.el or dired-aux.el (and maybe take into account
the command guessing behaviour of ! in dired-x.el).

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: mailcap viewers in dired; gnus-dired.el, mailcap.el
  2007-10-09 22:47                         ` Juri Linkov
@ 2007-10-10 21:20                           ` Reiner Steib
  2007-10-10 23:43                             ` Juri Linkov
  2007-10-15  1:37                             ` Richard Stallman
  0 siblings, 2 replies; 98+ messages in thread
From: Reiner Steib @ 2007-10-10 21:20 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

On Wed, Oct 10 2007, Juri Linkov wrote:

>>> There is already a file lisp/gnus/gnus-dired.el that binds `C-c C-m C-l'
>>> in Dired to the command that runs the program found in the mailcap file.

[ FWIW: It only binds the key if the users calls
  `gnus-dired-minor-mode' or `turn-on-gnus-dired-mode'. ]

>> The current versions of `mailcap.el' and `gnus-dired.el' have some
>> dependencies on Gnus.  I'm working on reducing these dependencies so
>> that it should possible to use them in other parts of Emacs without
>> loading significant parts of Gnus

In Emacs 22 (branch), ...
emacs22 -Q -l mailcap -l gnus-dired -f dired -f turn-on-gnus-dired-mode
... loads more than 50 gnusy packages...

ELISP> (length '(gnus-dired gnus-msg gnus-art mm-uu mml2015 pgg
  pgg-parse pgg-def mm-view gnus-sum nnoo gnus-group gnus-undo nnmail
  mail-source format-spec gnus-start gnus-spec gnus-int gnus-range
  gnus-win message rfc822 mml mml-sec mml-smime smime dig mm-decode
  mm-bodies mm-encode mailabbrev gmm-utils mailheader canlock sha1
  hex-util gnus nnheader gnus-util netrc mail-utils gnus-ems dired
  regexp-opt mailcap mail-parse rfc2231 rfc2047 rfc2045 qp ietf-drums
  mm-util mule-util time-date mail-prsvr))
==> 56

With these changes, only mailcap and gnus-dired are loaded.

> Thanks.  Do you see any problems with this?

I did only very limited testing.  I tested that
`gnus-dired-find-file-mailcap' still works without loading unnecessary
gnusy packages.  See the preliminary patches (against Gnus trunk)
below.

Not a problem, but a TODO: `mailcap-mime-data' should be splitted.
IMHO, it should be composed of...

(a) entries from a customizable variable

(b) the data from MAILCAPS (`mailcap-parse-mailcaps')

(c) Emacs-wide fallback entries for external viewers (e.g. for
    Windows), cf. `mailcap-poor-system-types'.

Of course, mailcap.el should prefer (a) over (b), and (b) over (c).

>> (probably `gnus-dired.el' should be renamed, e.g. to `dired-mime.el').
>
> gnus-dired.el has a function `gnus-dired-attach' that is Gnus-specific.

I think it could work with any message composition package that
supports using MML (Emacs MIME).  I don't know if any other exists
beside (Gnus) Message mode.  But it's MML-specific, yes.

> So I think it would be better to leave gnus-dired.el alone, and implement
> new commands in dired.el or dired-aux.el 

I don't use dired often, so I don't have a strong opinion how to
integrate mailcap functionality there.

I think the other functions `gnus-dired-attach' and `gnus-dired-print'
could be useful as well (cf. (info "(gnus)Other modes")).  But they
surely need to be modified for if no other Gnus features should be
loaded.

> (and maybe take into account the command guessing behaviour of ! in
> dired-x.el).

`!' (`dired-do-shell-command') is not exactly what
`gnus-dired-find-file-mailcap' does.  In mailcap.el you can also
specify Emacs-internal handling, IIRC.


Bye, Reiner.

--8<---------------cut here---------------start------------->8---
--- mailcap.el	4 Oct 2007 18:51:28 -0000	7.11
+++ mailcap.el	10 Oct 2007 20:59:53 -0000
@@ -33,8 +33,18 @@
 ;;; Code:
 
 (eval-when-compile (require 'cl))
-(require 'mail-parse)
-(require 'mm-util)
+;; (require 'mail-parse)
+(autoload 'mail-header-parse-content-type "mail-parse")
+
+;; (require 'mm-util)
+(autoload 'mm-delete-duplicates "mm-util")
+;; `mm-delete-duplicates' is an alias for `delete-dups' in Emacs 22.
+
+(defalias 'mailcap-delete-duplicates
+  (if (fboundp 'delete-dups)
+      'delete-dups
+    (autoload 'mm-delete-duplicates "mm-util")
+    'mm-delete-duplicates))
 
 (defgroup mailcap nil
   "Definition of viewers for MIME types."
@@ -722,7 +732,7 @@
       t)
      (t nil))))
 
-(defun mailcap-mime-info (string &optional request)
+(defun mailcap-mime-info (string &optional request no-decode)
   "Get the MIME viewer command for STRING, return nil if none found.
 Expects a complete content-type header line as its argument.
 
@@ -732,7 +742,9 @@
 corresponding to that string will be returned (print, description,
 whatever).  If a number, then all the information for this specific
 viewer is returned.  If `all', then all possible viewers for
-this type is returned."
+this type is returned.
+
+If NO-DECODE is non-nil, don't decode STRING."
   (let (
 	major				; Major encoding (text, etc)
 	minor				; Minor encoding (html, etc)
@@ -746,7 +758,10 @@
 	viewer				; The one and only viewer
 	ctl)
     (save-excursion
-      (setq ctl (mail-header-parse-content-type (or string "text/plain")))
+      (setq ctl
+	    (if no-decode
+		(list (or string "text/plain"))
+	      (mail-header-parse-content-type (or string "text/plain"))))
       (setq major (split-string (car ctl) "/"))
       (setq minor (cadr major)
 	    major (car major))
@@ -766,7 +781,7 @@
 	(setq viewer (car passed)))
       (cond
        ((and (null viewer) (not (equal major "default")) request)
-	(mailcap-mime-info "default" request))
+	(mailcap-mime-info "default" request no-decode))
        ((or (null request) (equal request ""))
 	(mailcap-unescape-mime-test (cdr (assq 'viewer viewer)) info))
        ((stringp request)
@@ -976,7 +991,7 @@
 (defun mailcap-mime-types ()
   "Return a list of MIME media types."
   (mailcap-parse-mimetypes)
-  (mm-delete-duplicates
+  (mailcap-delete-duplicates
    (nconc
     (mapcar 'cdr mailcap-mime-extensions)
     (apply
--8<---------------cut here---------------end--------------->8---

--8<---------------cut here---------------start------------->8---
--- gnus-dired.el	4 Oct 2007 18:51:27 -0000	7.8
+++ gnus-dired.el	10 Oct 2007 20:57:48 -0000
@@ -42,25 +42,42 @@
 ;;; Code:
 
 (require 'dired)
-(require 'gnus-ems)
-(require 'gnus-msg)
-(require 'gnus-util)
-(require 'message)
-(require 'mm-encode)
-(require 'mml)
+;; (require 'mm-encode)
+;; (require 'mml)
+(autoload 'mml-attach-file "mml")
+;; Maybe shift this function to `mailcap.el'?
+(autoload 'mm-default-file-encoding "mm-decode")
+(autoload 'mailcap-extension-to-mime "mailcap")
+(autoload 'mailcap-mime-info "mailcap")
+
+;; Maybe shift this function to `mailcap.el'?
+(autoload 'mm-mailcap-command "mm-decode")
+
+(autoload 'ps-print-preprint "ps-print")
+
+;; Autoloads to avoid byte-compiler warnings.  These are used only if
+;; the user customizes `gnus-dired-mail-mode' to use Message and/or
+;; Gnus.
+(autoload 'message-buffers "message")
+(autoload 'gnus-setup-message "gnus-msg")
+(autoload 'gnus-print-buffer "gnus-sum")
+
+(defvar gnus-dired-mail-mode 'message) ;; 'gnus 'mail
+;;
+;; FIXME: Make it customizable, change the default to `mail' when this
+;; file if renamed to `dired-mime.el'.
 
 (defvar gnus-dired-mode nil
-  "Minor mode for intersections of gnus and dired.")
+  "Minor mode for intersections of MIME mail composition and dired.")
 
 (defvar gnus-dired-mode-map nil)
 
 (unless gnus-dired-mode-map
   (setq gnus-dired-mode-map (make-sparse-keymap))
 
-  (gnus-define-keys gnus-dired-mode-map
-    "\C-c\C-m\C-a" gnus-dired-attach
-    "\C-c\C-m\C-l" gnus-dired-find-file-mailcap
-    "\C-c\C-m\C-p" gnus-dired-print))
+  (define-key gnus-dired-mode-map "\C-c\C-m\C-a" 'gnus-dired-attach)
+  (define-key gnus-dired-mode-map "\C-c\C-m\C-l" 'gnus-dired-find-file-mailcap)
+  (define-key gnus-dired-mode-map "\C-c\C-m\C-p" 'gnus-dired-print))
 
 (defun gnus-dired-mode (&optional arg)
   "Minor mode for intersections of gnus and dired.
@@ -73,14 +90,31 @@
 	   (> (prefix-numeric-value arg) 0)))
     (when gnus-dired-mode
       (add-minor-mode 'gnus-dired-mode "" gnus-dired-mode-map)
-      (gnus-run-hooks 'gnus-dired-mode-hook))))
+      (save-current-buffer
+	(run-hooks 'gnus-dired-mode-hook)))))
 
 ;;;###autoload
 (defun turn-on-gnus-dired-mode ()
   "Convenience method to turn on gnus-dired-mode."
+  (interactive)
   (gnus-dired-mode 1))
 
-;; Method to attach files to a gnus composition.
+(defun gnus-dired-mail-buffers ()
+  "Return a list of active mail composition buffers."
+  (if (and (memq gnus-dired-mail-mode '(message gnus))
+	   (require 'message)
+	   (fboundp 'message-buffers))
+      (message-buffers)
+    ;; Cf. `message-buffers' in `message.el':
+    (let (buffers)
+      (save-excursion
+	(dolist (buffer (buffer-list t))
+	  (set-buffer buffer)
+	  (when (eq major-mode 'mail-mode)
+	    (push (buffer-name buffer) buffers))))
+      (nreverse buffers))))
+
+;; Method to attach files to a mail composition.
 (defun gnus-dired-attach (files-to-attach)
   "Attach dired's marked files to a gnus message composition.
 If called non-interactively, FILES-TO-ATTACH should be a list of
@@ -102,22 +136,25 @@
 	    (mapconcat
 	     (lambda (f) (file-name-nondirectory f))
 	     files-to-attach ", "))
-      (setq bufs (message-buffers))
+      (setq bufs (gnus-dired-mail-buffers))
 
-      ;; set up destination message buffer
+      ;; set up destination mail composition buffer
       (if (and bufs
-	       (y-or-n-p "Attach files to existing message buffer? "))
+	       (y-or-n-p "Attach files to existing mail composition buffer? "))
 	  (setq destination
 		(if (= (length bufs) 1)
 		    (get-buffer (car bufs))
-		  (completing-read "Attach to which message buffer: "
+		  (completing-read "Attach to which mail composition buffer: "
 				   (mapcar
 				    (lambda (b)
 				      (cons b (get-buffer b)))
 				    bufs)
 				   nil t)))
-	;; setup a new gnus message buffer
-	(gnus-setup-message 'message (message-mail))
+	;; setup a new mail composition buffer
+	(if (eq gnus-dired-mail-mode 'gnus)
+	    (gnus-setup-message 'message (message-mail))
+	  ;; FIXME: Is this the right thing?
+	  (compose-mail))
 	(setq destination (current-buffer)))
 
       ;; set buffer to destination buffer, and attach files
@@ -151,7 +188,8 @@
 		  (setq method
 			(cdr (assoc 'viewer
 				    (car (mailcap-mime-info mime-type
-							    'all)))))))
+							    'all 
+							    'no-decode)))))))
 	    (let ((view-command (mm-mailcap-command method file-name nil)))
 	      (message "viewing via %s" view-command)
 	      (start-process "*display*"
@@ -186,7 +224,8 @@
 		     (mailcap-extension-to-mime
 		      (match-string 0 file-name)))
 	       (stringp
-		(setq method (mailcap-mime-info mime-type "print"))))
+		(setq method (mailcap-mime-info mime-type "print"
+						'no-decode))))
 	  (call-process shell-file-name nil
 			(generate-new-buffer " *mm*")
 			nil
@@ -194,7 +233,10 @@
 			(mm-mailcap-command method file-name mime-type))
 	(with-temp-buffer
 	  (insert-file-contents file-name)
-	  (gnus-print-buffer))
+	  (if (eq gnus-dired-mail-mode 'gnus)
+	      (gnus-print-buffer)
+	    ;; FIXME:
+	    (error "MIME print only implemeted via Gnus")))
 	(ps-despool print-to))))
    ((file-symlink-p file-name)
      (error "File is a symlink to a nonexistent target"))
--8<---------------cut here---------------end--------------->8---
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: mailcap viewers in dired; gnus-dired.el, mailcap.el
  2007-10-10 21:20                           ` mailcap viewers in dired; gnus-dired.el, mailcap.el Reiner Steib
@ 2007-10-10 23:43                             ` Juri Linkov
  2007-10-15  1:37                             ` Richard Stallman
  1 sibling, 0 replies; 98+ messages in thread
From: Juri Linkov @ 2007-10-10 23:43 UTC (permalink / raw)
  To: emacs-devel

> In Emacs 22 (branch), ...
> emacs22 -Q -l mailcap -l gnus-dired -f dired -f turn-on-gnus-dired-mode
> ... loads more than 50 gnusy packages...
>
> ELISP> (length '(gnus-dired gnus-msg gnus-art mm-uu mml2015 pgg
>   pgg-parse pgg-def mm-view gnus-sum nnoo gnus-group gnus-undo nnmail
>   mail-source format-spec gnus-start gnus-spec gnus-int gnus-range
>   gnus-win message rfc822 mml mml-sec mml-smime smime dig mm-decode
>   mm-bodies mm-encode mailabbrev gmm-utils mailheader canlock sha1
>   hex-util gnus nnheader gnus-util netrc mail-utils gnus-ems dired
>   regexp-opt mailcap mail-parse rfc2231 rfc2047 rfc2045 qp ietf-drums
>   mm-util mule-util time-date mail-prsvr))
> ==> 56
>
> With these changes, only mailcap and gnus-dired are loaded.

Most of these packages get loaded only for the function `gnus-dired-attach'
in gnus-dired.el which is unrelated to running programs using the mailcap
mechanism.  When I manually eval `gnus-dired-find-file-mailcap' without
loading gnus-dired.el, then the list of loaded packages is much smaller,
maybe only the necessary packages get loaded.

>> Thanks.  Do you see any problems with this?
>
> I did only very limited testing.  I tested that
> `gnus-dired-find-file-mailcap' still works without loading unnecessary
> gnusy packages.  See the preliminary patches (against Gnus trunk)
> below.

I think the goal is not to fix gnus-dired.el to not load unnecessary
packages when only one function is needed from this file, because this
file is already ad-hoc and contains unrelated commands.  I think we should
only look at this file as an example of using the mailcap mechanism and
create a more general commands not in the gnus directory.

> Not a problem, but a TODO: `mailcap-mime-data' should be splitted.
> IMHO, it should be composed of...
>
> (a) entries from a customizable variable
>
> (b) the data from MAILCAPS (`mailcap-parse-mailcaps')
>
> (c) Emacs-wide fallback entries for external viewers (e.g. for
>     Windows), cf. `mailcap-poor-system-types'.
>
> Of course, mailcap.el should prefer (a) over (b), and (b) over (c).

I agree.  This would be a good priority system.

>> gnus-dired.el has a function `gnus-dired-attach' that is Gnus-specific.
>
> I think it could work with any message composition package that
> supports using MML (Emacs MIME).  I don't know if any other exists
> beside (Gnus) Message mode.  But it's MML-specific, yes.

`gnus-dired-attach' already works well for attaching files to the Gnus
messages, so I see no reason to change gnus-dired.el.  What is more useful to
do is to see whether calling mailcap-related functions (not in gnus-dired.el)
will load too many packages.

>> So I think it would be better to leave gnus-dired.el alone, and implement
>> new commands in dired.el or dired-aux.el
>
> I don't use dired often, so I don't have a strong opinion how to
> integrate mailcap functionality there.

`gnus-dired-find-file-mailcap' has a serious deficiency: it always starts
the program that happens to be the first in the list of equal mailcap
alternatives without allowing the user to select the preferable program
and possibly edit its command line.

> I think the other functions `gnus-dired-attach' and `gnus-dired-print'
> could be useful as well (cf. (info "(gnus)Other modes")).  But they
> surely need to be modified for if no other Gnus features should be
> loaded.

`P' (`dired-do-print') could provide a list of available printing commands
from the mailcap file.

>> (and maybe take into account the command guessing behaviour of ! in
>> dired-x.el).
>
> `!' (`dired-do-shell-command') is not exactly what
> `gnus-dired-find-file-mailcap' does.  In mailcap.el you can also
> specify Emacs-internal handling, IIRC.

This is an interesting problem.  It seems that Emacs-internal handling in
mailcap-mime-data mostly duplicates auto-mode-alist, isn't it?

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Doc-view as default viewer for pdf, ps and dvi files (was: Please install: Some improvements to doc-view.el)
  2007-10-09 21:55                         ` Juri Linkov
@ 2007-10-11  1:28                           ` Tassilo Horn
  2007-10-12  2:46                             ` Richard Stallman
  2007-10-17 23:34                             ` Juri Linkov
  0 siblings, 2 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-11  1:28 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Richard Stallman, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 767 bytes --]

Hi all,

the attached patch makes doc-view the standard viewer for pdf, ps and
dvi files.  It's done as Juri proposed and image-mode already does.

Whenever you find such a file it will be opened with doc-view-mode in a
text representation.  If emacs was compiled with image (png) support, it
will be switched to the rendered image presentation immediately,
otherwise we stay in the text display mode.

With `C-c C-c' one can toggle between image and source text display.
Both display modes are read-only.  With `C-c C-e' one can switch to an
appropriate editing mode -- ps-mode for ps files and fundamental-mode
for pdf and dvi files.

In the rendered image representation the binding `g' reconverts the
document.

I've tested it briefly and it seems to work well.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: make-doc-view-default-viewer.patch --]
[-- Type: text/x-patch, Size: 17279 bytes --]

Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.931
diff -u -r1.931 files.el
--- lisp/files.el	9 Oct 2007 08:52:45 -0000	1.931
+++ lisp/files.el	11 Oct 2007 01:22:06 -0000
@@ -2058,7 +2058,7 @@
      ("\\.\\(as\\|mi\\|sm\\)2\\'" . snmpv2-mode)
      ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
      ("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MSDOG
-     ("\\.[eE]?[pP][sS]\\'" . ps-mode)
+     ("\\.\\(?:DVI\\|P\\(?:DF\\|S\\)\\|dvi\\|p\\(?:df\\|s\\)\\)$" . doc-view-mode)
      ("configure\\.\\(ac\\|in\\)\\'" . autoconf-mode)
      ("BROWSE\\'" . ebrowse-tree-mode)
      ("\\.ebrowse\\'" . ebrowse-tree-mode)
Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.4
diff -u -r1.4 doc-view.el
--- lisp/doc-view.el	3 Oct 2007 23:39:58 -0000	1.4
+++ lisp/doc-view.el	11 Oct 2007 01:22:06 -0000
@@ -5,7 +5,7 @@
 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
 ;; Keywords: files, pdf, ps, dvi
-;; Version: <2007-10-02 Tue 18:21>
+;; Version: <2007-10-10 Wed 23:52>
 
 ;; This file is part of GNU Emacs.
 
@@ -37,16 +37,19 @@
 ;; inside an Emacs buffer.  This buffer uses `doc-view-mode' which provides
 ;; convenient key bindings for browsing the document.
 ;;
-;; To use it simply do
+;; To use it simply open a document file with
 ;;
-;;     M-x doc-view RET
+;;     C-x C-f ~/path/to/document RET
 ;;
-;; and you'll be queried for a document to open.
+;; and the document will be converted and displayed, if your emacs supports png
+;; images.  With `C-c C-c' you can toggle between the rendered images
+;; representation and the source text representation of the document.  With
+;; `C-c C-e' you can switch to an appropriate editing mode for the document.
 ;;
 ;; 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 view
-;; that file again.  This reusing can be omitted if you provide a prefx
-;; argument to `doc-view'.  To delete all cached files use
+;; that file again.  To reconvert a document hit `g' (`doc-view-reconvert-doc')
+;; when displaying the document.  To delete all cached files use
 ;; `doc-view-clear-cache'.  To open the cache with dired, so that you can tidy
 ;; it out use `doc-view-dired-cache'.
 ;;
@@ -67,8 +70,6 @@
 ;; bottom-right corner of the desired slice.  To reset the slice use
 ;; `doc-view-reset-slice' (bound to `s r').
 ;;
-;; Dired users should have a look at `doc-view-dired'.
-;;
 ;; You can also search within the document.  The command `doc-view-search'
 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
 ;; matching pages and messages how many match-pages were found.  After that you
@@ -80,17 +81,16 @@
 ;; conversion.  When that finishes and you're still viewing the document
 ;; (i.e. you didn't switch to another buffer) you're queried for the regexp
 ;; then.
+;;
+;; Dired users can simply hit `v' on a document file.  If it's a PS, PDF or DVI
+;; it will be opened using `doc-view-mode'.
+;;
 
 ;;; Configuration:
 
-;; Basically doc-view should be quite usable with its standard settings, so
-;; putting
-;;
-;;     (require 'doc-view)
-;;
-;; into your `user-init-file' should be enough.  If the images are too small or
-;; too big you should set the "-rXXX" option in `doc-view-ghostscript-options'
-;; to another value.  (The bigger your screen, the higher the value.)
+;; If the images are too small or too big you should set the "-rXXX" option in
+;; `doc-view-ghostscript-options' to another value.  (The bigger your screen,
+;; the higher the value.)
 ;;
 ;; This and all other options can be set with the customization interface.
 ;; Simply do
@@ -201,7 +201,10 @@
 (defvar doc-view-current-info nil
   "Only used internally.")
 
-;;;; DocView Keymap
+(defvar doc-view-current-display nil
+  "Only used internally.")
+
+;;;; DocView Keymaps
 
 (defvar doc-view-mode-map
   (let ((map (make-sparse-keymap)))
@@ -235,9 +238,21 @@
     (define-key map (kbd "M-v")       'scroll-down)
     ;; Show the tooltip
     (define-key map (kbd "C-t")       'doc-view-show-tooltip)
+    ;; Toggle between text and image display or editing
+    (define-key map (kbd "C-c C-c")   'doc-view-toggle-display)
+    (define-key map (kbd "C-c C-e") 'doc-view-edit-doc)
+    ;; Reconvert the current document
+    (define-key map (kbd "g")         'doc-view-reconvert-doc)
     (suppress-keymap map)
     map)
-  "Keymap used by `doc-view-mode'.")
+  "Keymap used by `doc-view-mode' when displaying a doc as a set of images.")
+
+(defvar doc-view-mode-text-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "C-c C-c") 'doc-view-toggle-display)
+    (define-key map (kbd "C-c C-e") 'doc-view-edit-doc)
+    map)
+  "Keymap used by `doc-view-mode' when displaying a document as text.")
 
 ;;;; Navigation Commands
 
@@ -271,16 +286,16 @@
 			 (setq contexts (concat contexts "  - \"" m "\"\n")))
 		       contexts)))))
     ;; Update the buffer
-    (setq inhibit-read-only t)
-    (erase-buffer)
-    (let ((beg (point)))
-      (doc-view-insert-image (nth (1- page) doc-view-current-files)
-			     :pointer 'arrow)
-      (put-text-property beg (point) 'help-echo doc-view-current-info))
-    (insert "\n" doc-view-current-info)
-    (goto-char (point-min))
-    (forward-char)
-    (setq inhibit-read-only nil)))
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (let ((beg (point)))
+	(doc-view-insert-image (nth (1- page) doc-view-current-files)
+			       :pointer 'arrow)
+	(put-text-property beg (point) 'help-echo doc-view-current-info))
+      (insert "\n" doc-view-current-info)
+      (goto-char (point-min))
+      (forward-char))
+    (set-buffer-modified-p nil)))
 
 (defun doc-view-next-page (&optional arg)
   "Browse ARG pages forward."
@@ -330,10 +345,21 @@
 
 ;;;; Conversion Functions
 
+(defun doc-view-reconvert-doc ()
+  "Reconvert the current document.
+Should be invoked when the cached images aren't up-to-date."
+  (interactive)
+  (let ((inhibit-read-only t)
+	(doc doc-view-current-doc))
+    ;; Clear the old cached files
+    (when (file-exists-p doc-view-current-cache-dir)
+      (dired-delete-file doc-view-current-cache-dir 'always))
+    (doc-view-kill-proc-and-buffer)
+    (find-file doc)))
+
 (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'."
+It's a subdirectory of `doc-view-cache-directory'."
   (if doc-view-current-cache-dir
       doc-view-current-cache-dir
     (file-name-as-directory
@@ -398,7 +424,7 @@
   (when doc-view-conversion-refresh-interval
     (setq doc-view-current-timer
 	  (run-at-time "1 secs" doc-view-conversion-refresh-interval
-		       'doc-view-display
+		       'doc-view-display-maybe
 		       doc-view-current-doc))))
 
 (defun doc-view-pdf->txt-sentinel (proc event)
@@ -449,45 +475,26 @@
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
   (process-put doc-view-current-converter-process 'pdf-file pdf))
 
-(defun doc-view-convert-doc (doc)
-  "Convert DOC to a set of png files, one file per page.
-
+(defun doc-view-convert-current-doc ()
+  "Convert `doc-view-current-doc' 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'."
   (clear-image-cache)
-  (let* ((dir (doc-view-file-name-to-directory-name doc))
-	 (png-file (concat (file-name-as-directory dir) "page-%d.png")))
-    (when (file-exists-p dir)
-      (dired-delete-file dir 'always))
-    (make-directory dir t)
-    (if (not (string= (file-name-extension doc) "dvi"))
+  ;; Calculate the cache dir
+  (setq doc-view-current-cache-dir
+	(doc-view-file-name-to-directory-name doc-view-current-doc))
+  (let ((png-file (concat (file-name-as-directory doc-view-current-cache-dir)
+			  "page-%d.png")))
+    (make-directory doc-view-current-cache-dir t)
+    (if (not (string= (file-name-extension doc-view-current-doc) "dvi"))
 	;; Convert to PNG images.
-	(doc-view-pdf/ps->png doc png-file)
+	(doc-view-pdf/ps->png doc-view-current-doc png-file)
       ;; DVI files have to be converted to PDF before GhostScript can process
       ;; it.
-      (doc-view-dvi->pdf doc
-			 (concat (file-name-as-directory dir)
+      (doc-view-dvi->pdf doc-view-current-doc
+			 (concat (file-name-as-directory doc-view-current-cache-dir)
 				 "doc.pdf")))))
 
-;;;; DocView Mode
-
-(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-doc)
-  (make-local-variable 'doc-view-current-image)
-  (make-local-variable 'doc-view-current-page)
-  (make-local-variable 'doc-view-current-converter-process)
-  (make-local-variable 'doc-view-current-timer)
-  (make-local-variable 'doc-view-current-slice)
-  (make-local-variable 'doc-view-current-cache-dir)
-  (make-local-variable 'doc-view-current-info)
-  (make-local-variable 'doc-view-current-search-matches))
-
 ;;;; Slicing
 
 (defun doc-view-set-slice (x y width height)
@@ -555,10 +562,15 @@
 	nil
       (string< a b))))
 
+(defun doc-view-display-maybe (doc)
+  "Call `doc-view-display' iff we're in the image display."
+  (when (eq doc-view-current-display 'image)
+    (doc-view-display doc)))
+
 (defun doc-view-display (doc)
   "Start viewing the document DOC."
   (let ((dir (doc-view-file-name-to-directory-name doc)))
-    (set-buffer (format "*DocView: %s*" doc))
+    (set-buffer (get-file-buffer doc))
     (setq doc-view-current-files
 	  (sort (directory-files dir t "page-[0-9]+\\.png" t)
 		'doc-view-sort))
@@ -566,8 +578,6 @@
       (doc-view-goto-page doc-view-current-page))))
 
 (defun doc-view-buffer-message ()
-  (setq inhibit-read-only t)
-  (erase-buffer)
   (insert (propertize "Welcome to DocView!" 'face 'bold)
 	  "\n"
 	  "
@@ -580,12 +590,60 @@
 
 `q' : Bury this buffer.  Conversion will go on in background.
 `k' : Kill the conversion process and this buffer.\n")
-  (setq inhibit-read-only nil))
+  (set-buffer-modified-p nil))
 
 (defun doc-view-show-tooltip ()
   (interactive)
   (tooltip-show doc-view-current-info))
 
+;;;;; Toggle between text and image display
+
+(defun doc-view-toggle-display ()
+  "Start or stop displaying a document file as a set of images.
+This command toggles between showing the text of the document
+file and showing the document as a set of images."
+  (interactive)
+  (if (get-text-property (point-min) 'display)
+      ;; Switch to text display
+      (let ((inhibit-read-only t))
+	(erase-buffer)
+	(insert-file-contents doc-view-current-doc)
+	(use-local-map doc-view-mode-text-map)
+	(setq mode-name "DocView[text]"
+	      doc-view-current-display 'text)
+	(if (called-interactively-p)
+	    (message "Repeat this command to go back to displaying the file as images")))
+    ;; Switch to image display
+    (let ((filename (buffer-file-name))
+	  (inhibit-read-only t))
+      (erase-buffer)
+      (doc-view-buffer-message)
+      (setq doc-view-current-page (or doc-view-current-page 1)
+	    doc-view-current-cache-dir (doc-view-file-name-to-directory-name filename))
+      (if (file-exists-p doc-view-current-cache-dir)
+	  (progn
+	    (message "DocView: using cached files!")
+	    (doc-view-display doc-view-current-doc))
+	(doc-view-convert-current-doc))
+      (use-local-map doc-view-mode-map)
+      (setq mode-name (format "DocView")
+	    doc-view-current-display 'image)
+      (if (called-interactively-p)
+	  (message "Repeat this command to go back to displaying the file as text"))))
+  (set-buffer-modified-p nil))
+
+;;;;; Leave doc-view-mode and open the file for edit
+
+(defun doc-view-edit-doc ()
+  "Leave `doc-view-mode' and open the current doc with an appropriate editing mode."
+  (interactive)
+  (let ((filename doc-view-current-doc)
+	(auto-mode-alist (append '(("\\.[eE]?[pP][sS]\\'" . ps-mode)
+				   ("\\.\\(pdf\\|PDF\\|dvi\\|DVI\\)$" . fundamental-mode))
+				 auto-mode-alist)))
+    (kill-buffer (current-buffer))
+    (find-file filename)))
+
 ;;;; Searching
 
 (defun doc-view-search-internal (regexp file)
@@ -698,52 +756,41 @@
 	     (y-or-n-p "No more matches before current page.  Wrap to last match? "))
 	(doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
 
-;;;; User Interface Commands
+;;;; User interface commands and the mode
+
+(put 'doc-view-mode 'mode-class 'special)
 
 ;;;###autoload
-(defun doc-view (no-cache &optional file)
-  "Convert FILE to png and start viewing it.
-If no FILE is given, query for on.
-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.")
-    (let* ((doc (or file
-		    (expand-file-name
-		     (let ((completion-ignored-extensions
-			    ;; Don't hide files doc-view can display
-			    (remove-if (lambda (str)
-					 (string-match "\\.\\(ps\\|pdf\\|dvi\\)$"
-						       str))
-				       completion-ignored-extensions)))
-		       (read-file-name "File: " nil nil t)))))
-	   (buffer (get-buffer-create (format "*DocView: %s*" doc)))
-	   (dir (doc-view-file-name-to-directory-name doc)))
-      (switch-to-buffer buffer)
-      (doc-view-buffer-message)
-      (doc-view-mode)
-      (setq doc-view-current-doc doc)
-      (setq doc-view-current-page 1)
-      (if (not (and (file-exists-p dir)
-		    (not no-cache)))
-	  (progn
-	    (setq doc-view-current-cache-dir nil)
-	    (doc-view-convert-doc doc-view-current-doc))
-	(message "DocView: using cached files!")
-	(doc-view-display doc-view-current-doc)))))
-
-(defun doc-view-dired (no-cache)
-  "View the current dired file with doc-view.
-NO-CACHE is the same as in `doc-view'.
-
-You might want to bind this command to a dired key, e.g.
-
-    (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)"
-  (interactive "P")
-  (doc-view no-cache (dired-get-file-for-visit)))
+(define-derived-mode doc-view-mode nil "DocView"
+  "Major mode in DocView buffers.
+You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
+toggle between display as a set of images and display as text."
+  :group 'doc-view
+  (make-local-variable 'doc-view-current-files)
+  (make-local-variable 'doc-view-current-doc)
+  (make-local-variable 'doc-view-current-image)
+  (make-local-variable 'doc-view-current-page)
+  (make-local-variable 'doc-view-current-converter-process)
+  (make-local-variable 'doc-view-current-timer)
+  (make-local-variable 'doc-view-current-slice)
+  (make-local-variable 'doc-view-current-cache-dir)
+  (make-local-variable 'doc-view-current-info)
+  (make-local-variable 'doc-view-current-search-matches)
+  (setq doc-view-current-doc buffer-file-name)
+  (insert-file-contents doc-view-current-doc)
+  (use-local-map doc-view-mode-text-map)
+  (setq mode-name "DocView[text]"
+	doc-view-current-display 'text
+	buffer-read-only t)
+  ;; Switch to image display if possible
+  (if (and (display-images-p)
+	   (image-type-available-p 'png)
+	   (not (get-text-property (point-min) 'display)))
+      (doc-view-toggle-display))
+  (message
+   "%s"
+   (substitute-command-keys
+    "Type \\[doc-view-toggle-display] to toggle between image and text display.")))
 
 (defun doc-view-clear-cache ()
   "Delete the whole cache (`doc-view-cache-directory')."
Index: lisp/bindings.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.185
diff -u -r1.185 bindings.el
--- lisp/bindings.el	6 Oct 2007 22:15:43 -0000	1.185
+++ lisp/bindings.el	11 Oct 2007 01:22:07 -0000
@@ -536,7 +536,7 @@
        '(".elc" ".lof"
 	 ".glo" ".idx" ".lot"
 	 ;; TeX-related
-	 ".dvi" ".fmt" ".tfm" ".pdf"
+	 ".fmt" ".tfm"
 	 ;; Java compiled
 	 ".class"
 	 ;; CLISP
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.11892
diff -u -r1.11892 ChangeLog
--- lisp/ChangeLog	10 Oct 2007 23:57:32 -0000	1.11892
+++ lisp/ChangeLog	11 Oct 2007 01:22:14 -0000
@@ -1,3 +1,16 @@
+2007-10-10  Tassilo Horn  <tassilo@member.fsf.org>
+
+	* bindings.el (completion-ignored-extensions): Remove pdf and dvi
+	extensions since they can be viewed with doc-view.
+
+	* files.el (auto-mode-alist): Make doc-view-mode the default mode
+	for pdf, ps and dvi files.
+
+	* doc-view.el: Make doc-view-mode the standard mode for viewing
+	pdf, ps and dvi files and add binding C-c C-c to toggle between
+	text and image display.  Add binding C-c C-e to switch to an
+	editing mode.
+
 2007-10-10  Carsten Dominik  <dominik@science.uva.nl>
 
 	* org.el (org-additional-option-like-keywords): New constant.

[-- Attachment #3: Type: text/plain, Size: 34 bytes --]


What do you think?

Bye,
Tassilo

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Doc-view as default viewer for pdf, ps and dvi files (was: Please install: Some improvements to doc-view.el)
  2007-10-11  1:28                           ` Doc-view as default viewer for pdf, ps and dvi files (was: Please install: Some improvements to doc-view.el) Tassilo Horn
@ 2007-10-12  2:46                             ` Richard Stallman
  2007-10-12 13:09                               ` Doc-view as default viewer for pdf, ps and dvi files Tassilo Horn
  2007-10-17 23:34                             ` Juri Linkov
  1 sibling, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-12  2:46 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: juri, emacs-devel

    Whenever you find such a file it will be opened with doc-view-mode in a
    text representation.  If emacs was compiled with image (png) support, it
    will be switched to the rendered image presentation immediately,
    otherwise we stay in the text display mode.

I want to make sure I understand right.

If Emacs does not have PNG support, doc-view cannot show the image,
and C-c C-c won't really do anything.  If Emacs does have PNG support,
doc-view will display the file graphically at first, and you only need
C-c C-c if you want to see the text.

Is that right?  Please tell me if any part of that is not correct.

    Both display modes are read-only.  With `C-c C-e' one can switch to an
    appropriate editing mode -- ps-mode for ps files and fundamental-mode
    for pdf and dvi files.

Why not do this by default?

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Doc-view as default viewer for pdf, ps and dvi files
  2007-10-12  2:46                             ` Richard Stallman
@ 2007-10-12 13:09                               ` Tassilo Horn
  2007-10-13  0:18                                 ` Richard Stallman
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-10-12 13:09 UTC (permalink / raw)
  To: rms; +Cc: juri, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     Whenever you find such a file it will be opened with doc-view-mode
>     in a text representation.  If emacs was compiled with image (png)
>     support, it will be switched to the rendered image presentation
>     immediately, otherwise we stay in the text display mode.
>
> I want to make sure I understand right.
>
> If Emacs does not have PNG support, doc-view cannot show the image,
> and C-c C-c won't really do anything.

It toggles, but in the image display only

  [page-22.png]

is displayed instead of the image.

> If Emacs does have PNG support, doc-view will display the file
> graphically at first, and you only need C-c C-c if you want to see the
> text.
>
> Is that right?  Please tell me if any part of that is not correct.

Yes, that's correct.

>     Both display modes are read-only.  With `C-c C-e' one can switch
>     to an appropriate editing mode -- ps-mode for ps files and
>     fundamental-mode for pdf and dvi files.
>
> Why not do this by default?

Because with C-c C-c you can toggle between image or text display, but
you wen't leave doc-view-mode.  After C-c C-e you switch to another
major mode and cannot toggle back with another C-c C-e.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Doc-view as default viewer for pdf, ps and dvi files
  2007-10-12 13:09                               ` Doc-view as default viewer for pdf, ps and dvi files Tassilo Horn
@ 2007-10-13  0:18                                 ` Richard Stallman
  2007-10-13  8:25                                   ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-13  0:18 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: juri, emacs-devel

    Because with C-c C-c you can toggle between image or text display, but
    you wen't leave doc-view-mode.  After C-c C-e you switch to another
    major mode and cannot toggle back with another C-c C-e.

Now that I understand that, it makes sense.  But I did not grasp this
after the first message.  So could you please say this explicitly
where this feature is documented?

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Doc-view as default viewer for pdf, ps and dvi files
  2007-10-13  0:18                                 ` Richard Stallman
@ 2007-10-13  8:25                                   ` Tassilo Horn
  2007-10-13 19:48                                     ` Richard Stallman
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-10-13  8:25 UTC (permalink / raw)
  To: rms; +Cc: juri, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     Because with C-c C-c you can toggle between image or text display,
>     but you wen't leave doc-view-mode.  After C-c C-e you switch to
>     another major mode and cannot toggle back with another C-c C-e.
>
> Now that I understand that, it makes sense.  But I did not grasp this
> after the first message.  So could you please say this explicitly
> where this feature is documented?

The usage comment in doc-view.el says

,----
| ;; To use it simply open a document file with
| ;;
| ;;     C-x C-f ~/path/to/document RET
| ;;
| ;; and the document will be converted and displayed, if your emacs supports png
| ;; images.  With `C-c C-c' you can toggle between the rendered images
| ;; representation and the source text representation of the document.  With
| ;; `C-c C-e' you can switch to an appropriate editing mode for the document.
`----

And the function docstrings say

,----
| (defun doc-view-toggle-display ()
|   "Start or stop displaying a document file as a set of images.
| This command toggles between showing the text of the document
| file and showing the document as a set of images."
`----

and

,----
| (defun doc-view-edit-doc ()
|   "Leave `doc-view-mode' and open the current doc with an appropriate editing mode."
`----

If you decide to install the patch this feature should be added to the
texinfo docs, too.  Here's the entry for image-mode, the entry for
doc-view-mode would be quite similar, because I took image-mode as
pattern.

,----[ (info "(emacs)File Conveniences") ]
|    Visiting image files automatically selects Image mode.  This major
| mode allows you to toggle between displaying the file as an image in
| the Emacs buffer, and displaying its underlying text representation,
| using the command `C-c C-c' (`image-toggle-display').  This works only
| when Emacs can display the specific image type.  If the displayed
| image is wider or taller than the frame, the usual point motion keys
| (`C-f', `C-p', and so forth) cause different parts of the image to be
| displayed.
`----

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Doc-view as default viewer for pdf, ps and dvi files
  2007-10-13  8:25                                   ` Tassilo Horn
@ 2007-10-13 19:48                                     ` Richard Stallman
  0 siblings, 0 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-13 19:48 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: juri, emacs-devel

You've documented it thoroughly.  Thanks.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: mailcap viewers in dired; gnus-dired.el, mailcap.el
  2007-10-10 21:20                           ` mailcap viewers in dired; gnus-dired.el, mailcap.el Reiner Steib
  2007-10-10 23:43                             ` Juri Linkov
@ 2007-10-15  1:37                             ` Richard Stallman
  2007-10-15 23:46                               ` Juri Linkov
  2007-10-18 17:48                               ` Lars Magne Ingebrigtsen
  1 sibling, 2 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-15  1:37 UTC (permalink / raw)
  To: Reiner Steib; +Cc: juri, emacs-devel

    The current versions of `mailcap.el' and `gnus-dired.el' have some
    dependencies on Gnus.  I'm working on reducing these dependencies so
    that it should possible to use them in other parts of Emacs without
    loading significant parts of Gnus (probably `gnus-dired.el' should be
    renamed, e.g. to `dired-mime.el').

Thanks for doing that.  It needs to be done, to make Emacs clean
and well organized.

However, it would be even better to install these features
in the right place to start with.

I've seen several examples where Gnus developers added to Gnus a
general facility which isn't specificly for reading news or mail.
That's not the way to add these facilities.  They ought to be
added in the right place, as separate facilities in Emacs.

Can we arrange with Gnus maintainers to do this differently?

Juri wrote:

    I think the goal is not to fix gnus-dired.el to not load unnecessary
    packages when only one function is needed from this file, because this
    file is already ad-hoc and contains unrelated commands.  I think we should
    only look at this file as an example of using the mailcap mechanism and
    create a more general commands not in the gnus directory.

I agree.

    > `!' (`dired-do-shell-command') is not exactly what
    > `gnus-dired-find-file-mailcap' does.  In mailcap.el you can also
    > specify Emacs-internal handling, IIRC.

    This is an interesting problem.  It seems that Emacs-internal handling in
    mailcap-mime-data mostly duplicates auto-mode-alist, isn't it?

If this is a matter of deciding how to handle an attachment based on
its mime type, I do not see that as redundant with `auto-mode-alist'.
That decides how to handle a file based on its name.  A file does
not carry anything with it analogous to a stated mime type.
You only have the file name and the data (magic numbers).


such a 

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-09 21:54                     ` Please install: Some improvements to doc-view.el Juri Linkov
  2007-10-09 22:17                       ` mailcap viewers in dired; gnus-dired.el, mailcap.el (was: Please install: Some improvements to doc-view.el) Reiner Steib
@ 2007-10-15  1:37                       ` Richard Stallman
  2007-10-15 23:45                         ` Juri Linkov
  1 sibling, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-15  1:37 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

    > So do we really want both methods?  If so, when should each
    > method be used?  Or how should the user choose?

    I think both methods are very useful.

Why are they both useful?

    The Gnus mailcap mechanism provides several alternatives of external
    programs to run.  There are many different file types associated with
    programs in the mailcap file, not only documents supported by doc-view.

Ok, but when mailcap finds these kinds of documents,
should it run the external program or should it use doc-view?

    But I think a better way would be to allow the user to select the
    preferred program, inspect the command line and be able to edit the
    command line before running a command.  This can be achieved by putting
    program names found by the Gnus mailcap mechanism to the default value
    in the minibuffer activated after typing !  in Dired.

This seems to be a suggestion for changing the Gnus mailcap
feature.  Is that right?

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-09 21:30                     ` Tassilo Horn
@ 2007-10-15 18:31                       ` Richard Stallman
  2007-10-15 20:58                         ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-15 18:31 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: juri, emacs-devel

    Personally I think a solution which doesn't give the focus to another
    application is preferable and thus should be the default.  Gnus cannot
    use doc-view since that depends on GNU Emacs whereas Gnus wants to run
    on all Emacsen.

XEmacs is a modified version of GNU Emacs, so please don't use the
word "GNU" to distinguish one from the other, as if XEmacs had nothing
to do with GNU.

When Gnus runs in Emacs, it should do whatever is best to do in Emacs.
XEmacs concerns should not get in the way.

    1. He proposed to make doc-view the standard viewer for pdf/dvi/ps files
       and add a binding `C-c C-c' which would toggle between the rendered
       image representation and the text representation just like image-mode
       does.  This way `v' in dired would use doc-view by default and `C-c
       C-c' in doc-view-mode would switch to the text representation you get
       when you hit `v' on a doc nowadays.

I said yes to this; maybe he has implemented itby now.

    2. The Gnus mailcap mechanism could be used for the default command for
       `dired-do-shell-command' (bound to `!' in dired).

Maybe so, as long as in Emacs this mechanism is set up to use
docview when appropriate.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-15 18:31                       ` Richard Stallman
@ 2007-10-15 20:58                         ` Tassilo Horn
  2007-10-17 23:49                           ` Scrolling in doc-view Chong Yidong
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-10-15 20:58 UTC (permalink / raw)
  To: rms; +Cc: juri, emacs-devel

Richard Stallman <rms@gnu.org> writes:

> XEmacs is a modified version of GNU Emacs, so please don't use the
> word "GNU" to distinguish one from the other, as if XEmacs had nothing
> to do with GNU.

Ok.

> When Gnus runs in Emacs, it should do whatever is best to do in Emacs.
> XEmacs concerns should not get in the way.
>
>     1. He proposed to make doc-view the standard viewer for pdf/dvi/ps files
>        and add a binding `C-c C-c' which would toggle between the rendered
>        image representation and the text representation just like image-mode
>        does.  This way `v' in dired would use doc-view by default and `C-c
>        C-c' in doc-view-mode would switch to the text representation you get
>        when you hit `v' on a doc nowadays.
>
> I said yes to this; maybe he has implemented itby now.

Erm, I have implemented this and you've replied to my mail which had the
patch attached (<87r6k2l9sr.fsf_-_@baldur.tsdh.de>).

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-15  1:37                       ` Please install: Some improvements to doc-view.el Richard Stallman
@ 2007-10-15 23:45                         ` Juri Linkov
  2007-10-16 19:09                           ` Richard Stallman
  0 siblings, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-10-15 23:45 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

>     I think both methods are very useful.
>
> Why are they both useful?

The mailcap feature is useful to get the names of the external programs.
Doc-view is useful to view rendered images of PDF/PS/DVI files in a
Emacs buffer.

>     The Gnus mailcap mechanism provides several alternatives of external
>     programs to run.  There are many different file types associated with
>     programs in the mailcap file, not only documents supported by doc-view.
>
> Ok, but when mailcap finds these kinds of documents,
> should it run the external program or should it use doc-view?

I think on Gnus attachments of PDF/PS/DVI files it should now use doc-view.

>     But I think a better way would be to allow the user to select the
>     preferred program, inspect the command line and be able to edit the
>     command line before running a command.  This can be achieved by putting
>     program names found by the Gnus mailcap mechanism to the default value
>     in the minibuffer activated after typing !  in Dired.
>
> This seems to be a suggestion for changing the Gnus mailcap
> feature.  Is that right?

No, the mailcap feature only returns the names of the external programs.
So how to use them is a matter of other packages.  Gnus always runs the
first found program to view the Gnus attachment.  However, I think Dired
should get programs names from the mailcap feature, and present them in the
minibuffer activated by ! in Dired to allow the user select the desired
program.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: mailcap viewers in dired; gnus-dired.el, mailcap.el
  2007-10-15  1:37                             ` Richard Stallman
@ 2007-10-15 23:46                               ` Juri Linkov
  2007-10-16  6:49                                 ` Tassilo Horn
  2007-10-18 17:48                               ` Lars Magne Ingebrigtsen
  1 sibling, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-10-15 23:46 UTC (permalink / raw)
  To: rms; +Cc: Reiner Steib, emacs-devel

>     > `!' (`dired-do-shell-command') is not exactly what
>     > `gnus-dired-find-file-mailcap' does.  In mailcap.el you can also
>     > specify Emacs-internal handling, IIRC.
>
>     This is an interesting problem.  It seems that Emacs-internal handling in
>     mailcap-mime-data mostly duplicates auto-mode-alist, isn't it?
>
> If this is a matter of deciding how to handle an attachment based on
> its mime type, I do not see that as redundant with `auto-mode-alist'.
> That decides how to handle a file based on its name.  A file does
> not carry anything with it analogous to a stated mime type.
> You only have the file name and the data (magic numbers).

The mailcap feature contains two basic parts:

1. file extension to the mime type mapping (e.g. ".pdf" -> "application/pdf"),
2. mime type to the view command name mapping (e.g. "application/pdf" -> "xpdf").

But also it allows mappings from the mime type to the Emacs function
(e.g. "application/pdf" -> `doc-view').

For Gnus attachments these types are necessary, and perhaps we should add
now the `doc-view' mappings for PDF/PS/DVI mime types to mailcap.el,
because I think viewing PDF/PS/DVI attachments is more preferable than
running an external program.

In the latest patch Tassilo added a new `auto-mode-alist' mapping
from .pdf/.ps/.dvi to `doc-view-mode', and I think this is right because
this is for visiting a file in Emacs, not an attachment in Gnus.

BTW, I don't understand why .eps is removed from `auto-mode-alist' in the
latest patch?

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: mailcap viewers in dired; gnus-dired.el, mailcap.el
  2007-10-15 23:46                               ` Juri Linkov
@ 2007-10-16  6:49                                 ` Tassilo Horn
  0 siblings, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-16  6:49 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, Reiner Steib, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 300 bytes --]

Juri Linkov <juri@jurta.org> writes:

Hi Juri,

> BTW, I don't understand why .eps is removed from `auto-mode-alist' in
> the latest patch?

Ups, that's an error.  Of course, eps files work fine with doc-view.  I
attached a new patch which adds eps files to the doc-view-mode
auto-mode-alist entry.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: doc-view-as-standard-viewer-2007-10-16_08:50.patch --]
[-- Type: text/x-patch, Size: 17283 bytes --]

Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.932
diff -u -r1.932 files.el
--- lisp/files.el	15 Oct 2007 02:07:46 -0000	1.932
+++ lisp/files.el	16 Oct 2007 06:45:23 -0000
@@ -2059,7 +2059,7 @@
      ("\\.\\(as\\|mi\\|sm\\)2\\'" . snmpv2-mode)
      ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
      ("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MSDOG
-     ("\\.[eE]?[pP][sS]\\'" . ps-mode)
+     ("\\(?:DVI\\|EPS\\|P\\(?:DF\\|S\\)\\|dvi\\|eps\\|p\\(?:df\\|s\\)\\)" . doc-view-mode)
      ("configure\\.\\(ac\\|in\\)\\'" . autoconf-mode)
      ("BROWSE\\'" . ebrowse-tree-mode)
      ("\\.ebrowse\\'" . ebrowse-tree-mode)
Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.4
diff -u -r1.4 doc-view.el
--- lisp/doc-view.el	3 Oct 2007 23:39:58 -0000	1.4
+++ lisp/doc-view.el	16 Oct 2007 06:45:24 -0000
@@ -5,7 +5,7 @@
 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
 ;; Keywords: files, pdf, ps, dvi
-;; Version: <2007-10-02 Tue 18:21>
+;; Version: <2007-10-16 Tue 08:42>
 
 ;; This file is part of GNU Emacs.
 
@@ -37,16 +37,19 @@
 ;; inside an Emacs buffer.  This buffer uses `doc-view-mode' which provides
 ;; convenient key bindings for browsing the document.
 ;;
-;; To use it simply do
+;; To use it simply open a document file with
 ;;
-;;     M-x doc-view RET
+;;     C-x C-f ~/path/to/document RET
 ;;
-;; and you'll be queried for a document to open.
+;; and the document will be converted and displayed, if your emacs supports png
+;; images.  With `C-c C-c' you can toggle between the rendered images
+;; representation and the source text representation of the document.  With
+;; `C-c C-e' you can switch to an appropriate editing mode for the document.
 ;;
 ;; 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 view
-;; that file again.  This reusing can be omitted if you provide a prefx
-;; argument to `doc-view'.  To delete all cached files use
+;; that file again.  To reconvert a document hit `g' (`doc-view-reconvert-doc')
+;; when displaying the document.  To delete all cached files use
 ;; `doc-view-clear-cache'.  To open the cache with dired, so that you can tidy
 ;; it out use `doc-view-dired-cache'.
 ;;
@@ -67,8 +70,6 @@
 ;; bottom-right corner of the desired slice.  To reset the slice use
 ;; `doc-view-reset-slice' (bound to `s r').
 ;;
-;; Dired users should have a look at `doc-view-dired'.
-;;
 ;; You can also search within the document.  The command `doc-view-search'
 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
 ;; matching pages and messages how many match-pages were found.  After that you
@@ -80,17 +81,16 @@
 ;; conversion.  When that finishes and you're still viewing the document
 ;; (i.e. you didn't switch to another buffer) you're queried for the regexp
 ;; then.
+;;
+;; Dired users can simply hit `v' on a document file.  If it's a PS, PDF or DVI
+;; it will be opened using `doc-view-mode'.
+;;
 
 ;;; Configuration:
 
-;; Basically doc-view should be quite usable with its standard settings, so
-;; putting
-;;
-;;     (require 'doc-view)
-;;
-;; into your `user-init-file' should be enough.  If the images are too small or
-;; too big you should set the "-rXXX" option in `doc-view-ghostscript-options'
-;; to another value.  (The bigger your screen, the higher the value.)
+;; If the images are too small or too big you should set the "-rXXX" option in
+;; `doc-view-ghostscript-options' to another value.  (The bigger your screen,
+;; the higher the value.)
 ;;
 ;; This and all other options can be set with the customization interface.
 ;; Simply do
@@ -201,7 +201,10 @@
 (defvar doc-view-current-info nil
   "Only used internally.")
 
-;;;; DocView Keymap
+(defvar doc-view-current-display nil
+  "Only used internally.")
+
+;;;; DocView Keymaps
 
 (defvar doc-view-mode-map
   (let ((map (make-sparse-keymap)))
@@ -235,9 +238,21 @@
     (define-key map (kbd "M-v")       'scroll-down)
     ;; Show the tooltip
     (define-key map (kbd "C-t")       'doc-view-show-tooltip)
+    ;; Toggle between text and image display or editing
+    (define-key map (kbd "C-c C-c")   'doc-view-toggle-display)
+    (define-key map (kbd "C-c C-e")   'doc-view-edit-doc)
+    ;; Reconvert the current document
+    (define-key map (kbd "g")         'doc-view-reconvert-doc)
     (suppress-keymap map)
     map)
-  "Keymap used by `doc-view-mode'.")
+  "Keymap used by `doc-view-mode' when displaying a doc as a set of images.")
+
+(defvar doc-view-mode-text-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "C-c C-c") 'doc-view-toggle-display)
+    (define-key map (kbd "C-c C-e") 'doc-view-edit-doc)
+    map)
+  "Keymap used by `doc-view-mode' when displaying a document as text.")
 
 ;;;; Navigation Commands
 
@@ -271,16 +286,16 @@
 			 (setq contexts (concat contexts "  - \"" m "\"\n")))
 		       contexts)))))
     ;; Update the buffer
-    (setq inhibit-read-only t)
-    (erase-buffer)
-    (let ((beg (point)))
-      (doc-view-insert-image (nth (1- page) doc-view-current-files)
-			     :pointer 'arrow)
-      (put-text-property beg (point) 'help-echo doc-view-current-info))
-    (insert "\n" doc-view-current-info)
-    (goto-char (point-min))
-    (forward-char)
-    (setq inhibit-read-only nil)))
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (let ((beg (point)))
+	(doc-view-insert-image (nth (1- page) doc-view-current-files)
+			       :pointer 'arrow)
+	(put-text-property beg (point) 'help-echo doc-view-current-info))
+      (insert "\n" doc-view-current-info)
+      (goto-char (point-min))
+      (forward-char))
+    (set-buffer-modified-p nil)))
 
 (defun doc-view-next-page (&optional arg)
   "Browse ARG pages forward."
@@ -330,10 +345,21 @@
 
 ;;;; Conversion Functions
 
+(defun doc-view-reconvert-doc ()
+  "Reconvert the current document.
+Should be invoked when the cached images aren't up-to-date."
+  (interactive)
+  (let ((inhibit-read-only t)
+	(doc doc-view-current-doc))
+    ;; Clear the old cached files
+    (when (file-exists-p doc-view-current-cache-dir)
+      (dired-delete-file doc-view-current-cache-dir 'always))
+    (doc-view-kill-proc-and-buffer)
+    (find-file doc)))
+
 (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'."
+It's a subdirectory of `doc-view-cache-directory'."
   (if doc-view-current-cache-dir
       doc-view-current-cache-dir
     (file-name-as-directory
@@ -398,7 +424,7 @@
   (when doc-view-conversion-refresh-interval
     (setq doc-view-current-timer
 	  (run-at-time "1 secs" doc-view-conversion-refresh-interval
-		       'doc-view-display
+		       'doc-view-display-maybe
 		       doc-view-current-doc))))
 
 (defun doc-view-pdf->txt-sentinel (proc event)
@@ -449,45 +475,26 @@
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
   (process-put doc-view-current-converter-process 'pdf-file pdf))
 
-(defun doc-view-convert-doc (doc)
-  "Convert DOC to a set of png files, one file per page.
-
+(defun doc-view-convert-current-doc ()
+  "Convert `doc-view-current-doc' 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'."
   (clear-image-cache)
-  (let* ((dir (doc-view-file-name-to-directory-name doc))
-	 (png-file (concat (file-name-as-directory dir) "page-%d.png")))
-    (when (file-exists-p dir)
-      (dired-delete-file dir 'always))
-    (make-directory dir t)
-    (if (not (string= (file-name-extension doc) "dvi"))
+  ;; Calculate the cache dir
+  (setq doc-view-current-cache-dir
+	(doc-view-file-name-to-directory-name doc-view-current-doc))
+  (let ((png-file (concat (file-name-as-directory doc-view-current-cache-dir)
+			  "page-%d.png")))
+    (make-directory doc-view-current-cache-dir t)
+    (if (not (string= (file-name-extension doc-view-current-doc) "dvi"))
 	;; Convert to PNG images.
-	(doc-view-pdf/ps->png doc png-file)
+	(doc-view-pdf/ps->png doc-view-current-doc png-file)
       ;; DVI files have to be converted to PDF before GhostScript can process
       ;; it.
-      (doc-view-dvi->pdf doc
-			 (concat (file-name-as-directory dir)
+      (doc-view-dvi->pdf doc-view-current-doc
+			 (concat (file-name-as-directory doc-view-current-cache-dir)
 				 "doc.pdf")))))
 
-;;;; DocView Mode
-
-(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-doc)
-  (make-local-variable 'doc-view-current-image)
-  (make-local-variable 'doc-view-current-page)
-  (make-local-variable 'doc-view-current-converter-process)
-  (make-local-variable 'doc-view-current-timer)
-  (make-local-variable 'doc-view-current-slice)
-  (make-local-variable 'doc-view-current-cache-dir)
-  (make-local-variable 'doc-view-current-info)
-  (make-local-variable 'doc-view-current-search-matches))
-
 ;;;; Slicing
 
 (defun doc-view-set-slice (x y width height)
@@ -555,10 +562,15 @@
 	nil
       (string< a b))))
 
+(defun doc-view-display-maybe (doc)
+  "Call `doc-view-display' iff we're in the image display."
+  (when (eq doc-view-current-display 'image)
+    (doc-view-display doc)))
+
 (defun doc-view-display (doc)
   "Start viewing the document DOC."
   (let ((dir (doc-view-file-name-to-directory-name doc)))
-    (set-buffer (format "*DocView: %s*" doc))
+    (set-buffer (get-file-buffer doc))
     (setq doc-view-current-files
 	  (sort (directory-files dir t "page-[0-9]+\\.png" t)
 		'doc-view-sort))
@@ -566,8 +578,6 @@
       (doc-view-goto-page doc-view-current-page))))
 
 (defun doc-view-buffer-message ()
-  (setq inhibit-read-only t)
-  (erase-buffer)
   (insert (propertize "Welcome to DocView!" 'face 'bold)
 	  "\n"
 	  "
@@ -580,12 +590,60 @@
 
 `q' : Bury this buffer.  Conversion will go on in background.
 `k' : Kill the conversion process and this buffer.\n")
-  (setq inhibit-read-only nil))
+  (set-buffer-modified-p nil))
 
 (defun doc-view-show-tooltip ()
   (interactive)
   (tooltip-show doc-view-current-info))
 
+;;;;; Toggle between text and image display
+
+(defun doc-view-toggle-display ()
+  "Start or stop displaying a document file as a set of images.
+This command toggles between showing the text of the document
+file and showing the document as a set of images."
+  (interactive)
+  (if (get-text-property (point-min) 'display)
+      ;; Switch to text display
+      (let ((inhibit-read-only t))
+	(erase-buffer)
+	(insert-file-contents doc-view-current-doc)
+	(use-local-map doc-view-mode-text-map)
+	(setq mode-name "DocView[text]"
+	      doc-view-current-display 'text)
+	(if (called-interactively-p)
+	    (message "Repeat this command to go back to displaying the file as images")))
+    ;; Switch to image display
+    (let ((filename (buffer-file-name))
+	  (inhibit-read-only t))
+      (erase-buffer)
+      (doc-view-buffer-message)
+      (setq doc-view-current-page (or doc-view-current-page 1)
+	    doc-view-current-cache-dir (doc-view-file-name-to-directory-name filename))
+      (if (file-exists-p doc-view-current-cache-dir)
+	  (progn
+	    (message "DocView: using cached files!")
+	    (doc-view-display doc-view-current-doc))
+	(doc-view-convert-current-doc))
+      (use-local-map doc-view-mode-map)
+      (setq mode-name (format "DocView")
+	    doc-view-current-display 'image)
+      (if (called-interactively-p)
+	  (message "Repeat this command to go back to displaying the file as text"))))
+  (set-buffer-modified-p nil))
+
+;;;;; Leave doc-view-mode and open the file for edit
+
+(defun doc-view-edit-doc ()
+  "Leave `doc-view-mode' and open the current doc with an appropriate editing mode."
+  (interactive)
+  (let ((filename doc-view-current-doc)
+	(auto-mode-alist (append '(("\\.[eE]?[pP][sS]\\'" . ps-mode)
+				   ("\\.\\(pdf\\|PDF\\|dvi\\|DVI\\)$" . fundamental-mode))
+				 auto-mode-alist)))
+    (kill-buffer (current-buffer))
+    (find-file filename)))
+
 ;;;; Searching
 
 (defun doc-view-search-internal (regexp file)
@@ -698,52 +756,41 @@
 	     (y-or-n-p "No more matches before current page.  Wrap to last match? "))
 	(doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
 
-;;;; User Interface Commands
+;;;; User interface commands and the mode
+
+(put 'doc-view-mode 'mode-class 'special)
 
 ;;;###autoload
-(defun doc-view (no-cache &optional file)
-  "Convert FILE to png and start viewing it.
-If no FILE is given, query for on.
-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.")
-    (let* ((doc (or file
-		    (expand-file-name
-		     (let ((completion-ignored-extensions
-			    ;; Don't hide files doc-view can display
-			    (remove-if (lambda (str)
-					 (string-match "\\.\\(ps\\|pdf\\|dvi\\)$"
-						       str))
-				       completion-ignored-extensions)))
-		       (read-file-name "File: " nil nil t)))))
-	   (buffer (get-buffer-create (format "*DocView: %s*" doc)))
-	   (dir (doc-view-file-name-to-directory-name doc)))
-      (switch-to-buffer buffer)
-      (doc-view-buffer-message)
-      (doc-view-mode)
-      (setq doc-view-current-doc doc)
-      (setq doc-view-current-page 1)
-      (if (not (and (file-exists-p dir)
-		    (not no-cache)))
-	  (progn
-	    (setq doc-view-current-cache-dir nil)
-	    (doc-view-convert-doc doc-view-current-doc))
-	(message "DocView: using cached files!")
-	(doc-view-display doc-view-current-doc)))))
-
-(defun doc-view-dired (no-cache)
-  "View the current dired file with doc-view.
-NO-CACHE is the same as in `doc-view'.
-
-You might want to bind this command to a dired key, e.g.
-
-    (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)"
-  (interactive "P")
-  (doc-view no-cache (dired-get-file-for-visit)))
+(define-derived-mode doc-view-mode nil "DocView"
+  "Major mode in DocView buffers.
+You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
+toggle between display as a set of images and display as text."
+  :group 'doc-view
+  (make-local-variable 'doc-view-current-files)
+  (make-local-variable 'doc-view-current-doc)
+  (make-local-variable 'doc-view-current-image)
+  (make-local-variable 'doc-view-current-page)
+  (make-local-variable 'doc-view-current-converter-process)
+  (make-local-variable 'doc-view-current-timer)
+  (make-local-variable 'doc-view-current-slice)
+  (make-local-variable 'doc-view-current-cache-dir)
+  (make-local-variable 'doc-view-current-info)
+  (make-local-variable 'doc-view-current-search-matches)
+  (setq doc-view-current-doc buffer-file-name)
+  (insert-file-contents doc-view-current-doc)
+  (use-local-map doc-view-mode-text-map)
+  (setq mode-name "DocView[text]"
+	doc-view-current-display 'text
+	buffer-read-only t)
+  ;; Switch to image display if possible
+  (if (and (display-images-p)
+	   (image-type-available-p 'png)
+	   (not (get-text-property (point-min) 'display)))
+      (doc-view-toggle-display))
+  (message
+   "%s"
+   (substitute-command-keys
+    "Type \\[doc-view-toggle-display] to toggle between image and text display.")))
 
 (defun doc-view-clear-cache ()
   "Delete the whole cache (`doc-view-cache-directory')."
Index: lisp/bindings.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.185
diff -u -r1.185 bindings.el
--- lisp/bindings.el	6 Oct 2007 22:15:43 -0000	1.185
+++ lisp/bindings.el	16 Oct 2007 06:45:25 -0000
@@ -536,7 +536,7 @@
        '(".elc" ".lof"
 	 ".glo" ".idx" ".lot"
 	 ;; TeX-related
-	 ".dvi" ".fmt" ".tfm" ".pdf"
+	 ".fmt" ".tfm"
 	 ;; Java compiled
 	 ".class"
 	 ;; CLISP
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.11939
diff -u -r1.11939 ChangeLog
--- lisp/ChangeLog	16 Oct 2007 02:41:08 -0000	1.11939
+++ lisp/ChangeLog	16 Oct 2007 06:45:31 -0000
@@ -1,3 +1,16 @@
+2007-10-16  Tassilo Horn  <tassilo@member.fsf.org>
+
+	* bindings.el (completion-ignored-extensions): Remove pdf and dvi
+	extensions since they can be viewed with doc-view.
+
+	* files.el (auto-mode-alist): Make doc-view-mode the default mode
+	for pdf, ps and dvi files.
+
+	* doc-view.el: Make doc-view-mode the standard mode for viewing
+	pdf, [e]ps and dvi files and add binding C-c C-c to toggle between
+	text and image display.  Add binding C-c C-e to switch to an
+	editing mode.
+
 2007-10-16  Glenn Morris  <rgm@gnu.org>
 
 	* simple.el (blink-matching-open): Don't report false errors with

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


Bye,
Tassilo

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-15 23:45                         ` Juri Linkov
@ 2007-10-16 19:09                           ` Richard Stallman
  2007-10-16 19:26                             ` Leo
                                               ` (2 more replies)
  0 siblings, 3 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-16 19:09 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

    > Ok, but when mailcap finds these kinds of documents,
    > should it run the external program or should it use doc-view?

    I think on Gnus attachments of PDF/PS/DVI files it should now use doc-view.

What do others think about this question?  Does anyone disagree with that?

    > This seems to be a suggestion for changing the Gnus mailcap
    > feature.  Is that right?

    No, the mailcap feature only returns the names of the external programs.
    So how to use them is a matter of other packages.  Gnus always runs the
    first found program to view the Gnus attachment.

Is there a difference between "the mailcap feature" and "deciding what
to do based on mime types"?  In your other message you said that it
can specify a Lisp expression instead of an external program.  If we
want Gnus to use doc-view, we would do it that way, right?

      However, I think Dired
    should get programs names from the mailcap feature, and present them in the
    minibuffer activated by ! in Dired to allow the user select the desired
    program.

The usual thing we want Dired to do with a PDF/PS/DVI file is
doc-view.  But you can do that by typing RET or e.  Therefore, it is
ok if ! always offers the external program.

By contrast, you and I am proposing that Gnus prefer doc-view to the
external program, for these files.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-16 19:09                           ` Richard Stallman
@ 2007-10-16 19:26                             ` Leo
  2007-10-17  5:03                               ` Richard Stallman
  2007-10-16 20:43                             ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Reiner Steib
  2007-10-16 23:52                             ` Please install: Some improvements to doc-view.el Juri Linkov
  2 siblings, 1 reply; 98+ messages in thread
From: Leo @ 2007-10-16 19:26 UTC (permalink / raw)
  To: emacs-devel

On 2007-10-16 20:09 +0100, Richard Stallman wrote:
>     > Ok, but when mailcap finds these kinds of documents,
>     > should it run the external program or should it use doc-view?
>
>     I think on Gnus attachments of PDF/PS/DVI files it should now use doc-view.
>
> What do others think about this question?  Does anyone disagree with that?

Only if it also works for Emacs running in terminal.

-- 
.:  Leo  :.  [ sdl.web AT gmail.com ]  .:  [ GPG Key: 9283AA3F ]  :.

       Use the most powerful email client -- http://gnus.org/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* doc-view and mailcap (was: Please install: Some improvements to doc-view.el)
  2007-10-16 19:09                           ` Richard Stallman
  2007-10-16 19:26                             ` Leo
@ 2007-10-16 20:43                             ` Reiner Steib
  2007-10-17  1:16                               ` doc-view and mailcap Stefan Monnier
  2007-10-17  5:03                               ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Richard Stallman
  2007-10-16 23:52                             ` Please install: Some improvements to doc-view.el Juri Linkov
  2 siblings, 2 replies; 98+ messages in thread
From: Reiner Steib @ 2007-10-16 20:43 UTC (permalink / raw)
  To: Richard Stallman; +Cc: Juri Linkov, emacs-devel

On Tue, Oct 16 2007, Richard Stallman wrote:

>     > Ok, but when mailcap finds these kinds of documents,
>     > should it run the external program or should it use doc-view?
>
>     I think on Gnus attachments of PDF/PS/DVI files it should now
>     use doc-view.
>
> What do others think about this question?  Does anyone disagree with that?

I didn't have time to try doc-view yet (and currently the trunk
doesn't bootstrap for me; will look into this later), so I don't know
if doc-view makes sense for attachments.

Gnus wants to stay compatible with Emacs 21 and XEmacs 21.4.  When
adding doc-view specific entries, please do it in a compatible way.

(Additionally, such non-bugfix changes should not go into the stable
Gnus version, I think.)

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-16 19:09                           ` Richard Stallman
  2007-10-16 19:26                             ` Leo
  2007-10-16 20:43                             ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Reiner Steib
@ 2007-10-16 23:52                             ` Juri Linkov
  2 siblings, 0 replies; 98+ messages in thread
From: Juri Linkov @ 2007-10-16 23:52 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

> Is there a difference between "the mailcap feature" and "deciding what
> to do based on mime types"?  In your other message you said that it
> can specify a Lisp expression instead of an external program.  If we
> want Gnus to use doc-view, we would do it that way, right?

Yes, it seems this is just a matter of adding

     ("application/postscript"
      (viewer . doc-view-mode)
      (test   . (fboundp 'doc-view-mode))
      (type   . "application/postscript"))
     ("application/pdf"
      (viewer . doc-view-mode)
      (test   . (fboundp 'doc-view-mode))
      (type   . "application/pdf"))
     ("application/dvi"
      (viewer . doc-view-mode)
      (test   . (fboundp 'doc-view-mode))
      (type   . "application/dvi"))

to `mailcap-mime-data'.

>       However, I think Dired
>     should get programs names from the mailcap feature, and present them in the
>     minibuffer activated by ! in Dired to allow the user select the desired
>     program.
>
> The usual thing we want Dired to do with a PDF/PS/DVI file is
> doc-view.  But you can do that by typing RET or e.  Therefore, it is
> ok if ! always offers the external program.

I agree.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-16 20:43                             ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Reiner Steib
@ 2007-10-17  1:16                               ` Stefan Monnier
  2007-10-17 14:10                                 ` Richard Stallman
  2007-10-17  5:03                               ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Richard Stallman
  1 sibling, 1 reply; 98+ messages in thread
From: Stefan Monnier @ 2007-10-17  1:16 UTC (permalink / raw)
  To: rms; +Cc: Juri Linkov, emacs-devel

> I didn't have time to try doc-view yet (and currently the trunk
> doesn't bootstrap for me; will look into this later), so I don't know
> if doc-view makes sense for attachments.

> Gnus wants to stay compatible with Emacs 21 and XEmacs 21.4.  When
> adding doc-view specific entries, please do it in a compatible way.

> (Additionally, such non-bugfix changes should not go into the stable
> Gnus version, I think.)

For what it's worth, w.r.t attachments, I see no problem with Gnus's
attachment and doc-view support: if viewed internally the attachment will
use doc-view-mode and if used externally it'll use whichever program you
prefer (xpdf, xdvi, gv, evince, ...).


        Stefan

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap (was: Please install: Some improvements to doc-view.el)
  2007-10-16 20:43                             ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Reiner Steib
  2007-10-17  1:16                               ` doc-view and mailcap Stefan Monnier
@ 2007-10-17  5:03                               ` Richard Stallman
  2007-10-17 17:59                                 ` doc-view and mailcap Reiner Steib
  1 sibling, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-17  5:03 UTC (permalink / raw)
  To: Reiner Steib; +Cc: juri, emacs-devel

    I didn't have time to try doc-view yet (and currently the trunk
    doesn't bootstrap for me; will look into this later), so I don't know
    if doc-view makes sense for attachments.

Would you please report back when you are able to try it?

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-16 19:26                             ` Leo
@ 2007-10-17  5:03                               ` Richard Stallman
  2007-10-17 10:15                                 ` Leo
  0 siblings, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-17  5:03 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

    >     I think on Gnus attachments of PDF/PS/DVI files it should now use doc-view.
    >
    > What do others think about this question?  Does anyone disagree with that?

    Only if it also works for Emacs running in terminal.

If you are not running on a terminal, will the external program work?
I doubt it.

So we lose nothing by selecting doc-view instead.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-17  5:03                               ` Richard Stallman
@ 2007-10-17 10:15                                 ` Leo
  2007-10-17 20:49                                   ` Richard Stallman
  0 siblings, 1 reply; 98+ messages in thread
From: Leo @ 2007-10-17 10:15 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

On 2007-10-17 06:03 +0100, Richard Stallman wrote:
>     >     I think on Gnus attachments of PDF/PS/DVI files it should now use doc-view.
>     >
>     > What do others think about this question?  Does anyone disagree with that?
>
>     Only if it also works for Emacs running in terminal.
>
> If you are not running on a terminal, will the external program work?
> I doubt it.

Yes. By terminal I mean "XTerm" etc.

> So we lose nothing by selecting doc-view instead.

-- 
.:  Leo  :.  [ sdl.web AT gmail.com ]  .:  [ GPG Key: 9283AA3F ]  :.

       Use the most powerful email client -- http://gnus.org/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17  1:16                               ` doc-view and mailcap Stefan Monnier
@ 2007-10-17 14:10                                 ` Richard Stallman
  2007-10-17 14:39                                   ` Stefan Monnier
  0 siblings, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-17 14:10 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: juri, emacs-devel

    For what it's worth, w.r.t attachments, I see no problem with Gnus's
    attachment and doc-view support: if viewed internally the attachment will
    use doc-view-mode and if used externally it'll use whichever program you
    prefer (xpdf, xdvi, gv, evince, ...).

I don't understand the "ifs" in the last sentence.  What condition
would choose between those two methods

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 14:10                                 ` Richard Stallman
@ 2007-10-17 14:39                                   ` Stefan Monnier
  2007-10-17 16:55                                     ` Reiner Steib
  2007-10-18  5:02                                     ` Richard Stallman
  0 siblings, 2 replies; 98+ messages in thread
From: Stefan Monnier @ 2007-10-17 14:39 UTC (permalink / raw)
  To: rms; +Cc: juri, emacs-devel

>     For what it's worth, w.r.t attachments, I see no problem with Gnus's
>     attachment and doc-view support: if viewed internally the attachment will
>     use doc-view-mode and if used externally it'll use whichever program you
>     prefer (xpdf, xdvi, gv, evince, ...).

> I don't understand the "ifs" in the last sentence.  What condition
> would choose between those two methods

The user:  when right-clicking on the attachment, the context menu allows
you to view the attachment either internally or externally (or to save).


        Stefan

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 14:39                                   ` Stefan Monnier
@ 2007-10-17 16:55                                     ` Reiner Steib
  2007-10-17 23:36                                       ` Juri Linkov
  2007-10-18  5:02                                     ` Richard Stallman
  1 sibling, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-10-17 16:55 UTC (permalink / raw)
  To: emacs-devel

On Wed, Oct 17 2007, Stefan Monnier wrote:

>>     if viewed internally the attachment will use doc-view-mode and
>>     if used externally it'll use whichever program you prefer
>>     (xpdf, xdvi, gv, evince, ...).
>
>> I don't understand the "ifs" in the last sentence.  What condition
>> would choose between those two methods
>
> The user:  when right-clicking on the attachment, the context menu allows
> you to view the attachment either internally or externally (or to save).

Beside choosing interactively, it can be customized using the
variables described in (info "(emacs-mime)Display Customization").

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17  5:03                               ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Richard Stallman
@ 2007-10-17 17:59                                 ` Reiner Steib
  2007-10-17 20:32                                   ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-10-17 17:59 UTC (permalink / raw)
  To: Richard Stallman; +Cc: Tassilo Horn, emacs-devel

On Wed, Oct 17 2007, Richard Stallman wrote:

>     I didn't have time to try doc-view yet [...], so I don't know if
>     doc-view makes sense for attachments.
>
> Would you please report back when you are able to try it?

I had a quick look at `doc-view.el'.  There's a security issue when
using `doc-view' in mailcap.  mailcap attempts to use a safe viewer
with the safest options[1], e.g. it calls gv, gs and xdvi with the
"-safer" option [2].  AFAICS, `doc-view' doesn't use such options.  At
least "-dSAFER" should be added in `doc-view-ghostscript-options' and
`doc-view-ps2pdf-program' (or a new variable
`doc-view-ps2pdf-options'?) when used with mailcap (or even always?).
I don't know if similar security options are available for dvipdfm and
pdftotext.

Bye, Reiner.

[1]
,----[ (info "(emacs-mime)Display Customization") ]
| `mm-enable-external'
|      Indicate whether external MIME handlers should be used.
| 
|      If `t', all defined external MIME handlers are used.  If `nil',
|      files are saved to disk (`mailcap-save-binary-file').  If it is
|      the symbol `ask', you are prompted before the external MIME
|      handler is invoked.
| 
|      When you launch an attachment through mailcap (*note mailcap::) an
|      attempt is made to use a safe viewer with the safest options--this
|      isn't the case if you save it to disk and launch it in a different
|      way (command line or double-clicking).  Anyhow, if you want to be
|      sure not to launch any external programs, set this variable to
|      `nil' or `ask'.
`----

[2]

,----[ M-x occur RET safer RET ]
| 4 matches for "safer" in buffer: mailcap.el
|      94:      (viewer . "xdvi -safer %s")
|     140:      (viewer . "gv -safer %s")
|     160:      (viewer . "gv -safer %s")
|     166:      (viewer . "ghostview -dSAFER %s")
`----

,----[ gv(1) ]
| 	-safer, -nosafer
| 
| 		Whether to start ghostscript with the -dSAFER option.
`----

,----[ gs(1) ]
| 	-dSAFER
| 		Disables  the "deletefile"  and  "renamefile" operators
| 		and the  ability to open  files in any mode  other than
| 		read-only.   This  strongly  recommended for  spoolers,
| 		conversion  scripts  or  other  sensitive  environments
| 		where a badly   written or malicious PostScript program
| 		code must be prevented from changing important files.
`----

,----[ xdvi(1) ]
| 	-safer
| 		(.safer)  This option turns  on all  available security
| 		options; it is designed for  use when xdvi is called by
| 		a browser that  obtains a dvi or TeX  file from another
| 		site.  This option selects +nogssafer and +allowshell.
`----
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 17:59                                 ` doc-view and mailcap Reiner Steib
@ 2007-10-17 20:32                                   ` Tassilo Horn
  2007-10-17 21:45                                     ` Reiner Steib
  2007-10-18 20:08                                     ` Richard Stallman
  0 siblings, 2 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-17 20:32 UTC (permalink / raw)
  To: reiner.steib; +Cc: Richard Stallman, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 937 bytes --]

Reiner Steib <reinersteib+gmane@imap.cc> writes:

>> Would you please report back when you are able to try it?
>
> I had a quick look at `doc-view.el'.  There's a security issue when
> using `doc-view' in mailcap.  mailcap attempts to use a safe viewer
> with the safest options[1], e.g. it calls gv, gs and xdvi with the
> "-safer" option [2].  AFAICS, `doc-view' doesn't use such options.  At
> least "-dSAFER" should be added in `doc-view-ghostscript-options' and
> `doc-view-ps2pdf-program' (or a new variable
> `doc-view-ps2pdf-options'?) when used with mailcap (or even always?).

I do that now.  Thanks for the hint.

In order not to get confused with all those new versions of my patch,
I'll upload the current version to my homepage [1] in addition to
posting it here.  So if someone finally decides to install it, be sure
to use the version from my homepage.

(Of course you could add me as project member, too.)

Bye,
Tassilo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: doc-view.patch --]
[-- Type: text/x-patch, Size: 25923 bytes --]

Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.932
diff -u -r1.932 files.el
--- lisp/files.el	15 Oct 2007 02:07:46 -0000	1.932
+++ lisp/files.el	17 Oct 2007 20:26:17 -0000
@@ -2059,7 +2059,7 @@
      ("\\.\\(as\\|mi\\|sm\\)2\\'" . snmpv2-mode)
      ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)
      ("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MSDOG
-     ("\\.[eE]?[pP][sS]\\'" . ps-mode)
+     ("\\(?:DVI\\|EPS\\|P\\(?:DF\\|S\\)\\|dvi\\|eps\\|p\\(?:df\\|s\\)\\)" . doc-view-mode)
      ("configure\\.\\(ac\\|in\\)\\'" . autoconf-mode)
      ("BROWSE\\'" . ebrowse-tree-mode)
      ("\\.ebrowse\\'" . ebrowse-tree-mode)
Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.4
diff -u -r1.4 doc-view.el
--- lisp/doc-view.el	3 Oct 2007 23:39:58 -0000	1.4
+++ lisp/doc-view.el	17 Oct 2007 20:26:19 -0000
@@ -5,7 +5,7 @@
 ;; Author: Tassilo Horn <tassilo@member.fsf.org>
 ;; Maintainer: Tassilo Horn <tassilo@member.fsf.org>
 ;; Keywords: files, pdf, ps, dvi
-;; Version: <2007-10-02 Tue 18:21>
+;; Version: <2007-10-17 Wed 22:15>
 
 ;; This file is part of GNU Emacs.
 
@@ -26,9 +26,9 @@
 
 ;;; Requirements:
 
-;; doc-view.el requires GNU Emacs 22.1 or newer.  You also need GhostScript,
-;; `dvipdfm' which comes with TeTeX and `pdftotext', which comes with poppler
-;; (http://poppler.freedesktop.org/).
+;; doc-view.el requires GNU Emacs 22.1 or newer.  You also need Ghostscript,
+;; `dvipdfm' which comes with teTeX and `pdftotext', which comes with xpdf
+;; (http://www.foolabs.com/xpdf/) or poppler (http://poppler.freedesktop.org/).
 
 ;;; Commentary:
 
@@ -37,16 +37,19 @@
 ;; inside an Emacs buffer.  This buffer uses `doc-view-mode' which provides
 ;; convenient key bindings for browsing the document.
 ;;
-;; To use it simply do
+;; To use it simply open a document file with
 ;;
-;;     M-x doc-view RET
+;;     C-x C-f ~/path/to/document RET
 ;;
-;; and you'll be queried for a document to open.
+;; and the document will be converted and displayed, if your emacs supports png
+;; images.  With `C-c C-c' you can toggle between the rendered images
+;; representation and the source text representation of the document.  With
+;; `C-c C-e' you can switch to an appropriate editing mode for the document.
 ;;
 ;; 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 view
-;; that file again.  This reusing can be omitted if you provide a prefx
-;; argument to `doc-view'.  To delete all cached files use
+;; that file again.  To reconvert a document hit `g' (`doc-view-reconvert-doc')
+;; when displaying the document.  To delete all cached files use
 ;; `doc-view-clear-cache'.  To open the cache with dired, so that you can tidy
 ;; it out use `doc-view-dired-cache'.
 ;;
@@ -67,8 +70,6 @@
 ;; bottom-right corner of the desired slice.  To reset the slice use
 ;; `doc-view-reset-slice' (bound to `s r').
 ;;
-;; Dired users should have a look at `doc-view-dired'.
-;;
 ;; You can also search within the document.  The command `doc-view-search'
 ;; (bound to `C-s') queries for a search regexp and initializes a list of all
 ;; matching pages and messages how many match-pages were found.  After that you
@@ -80,17 +81,16 @@
 ;; conversion.  When that finishes and you're still viewing the document
 ;; (i.e. you didn't switch to another buffer) you're queried for the regexp
 ;; then.
+;;
+;; Dired users can simply hit `v' on a document file.  If it's a PS, PDF or DVI
+;; it will be opened using `doc-view-mode'.
+;;
 
 ;;; Configuration:
 
-;; Basically doc-view should be quite usable with its standard settings, so
-;; putting
-;;
-;;     (require 'doc-view)
-;;
-;; into your `user-init-file' should be enough.  If the images are too small or
-;; too big you should set the "-rXXX" option in `doc-view-ghostscript-options'
-;; to another value.  (The bigger your screen, the higher the value.)
+;; If the images are too small or too big you should set the "-rXXX" option in
+;; `doc-view-ghostscript-options' to another value.  (The bigger your screen,
+;; the higher the value.)
 ;;
 ;; This and all other options can be set with the customization interface.
 ;; Simply do
@@ -122,8 +122,8 @@
 (defcustom doc-view-ghostscript-options
   '("-dNOPAUSE" "-sDEVICE=png16m" "-dTextAlphaBits=4"
     "-dBATCH" "-dGraphicsAlphaBits=4" "-dQUIET"
-    "-r100")
-  "A list of options to give to ghostview."
+    "-dSAFER" "-r100")
+  "A list of options to give to ghostscript."
   :type '(sexp)
   :group 'doc-view)
 
@@ -201,7 +201,10 @@
 (defvar doc-view-current-info nil
   "Only used internally.")
 
-;;;; DocView Keymap
+(defvar doc-view-current-display nil
+  "Only used internally.")
+
+;;;; DocView Keymaps
 
 (defvar doc-view-mode-map
   (let ((map (make-sparse-keymap)))
@@ -235,9 +238,26 @@
     (define-key map (kbd "M-v")       'scroll-down)
     ;; Show the tooltip
     (define-key map (kbd "C-t")       'doc-view-show-tooltip)
+    ;; Toggle between text and image display or editing
+    (define-key map (kbd "C-c C-c")   'doc-view-toggle-display)
+    (define-key map (kbd "C-c C-e")   'doc-view-edit-doc)
+    ;; Reconvert the current document
+    (define-key map (kbd "g")         'doc-view-reconvert-doc)
     (suppress-keymap map)
     map)
-  "Keymap used by `doc-view-mode'.")
+  "Keymap used by `doc-view-mode' when displaying a doc as a set of images.")
+
+(defvar doc-view-mode-text-map
+  (let ((map (make-sparse-keymap)))
+    ;; Toggle between text and image display or editing
+    (define-key map (kbd "C-c C-c") 'doc-view-toggle-display)
+    (define-key map (kbd "C-c C-e") 'doc-view-edit-doc)
+    ;; Killing/burying the buffer (and the process)
+    (define-key map (kbd "q")         'bury-buffer)
+    (define-key map (kbd "k")         'doc-view-kill-proc-and-buffer)
+    (define-key map (kbd "C-x k")     'doc-view-kill-proc-and-buffer)
+    map)
+  "Keymap used by `doc-view-mode' when displaying a document as text.")
 
 ;;;; Navigation Commands
 
@@ -271,16 +291,16 @@
 			 (setq contexts (concat contexts "  - \"" m "\"\n")))
 		       contexts)))))
     ;; Update the buffer
-    (setq inhibit-read-only t)
-    (erase-buffer)
-    (let ((beg (point)))
-      (doc-view-insert-image (nth (1- page) doc-view-current-files)
-			     :pointer 'arrow)
-      (put-text-property beg (point) 'help-echo doc-view-current-info))
-    (insert "\n" doc-view-current-info)
-    (goto-char (point-min))
-    (forward-char)
-    (setq inhibit-read-only nil)))
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (let ((beg (point)))
+	(doc-view-insert-image (nth (1- page) doc-view-current-files)
+			       :pointer 'arrow)
+	(put-text-property beg (point) 'help-echo doc-view-current-info))
+      (insert "\n" doc-view-current-info)
+      (goto-char (point-min))
+      (forward-char))
+    (set-buffer-modified-p nil)))
 
 (defun doc-view-next-page (&optional arg)
   "Browse ARG pages forward."
@@ -317,42 +337,62 @@
     (error (doc-view-previous-page)
 	   (goto-char (point-max)))))
 
+(defun doc-view-kill-proc ()
+  "Kill the current converter process."
+  (interactive)
+  (when doc-view-current-converter-process
+    (kill-process doc-view-current-converter-process))
+  (when doc-view-current-timer
+    (cancel-timer doc-view-current-timer)
+    (setq doc-view-current-timer nil))
+  (setq mode-line-process nil))
+
 (defun doc-view-kill-proc-and-buffer ()
   "Kill the current converter process and buffer."
   (interactive)
+  (doc-view-kill-proc)
   (when (eq major-mode 'doc-view-mode)
-    (when doc-view-current-converter-process
-      (kill-process doc-view-current-converter-process))
-    (when doc-view-current-timer
-      (cancel-timer doc-view-current-timer)
-      (setq doc-view-current-timer nil))
     (kill-buffer (current-buffer))))
 
 ;;;; Conversion Functions
 
-(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'."
+(defun doc-view-reconvert-doc (&rest args)
+  "Reconvert the current document.
+Should be invoked when the cached images aren't up-to-date."
+  (interactive)
+  (let ((inhibit-read-only t)
+	(doc doc-view-current-doc))
+    (doc-view-kill-proc)
+    ;; Clear the old cached files
+    (when (file-exists-p (doc-view-current-cache-dir))
+      (dired-delete-file (doc-view-current-cache-dir) 'always))
+    (doc-view-kill-proc-and-buffer)
+    (find-file doc)))
+
+(defun doc-view-current-cache-dir ()
+  "Return the directory where the png files of the current doc should be saved.
+It's a subdirectory of `doc-view-cache-directory'."
   (if doc-view-current-cache-dir
       doc-view-current-cache-dir
-    (file-name-as-directory
-     (concat (file-name-as-directory doc-view-cache-directory)
-	     (with-temp-buffer
-	       (insert-file-contents-literally file)
-	       (md5 (current-buffer)))))))
+    (setq doc-view-current-cache-dir
+	  (file-name-as-directory
+	   (concat (file-name-as-directory doc-view-cache-directory)
+		   (let ((doc doc-view-current-doc))
+		     (with-temp-buffer
+		       (insert-file-contents-literally doc)
+		       (md5 (current-buffer)))))))))
 
 (defun doc-view-dvi->pdf-sentinel (proc event)
   "If DVI->PDF conversion was successful, convert the PDF to PNG now."
   (if (not (string-match "finished" event))
       (message "DocView: dvi->pdf process changed status to %s." event)
     (set-buffer (process-get proc 'buffer))
-    (setq doc-view-current-converter-process nil)
+    (setq doc-view-current-converter-process nil
+	  mode-line-process nil)
     (message "DocView: finished conversion from DVI to PDF!")
     ;; Now go on converting this PDF to a set of PNG files.
     (let* ((pdf (process-get proc 'pdf-file))
-	   (png (concat (doc-view-file-name-to-directory-name
-			 doc-view-current-doc)
+	   (png (concat (doc-view-current-cache-dir)
 			"page-%d.png")))
       (doc-view-pdf/ps->png pdf png))))
 
@@ -360,9 +400,10 @@
   "Convert DVI to PDF asynchrounously."
   (message "DocView: converting DVI to PDF now!")
   (setq doc-view-current-converter-process
-	(start-process "doc-view-dvi->pdf" doc-view-conversion-buffer
+	(start-process "dvi->pdf" doc-view-conversion-buffer
 		       doc-view-dvipdfm-program
-		       "-o" pdf dvi))
+		       "-o" pdf dvi)
+	mode-line-process (list (format ":%s" doc-view-current-converter-process)))
   (set-process-sentinel doc-view-current-converter-process
 			'doc-view-dvi->pdf-sentinel)
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
@@ -373,7 +414,8 @@
   (if (not (string-match "finished" event))
       (message "DocView: converter process changed status to %s." event)
     (set-buffer (process-get proc 'buffer))
-    (setq doc-view-current-converter-process nil)
+    (setq doc-view-current-converter-process nil
+	  mode-line-process nil)
     (when doc-view-current-timer
       (cancel-timer doc-view-current-timer)
       (setq doc-view-current-timer nil))
@@ -386,11 +428,12 @@
   (message "DocView: converting PDF or PS to PNG now!")
   (setq doc-view-current-converter-process
 	(apply 'start-process
-	       (append (list "doc-view-pdf/ps->png" doc-view-conversion-buffer
+	       (append (list "pdf/ps->png" doc-view-conversion-buffer
 			     doc-view-ghostscript-program)
 		       doc-view-ghostscript-options
 		       (list (concat "-sOutputFile=" png))
-		       (list pdf-ps))))
+		       (list pdf-ps)))
+	mode-line-process (list (format ":%s" doc-view-current-converter-process)))
   (process-put doc-view-current-converter-process
 	       'buffer (current-buffer))
   (set-process-sentinel doc-view-current-converter-process
@@ -398,7 +441,7 @@
   (when doc-view-conversion-refresh-interval
     (setq doc-view-current-timer
 	  (run-at-time "1 secs" doc-view-conversion-refresh-interval
-		       'doc-view-display
+		       'doc-view-display-maybe
 		       doc-view-current-doc))))
 
 (defun doc-view-pdf->txt-sentinel (proc event)
@@ -407,7 +450,8 @@
     (let ((current-buffer (current-buffer))
 	  (proc-buffer    (process-get proc 'buffer)))
       (set-buffer proc-buffer)
-      (setq doc-view-current-converter-process nil)
+      (setq doc-view-current-converter-process nil
+	    mode-line-process nil)
       (message "DocView: finished conversion from PDF to TXT!")
       ;; If the user looks at the DocView buffer where the conversion was
       ;; performed, search anew.  This time it will be queried for a regexp.
@@ -418,9 +462,10 @@
   "Convert PDF to TXT asynchrounously."
   (message "DocView: converting PDF to TXT now!")
   (setq doc-view-current-converter-process
-	(start-process "doc-view-pdf->txt" doc-view-conversion-buffer
+	(start-process "pdf->txt" doc-view-conversion-buffer
 		       doc-view-pdftotext-program "-raw"
-		       pdf txt))
+		       pdf txt)
+	mode-line-process (list (format ":%s" doc-view-current-converter-process)))
   (set-process-sentinel doc-view-current-converter-process
 			'doc-view-pdf->txt-sentinel)
   (process-put doc-view-current-converter-process 'buffer (current-buffer)))
@@ -429,65 +474,44 @@
   (if (not (string-match "finished" event))
       (message "DocView: converter process changed status to %s." event)
     (set-buffer (process-get proc 'buffer))
-    (setq doc-view-current-converter-process nil)
+    (setq doc-view-current-converter-process nil
+	  mode-line-process nil)
     (message "DocView: finished conversion from PS to PDF!")
     ;; Now we can transform to plain text.
     (doc-view-pdf->txt (process-get proc 'pdf-file)
-		       (concat (doc-view-file-name-to-directory-name
-				doc-view-current-doc)
+		       (concat (doc-view-current-cache-dir)
 			       "doc.txt"))))
 
 (defun doc-view-ps->pdf (ps pdf)
   "Convert PS to PDF asynchronously."
   (message "DocView: converting PS to PDF now!")
   (setq doc-view-current-converter-process
-	(start-process "doc-view-ps->pdf" doc-view-conversion-buffer
+	(start-process "ps->pdf" doc-view-conversion-buffer
 		       doc-view-ps2pdf-program
-		       ps pdf))
+		       ps pdf "-dSAFER")
+	mode-line-process (list (format ":%s" doc-view-current-converter-process)))
   (set-process-sentinel doc-view-current-converter-process
 			'doc-view-ps->pdf-sentinel)
   (process-put doc-view-current-converter-process 'buffer   (current-buffer))
   (process-put doc-view-current-converter-process 'pdf-file pdf))
 
-(defun doc-view-convert-doc (doc)
-  "Convert DOC 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'."
+(defun doc-view-convert-current-doc ()
+  "Convert `doc-view-current-doc' 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'."
   (clear-image-cache)
-  (let* ((dir (doc-view-file-name-to-directory-name doc))
-	 (png-file (concat (file-name-as-directory dir) "page-%d.png")))
-    (when (file-exists-p dir)
-      (dired-delete-file dir 'always))
-    (make-directory dir t)
-    (if (not (string= (file-name-extension doc) "dvi"))
+  (let ((png-file (concat (doc-view-current-cache-dir)
+			  "page-%d.png")))
+    (make-directory doc-view-current-cache-dir t)
+    (if (not (string= (file-name-extension doc-view-current-doc) "dvi"))
 	;; Convert to PNG images.
-	(doc-view-pdf/ps->png doc png-file)
-      ;; DVI files have to be converted to PDF before GhostScript can process
+	(doc-view-pdf/ps->png doc-view-current-doc png-file)
+      ;; DVI files have to be converted to PDF before Ghostscript can process
       ;; it.
-      (doc-view-dvi->pdf doc
-			 (concat (file-name-as-directory dir)
+      (doc-view-dvi->pdf doc-view-current-doc
+			 (concat (file-name-as-directory doc-view-current-cache-dir)
 				 "doc.pdf")))))
 
-;;;; DocView Mode
-
-(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-doc)
-  (make-local-variable 'doc-view-current-image)
-  (make-local-variable 'doc-view-current-page)
-  (make-local-variable 'doc-view-current-converter-process)
-  (make-local-variable 'doc-view-current-timer)
-  (make-local-variable 'doc-view-current-slice)
-  (make-local-variable 'doc-view-current-cache-dir)
-  (make-local-variable 'doc-view-current-info)
-  (make-local-variable 'doc-view-current-search-matches))
-
 ;;;; Slicing
 
 (defun doc-view-set-slice (x y width height)
@@ -555,19 +579,22 @@
 	nil
       (string< a b))))
 
+(defun doc-view-display-maybe (doc)
+  "Call `doc-view-display' iff we're in the image display."
+  (when (eq doc-view-current-display 'image)
+    (doc-view-display doc)))
+
 (defun doc-view-display (doc)
   "Start viewing the document DOC."
-  (let ((dir (doc-view-file-name-to-directory-name doc)))
-    (set-buffer (format "*DocView: %s*" doc))
-    (setq doc-view-current-files
-	  (sort (directory-files dir t "page-[0-9]+\\.png" t)
-		'doc-view-sort))
-    (when (> (length doc-view-current-files) 0)
-      (doc-view-goto-page doc-view-current-page))))
+  (set-buffer (get-file-buffer doc))
+  (setq doc-view-current-files
+	(sort (directory-files (doc-view-current-cache-dir) t
+			       "page-[0-9]+\\.png" t)
+	      'doc-view-sort))
+  (when (> (length doc-view-current-files) 0)
+    (doc-view-goto-page doc-view-current-page)))
 
 (defun doc-view-buffer-message ()
-  (setq inhibit-read-only t)
-  (erase-buffer)
   (insert (propertize "Welcome to DocView!" 'face 'bold)
 	  "\n"
 	  "
@@ -580,12 +607,58 @@
 
 `q' : Bury this buffer.  Conversion will go on in background.
 `k' : Kill the conversion process and this buffer.\n")
-  (setq inhibit-read-only nil))
+  (set-buffer-modified-p nil))
 
 (defun doc-view-show-tooltip ()
   (interactive)
   (tooltip-show doc-view-current-info))
 
+;;;;; Toggle between text and image display
+
+(defun doc-view-toggle-display ()
+  "Start or stop displaying a document file as a set of images.
+This command toggles between showing the text of the document
+file and showing the document as a set of images."
+  (interactive)
+  (if (get-text-property (point-min) 'display)
+      ;; Switch to text display
+      (let ((inhibit-read-only t))
+	(erase-buffer)
+	(insert-file-contents doc-view-current-doc)
+	(use-local-map doc-view-mode-text-map)
+	(setq mode-name "DocView[text]"
+	      doc-view-current-display 'text)
+	(if (called-interactively-p)
+	    (message "Repeat this command to go back to displaying the file as images")))
+    ;; Switch to image display
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (doc-view-buffer-message)
+      (setq doc-view-current-page (or doc-view-current-page 1))
+      (if (file-exists-p (doc-view-current-cache-dir))
+	  (progn
+	    (message "DocView: using cached files!")
+	    (doc-view-display doc-view-current-doc))
+	(doc-view-convert-current-doc))
+      (use-local-map doc-view-mode-map)
+      (setq mode-name (format "DocView")
+	    doc-view-current-display 'image)
+      (if (called-interactively-p)
+	  (message "Repeat this command to go back to displaying the file as text"))))
+  (set-buffer-modified-p nil))
+
+;;;;; Leave doc-view-mode and open the file for edit
+
+(defun doc-view-edit-doc ()
+  "Leave `doc-view-mode' and open the current doc with an appropriate editing mode."
+  (interactive)
+  (let ((filename doc-view-current-doc)
+	(auto-mode-alist (append '(("\\.[eE]?[pP][sS]\\'" . ps-mode)
+				   ("\\.\\(pdf\\|PDF\\|dvi\\|DVI\\)$" . fundamental-mode))
+				 auto-mode-alist)))
+    (kill-buffer (current-buffer))
+    (find-file filename)))
+
 ;;;; Searching
 
 (defun doc-view-search-internal (regexp file)
@@ -636,8 +709,7 @@
   (interactive)
   ;; New search, so forget the old results.
   (setq doc-view-current-search-matches nil)
-  (let ((txt (concat (doc-view-file-name-to-directory-name
-		      doc-view-current-doc)
+  (let ((txt (concat (doc-view-current-cache-dir)
 		     "doc.txt")))
     (if (file-readable-p txt)
 	(progn
@@ -660,14 +732,12 @@
 	    ;; Doc is a PS, so convert it to PDF (which will be converted to
 	    ;; TXT thereafter).
 	    (doc-view-ps->pdf doc-view-current-doc
-			      (concat (doc-view-file-name-to-directory-name
-				       doc-view-current-doc)
+			      (concat (doc-view-current-cache-dir)
 				      "doc.pdf")))
 	   ((string= ext "dvi")
 	    ;; Doc is a DVI.  This means that a doc.pdf already exists in its
 	    ;; cache subdirectory.
-	    (doc-view-pdf->txt (concat (doc-view-file-name-to-directory-name
-					doc-view-current-doc)
+	    (doc-view-pdf->txt (concat (doc-view-current-cache-dir)
 				       "doc.pdf")
 			       txt))
 	   (t (error "DocView doesn't know what to do"))))))))
@@ -698,52 +768,42 @@
 	     (y-or-n-p "No more matches before current page.  Wrap to last match? "))
 	(doc-view-goto-page (caar (last doc-view-current-search-matches)))))))
 
-;;;; User Interface Commands
+;;;; User interface commands and the mode
+
+(put 'doc-view-mode 'mode-class 'special)
 
 ;;;###autoload
-(defun doc-view (no-cache &optional file)
-  "Convert FILE to png and start viewing it.
-If no FILE is given, query for on.
-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.")
-    (let* ((doc (or file
-		    (expand-file-name
-		     (let ((completion-ignored-extensions
-			    ;; Don't hide files doc-view can display
-			    (remove-if (lambda (str)
-					 (string-match "\\.\\(ps\\|pdf\\|dvi\\)$"
-						       str))
-				       completion-ignored-extensions)))
-		       (read-file-name "File: " nil nil t)))))
-	   (buffer (get-buffer-create (format "*DocView: %s*" doc)))
-	   (dir (doc-view-file-name-to-directory-name doc)))
-      (switch-to-buffer buffer)
-      (doc-view-buffer-message)
-      (doc-view-mode)
-      (setq doc-view-current-doc doc)
-      (setq doc-view-current-page 1)
-      (if (not (and (file-exists-p dir)
-		    (not no-cache)))
-	  (progn
-	    (setq doc-view-current-cache-dir nil)
-	    (doc-view-convert-doc doc-view-current-doc))
-	(message "DocView: using cached files!")
-	(doc-view-display doc-view-current-doc)))))
-
-(defun doc-view-dired (no-cache)
-  "View the current dired file with doc-view.
-NO-CACHE is the same as in `doc-view'.
-
-You might want to bind this command to a dired key, e.g.
-
-    (define-key dired-mode-map (kbd \"C-c d\") 'doc-view-dired)"
-  (interactive "P")
-  (doc-view no-cache (dired-get-file-for-visit)))
+(define-derived-mode doc-view-mode nil "DocView"
+  "Major mode in DocView buffers.
+You can use \\<doc-view-mode-map>\\[doc-view-toggle-display] to
+toggle between display as a set of images and display as text."
+  :group 'doc-view
+  (make-local-variable 'doc-view-current-files)
+  (make-local-variable 'doc-view-current-doc)
+  (make-local-variable 'doc-view-current-image)
+  (make-local-variable 'doc-view-current-page)
+  (make-local-variable 'doc-view-current-converter-process)
+  (make-local-variable 'doc-view-current-timer)
+  (make-local-variable 'doc-view-current-slice)
+  (make-local-variable 'doc-view-current-cache-dir)
+  (make-local-variable 'doc-view-current-info)
+  (make-local-variable 'doc-view-current-search-matches)
+  (setq doc-view-current-doc (buffer-file-name))
+  (insert-file-contents doc-view-current-doc)
+  (use-local-map doc-view-mode-text-map)
+  (setq mode-name "DocView[text]"
+	doc-view-current-display 'text
+	buffer-read-only t
+	revert-buffer-function 'doc-view-reconvert-doc)
+  ;; Switch to image display if possible
+  (if (and (display-images-p)
+	   (image-type-available-p 'png)
+	   (not (get-text-property (point-min) 'display)))
+      (doc-view-toggle-display))
+  (message
+   "%s"
+   (substitute-command-keys
+    "Type \\[doc-view-toggle-display] to toggle between image and text display.")))
 
 (defun doc-view-clear-cache ()
   "Delete the whole cache (`doc-view-cache-directory')."
Index: lisp/bindings.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.185
diff -u -r1.185 bindings.el
--- lisp/bindings.el	6 Oct 2007 22:15:43 -0000	1.185
+++ lisp/bindings.el	17 Oct 2007 20:26:19 -0000
@@ -536,7 +536,7 @@
        '(".elc" ".lof"
 	 ".glo" ".idx" ".lot"
 	 ;; TeX-related
-	 ".dvi" ".fmt" ".tfm" ".pdf"
+	 ".fmt" ".tfm"
 	 ;; Java compiled
 	 ".class"
 	 ;; CLISP
Index: lisp/ChangeLog
===================================================================
RCS file: /sources/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.11948
diff -u -r1.11948 ChangeLog
--- lisp/ChangeLog	17 Oct 2007 16:24:33 -0000	1.11948
+++ lisp/ChangeLog	17 Oct 2007 20:26:26 -0000
@@ -1,3 +1,16 @@
+2007-10-17  Tassilo Horn  <tassilo@member.fsf.org>
+
+	* bindings.el (completion-ignored-extensions): Remove pdf and dvi
+	extensions since they can be viewed with doc-view.
+
+	* files.el (auto-mode-alist): Make doc-view-mode the default mode
+	for pdf, ps and dvi files.
+
+	* doc-view.el: Make doc-view-mode the standard mode for viewing
+	pdf, [e]ps and dvi files and add binding C-c C-c to toggle between
+	text and image display.  Add binding C-c C-e to switch to an
+	editing mode.
+
 2007-10-17  Stefan Monnier  <monnier@iro.umontreal.ca>
 
 	* progmodes/compile.el (compilation-next-error-function): Fix timestamp

[-- Attachment #3: Type: text/plain, Size: 55 bytes --]

__________
[1] http://www.tsdh.de/stuff/doc-view.patch

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-17 10:15                                 ` Leo
@ 2007-10-17 20:49                                   ` Richard Stallman
  2007-10-17 21:12                                     ` Leo
  2007-10-17 22:04                                     ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Reiner Steib
  0 siblings, 2 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-17 20:49 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

    >     >     I think on Gnus attachments of PDF/PS/DVI files it should now use doc-view.
    >     >
    >     > What do others think about this question?  Does anyone disagree with that?
    >
    >     Only if it also works for Emacs running in terminal.
    >
    > If you are not running on a terminal, will the external program work?
    > I doubt it.

    Yes. By terminal I mean "XTerm" etc.

That is a good point.  If the current terminal is not graphical,
Gnus should fall back on the external displayer, since in some
cases that will work.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-17 20:49                                   ` Richard Stallman
@ 2007-10-17 21:12                                     ` Leo
  2007-10-19  5:40                                       ` Richard Stallman
  2007-10-17 22:04                                     ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Reiner Steib
  1 sibling, 1 reply; 98+ messages in thread
From: Leo @ 2007-10-17 21:12 UTC (permalink / raw)
  To: emacs-devel

On 2007-10-17 21:49 +0100, Richard Stallman wrote:
>     >     >     I think on Gnus attachments of PDF/PS/DVI files it should now use doc-view.
>     >     >
>     >     > What do others think about this question?  Does anyone disagree with that?
>     >
>     >     Only if it also works for Emacs running in terminal.
>     >
>     > If you are not running on a terminal, will the external program work?
>     > I doubt it.
>
>     Yes. By terminal I mean "XTerm" etc.
>
> That is a good point.  If the current terminal is not graphical,
> Gnus should fall back on the external displayer, since in some
> cases that will work.

Many programs can display images in terminals (including the linux
consoles) for example 'elinks' and 'w3m'. I'd be best if Emacs can also
do it.

-- 
.:  Leo  :.  [ sdl.web AT gmail.com ]  .:  [ GPG Key: 9283AA3F ]  :.

       Use the most powerful email client -- http://gnus.org/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 20:32                                   ` Tassilo Horn
@ 2007-10-17 21:45                                     ` Reiner Steib
  2007-10-18  4:19                                       ` Stefan Monnier
  2007-10-18  6:24                                       ` Tassilo Horn
  2007-10-18 20:08                                     ` Richard Stallman
  1 sibling, 2 replies; 98+ messages in thread
From: Reiner Steib @ 2007-10-17 21:45 UTC (permalink / raw)
  To: emacs-devel

On Wed, Oct 17 2007, Tassilo Horn wrote:

> Reiner Steib <reinersteib+gmane@imap.cc> writes:
>> At least "-dSAFER" should be added in
>> `doc-view-ghostscript-options' and `doc-view-ps2pdf-program' [...]
>
> I do that now.  Thanks for the hint.
>
> In order not to get confused with all those new versions of my patch,
> I'll upload the current version to my homepage [1] in addition to
> posting it here.  So if someone finally decides to install it, be sure
> to use the version from my homepage.

As I understood, these changes have already been approved by Richard,
so I've installed it.  If not, please let me know.

A few remarks:

- Your patch mixed my minor corrections and your changes.  Both should
  be mentioned in separate ChangeLog entries.

- The ChangeLog entry...

	* doc-view.el: Make doc-view-mode the standard mode for viewing
	pdf, [e]ps and dvi files and add binding C-c C-c to toggle between
	text and image display.  Add binding C-c C-e to switch to an
	editing mode.

  ... is quite terse, IMHO.  Usually we add the relevant functions or
  variables.  (`C-x 4 a' (in the lisp or diff buffer) and friends are
  handy for this.)

- The security enhancements should be mentioned in the ChangeLog, so I
  added...

	(doc-view-ghostscript-options, doc-view-ps->pdf): Add "-dSAFER" to
	avoid security problems when rendering files untrusted sources.

> (Of course you could add me as project member, too.)

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* doc-view and mailcap (was: Please install: Some improvements to doc-view.el)
  2007-10-17 20:49                                   ` Richard Stallman
  2007-10-17 21:12                                     ` Leo
@ 2007-10-17 22:04                                     ` Reiner Steib
  2007-10-17 23:35                                       ` doc-view and mailcap Juri Linkov
  1 sibling, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-10-17 22:04 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

On Wed, Oct 17 2007, Richard Stallman wrote:

> If the current terminal is not graphical, Gnus should fall back on
> the external displayer, since in some cases that will work.

On Wed, Oct 17 2007, Juri Linkov wrote:

[...]
> Yes, it seems this is just a matter of adding
>
>      ("application/postscript"
>       (viewer . doc-view-mode)
>       (test   . (fboundp 'doc-view-mode))
>       (type   . "application/postscript"))
[...]
> to `mailcap-mime-data'.

To follow Richard's suggestion, the test should be something like...

(and (fboundp 'doc-view-mode)
     (display-graphic-p)
     (image-type-available-p 'png))

or...

(and (fboundp 'doc-view-mode-p)
     (doc-view-mode-p))

with (in `doc-view.el')...

(defun doc-view-mode-p ()
  (and (display-graphic-p)
       (image-type-available-p 'png)))

Shouldn't it?

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Doc-view as default viewer for pdf, ps and dvi files
  2007-10-11  1:28                           ` Doc-view as default viewer for pdf, ps and dvi files (was: Please install: Some improvements to doc-view.el) Tassilo Horn
  2007-10-12  2:46                             ` Richard Stallman
@ 2007-10-17 23:34                             ` Juri Linkov
  2007-10-18  6:47                               ` Tassilo Horn
  2007-10-18  8:28                               ` Tassilo Horn
  1 sibling, 2 replies; 98+ messages in thread
From: Juri Linkov @ 2007-10-17 23:34 UTC (permalink / raw)
  To: emacs-devel; +Cc: Richard Stallman

> With `C-c C-c' one can toggle between image and source text display.
> Both display modes are read-only.  With `C-c C-e' one can switch to an
> appropriate editing mode -- ps-mode for ps files and fundamental-mode
> for pdf and dvi files.

I still have doubts that `C-c C-e' is necessary.  Isn't it possible
to put .ps files in ps-mode, and also put it in `doc-view-minor-mode'?
It would be like `image-minor-mode'.

Also rebinding `C-x k' to a different command is not a good thing.
When the user has a habit to type `C-x k RET' to kill the current buffer,
then if a pdf file was visited from the dired buffer, typing `C-x k RET'
in doc-view-mode will visit it again (rebound `C-x k' will kill the buffer
without confirmation, and RET will revisit from the dired buffer :-)

I suggest you to bind `q' to `doc-view-kill-proc-and-buffer' and don't
rebind `C-x k'.

Also I noticed that often the message
"DocView: finished conversion from PDF/PS to PNG!"
overwrites the message
"Type C-c C-c to toggle between image and text display."
in the minibuffer, so the user may miss this information.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 22:04                                     ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Reiner Steib
@ 2007-10-17 23:35                                       ` Juri Linkov
  2007-10-18  7:31                                         ` Reiner Steib
  0 siblings, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-10-17 23:35 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

> To follow Richard's suggestion, the test should be something like...
>
> (and (fboundp 'doc-view-mode)
>      (display-graphic-p)
>      (image-type-available-p 'png))
>
> or...
>
> (and (fboundp 'doc-view-mode-p)
>      (doc-view-mode-p))
>
> with (in `doc-view.el')...
>
> (defun doc-view-mode-p ()
>   (and (display-graphic-p)
>        (image-type-available-p 'png)))
>
> Shouldn't it?

I think the second variant is better.  Since this is a matter of doc-view
to decide if it can support displaying, it should have such a function
(autoloaded).

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 16:55                                     ` Reiner Steib
@ 2007-10-17 23:36                                       ` Juri Linkov
  0 siblings, 0 replies; 98+ messages in thread
From: Juri Linkov @ 2007-10-17 23:36 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 638 bytes --]

>>>     if viewed internally the attachment will use doc-view-mode and
>>>     if used externally it'll use whichever program you prefer
>>>     (xpdf, xdvi, gv, evince, ...).
>>
>>> I don't understand the "ifs" in the last sentence.  What condition
>>> would choose between those two methods
>>
>> The user:  when right-clicking on the attachment, the context menu allows
>> you to view the attachment either internally or externally (or to save).
>
> Beside choosing interactively, it can be customized using the
> variables described in (info "(emacs-mime)Display Customization").

Here is a test file to see how well it now works :)


[-- Attachment #2: refcard.pdf --]
[-- Type: application/pdf, Size: 75621 bytes --]

[-- Attachment #3: Type: text/plain, Size: 45 bytes --]


-- 
Juri Linkov
http://www.jurta.org/emacs/

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Scrolling in doc-view
  2007-10-15 20:58                         ` Tassilo Horn
@ 2007-10-17 23:49                           ` Chong Yidong
  2007-10-18  6:27                             ` Tassilo Horn
  2007-10-18  8:29                             ` Tassilo Horn
  0 siblings, 2 replies; 98+ messages in thread
From: Chong Yidong @ 2007-10-17 23:49 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

The newly-installed doc-view package doesn't properly handle images
that are wider or taller than the Emacs window.  The left/right keys
don't scroll the image horizontally, and scrolling vertically is
cumbersome (because once you reach the bottom of the image, it
disappears without warning, whereupon trying to scroll back up jumps
back to the top of the image).

Image-mode used to have the same problems, but I recently enhanced it
so that large images can be scrolled vertically and horizontally.  It
would be good to avoid re-introducing these annoyances with doc-view
mode.  Could you take a look at the relevant functions in
image-mode.el (image-forward-hscroll, image-backward-hscroll,
image-previous-line, image-next-line, etc.) and try to use them in
doc-view mode?

Thanks.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 21:45                                     ` Reiner Steib
@ 2007-10-18  4:19                                       ` Stefan Monnier
  2007-10-18  7:33                                         ` Reiner Steib
  2007-10-18  6:24                                       ` Tassilo Horn
  1 sibling, 1 reply; 98+ messages in thread
From: Stefan Monnier @ 2007-10-18  4:19 UTC (permalink / raw)
  To: emacs-devel

> 	(doc-view-ghostscript-options, doc-view-ps->pdf): Add "-dSAFER" to
> 	avoid security problems when rendering files untrusted sources.

Actually, the first of those two lines should be in ChangeLog but the second
should in the file's comments.


        Stefan

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 14:39                                   ` Stefan Monnier
  2007-10-17 16:55                                     ` Reiner Steib
@ 2007-10-18  5:02                                     ` Richard Stallman
  1 sibling, 0 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-18  5:02 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: juri, emacs-devel

    The user:  when right-clicking on the attachment, the context menu allows
    you to view the attachment either internally or externally (or to save).

That sounds ok to me.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 21:45                                     ` Reiner Steib
  2007-10-18  4:19                                       ` Stefan Monnier
@ 2007-10-18  6:24                                       ` Tassilo Horn
  1 sibling, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-18  6:24 UTC (permalink / raw)
  To: emacs-devel

Reiner Steib <reinersteib+gmane@imap.cc> writes:

>> In order not to get confused with all those new versions of my patch,
>> I'll upload the current version to my homepage [1] in addition to
>> posting it here.  So if someone finally decides to install it, be
>> sure to use the version from my homepage.
>
> As I understood, these changes have already been approved by Richard,
> so I've installed it.  If not, please let me know.

Thanks!

And I'll obey your remarks the next time.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Scrolling in doc-view
  2007-10-17 23:49                           ` Scrolling in doc-view Chong Yidong
@ 2007-10-18  6:27                             ` Tassilo Horn
  2007-10-18  8:29                             ` Tassilo Horn
  1 sibling, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-18  6:27 UTC (permalink / raw)
  To: emacs-devel

Chong Yidong <cyd@stupidchicken.com> writes:

> The newly-installed doc-view package doesn't properly handle images
> that are wider or taller than the Emacs window.  The left/right keys
> don't scroll the image horizontally, and scrolling vertically is
> cumbersome (because once you reach the bottom of the image, it
> disappears without warning, whereupon trying to scroll back up jumps
> back to the top of the image).
>
> Image-mode used to have the same problems, but I recently enhanced it
> so that large images can be scrolled vertically and horizontally.  It
> would be good to avoid re-introducing these annoyances with doc-view
> mode.  Could you take a look at the relevant functions in
> image-mode.el (image-forward-hscroll, image-backward-hscroll,
> image-previous-line, image-next-line, etc.) and try to use them in
> doc-view mode?

Sure.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Doc-view as default viewer for pdf, ps and dvi files
  2007-10-17 23:34                             ` Juri Linkov
@ 2007-10-18  6:47                               ` Tassilo Horn
  2007-10-18  8:28                               ` Tassilo Horn
  1 sibling, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-18  6:47 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Richard Stallman, emacs-devel

Juri Linkov <juri@jurta.org> writes:

>> With `C-c C-c' one can toggle between image and source text display.
>> Both display modes are read-only.  With `C-c C-e' one can switch to
>> an appropriate editing mode -- ps-mode for ps files and
>> fundamental-mode for pdf and dvi files.
>
> I still have doubts that `C-c C-e' is necessary.  Isn't it possible to
> put .ps files in ps-mode, and also put it in `doc-view-minor-mode'?
> It would be like `image-minor-mode'.

Then I'd have to make doc-view-mode a minor mode, right?  Are there
other benefits except that you get font-locking for PS files then?

Currently I don't have too much time to work on this, but I'll put it on
my todo list.

> Also rebinding `C-x k' to a different command is not a good thing.
> When the user has a habit to type `C-x k RET' to kill the current buffer,
> then if a pdf file was visited from the dired buffer, typing `C-x k RET'
> in doc-view-mode will visit it again (rebound `C-x k' will kill the buffer
> without confirmation, and RET will revisit from the dired buffer :-)
>
> I suggest you to bind `q' to `doc-view-kill-proc-and-buffer' and don't
> rebind `C-x k'.

I like `q' to be bound to bury-buffer, but I agree that rebinding `C-x
k' isn't perfect and I'll take it out.

> Also I noticed that often the message
> "DocView: finished conversion from PDF/PS to PNG!"
> overwrites the message
> "Type C-c C-c to toggle between image and text display."
> in the minibuffer, so the user may miss this information.

Right.  But since I implemented this mode-line-process indicator, those
messages are superfluous anyway and I'll take them out.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 23:35                                       ` doc-view and mailcap Juri Linkov
@ 2007-10-18  7:31                                         ` Reiner Steib
  2007-11-25 22:53                                           ` Reiner Steib
  0 siblings, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-10-18  7:31 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

On Thu, Oct 18 2007, Juri Linkov wrote:

>> (and (fboundp 'doc-view-mode-p)
>>      (doc-view-mode-p))
>>
>> with (in `doc-view.el')...
>>
>> (defun doc-view-mode-p ()
>>   (and (display-graphic-p)

Maybe an additional test like "(executable-find
doc-view-ghostscript-program)" would be useful here.

>>        (image-type-available-p 'png)))
>>
>> Shouldn't it?
>
> I think the second variant is better.  Since this is a matter of doc-view
> to decide if it can support displaying, it should have such a function
> (autoloaded).

I agree.  And it should accept an argument TYPE (`postscript', `pdf',
`dvi') like `image-type-available-p' to decide it for each document
type, e.g. ...

      ("application/postscript"
       (viewer . doc-view-mode)
       (test   . (and (fboundp 'doc-view-mode-p)
                      (doc-view-mode-p 'postscript))
       (type   . "application/postscript"))

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-18  4:19                                       ` Stefan Monnier
@ 2007-10-18  7:33                                         ` Reiner Steib
  2007-10-18  8:24                                           ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-10-18  7:33 UTC (permalink / raw)
  To: emacs-devel

On Thu, Oct 18 2007, Stefan Monnier wrote:

>> 	(doc-view-ghostscript-options, doc-view-ps->pdf): Add "-dSAFER" to
>> 	avoid security problems when rendering files untrusted sources.
>
> Actually, the first of those two lines should be in ChangeLog but the second
> should in the file's comments.

Thanks for the correction.  I will add comments (unless Tassilo beats
me to it).

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-18  7:33                                         ` Reiner Steib
@ 2007-10-18  8:24                                           ` Tassilo Horn
  0 siblings, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-18  8:24 UTC (permalink / raw)
  To: emacs-devel

Reiner Steib <reinersteib+gmane@imap.cc> writes:

> On Thu, Oct 18 2007, Stefan Monnier wrote:
>
>>> 	(doc-view-ghostscript-options, doc-view-ps->pdf): Add "-dSAFER" to
>>> 	avoid security problems when rendering files untrusted sources.
>>
>> Actually, the first of those two lines should be in ChangeLog but the
>> second should in the file's comments.
>
> Thanks for the correction.  I will add comments (unless Tassilo beats
> me to it).

Please do so.  And please install my patch at [1].  It makes use of the
image-mode scrolling commands (works brilliant!) [2], removes the
rebinding of `C-x k' and all messages that aren't needed anymore because
of `mode-line-process' [3].

__________
[1] http://www.tsdh.de/stuff/doc-view.patch
[2] See Chong's message <87myuhuwrr.fsf_-_@stupidchicken.com>
[3] See Juri's message <878x61nx3k.fsf@jurta.org>

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Doc-view as default viewer for pdf, ps and dvi files
  2007-10-17 23:34                             ` Juri Linkov
  2007-10-18  6:47                               ` Tassilo Horn
@ 2007-10-18  8:28                               ` Tassilo Horn
  1 sibling, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-18  8:28 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@jurta.org> writes:

> I still have doubts that `C-c C-e' is necessary.  Isn't it possible to
> put .ps files in ps-mode, and also put it in `doc-view-minor-mode'?
> It would be like `image-minor-mode'.

Delayed.  If someone else wants to implement that, feel free to do so.

> Also rebinding `C-x k' to a different command is not a good thing.
> When the user has a habit to type `C-x k RET' to kill the current
> buffer, then if a pdf file was visited from the dired buffer, typing
> `C-x k RET' in doc-view-mode will visit it again (rebound `C-x k' will
> kill the buffer without confirmation, and RET will revisit from the
> dired buffer :-)
>
> I suggest you to bind `q' to `doc-view-kill-proc-and-buffer' and don't
> rebind `C-x k'.

I removed the `C-x k' binding but still use `k' for
`doc-view-kill-proc-and-buffer' because I like `q' to bury-buffer.

> Also I noticed that often the message
> "DocView: finished conversion from PDF/PS to PNG!"
> overwrites the message
> "Type C-c C-c to toggle between image and text display."
> in the minibuffer, so the user may miss this information.

I deleted all messages that became superfluous due to mode-line-process.

See my message <874pgou8xm.fsf@baldur.tsdh.de>.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Scrolling in doc-view
  2007-10-17 23:49                           ` Scrolling in doc-view Chong Yidong
  2007-10-18  6:27                             ` Tassilo Horn
@ 2007-10-18  8:29                             ` Tassilo Horn
  1 sibling, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-18  8:29 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel

Chong Yidong <cyd@stupidchicken.com> writes:

> The newly-installed doc-view package doesn't properly handle images
> that are wider or taller than the Emacs window.  The left/right keys
> don't scroll the image horizontally, and scrolling vertically is
> cumbersome (because once you reach the bottom of the image, it
> disappears without warning, whereupon trying to scroll back up jumps
> back to the top of the image).
>
> Image-mode used to have the same problems, but I recently enhanced it
> so that large images can be scrolled vertically and horizontally.  It
> would be good to avoid re-introducing these annoyances with doc-view
> mode.  Could you take a look at the relevant functions in
> image-mode.el (image-forward-hscroll, image-backward-hscroll,
> image-previous-line, image-next-line, etc.) and try to use them in
> doc-view mode?

Thanks for the hint.  Now I use your commands and it works brilliant!

See my message <874pgou8xm.fsf@baldur.tsdh.de>.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: mailcap viewers in dired; gnus-dired.el, mailcap.el
  2007-10-15  1:37                             ` Richard Stallman
  2007-10-15 23:46                               ` Juri Linkov
@ 2007-10-18 17:48                               ` Lars Magne Ingebrigtsen
  2007-10-19  5:40                                 ` Richard Stallman
  1 sibling, 1 reply; 98+ messages in thread
From: Lars Magne Ingebrigtsen @ 2007-10-18 17:48 UTC (permalink / raw)
  To: emacs-devel

Richard Stallman <rms@gnu.org> writes:

> However, it would be even better to install these features
> in the right place to start with.

I agree.

> I've seen several examples where Gnus developers added to Gnus a
> general facility which isn't specificly for reading news or mail.
> That's not the way to add these facilities.  They ought to be
> added in the right place, as separate facilities in Emacs.
>
> Can we arrange with Gnus maintainers to do this differently?

However, that hasn't been trivial in the past (what with the Emacs
feature freeze that lasted two years and all).  When a new, general
facility has been developed because Gnus needed it, it would be
counter-productive to not distribute it with Gnus just because it's not
Gnus-specific.

But when merging, the general stuff should not end up in the Gnus
directory, though.

-- 
(domestic pets only, the antidote for overdose, milk.)
  larsi@gnus.org * Lars Magne Ingebrigtsen

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-17 20:32                                   ` Tassilo Horn
  2007-10-17 21:45                                     ` Reiner Steib
@ 2007-10-18 20:08                                     ` Richard Stallman
  2007-10-18 20:30                                       ` Reiner Steib
  1 sibling, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-10-18 20:08 UTC (permalink / raw)
  To: emacs-devel; +Cc: Tassilo Horn, reiner.steib

Would someone please install Tassilo's latest changes, then ack?

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-18 20:08                                     ` Richard Stallman
@ 2007-10-18 20:30                                       ` Reiner Steib
  2007-10-18 21:22                                         ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-10-18 20:30 UTC (permalink / raw)
  To: Richard Stallman; +Cc: Tassilo Horn, emacs-devel

On Thu, Oct 18 2007, Richard Stallman wrote:

> Would someone please install Tassilo's latest changes, then ack?

ACK.  I modified change to `auto-mode-alist' (don't open PS and EPS
with doc-view by default) as this seem to be controversial.  IMHO, it
should do the same as image mode for XPM files: "Type C-c C-c to view
the image as an image."  IIUC, this has not been implemented for
doc-view yet, so I think we should open them with ps-mode for now.

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-18 20:30                                       ` Reiner Steib
@ 2007-10-18 21:22                                         ` Tassilo Horn
  2007-10-19  0:42                                           ` Juri Linkov
  2007-10-19 17:42                                           ` Richard Stallman
  0 siblings, 2 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-10-18 21:22 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

Reiner Steib <reinersteib+gmane@imap.cc> writes:

Hi!

>> Would someone please install Tassilo's latest changes, then ack?
>
> ACK.

Thanks.

> I modified change to `auto-mode-alist' (don't open PS and EPS with
> doc-view by default) as this seem to be controversial.

I agree.

> IMHO, it should do the same as image mode for XPM files: "Type C-c C-c
> to view the image as an image."  IIUC, this has not been implemented
> for doc-view yet, so I think we should open them with ps-mode for now.

At least it should be consistent for all files that can both be edited
(as text) or viewed.  One solution I see is

  - open the files always with the editing mode because that's what the
    find-file docstring says and one expects from an editor

  - in that editing mode's hook turn on a minor-mode that only provides
    a simple keybinding (like C-c C-c) that switches to the viewing mode

  - in the viewing mode the same binding switches back to the editing
    mode

So opening a PS file would activate ps-mode and doc-view-minor-mode is
activated in ps-mode-hook.

But how could we activate doc-view-minor-mode for DVI/PDF files which
would be opened in fundamental-mode, since there's no
fundamental-mode-hook?

What do you think?

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-18 21:22                                         ` Tassilo Horn
@ 2007-10-19  0:42                                           ` Juri Linkov
  2007-10-19 17:42                                           ` Richard Stallman
  1 sibling, 0 replies; 98+ messages in thread
From: Juri Linkov @ 2007-10-19  0:42 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

>> IMHO, it should do the same as image mode for XPM files: "Type C-c C-c
>> to view the image as an image."  IIUC, this has not been implemented
>> for doc-view yet, so I think we should open them with ps-mode for now.
>
> At least it should be consistent for all files that can both be edited
> (as text) or viewed.

However, there is a difference: some file types are more likely to be
edited (.ps files) while other are not (.pdf and .dvi).  Almost nobody
will want to edit .pdf and .dvi.

So you can put .ps files in ps-mode and doc-view-minor-mode,
and put .pdf/.dvi files in major mode doc-view-mode
(there is no need to put .pdf/.dvi in fundamental-mode).

For a solution how to activate a major/minor mode you could look
in image-mode-maybe.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: mailcap viewers in dired; gnus-dired.el, mailcap.el
  2007-10-18 17:48                               ` Lars Magne Ingebrigtsen
@ 2007-10-19  5:40                                 ` Richard Stallman
  0 siblings, 0 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-19  5:40 UTC (permalink / raw)
  To: Lars Magne Ingebrigtsen; +Cc: emacs-devel

    However, that hasn't been trivial in the past (what with the Emacs
    feature freeze that lasted two years and all).  When a new, general
    facility has been developed because Gnus needed it, it would be
    counter-productive to not distribute it with Gnus just because it's not
    Gnus-specific.

I don't mind if you distribute it with Gnus.  The point is to install it
into Emacs.

    But when merging, the general stuff should not end up in the Gnus
    directory, though.

If that means thinking of these added files as Emacs facilities rather
than as part of Gnus, that would do the job.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: Please install: Some improvements to doc-view.el
  2007-10-17 21:12                                     ` Leo
@ 2007-10-19  5:40                                       ` Richard Stallman
  0 siblings, 0 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-19  5:40 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

    Many programs can display images in terminals (including the linux
    consoles) for example 'elinks' and 'w3m'. I'd be best if Emacs can also
    do it.

In theory I agree, but nobody has implemented this in Emacs,
so we need not worry about it in Emacs.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-18 21:22                                         ` Tassilo Horn
  2007-10-19  0:42                                           ` Juri Linkov
@ 2007-10-19 17:42                                           ` Richard Stallman
  1 sibling, 0 replies; 98+ messages in thread
From: Richard Stallman @ 2007-10-19 17:42 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

    At least it should be consistent for all files that can both be edited
    (as text) or viewed.

I think it is more important to treat each type as is most useful.
PDF and DVI files should show the rendered form initially.  PS should
not.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-10-18  7:31                                         ` Reiner Steib
@ 2007-11-25 22:53                                           ` Reiner Steib
  2007-11-26 11:16                                             ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-11-25 22:53 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Tassilo Horn, rms, emacs-devel

On Thu, Oct 18 2007, Reiner Steib wrote:

> On Thu, Oct 18 2007, Juri Linkov wrote:
[...]
>>> (defun doc-view-mode-p ()
>>>   (and (display-graphic-p)
>
> Maybe an additional test like "(executable-find
> doc-view-ghostscript-program)" would be useful here.
>
>>>        (image-type-available-p 'png)))
>>>
>>> Shouldn't it?
>>
>> I think the second variant is better.  Since this is a matter of doc-view
>> to decide if it can support displaying, it should have such a function
>> (autoloaded).
>
> I agree.  

Committed:

(defun doc-view-mode-p (type)
  "Return non-nil if image type TYPE is available for `doc-view'.
Image types are symbols like `dvi', `postscript' or `pdf'."
  (and (display-graphic-p)
       (image-type-available-p 'png)
       (cond
	((eq type 'dvi)
	 (and (doc-view-mode-p 'pdf)
	      doc-view-dvipdfm-program
	      (executable-find doc-view-dvipdfm-program)))
	((or (eq type 'postscript) (eq type 'ps)
	     (eq type 'pdf))
	 (and doc-view-ghostscript-program
	      (executable-find doc-view-ghostscript-program)))
	(t ;; unknown image type
	 nil))))

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-11-25 22:53                                           ` Reiner Steib
@ 2007-11-26 11:16                                             ` Tassilo Horn
  2007-12-01 18:26                                               ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-11-26 11:16 UTC (permalink / raw)
  To: Juri Linkov; +Cc: rms, emacs-devel

Reiner Steib <reinersteib+gmane@imap.cc> writes:

Hi Reiner,

> Committed:
>
> (defun doc-view-mode-p (type)
>   "Return non-nil if image type TYPE is available for `doc-view'.
> Image types are symbols like `dvi', `postscript' or `pdf'."
>   (and (display-graphic-p)
>        (image-type-available-p 'png)
>        (cond
> 	((eq type 'dvi)
> 	 (and (doc-view-mode-p 'pdf)
> 	      doc-view-dvipdfm-program
> 	      (executable-find doc-view-dvipdfm-program)))
> 	((or (eq type 'postscript) (eq type 'ps)
> 	     (eq type 'pdf))
> 	 (and doc-view-ghostscript-program
> 	      (executable-find doc-view-ghostscript-program)))
> 	(t ;; unknown image type
> 	 nil))))

Yes, that looks fine.  Here's a patch that lets
`doc-view-initiate-display' use the new function.

--8<---------------cut here---------------start------------->8---
2007-11-26  Tassilo Horn  <tassilo@member.fsf.org>

	* doc-view.el (doc-view-initiate-display): Use `doc-view-mode-p'.
--8<---------------cut here---------------end--------------->8---

--8<---------------cut here---------------start------------->8---
Index: lisp/doc-view.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/doc-view.el,v
retrieving revision 1.24
diff -u -r1.24 doc-view.el
--- lisp/doc-view.el	25 Nov 2007 20:11:47 -0000	1.24
+++ lisp/doc-view.el	26 Nov 2007 11:14:53 -0000
@@ -234,8 +234,12 @@
 
 (defvar doc-view-current-image nil
   "Only used internally.")
-(defvar doc-view-current-overlay)
-(defvar doc-view-pending-cache-flush nil)
+
+(defvar doc-view-current-overlay nil
+  "Only used internally.")
+
+(defvar doc-view-pending-cache-flush nil
+  "Only used internally.")
 
 (defvar doc-view-current-info nil
   "Only used internally.")
@@ -887,8 +891,7 @@
 
 (defun doc-view-initiate-display ()
   ;; Switch to image display if possible
-  (if (and (display-images-p)
-	   (image-type-available-p 'png))
+  (if (doc-view-mode-p (intern (file-name-extension buffer-file-name)))
       (progn
 	(doc-view-buffer-message)
 	(setq doc-view-current-page (or doc-view-current-page 1))
@@ -905,8 +908,9 @@
     (message
      "%s"
      (substitute-command-keys
-      (concat "No image (png) support available.  Type \\[doc-view-toggle-display] "
-	      "to switch to an editing mode.")))))
+      (concat "No image (png) support available or some conversion utility for "
+	      (file-name-extension buffer-file-name)" files is missing.  "
+	      "Type \\[doc-view-toggle-display] to switch to an editing mode.")))))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-11-26 11:16                                             ` Tassilo Horn
@ 2007-12-01 18:26                                               ` Tassilo Horn
  2007-12-01 19:50                                                 ` Reiner Steib
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-12-01 18:26 UTC (permalink / raw)
  To: emacs-devel

Tassilo Horn <tassilo@member.fsf.org> writes:

> Yes, that looks fine.  Here's a patch that lets
> `doc-view-initiate-display' use the new function.
>
> [...]

Would somebody please install it for me?

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-01 18:26                                               ` Tassilo Horn
@ 2007-12-01 19:50                                                 ` Reiner Steib
  2007-12-03  0:33                                                   ` Juri Linkov
  0 siblings, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-12-01 19:50 UTC (permalink / raw)
  To: emacs-devel

On Sat, Dec 01 2007, Tassilo Horn wrote:

> Tassilo Horn <tassilo@member.fsf.org> writes:
>
>> Yes, that looks fine.  Here's a patch that lets
>> `doc-view-initiate-display' use the new function.
>
> Would somebody please install it for me?

Done.

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-01 19:50                                                 ` Reiner Steib
@ 2007-12-03  0:33                                                   ` Juri Linkov
  2007-12-03  7:41                                                     ` Reiner Steib
  0 siblings, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-12-03  0:33 UTC (permalink / raw)
  To: emacs-devel

> On Sat, Dec 01 2007, Tassilo Horn wrote:
>
>> Tassilo Horn <tassilo@member.fsf.org> writes:
>>
>>> Yes, that looks fine.  Here's a patch that lets
>>> `doc-view-initiate-display' use the new function.
>>
>> Would somebody please install it for me?
>
> Done.

I don't see it installed in CVS.  Maybe, Tassilo as an active developer
should get CVS access?

BTW, did you try using a new function `doc-view-mode-p' in Gnus
as we discussed earlier?

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-03  0:33                                                   ` Juri Linkov
@ 2007-12-03  7:41                                                     ` Reiner Steib
  2007-12-03  8:18                                                       ` Tassilo Horn
  2007-12-03 22:55                                                       ` Juri Linkov
  0 siblings, 2 replies; 98+ messages in thread
From: Reiner Steib @ 2007-12-03  7:41 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

On Mon, Dec 03 2007, Juri Linkov wrote:

>> On Sat, Dec 01 2007, Tassilo Horn wrote:
>>> Would somebody please install it for me?
>>
>> Done.
>
> I don't see it installed in CVS.  

Now it should be there.

> Maybe, Tassilo as an active developer should get CVS access?

Seconded.

> BTW, did you try using a new function `doc-view-mode-p' in Gnus
> as we discussed earlier?

Not yet.  Feel free to add.

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-03  7:41                                                     ` Reiner Steib
@ 2007-12-03  8:18                                                       ` Tassilo Horn
  2007-12-03 18:42                                                         ` Richard Stallman
  2007-12-03 22:55                                                       ` Juri Linkov
  1 sibling, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-12-03  8:18 UTC (permalink / raw)
  To: emacs-devel

Reiner Steib <reinersteib+gmane@imap.cc> writes:

Hi Reiner,

> Now it should be there.

It is.  Thanks.

>> Maybe, Tassilo as an active developer should get CVS access?
>
> Seconded.

Don't you like beeing my personal CVS slaves? ;-)

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-03  8:18                                                       ` Tassilo Horn
@ 2007-12-03 18:42                                                         ` Richard Stallman
  2007-12-03 22:16                                                           ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Richard Stallman @ 2007-12-03 18:42 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

I will agree to CVS access for you.

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-03 18:42                                                         ` Richard Stallman
@ 2007-12-03 22:16                                                           ` Tassilo Horn
  0 siblings, 0 replies; 98+ messages in thread
From: Tassilo Horn @ 2007-12-03 22:16 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

> I will agree to CVS access for you.

Thanks a lot.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-03  7:41                                                     ` Reiner Steib
  2007-12-03  8:18                                                       ` Tassilo Horn
@ 2007-12-03 22:55                                                       ` Juri Linkov
  2007-12-04  9:20                                                         ` Tassilo Horn
  1 sibling, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-12-03 22:55 UTC (permalink / raw)
  To: emacs-devel

>> BTW, did you try using a new function `doc-view-mode-p' in Gnus
>> as we discussed earlier?
>
> Not yet.  Feel free to add.

To be able to display an attached pdf file inline in the Article buffer,
you need to add a new application/pdf handler to `mm-inline-media-tests'.

But it is unclear what should it display: all page images of the whole
pdf file (this requires improvements in doc-view to support this) or
only the first page (using something like `mm-inline-image')?  And in
case of one page how the user is supposed to navigate to other pages?
Maybe, with the help of key bindings local only to the area of pdf image
in the Article buffer?

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-03 22:55                                                       ` Juri Linkov
@ 2007-12-04  9:20                                                         ` Tassilo Horn
  2007-12-04 18:22                                                           ` Reiner Steib
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-12-04  9:20 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@jurta.org> writes:

>>> BTW, did you try using a new function `doc-view-mode-p' in Gnus as
>>> we discussed earlier?
>>
>> Not yet.  Feel free to add.
>
> To be able to display an attached pdf file inline in the Article
> buffer, you need to add a new application/pdf handler to
> `mm-inline-media-tests'.

I don't think inlining the pdf in the article buffer is a good idea.  We
would have to fight with navigation and other stuff that makes me feel
it's not worth the trouble.  Why not open a new doc-view buffer instead?

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-04  9:20                                                         ` Tassilo Horn
@ 2007-12-04 18:22                                                           ` Reiner Steib
  2007-12-04 22:45                                                             ` Juri Linkov
  0 siblings, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-12-04 18:22 UTC (permalink / raw)
  To: ding, emacs-devel

[ Adding ding.

  Summary: Using the new doc-view mode in Emacs 23 (CVS) to display
  PDF/Postscript/DVI attachments inline in Gnus. ]

On Tue, Dec 04 2007, Tassilo Horn wrote:

> Juri Linkov <juri@jurta.org> writes:
>
>>>> BTW, did you try using a new function `doc-view-mode-p' in Gnus as
>>>> we discussed earlier?
>>>
>>> Not yet.  Feel free to add.
>>
>> To be able to display an attached pdf file inline in the Article
>> buffer, you need to add a new application/pdf handler to
>> `mm-inline-media-tests'.
>
> I don't think inlining the pdf in the article buffer is a good idea.  We
> would have to fight with navigation and other stuff that makes me feel
> it's not worth the trouble.  Why not open a new doc-view buffer instead?

PDF, PostScript and DVI files are usually A4 (or letter) paper sized
documents.  Displaying them in the article buffer doesn't seem useful
to me.  My personal preference would be a new Emacs frame.

BTW, I have committed the reduction of dependencies in mailcap.el and
gnus-dired.el in Gnus.

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-04 18:22                                                           ` Reiner Steib
@ 2007-12-04 22:45                                                             ` Juri Linkov
  2007-12-05 10:08                                                               ` Tassilo Horn
  0 siblings, 1 reply; 98+ messages in thread
From: Juri Linkov @ 2007-12-04 22:45 UTC (permalink / raw)
  To: ding; +Cc: emacs-devel

>>> To be able to display an attached pdf file inline in the Article
>>> buffer, you need to add a new application/pdf handler to
>>> `mm-inline-media-tests'.
>>
>> I don't think inlining the pdf in the article buffer is a good idea.  We
>> would have to fight with navigation and other stuff that makes me feel
>> it's not worth the trouble.  Why not open a new doc-view buffer instead?
>
> PDF, PostScript and DVI files are usually A4 (or letter) paper sized
> documents.  Displaying them in the article buffer doesn't seem useful
> to me.  My personal preference would be a new Emacs frame.

Large images get attached to the messages already, and Gnus displays them
inline just fine.  I think when the disposition type is `inline' we should
try to display it inline in the same article buffer if possible.  Otherwise,
it would be ok to display then in another buffer/frame like Gnus does when
it calls an external program to display an attachment.

> BTW, I have committed the reduction of dependencies in mailcap.el and
> gnus-dired.el in Gnus.

Thanks.  Could you also look at the problem of moving mailcap.el and its
related files out of Gnus?  It seems an appropriate directory for them is
`lisp/mail' or `lisp/net'.  Do you see a better directory?

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-04 22:45                                                             ` Juri Linkov
@ 2007-12-05 10:08                                                               ` Tassilo Horn
  2007-12-05 20:02                                                                 ` Reiner Steib
  0 siblings, 1 reply; 98+ messages in thread
From: Tassilo Horn @ 2007-12-05 10:08 UTC (permalink / raw)
  To: emacs-devel

Juri Linkov <juri@jurta.org> writes:

Hi Juri,

>> PDF, PostScript and DVI files are usually A4 (or letter) paper sized
>> documents.  Displaying them in the article buffer doesn't seem useful
>> to me.  My personal preference would be a new Emacs frame.
>
> Large images get attached to the messages already, and Gnus displays
> them inline just fine.

But the difference is that the images are just there and can be
displayed immediately whereas pdfs and such have to be converted first.
I don't think it would be good to unconditionally start a conversion run
if a document is attached with disposition type `inline'.  And if the
user has to type a key first to start the conversion and inline the
images I cannot see a big benefit.

> I think when the disposition type is `inline' we should try to display
> it inline in the same article buffer if possible.

I think it wouldn't be hard to add a function to doc-view that inserts
the images into the current buffer, but we'd loose (or have to
re-implement) all those nice features like searching or image-scrolling.

Bye,
Tassilo

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-05 10:08                                                               ` Tassilo Horn
@ 2007-12-05 20:02                                                                 ` Reiner Steib
  2007-12-05 22:45                                                                   ` Juri Linkov
  0 siblings, 1 reply; 98+ messages in thread
From: Reiner Steib @ 2007-12-05 20:02 UTC (permalink / raw)
  To: ding, emacs-devel

[ Adding ding again.  Tassilo, please don't strip ding as long as
  this thread is closely related to Gnus.  Thanks. ]

On Wed, Dec 05 2007, Tassilo Horn wrote:

> Juri Linkov <juri@jurta.org> writes:
>>> PDF, PostScript and DVI files are usually A4 (or letter) paper sized
>>> documents.  Displaying them in the article buffer doesn't seem useful
>>> to me.  My personal preference would be a new Emacs frame.
>>
>> Large images get attached to the messages already, and Gnus displays
>> them inline just fine.

At least by default it doesn't display them inline, see
`mm-inline-large-images'.  I toggled it and tried to view a wide image
(the frame is 80 chars wide).  I couldn't figure out how to view the
right hand side part of the image conveniently.  The best I could
think of was `scroll-left'.  (I used `i image' in the Emacs manual.)

> But the difference is that the images are just there and can be
> displayed immediately whereas pdfs and such have to be converted first.

Good point.

> I don't think it would be good to unconditionally start a conversion run
> if a document is attached with disposition type `inline'.  

I don't think any MUA in the wild sends PDFs as disposition=inline (of
course you can do with Gnus).

> And if the user has to type a key first to start the conversion and
> inline the images I cannot see a big benefit.
>
>> I think when the disposition type is `inline' we should try to display
>> it inline in the same article buffer if possible.
>
> I think it wouldn't be hard to add a function to doc-view that inserts
> the images into the current buffer, but we'd loose (or have to
> re-implement) all those nice features like searching or image-scrolling.

I'd suggest to implement viewing in an extra buffer first.  I think
it's not worth the trouble to implement inline display in the article
buffer.  But if someone wants to do it...

>> Could you also look at the problem of moving mailcap.el and its
>> related files out of Gnus?  

Which are the related files?  (mailcap.el doesn't require any other
packages after my changes.)

>> It seems an appropriate directory for them is `lisp/mail' or
>> `lisp/net'.  Do you see a better directory?

I don't have a strong opinion on this.

[ IIRC, Miles should be back soon, so hopefully the change are synced
  within a couple of days. ]

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 98+ messages in thread

* Re: doc-view and mailcap
  2007-12-05 20:02                                                                 ` Reiner Steib
@ 2007-12-05 22:45                                                                   ` Juri Linkov
  0 siblings, 0 replies; 98+ messages in thread
From: Juri Linkov @ 2007-12-05 22:45 UTC (permalink / raw)
  To: ding; +Cc: emacs-devel

>>> Could you also look at the problem of moving mailcap.el and its
>>> related files out of Gnus?
>
> Which are the related files?  (mailcap.el doesn't require any other
> packages after my changes.)

I thought mm-*.el files might be useful outside Gnus, mainly for other mail
programs.  But if they are now used only by Gnus there is no sense to move
them out of the gnus directory now.

So if there is only one file mailcap.el under question, maybe a suitable
place for it is the top lisp directory `emacs/lisp'?

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 98+ messages in thread

end of thread, other threads:[~2007-12-05 22:45 UTC | newest]

Thread overview: 98+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-02  9:15 Please install: Some improvements to doc-view.el Tassilo Horn
2007-10-02 13:04 ` Davis Herring
2007-10-02 14:42   ` Tassilo Horn
2007-10-02 16:49   ` Tassilo Horn
2007-10-02 17:33     ` Andreas Schwab
2007-10-02 18:19       ` Tassilo Horn
2007-10-03 18:37     ` Richard Stallman
2007-10-03 23:29       ` Michaël Cadilhac
2007-10-04  7:53       ` Tassilo Horn
2007-10-05 16:13         ` Richard Stallman
2007-10-05 16:43           ` Tassilo Horn
2007-10-06 14:16             ` Tassilo Horn
2007-10-06 23:54               ` Juri Linkov
2007-10-08 15:26                 ` Sascha Wilde
2007-10-08 15:51                   ` Tassilo Horn
2007-10-08 19:34                     ` Juri Linkov
2007-10-09  9:02                       ` Tassilo Horn
2007-10-09 21:55                         ` Juri Linkov
2007-10-11  1:28                           ` Doc-view as default viewer for pdf, ps and dvi files (was: Please install: Some improvements to doc-view.el) Tassilo Horn
2007-10-12  2:46                             ` Richard Stallman
2007-10-12 13:09                               ` Doc-view as default viewer for pdf, ps and dvi files Tassilo Horn
2007-10-13  0:18                                 ` Richard Stallman
2007-10-13  8:25                                   ` Tassilo Horn
2007-10-13 19:48                                     ` Richard Stallman
2007-10-17 23:34                             ` Juri Linkov
2007-10-18  6:47                               ` Tassilo Horn
2007-10-18  8:28                               ` Tassilo Horn
2007-10-07 13:10               ` Please install: Some improvements to doc-view.el Richard Stallman
2007-10-08 19:42                 ` Juri Linkov
2007-10-09 20:03                   ` Richard Stallman
2007-10-09 21:30                     ` Tassilo Horn
2007-10-15 18:31                       ` Richard Stallman
2007-10-15 20:58                         ` Tassilo Horn
2007-10-17 23:49                           ` Scrolling in doc-view Chong Yidong
2007-10-18  6:27                             ` Tassilo Horn
2007-10-18  8:29                             ` Tassilo Horn
2007-10-09 21:54                     ` Please install: Some improvements to doc-view.el Juri Linkov
2007-10-09 22:17                       ` mailcap viewers in dired; gnus-dired.el, mailcap.el (was: Please install: Some improvements to doc-view.el) Reiner Steib
2007-10-09 22:47                         ` Juri Linkov
2007-10-10 21:20                           ` mailcap viewers in dired; gnus-dired.el, mailcap.el Reiner Steib
2007-10-10 23:43                             ` Juri Linkov
2007-10-15  1:37                             ` Richard Stallman
2007-10-15 23:46                               ` Juri Linkov
2007-10-16  6:49                                 ` Tassilo Horn
2007-10-18 17:48                               ` Lars Magne Ingebrigtsen
2007-10-19  5:40                                 ` Richard Stallman
2007-10-15  1:37                       ` Please install: Some improvements to doc-view.el Richard Stallman
2007-10-15 23:45                         ` Juri Linkov
2007-10-16 19:09                           ` Richard Stallman
2007-10-16 19:26                             ` Leo
2007-10-17  5:03                               ` Richard Stallman
2007-10-17 10:15                                 ` Leo
2007-10-17 20:49                                   ` Richard Stallman
2007-10-17 21:12                                     ` Leo
2007-10-19  5:40                                       ` Richard Stallman
2007-10-17 22:04                                     ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Reiner Steib
2007-10-17 23:35                                       ` doc-view and mailcap Juri Linkov
2007-10-18  7:31                                         ` Reiner Steib
2007-11-25 22:53                                           ` Reiner Steib
2007-11-26 11:16                                             ` Tassilo Horn
2007-12-01 18:26                                               ` Tassilo Horn
2007-12-01 19:50                                                 ` Reiner Steib
2007-12-03  0:33                                                   ` Juri Linkov
2007-12-03  7:41                                                     ` Reiner Steib
2007-12-03  8:18                                                       ` Tassilo Horn
2007-12-03 18:42                                                         ` Richard Stallman
2007-12-03 22:16                                                           ` Tassilo Horn
2007-12-03 22:55                                                       ` Juri Linkov
2007-12-04  9:20                                                         ` Tassilo Horn
2007-12-04 18:22                                                           ` Reiner Steib
2007-12-04 22:45                                                             ` Juri Linkov
2007-12-05 10:08                                                               ` Tassilo Horn
2007-12-05 20:02                                                                 ` Reiner Steib
2007-12-05 22:45                                                                   ` Juri Linkov
2007-10-16 20:43                             ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Reiner Steib
2007-10-17  1:16                               ` doc-view and mailcap Stefan Monnier
2007-10-17 14:10                                 ` Richard Stallman
2007-10-17 14:39                                   ` Stefan Monnier
2007-10-17 16:55                                     ` Reiner Steib
2007-10-17 23:36                                       ` Juri Linkov
2007-10-18  5:02                                     ` Richard Stallman
2007-10-17  5:03                               ` doc-view and mailcap (was: Please install: Some improvements to doc-view.el) Richard Stallman
2007-10-17 17:59                                 ` doc-view and mailcap Reiner Steib
2007-10-17 20:32                                   ` Tassilo Horn
2007-10-17 21:45                                     ` Reiner Steib
2007-10-18  4:19                                       ` Stefan Monnier
2007-10-18  7:33                                         ` Reiner Steib
2007-10-18  8:24                                           ` Tassilo Horn
2007-10-18  6:24                                       ` Tassilo Horn
2007-10-18 20:08                                     ` Richard Stallman
2007-10-18 20:30                                       ` Reiner Steib
2007-10-18 21:22                                         ` Tassilo Horn
2007-10-19  0:42                                           ` Juri Linkov
2007-10-19 17:42                                           ` Richard Stallman
2007-10-16 23:52                             ` Please install: Some improvements to doc-view.el Juri Linkov
2007-10-06 21:47             ` Stefan Monnier
2007-10-07 13:10               ` Richard Stallman
2007-10-07  0:30             ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.