all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Reiner Steib <reinersteib+gmane@imap.cc>
To: Juri Linkov <juri@jurta.org>
Cc: emacs-devel@gnu.org
Subject: Re: mailcap viewers in dired; gnus-dired.el, mailcap.el
Date: Wed, 10 Oct 2007 23:20:44 +0200	[thread overview]
Message-ID: <v9tzoyzmxf.fsf@marauder.physik.uni-ulm.de> (raw)
In-Reply-To: <87ejg3q51o.fsf@jurta.org> (Juri Linkov's message of "Wed, 10 Oct 2007 01:47:15 +0300")

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/

  reply	other threads:[~2007-10-10 21:20 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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                           ` Reiner Steib [this message]
2007-10-10 23:43                             ` mailcap viewers in dired; gnus-dired.el, mailcap.el 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=v9tzoyzmxf.fsf@marauder.physik.uni-ulm.de \
    --to=reinersteib+gmane@imap.cc \
    --cc=Reiner.Steib@gmx.de \
    --cc=emacs-devel@gnu.org \
    --cc=juri@jurta.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.