From: morioka Date: Wed, 8 Jul 1998 09:05:24 +0000 (+0000) Subject: (mime-acting-situation-example-list-max-size): New variable. X-Git-Tag: remi-1_8_3~5 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=eb08c8cf42c9226c38d6649dbf95cd6b4b3f887f;p=elisp%2Fsemi.git (mime-acting-situation-example-list-max-size): New variable. (mime-reduce-acting-situation-examples): New function. (mime-preview-play-current-entity): Change interface to add `ignore-examples'. (mime-raw-play-entity): Add new optional argument `ignore-examples'. Reduce `mime-acting-situation-example-list' when loading example file. --- diff --git a/mime-play.el b/mime-play.el index 57ea22a..de83764 100644 --- a/mime-play.el +++ b/mime-play.el @@ -39,6 +39,8 @@ (defvar mime-acting-situation-example-list nil) +(defvar mime-acting-situation-example-list-max-size 16) + (defun mime-save-acting-situation-examples () (let* ((file mime-acting-situation-examples-file) (buffer (get-buffer-create " *mime-example*"))) @@ -62,25 +64,74 @@ (add-hook 'kill-emacs-hook 'mime-save-acting-situation-examples) - +(defun mime-reduce-acting-situation-examples () + (let* ((rest mime-acting-situation-example-list) + (min-example (car rest)) + (min-score (cdr min-example))) + (while rest + (let* ((example (car rest)) + (score (cdr example))) + (cond ((< score min-score) + (setq min-score score + min-example example) + ) + ((= score min-score) + (if (<= (length (car example))(length (car min-example))) + (setq min-example example) + )) + )) + (setq rest (cdr rest))) + (setq mime-acting-situation-example-list + (delq min-example mime-acting-situation-example-list)) + (setq min-example (car min-example)) + (let ((examples mime-acting-situation-example-list) + (max-score 0) + max-examples) + (while examples + (let* ((ret (mime-compare-situation-with-example min-example + (caar examples))) + (ret-score (car ret))) + (cond ((> ret-score max-score) + (setq max-score ret-score + max-examples (list (cdr ret))) + ) + ((= ret-score max-score) + (setq max-examples (cons (cdr ret) max-examples)) + ))) + (setq examples (cdr examples))) + (while max-examples + (let* ((example (car max-examples)) + (cell (assoc example mime-acting-situation-example-list))) + (if cell + (setcdr cell (1+ (cdr cell))) + (setq mime-acting-situation-example-list + (cons (cons example 0) + mime-acting-situation-example-list)) + )) + (setq max-examples (cdr max-examples)) + )))) + + ;;; @ content decoder ;;; (defvar mime-preview-after-decoded-position nil) -(defun mime-preview-play-current-entity (&optional mode) +(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) + (interactive "P") (let ((entity (get-text-property (point) 'mime-view-entity))) (if entity (let ((the-buf (current-buffer)) (raw-buffer (mime-entity-buffer entity))) (setq mime-preview-after-decoded-position (point)) (set-buffer raw-buffer) - (mime-raw-play-entity entity (or mode "play")) + (mime-raw-play-entity entity (or mode "play") nil ignore-examples) (when (eq (current-buffer) raw-buffer) (set-buffer the-buf) (goto-char mime-preview-after-decoded-position) @@ -149,7 +200,7 @@ If MODE is specified, play as it. Default MODE is \"play\"." (cons match example) )) -(defun mime-raw-play-entity (entity &optional mode situation) +(defun mime-raw-play-entity (entity &optional mode situation ignore-examples) "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 @@ -165,45 +216,56 @@ specified, play as it. Default MODE is \"play\"." (ctree-find-calist mime-acting-condition situation mime-view-find-every-acting-situation) 'method)) - (if (cdr ret) - (let ((rest ret) - (max-score 0) - max-examples - max-situations) - (while rest - (let ((situation (car rest)) - (examples mime-acting-situation-example-list)) - (while examples - (let* ((ret - (mime-compare-situation-with-example situation - (caar examples))) - (ret-score (car ret))) - (cond ((> ret-score max-score) - (setq max-score ret-score - max-examples (list (cdr ret)) - max-situations (list situation)) - ) - ((= ret-score max-score) - (setq max-examples (cons (cdr ret) max-examples)) - (or (member situation max-situations) - (setq max-situations - (cons situation max-situations))) - ))) - (setq examples (cdr examples)))) - (setq rest (cdr rest))) - (when max-situations - (setq ret max-situations) - (while max-examples - (let* ((example (car max-examples)) - (cell (assoc example mime-acting-situation-example-list))) - (if cell - (setcdr cell (1+ (cdr cell))) - (setq mime-acting-situation-example-list - (cons (cons example 0) - mime-acting-situation-example-list)) - )) - (setq max-examples (cdr max-examples)) - )))) + (or ignore-examples + (if (cdr ret) + (let ((rest ret) + (max-score 0) + max-escore + max-examples + max-situations) + (while rest + (let ((situation (car rest)) + (examples mime-acting-situation-example-list)) + (while examples + (let* ((ret + (mime-compare-situation-with-example + situation (caar examples))) + (ret-score (car ret))) + (cond ((> ret-score max-score) + (setq max-score ret-score + max-escore (cdar examples) + max-examples (list (cdr ret)) + max-situations (list situation)) + ) + ((= ret-score max-score) + (cond ((> (cdar examples) max-escore) + (setq max-escore (cdar examples) + max-examples (list (cdr ret)) + max-situations (list situation)) + ) + ((= (cdar examples) max-escore) + (setq max-examples + (cons (cdr ret) max-examples)) + (or (member situation max-situations) + (setq max-situations + (cons situation max-situations))) + ))))) + (setq examples (cdr examples)))) + (setq rest (cdr rest))) + (when max-situations + (setq ret max-situations) + (while max-examples + (let* ((example (car max-examples)) + (cell + (assoc example mime-acting-situation-example-list))) + (if cell + (setcdr cell (1+ (cdr cell))) + (setq mime-acting-situation-example-list + (cons (cons example 0) + mime-acting-situation-example-list)) + )) + (setq max-examples (cdr max-examples)) + ))))) (cond ((cdr ret) (setq ret (select-menu-alist "Methods" @@ -657,8 +719,12 @@ It is registered to variable `mime-preview-quitting-method-alist'." (insert-file-contents file) (eval-buffer) ;; format check - (or (consp (car (car mime-acting-situation-example-list))) - (setq mime-acting-situation-example-list nil)) + (condition-case nil + (if (> (length mime-acting-situation-example-list) + mime-acting-situation-example-list-max-size) + (mime-reduce-acting-situation-examples) + ) + (error (setq mime-acting-situation-example-list nil))) ) (kill-buffer buffer))))