`mime-view-scroll-up-content' -> `mime-view-scroll-up-entity'.
[elisp/semi.git] / mime-view.el
index 6ea8360..8bf4417 100644 (file)
@@ -6,7 +6,7 @@
 ;; Created: 1994/7/13
 ;;     Renamed: 1994/8/31 from tm-body.el
 ;;     Renamed: 1997/02/19 from tm-view.el
-;; Version: $Revision: 0.46 $
+;; Version: $Revision: 0.59 $
 ;; Keywords: MIME, multimedia, mail, news
 
 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
@@ -40,7 +40,7 @@
 ;;;
 
 (defconst mime-view-RCS-ID
-  "$Id: mime-view.el,v 0.46 1997-03-17 13:55:01 morioka Exp $")
+  "$Id: mime-view.el,v 0.59 1997-03-17 16:17:40 morioka Exp $")
 
 (defconst mime-view-version (get-version-string mime-view-RCS-ID))
 
@@ -167,15 +167,9 @@ Each elements are regexp of field-name. [mime-view.el]")
          (apply (function regexp-or) mime-view-ignored-field-list)
          ":"))
 
-(defvar mime-view-visible-field-list
-  '("Dnas.*" "Message-Id")
+(defvar mime-view-visible-field-list '("Dnas.*" "Message-Id")
   "All fields that match this list will be displayed in MIME preview buffer.
-Each elements are regexp of field-name. [mime-view.el]")
-
-(defvar mime-view-visible-field-regexp
-  (concat "^"
-         (apply (function regexp-or) mime-view-visible-field-list)
-         ":"))
+Each elements are regexp of field-name.")
 
 (defvar mime-view-redisplay nil)
 
@@ -275,7 +269,8 @@ Each elements are regexp of field-name. [mime-view.el]")
 
 (defun mime-view-entity-button-function
   (rcnum cinfo ctype params subj encoding)
-  "Insert entity button conditionally."
+  "Insert entity button conditionally.
+Please redefine this function if you want to change default setting."
   (or (null rcnum)
       (string= ctype "application/x-selection")
       (and (string= ctype "application/octet-stream")
@@ -289,28 +284,25 @@ Each elements are regexp of field-name. [mime-view.el]")
 ;;; @@ content header filter
 ;;;
 
-(defun mime-preview/cut-header ()
+(defsubst mime-view-cut-header ()
   (goto-char (point-min))
-  (while (and
-         (re-search-forward mime-view-ignored-field-regexp nil t)
-         (let* ((beg (match-beginning 0))
-                (end (match-end 0))
-                (name (buffer-substring beg end))
-                )
-           (if (not (string-match mime-view-visible-field-regexp name))
-               (delete-region
-                beg
-                (save-excursion
-                  (and
-                   (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
-                   (match-beginning 0)
-                   )))
-             )
-           t)))
-  )
+  (while (re-search-forward mime-view-ignored-field-regexp nil t)
+    (let* ((beg (match-beginning 0))
+          (end (match-end 0))
+          (name (buffer-substring beg end))
+          )
+      (or (member-if (function
+                     (lambda (regexp)
+                       (string-match regexp name)
+                       )) mime-view-visible-field-list)
+         (delete-region beg
+                        (if (re-search-forward "^\\([^ \t]\\|$\\)" nil t)
+                            (match-beginning 0)
+                          (point-max)))
+         ))))
 
 (defun mime-view-default-content-header-filter ()
-  (mime-preview/cut-header)
+  (mime-view-cut-header)
   (eword-decode-header)
   )
 
@@ -327,13 +319,14 @@ Each elements are regexp of field-name. [mime-view.el]")
     ))
 
 
-;;; @@ content separator
+;;; @@ entity separator
 ;;;
 
 (defun mime-view-entity-separator-function (rcnum cinfo ctype params subj)
-  (if (and (not (mime-view-header-visible-p rcnum cinfo))
-          (not (mime-view-body-visible-p rcnum cinfo ctype))
-          )
+  "Insert entity separator conditionally.
+Please redefine this function if you want to change default setting."
+  (or (mime-view-header-visible-p rcnum cinfo)
+      (mime-view-body-visible-p rcnum cinfo ctype)
       (progn
        (goto-char (point-max))
        (insert "\n")
@@ -369,8 +362,9 @@ Each elements are regexp of field-name. [mime-view.el]")
 ;;;
 
 (defvar mime-view-quitting-method-alist
-  '((mime/show-message-mode
-     . mime-view-quitting-method-for-mime/show-message-mode)))
+  '((mime-show-message-mode
+     . mime-view-quitting-method-for-mime-show-message-mode))
+  "Alist of major-mode vs. quitting-method of mime-view.")
 
 (defvar mime-view-over-to-previous-method-alist nil)
 (defvar mime-view-over-to-next-method-alist nil)
@@ -477,7 +471,7 @@ The compressed face will be piped to this command.")
     (let ((drest dest))
       (while pcl
        (setcar drest
-               (mime-preview/display-content (car pcl) cinfo the-buf obuf))
+               (mime-view-display-entity (car pcl) cinfo the-buf obuf))
        (setq pcl (cdr pcl)
              drest (cdr drest))
        ))
@@ -487,7 +481,8 @@ The compressed face will be piped to this command.")
     (list obuf dest)
     ))
 
-(defun mime-preview/display-content (content cinfo ibuf obuf)
+(defun mime-view-display-entity (content cinfo ibuf obuf)
+  "Display entity from content-info CONTENT."
   (let* ((beg (mime::content-info/point-min content))
         (end (mime::content-info/point-max content))
         (ctype (mime::content-info/type content))
@@ -543,6 +538,8 @@ The compressed face will be piped to this command.")
        (progn
          (setq ne (point-max))
          (widen)
+         (put-text-property nb ne 'mime-view-raw-buffer ibuf)
+         (put-text-property nb ne 'mime-view-cinfo content)
          (mime::preview-content-info/create nb (1- ne) ibuf content)
          )
       (goto-char ne)
@@ -702,11 +699,11 @@ The compressed face will be piped to this command.")
 
 (defconst mime-view-menu-title "MIME-View")
 (defconst mime-view-menu-list
-  '((up                 "Move to upper content"      mime-view-up-content)
-    (previous   "Move to previous content"   mime-view-previous-content)
-    (next       "Move to next content"       mime-view-next-content)
+  '((up                 "Move to upper content"      mime-view-move-to-upper)
+    (previous   "Move to previous content"   mime-view-move-to-previous)
+    (next       "Move to next content"       mime-view-move-to-next)
     (scroll-down "Scroll to previous content" mime-view-scroll-down-content)
-    (scroll-up  "Scroll to next content"     mime-view-scroll-up-content)
+    (scroll-up  "Scroll to next content"     mime-view-scroll-up-entity)
     (play       "Play Content"               mime-view-play-current-entity)
     (extract    "Extract Content"            mime-view-extract-current-entity)
     (print      "Print"                      mime-view-print-current-entity)
@@ -740,17 +737,17 @@ The compressed face will be piped to this command.")
                              (make-sparse-keymap)
                              )))
     (define-key mime-view-mode-map
-      "u"        (function mime-view-up-content))
+      "u"        (function mime-view-move-to-upper))
     (define-key mime-view-mode-map
-      "p"        (function mime-view-previous-content))
+      "p"        (function mime-view-move-to-previous))
     (define-key mime-view-mode-map
-      "n"        (function mime-view-next-content))
+      "n"        (function mime-view-move-to-next))
     (define-key mime-view-mode-map
-      "\e\t"     (function mime-view-previous-content))
+      "\e\t"     (function mime-view-move-to-previous))
     (define-key mime-view-mode-map
-      "\t"       (function mime-view-next-content))
+      "\t"       (function mime-view-move-to-next))
     (define-key mime-view-mode-map
-      " "        (function mime-view-scroll-up-content))
+      " "        (function mime-view-scroll-up-entity))
     (define-key mime-view-mode-map
       "\M- "     (function mime-view-scroll-down-content))
     (define-key mime-view-mode-map
@@ -1027,74 +1024,64 @@ It decodes current entity to call internal or external method as
     (mime-view-x-face-function)
     ))
 
-(defun mime-view-up-content ()
+(defun mime-view-move-to-upper ()
+  "Move to upper entity.
+If there is no upper entity, call function `mime-view-quit'."
   (interactive)
-  (let* ((pc (mime-preview/point-pcinfo (point)))
-        (cinfo (mime::preview-content-info/content-info pc))
-        (rcnum (mime::content-info/rcnum cinfo))
-        )
-    (if rcnum
-       (let ((r (save-excursion
-                  (set-buffer (mime::preview-content-info/buffer pc))
-                   (mime-article/rcnum-to-cinfo (cdr rcnum))
-                  ))
-             (rpcl mime::preview/content-list)
-             cell)
-         (while (and
-                 (setq cell (car rpcl))
-                 (not (eq r (mime::preview-content-info/content-info cell)))
-                 )
-           (setq rpcl (cdr rpcl))
+  (let (cinfo)
+    (while (null (setq cinfo (get-text-property (point) 'mime-view-cinfo)))
+      (backward-char)
+      )
+    (let ((r (mime-article/rcnum-to-cinfo
+             (cdr (mime::content-info/rcnum cinfo))
+             (get-text-property 1 'mime-view-cinfo)))
+         point)
+      (catch 'tag
+       (while (setq point (previous-single-property-change
+                           (point) 'mime-view-cinfo))
+         (goto-char point)
+         (if (eq r (get-text-property (point) 'mime-view-cinfo))
+             (throw 'tag t)
            )
-         (goto-char (mime::preview-content-info/point-min cell))
          )
-      (mime-view-quit)
-      )))
+       (mime-view-quit)
+       ))))
 
-(defun mime-view-previous-content ()
+(defun mime-view-move-to-previous ()
+  "Move to previous entity.
+If there is no previous entity, it calls function registered in
+variable `mime-view-over-to-previous-method-alist'."
   (interactive)
-  (let* ((pcl mime::preview/content-list)
-        (p (point))
-        (i (- (length pcl) 1))
-        beg)
-    (catch 'tag
-      (while (> i 0)
-       (setq beg (mime::preview-content-info/point-min (nth i pcl)))
-       (if (> p beg)
-           (throw 'tag (goto-char beg))
-         )
-       (setq i (- i 1))
-       )
+  (while (null (get-text-property (point) 'mime-view-cinfo))
+    (backward-char)
+    )
+  (let ((point (previous-single-property-change (point) 'mime-view-cinfo)))
+    (if point
+       (goto-char point)
       (let ((f (assq mime::preview/original-major-mode
                     mime-view-over-to-previous-method-alist)))
        (if f
            (funcall (cdr f))
          ))
-      )
-    ))
+      )))
 
-(defun mime-view-next-content ()
+(defun mime-view-move-to-next ()
+  "Move to next entity.
+If there is no previous entity, it calls function registered in
+variable `mime-view-over-to-next-method-alist'."
   (interactive)
-  (let ((pcl mime::preview/content-list)
-       (p (point))
-       beg)
-    (catch 'tag
-      (while pcl
-       (setq beg (mime::preview-content-info/point-min (car pcl)))
-       (if (< p beg)
-           (throw 'tag (goto-char beg))
-         )
-       (setq pcl (cdr pcl))
-       )
+  (let ((point (next-single-property-change (point) 'mime-view-cinfo)))
+    (if point
+       (goto-char point)
       (let ((f (assq mime::preview/original-major-mode
                     mime-view-over-to-next-method-alist)))
        (if f
            (funcall (cdr f))
          ))
-      )
-    ))
+      )))
 
-(defun mime-view-scroll-up-content (&optional h)
+(defun mime-view-scroll-up-entity (&optional h)
+  "Scroll up current entity."
   (interactive)
   (or h
       (setq h (- (window-height) 1))
@@ -1122,7 +1109,6 @@ It decodes current entity to call internal or external method as
       (if (> (point) np)
           (goto-char np)
         )
-      ;;(show-subtree)
       ))
   )
 
@@ -1160,7 +1146,7 @@ It decodes current entity to call internal or external method as
 
 (defun mime-view-next-line-content ()
   (interactive)
-  (mime-view-scroll-up-content 1)
+  (mime-view-scroll-up-entity 1)
   )
 
 (defun mime-view-previous-line-content ()