2000-10-07 08:19:17 ShengHuo ZHU <zsh@cs.rochester.edu>
[gnus] / lisp / gnus-art.el
index 4c1b155..d8f5fe0 100644 (file)
@@ -654,6 +654,20 @@ used."
                :value undisplayed-alternative)
          (function)))
 
+(defcustom gnus-mime-action-alist
+  '(("save to file" . gnus-mime-save-part)
+    ("display as text" . gnus-mime-inline-part)
+    ("view the part" . gnus-mime-view-part)
+    ("pipe to command" . gnus-mime-pipe-part)
+    ("toggle display" . gnus-article-press-button)
+    ("view as type" . gnus-mime-view-part-as-type)
+    ("internalize type" . gnus-mime-internalize-part)
+    ("externalize type" . gnus-mime-externalize-part))
+  "An alist of actions that run on the MIME attachment."
+  :group 'gnus-article-mime
+  :type '(repeat (cons (string :tag "name")
+                      (function))))
+
 ;;;
 ;;; The treatment variables
 ;;;
@@ -2824,6 +2838,8 @@ If ALL-HEADERS is non-nil, no headers are hidden."
                (gnus-set-global-variables)
                (setq gnus-have-all-headers
                      (or all-headers gnus-show-all-headers))))
+           (save-excursion
+             (gnus-configure-windows 'article))
            (when (or (numberp article)
                      (stringp article))
              (gnus-article-prepare-display)
@@ -2889,7 +2905,8 @@ If ALL-HEADERS is non-nil, no headers are hidden."
     (gnus-mime-inline-part "i" "View As Text, In This Buffer")
     (gnus-mime-internalize-part "E" "View Internally")
     (gnus-mime-externalize-part "e" "View Externally")
-    (gnus-mime-pipe-part "|" "Pipe To Command...")))
+    (gnus-mime-pipe-part "|" "Pipe To Command...")
+    (gnus-mime-action-on-part "." "Take action on the part")))
 
 (defun gnus-article-mime-part-status ()
   (if gnus-article-mime-handle-alist-1
@@ -3007,9 +3024,9 @@ If ALL-HEADERS is non-nil, no headers are hidden."
       (setq buffer-file-name nil))
     (goto-char (point-min))))
 
-(defun gnus-mime-inline-part (&optional handle)
+(defun gnus-mime-inline-part (&optional handle arg)
   "Insert the MIME part under point into the current buffer."
-  (interactive)
+  (interactive (list nil current-prefix-arg))
   (gnus-article-check-buffer)
   (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
         contents charset
@@ -3019,13 +3036,13 @@ If ALL-HEADERS is non-nil, no headers are hidden."
        (mm-remove-part handle)
       (setq contents (mm-get-part handle))
       (cond
-       ((not current-prefix-arg)
+       ((not arg)
        (setq charset (or (mail-content-type-get
                           (mm-handle-type handle) 'charset)
                          gnus-newsgroup-charset)))
-       ((numberp current-prefix-arg)
+       ((numberp arg)
        (setq charset
-             (or (cdr (assq current-prefix-arg 
+             (or (cdr (assq arg 
                             gnus-summary-show-article-charset-alist))
                  (read-coding-system "Charset: ")))))
       (forward-line 2)
@@ -3065,6 +3082,16 @@ In no internal viewer is available, use an external viewer."
        (mm-remove-part handle)
       (mm-display-part handle))))
 
+(defun gnus-mime-action-on-part (&optional action)
+  "Do something with the MIME attachment at \(point\)."
+  (interactive
+   (list (completing-read "Action: " gnus-mime-action-alist)))
+  (gnus-article-check-buffer)
+  (let ((action-pair (assoc action gnus-mime-action-alist)))
+    (if action-pair
+       (funcall (cdr action-pair)))))
+
+
 (defun gnus-article-part-wrapper (n function)
   (save-current-buffer
     (set-buffer gnus-article-buffer)
@@ -3243,8 +3270,8 @@ In no internal viewer is available, use an external viewer."
        ;; window, overlay, position.
        (if (mm-handle-displayed-p
             (if overlay
-                (with-current-buffer (overlay-buffer overlay)
-                  (widget-get (widget-at (overlay-start overlay))
+                (with-current-buffer (gnus-overlay-buffer overlay)
+                  (widget-get (widget-at (gnus-overlay-start overlay))
                               :mime-handle))
               (widget-get widget/window :mime-handle)))
            "hide" "show")
@@ -4716,11 +4743,13 @@ For example:
          (funcall (cadr elem)))))))
 
 ;; Dynamic variables.
-(defvar part-number)
-(defvar total-parts)
-(defvar type)
-(defvar condition)
-(defvar length)
+(eval-when-compile
+  (defvar part-number)
+  (defvar total-parts)
+  (defvar type)
+  (defvar condition)
+  (defvar length))
+
 (defun gnus-treat-predicate (val)
   (cond
    ((null val)