(mime-show-echo-buffer): Bind `buffer-read-only' to nil, while insert
[elisp/semi.git] / mime-play.el
index acf8e94..70fb849 100644 (file)
        (setq i d-i
              d-i d-j
              d-j i))
-    (setq j-r (nthcdr (1- d-j) mime-acting-situation-example-list))
-    (setcdr j-r (cddr j-r))
+    (setq jr (nthcdr (1- d-j) mime-acting-situation-example-list))
+    (setcdr jr (cddr jr))
     (if (= d-i 0)
        (setq mime-acting-situation-example-list
              (cdr mime-acting-situation-example-list))
-      (setq i-r (nthcdr (1- d-i) mime-acting-situation-example-list))
-      (setcdr i-r (cddr i-r))
+      (setq ir (nthcdr (1- d-i) mime-acting-situation-example-list))
+      (setcdr ir (cddr ir))
       )
-    (if (setq i-r (assoc (car dest) mime-acting-situation-example-list))
-       (setcdr i-r (+ (cdr i-r)(cdr dest)))
+    (if (setq ir (assoc (car dest) mime-acting-situation-example-list))
+       (setcdr ir (+ (cdr ir)(cdr dest)))
       (setq mime-acting-situation-example-list
            (cons dest mime-acting-situation-example-list))
       )))
 
+
+;;; @ content decoder
+;;;
+
+;;;###autoload
+(defun mime-preview-play-current-entity (&optional ignore-examples mode)
+  "Play current entity.
+It decodes current entity to call internal or external method.  The
+method is selected from variable `mime-acting-condition'.
+If IGNORE-EXAMPLES (C-u prefix) is specified, this function ignores
+`mime-acting-situation-example-list'.
+If MODE is specified, play as it.  Default MODE is \"play\"."
+  (interactive "P")
+  (let ((entity (get-text-property (point) 'mime-view-entity)))
+    (if entity
+       (let ((situation (list (cons 'mode (or mode "play")))))
+         (if ignore-examples
+             (setq situation
+                   (cons (cons 'ignore-examples ignore-examples)
+                         situation)))
+         (mime-play-entity entity situation)
+         ))))
+
 (defun mime-sort-situation (situation)
   (sort situation
        #'(lambda (a b)
     (cons match example)
     ))
 
+;;;###autoload
 (defun mime-play-entity (entity &optional situation ignored-method)
   "Play entity specified by ENTITY.
 It decodes the entity to call internal or external method.  The method
 is selected from variable `mime-acting-condition'.  If MODE is
 specified, play as it.  Default MODE is \"play\"."
   (let (method ret)
+    (in-calist-package 'mime-view)
     (setq ret
          (mime-delq-null-situation
           (ctree-find-calist mime-acting-condition
@@ -359,33 +384,46 @@ Otherwise `mime-show-echo-buffer' uses it as height of mime-echo
 window.")
 
 (defun mime-show-echo-buffer (&rest forms)
-  "Show mime-echo buffer to display MIME-playing information."
+  "Show mime-echo buffer to display MIME-playing information.
+It returns the list of window, start and end positions of inserted text.
+A window height of the buffer `mime-echo-buffer-name' will be determined
+by `mime-echo-window-height' (its value or its return value) whenever
+this function is called."
   (get-buffer-create mime-echo-buffer-name)
   (let ((the-win (selected-window))
-       (win (get-buffer-window mime-echo-buffer-name)))
-    (unless win
+       (win (get-buffer-window mime-echo-buffer-name))
+       (height (if (functionp mime-echo-window-height)
+                   (funcall mime-echo-window-height)
+                 mime-echo-window-height))
+       start)
+    (if win
+       (progn
+         (select-window win)
+         (enlarge-window (- height (window-height)))
+         )
       (unless (and mime-echo-window-is-shared-with-bbdb
                   (condition-case nil
-                      (setq win (get-buffer-window bbdb-buffer-name))
+                      (select-window
+                       (setq win (get-buffer-window bbdb-buffer-name))
+                       )
                     (error nil)))
        (select-window (get-buffer-window (or mime-preview-buffer
                                              (current-buffer))))
-       (setq win (split-window-vertically
-                  (- (window-height)
-                     (if (functionp mime-echo-window-height)
-                         (funcall mime-echo-window-height)
-                       mime-echo-window-height)
-                     )))
-       )
-      (set-window-buffer win mime-echo-buffer-name)
-      )
-    (select-window win)
-    (goto-char (point-max))
+       (let ((window-min-height 1))
+         (setq win (split-window-vertically (- (window-height) height)))
+         )
+       (set-window-buffer win mime-echo-buffer-name)
+       (select-window win)
+       ))
+    (goto-char (setq start (point-max)))
     (if forms
-       (insert (apply (function format) forms))
-      )
-    (select-window the-win)
-    ))
+       (let ((buffer-read-only nil))
+         (insert (apply (function format) forms))
+         ))
+    (prog1
+       (list win start (point))
+      (select-window the-win)
+      )))
 
 
 ;;; @ file name
@@ -521,7 +559,6 @@ It is registered to variable `mime-preview-quitting-method-alist'."
 ;;;
 
 (defun mime-store-message/partial-piece (entity cal)
-  (goto-char (mime-entity-point-min entity))
   (let* ((root-dir
          (expand-file-name
           (concat "m-prts-" (user-login-name)) temporary-file-directory))
@@ -529,7 +566,7 @@ It is registered to variable `mime-preview-quitting-method-alist'."
         (number (cdr (assoc "number" cal)))
         (total (cdr (assoc "total" cal)))
         file
-        (mother mime-preview-buffer)
+        (mother (current-buffer))
         )
     (or (file-exists-p root-dir)
        (make-directory root-dir)