-(defun wl-thread-entity-check-prev-mark-from-older-brother (entity prev-marks)
- (let* (older-brother parent)
- (catch 'done
- (while entity
- (setq older-brother
- (reverse (wl-thread-entity-get-older-brothers entity)))
- ;; check itself
- (let ((succeed-list (car prev-marks))
- (failure-list (cdr prev-marks))
- mark meaning success failure)
- (if (setq mark (wl-thread-entity-get-mark (car entity)))
- (if (setq meaning (wl-meaning-of-mark mark))
- (if (setq success (assq meaning succeed-list))
- (progn
- (setcdr success entity)
- (throw 'done nil))
- (setq failure (assq meaning failure-list))
- (unless (cdr failure)
- (setcdr (assq meaning failure-list) entity))))))
- ;; check older brothers
- (while older-brother
- (wl-thread-entity-check-prev-mark (wl-thread-get-entity
- (car older-brother))
- prev-marks)
- (if (wl-thread-meaning-alist-get-result
- (car prev-marks))
- (throw 'done nil))
- (setq older-brother (cdr older-brother)))
- (setq entity (wl-thread-entity-get-parent-entity entity))))))
-
-(defun wl-thread-entity-get-prev-marked-entity (entity prev-marks)
- (let ((older-brothers (reverse
- (wl-thread-entity-get-older-brothers entity)))
- marked)
- (or (catch 'done
- (while older-brothers
- (wl-thread-entity-check-prev-mark
- (wl-thread-get-entity (car older-brothers)) prev-marks)
- (if (setq marked
- (wl-thread-meaning-alist-get-result
- (car prev-marks)))
- (throw 'done marked))
- (setq older-brothers (cdr older-brothers))))
- (wl-thread-entity-check-prev-mark-from-older-brother
- (wl-thread-entity-get-parent-entity entity) prev-marks)
- (if (setq marked
- (wl-thread-meaning-alist-get-result
- (car prev-marks)))
- marked
- (if (setq marked
- (wl-thread-meaning-alist-get-result
- (cdr prev-marks)))
- marked)))))
-
-(defun wl-thread-get-prev-unread (msg &optional hereto)
- (let ((cur-entity (wl-thread-get-entity msg))
- (prev-marks (cond ((eq wl-summary-move-order 'new)
- (cons (list (cons 'new nil))
- (list (cons 'unread nil)
- (cons 'important nil))))
- ((eq wl-summary-move-order 'unread)
- (cons (list (cons 'unread nil)
- (cons 'new nil))
- (list (cons 'important nil))))
- (t
- (cons (list (cons 'unread nil)
- (cons 'new nil)
- (cons 'important nil))
- nil))))
- mark ret-val)
- (if hereto
- (when (wl-thread-next-mark-p (setq mark
- (wl-thread-entity-get-mark
- (car cur-entity)))
- (caaar prev-marks))
- ;;(setq mark (cons cur-entity
- ;;(wl-thread-entity-get-mark cur-entity)))
- (setq ret-val msg)))
- (when (and (not ret-val)
- (or (setq cur-entity
- (wl-thread-entity-get-prev-marked-entity
- cur-entity prev-marks))
- (and hereto mark)))
- (if (and hereto
- (catch 'done
- (let ((success-list (car prev-marks)))
- (while success-list
- (if (cdr (car success-list))
- (throw 'done nil))
- (setq success-list (cdr success-list)))
- t))
- (wl-thread-next-failure-mark-p mark (caaar prev-marks)))
- (setq ret-val msg)
- (when cur-entity
- (setq ret-val (car cur-entity)))))
- ret-val))
-
-(defun wl-thread-jump-to-prev-unread (&optional hereto)
- "If prev unread is a children of a closed message,
-the closed parent will be opened."
- (interactive "P")
- (let ((msg (wl-thread-get-prev-unread
- (wl-summary-message-number) hereto)))
- (when msg
- (wl-thread-entity-force-open (wl-thread-get-entity msg))
- (wl-summary-jump-to-msg msg)
- t)))
-