From 298179ef92e7400bdab05f509725ebfb9672b038 Mon Sep 17 00:00:00 2001 From: hmurata Date: Sat, 6 Nov 2004 11:11:45 +0000 Subject: [PATCH] * wl-summary.el (wl-summary-buffer-event-handler): New internal variable. (wl-summary-event-handler): New class. (elmo-event-handler-flag-changed): Define to update persistent mark. (wl-summary-buffer-set-folder): Register event handler to elmo-folder. (wl-summary-exit): Unregister event handler. (wl-summary-goto-folder-subr): Ditto. (wl-summary-mark-as-read-all): Does not call `wl-summary-update-persistent-mark' directly. (wl-summary-mark-as-read-internal): Ditto. (wl-summary-set-persistent-mark-internal): Ditto. (wl-summary-set-flags-internal): Ditto. * elmo.el (elmo-folder): Added handlers slot. (elmo-event-handler): New class. (elmo-event-handler-flag-changed): New API. (elmo-folder-add-handler): New function. (elmo-folder-remove-handler): Ditto. (elmo-folder-notify-event): Ditto. (elmo-folder-set-flag): Call `elmo-folder-notify-event' with event `flag-changed'. (elmo-folder-unset-flag): Ditto. * elmo-pipe.el (elmo-folder-set-flag): Ditto. (elmo-folder-unset-flag): Ditto. * elmo-multi.el (elmo-folder-set-flag): Ditto. (elmo-folder-unset-flag): Ditto. * elmo-filter.el (elmo-folder-set-flag): Ditto. (elmo-folder-unset-flag): Ditto. --- elmo/ChangeLog | 19 +++++++++++++++ elmo/elmo-filter.el | 6 +++-- elmo/elmo-multi.el | 6 +++-- elmo/elmo-pipe.el | 6 +++-- elmo/elmo.el | 32 +++++++++++++++++++++++-- wl/ChangeLog | 15 ++++++++++++ wl/wl-summary.el | 65 ++++++++++++++++++++++++++++++--------------------- 7 files changed, 115 insertions(+), 34 deletions(-) diff --git a/elmo/ChangeLog b/elmo/ChangeLog index 77fdcc5..7311f64 100644 --- a/elmo/ChangeLog +++ b/elmo/ChangeLog @@ -1,5 +1,24 @@ 2004-11-06 Hiroya Murata + * elmo.el (elmo-folder): Added handlers slot. + (elmo-event-handler): New class. + (elmo-event-handler-flag-changed): New API. + (elmo-folder-add-handler): New function. + (elmo-folder-remove-handler): Ditto. + (elmo-folder-notify-event): Ditto. + (elmo-folder-set-flag): Call `elmo-folder-notify-event' with event + `flag-changed'. + (elmo-folder-unset-flag): Ditto. + + * elmo-pipe.el (elmo-folder-set-flag): Ditto. + (elmo-folder-unset-flag): Ditto. + + * elmo-multi.el (elmo-folder-set-flag): Ditto. + (elmo-folder-unset-flag): Ditto. + + * elmo-filter.el (elmo-folder-set-flag): Ditto. + (elmo-folder-unset-flag): Ditto. + * elmo-version.el (elmo-version): Up to 2.11.33. 2004-10-25 Hiroya Murata diff --git a/elmo/elmo-filter.el b/elmo/elmo-filter.el index 8c59e89..d8b0461 100644 --- a/elmo/elmo-filter.el +++ b/elmo/elmo-filter.el @@ -374,7 +374,8 @@ (elmo-filter-folder-countup-message-flags folder numbers -1) (elmo-folder-set-flag (elmo-filter-folder-target-internal folder) numbers flag is-local) - (elmo-filter-folder-countup-message-flags folder numbers)) + (elmo-filter-folder-countup-message-flags folder numbers) + (elmo-folder-notify-event folder 'flag-changed numbers)) (luna-define-method elmo-folder-unset-flag ((folder elmo-filter-folder) numbers @@ -383,7 +384,8 @@ (elmo-filter-folder-countup-message-flags folder numbers -1) (elmo-folder-unset-flag (elmo-filter-folder-target-internal folder) numbers flag is-local) - (elmo-filter-folder-countup-message-flags folder numbers)) + (elmo-filter-folder-countup-message-flags folder numbers) + (elmo-folder-notify-event folder 'flag-changed numbers)) (luna-define-method elmo-message-folder ((folder elmo-filter-folder) number) diff --git a/elmo/elmo-multi.el b/elmo/elmo-multi.el index 5f3d5df..5903b1c 100644 --- a/elmo/elmo-multi.el +++ b/elmo/elmo-multi.el @@ -419,7 +419,8 @@ flag &optional is-local) (dolist (pair (elmo-multi-make-folder-numbers-list folder numbers)) - (elmo-folder-set-flag (car pair) (cdr pair) flag is-local))) + (elmo-folder-set-flag (car pair) (cdr pair) flag is-local)) + (elmo-folder-notify-event folder 'flag-changed numbers)) (luna-define-method elmo-folder-unset-flag ((folder elmo-multi-folder) numbers @@ -427,7 +428,8 @@ &optional is-local) (dolist (pair (elmo-multi-make-folder-numbers-list folder numbers)) (ignore-errors - (elmo-folder-unset-flag (car pair) (cdr pair) flag is-local)))) + (elmo-folder-unset-flag (car pair) (cdr pair) flag is-local))) + (elmo-folder-notify-event folder 'flag-changed numbers)) (luna-define-method elmo-folder-list-flagged ((folder elmo-multi-folder) flag diff --git a/elmo/elmo-pipe.el b/elmo/elmo-pipe.el index 5e02dab..d7e90dd 100644 --- a/elmo/elmo-pipe.el +++ b/elmo/elmo-pipe.el @@ -264,14 +264,16 @@ flag &optional is-local) (elmo-folder-set-flag (elmo-pipe-folder-dst-internal folder) - numbers flag is-local)) + numbers flag is-local) + (elmo-folder-notify-event folder 'flag-changed numbers)) (luna-define-method elmo-folder-unset-flag ((folder elmo-pipe-folder) numbers flag &optional is-local) (elmo-folder-unset-flag (elmo-pipe-folder-dst-internal folder) - numbers flag is-local)) + numbers flag is-local) + (elmo-folder-notify-event folder 'flag-changed numbers)) (luna-define-method elmo-folder-pack-numbers ((folder elmo-pipe-folder)) (elmo-folder-pack-numbers (elmo-pipe-folder-dst-internal folder))) diff --git a/elmo/elmo.el b/elmo/elmo.el index 6cedb36..7a8b781 100644 --- a/elmo/elmo.el +++ b/elmo/elmo.el @@ -123,6 +123,7 @@ If a folder name begins with PREFIX, use BACKEND." persistent ; non-nil if persistent. process-duplicates ; read or hide biff ; folder for biff + handlers ; list of event handler. )) (luna-define-internal-accessors 'elmo-folder)) @@ -1282,7 +1283,8 @@ VALUE is a value to set.") (elmo-global-flag-set flag folder number message-id))) (elmo-msgdb-set-flag (elmo-folder-msgdb folder) number - flag)))) + flag)) + (elmo-folder-notify-event folder 'flag-changed numbers))) (defun elmo-message-has-global-flag-p (folder number) "Return non-nil when the message in the FOLDER with NUMBER has global flag." @@ -1320,7 +1322,8 @@ If Optional LOCAL is non-nil, don't update server flag." (elmo-global-flag-detach flag folder number 'always)) (elmo-msgdb-unset-flag (elmo-folder-msgdb folder) number - flag)))) + flag)) + (elmo-folder-notify-event folder 'flag-changed numbers))) (luna-define-method elmo-folder-process-crosspost ((folder elmo-folder)) ;; Do nothing. @@ -1650,6 +1653,31 @@ Return a hashtable for newsgroups." (elmo-make-directory temp-dir) temp-dir)) +;; Event notification/observer framework +(eval-and-compile + (luna-define-class elmo-event-handler ())) + +(luna-define-generic elmo-event-handler-flag-changed (handler numbers) + "Notify flag of the messages with NUMBERS is changed.") + +(defun elmo-folder-add-handler (folder handler) + (unless (memq handler (elmo-folder-handlers-internal folder)) + (elmo-folder-set-handlers-internal + folder + (cons handler (elmo-folder-handlers-internal folder))))) + +(defun elmo-folder-remove-handler (folder handler) + (elmo-folder-set-handlers-internal + folder + (delq handler (elmo-folder-handlers-internal folder)))) + +(defun elmo-folder-notify-event (folder event &rest args) + (when (elmo-folder-handlers-internal folder) + (let ((message (format "elmo-event-handler-%s" event))) + (dolist (handler (elmo-folder-handlers-internal folder)) + (apply #'luna-send handler message handler args))))) + +;;; (defun elmo-init () "Initialize ELMO module." (elmo-crosspost-message-alist-load) diff --git a/wl/ChangeLog b/wl/ChangeLog index da6e216..30e9d11 100644 --- a/wl/ChangeLog +++ b/wl/ChangeLog @@ -1,5 +1,20 @@ 2004-11-06 Hiroya Murata + * wl-summary.el (wl-summary-buffer-event-handler): New internal + variable. + (wl-summary-event-handler): New class. + (elmo-event-handler-flag-changed): Define to update persistent + mark. + (wl-summary-buffer-set-folder): Register event handler to + elmo-folder. + (wl-summary-exit): Unregister event handler. + (wl-summary-goto-folder-subr): Ditto. + (wl-summary-mark-as-read-all): Does not call + `wl-summary-update-persistent-mark' directly. + (wl-summary-mark-as-read-internal): Ditto. + (wl-summary-set-persistent-mark-internal): Ditto. + (wl-summary-set-flags-internal): Ditto. + * Version number is increased to 2.11.33. 2004-10-28 TAKAHASHI Kaoru diff --git a/wl/wl-summary.el b/wl/wl-summary.el index d1b2f1b..afedf62 100644 --- a/wl/wl-summary.el +++ b/wl/wl-summary.el @@ -111,6 +111,7 @@ (defvar wl-summary-buffer-mode-line nil) (defvar wl-summary-buffer-display-mime-mode 'mime) (defvar wl-summary-buffer-display-all-header nil) +(defvar wl-summary-buffer-event-handler nil) (defvar wl-thread-indent-level-internal nil) (defvar wl-thread-have-younger-brother-str-internal nil) @@ -186,6 +187,7 @@ (make-variable-buffer-local 'wl-summary-buffer-mode-line) (make-variable-buffer-local 'wl-summary-buffer-display-mime-mode) (make-variable-buffer-local 'wl-summary-buffer-display-all-header) +(make-variable-buffer-local 'wl-summary-buffer-event-handler) (defvar wl-datevec) (defvar wl-thr-indent-string) @@ -618,6 +620,22 @@ See also variable `wl-use-petname'." (wl-summary-lazy-update-mark (list 'wl-summary-update-mark-window)))) +;; Handler of event from elmo-folder +(eval-and-compile + (luna-define-class wl-summary-event-handler (elmo-event-handler) + (buffer)) + (luna-define-internal-accessors 'wl-summary-event-handler)) + +(luna-define-method elmo-event-handler-flag-changed ((handler + wl-summary-event-handler) + numbers) + (with-current-buffer (wl-summary-event-handler-buffer-internal handler) + (save-excursion + (dolist (number numbers) + (when (and (wl-summary-message-visible-p number) + (wl-summary-jump-to-msg number)) + (wl-summary-update-persistent-mark number)))))) + (defun wl-status-update () (interactive) (wl-address-init)) @@ -801,6 +819,11 @@ you." (setq wl-summary-buffer-persistent (wl-folder-persistent-p (elmo-folder-name-internal folder))) (elmo-folder-set-persistent-internal folder wl-summary-buffer-persistent) + (elmo-folder-add-handler folder + (setq wl-summary-buffer-event-handler + (luna-make-entity + 'wl-summary-event-handler + :buffer (current-buffer)))) ;; process duplicates. (elmo-folder-set-process-duplicates-internal folder (cdr (elmo-string-matched-assoc @@ -1173,7 +1196,10 @@ Entering Folder mode calls the value of `wl-summary-mode-hook'." (progn (wl-summary-save-view) (if (or force-exit (not sticky)) - (elmo-folder-close wl-summary-buffer-elmo-folder) + (progn + (elmo-folder-close wl-summary-buffer-elmo-folder) + (elmo-folder-remove-handler wl-summary-buffer-elmo-folder + wl-summary-buffer-event-handler)) (elmo-folder-commit wl-summary-buffer-elmo-folder) (elmo-folder-check wl-summary-buffer-elmo-folder)) (if wl-use-scoring (wl-score-save))) @@ -1663,11 +1689,6 @@ If ARG is non-nil, checking is omitted." folder (elmo-folder-list-flagged folder 'unread 'in-msgdb) 'unread) - (save-excursion - (goto-char (point-min)) - (while (not (eobp)) - (wl-summary-update-persistent-mark) - (forward-line 1))) (wl-folder-update-unread (wl-summary-buffer-folder-name) 0) (setq wl-summary-buffer-unread-count 0) (setq wl-summary-buffer-new-count 0) @@ -2299,6 +2320,9 @@ If ARG, without confirm." (if other-window (delete-other-windows)) (set-buffer buf) + (when wl-summary-buffer-event-handler + (elmo-folder-remove-handler wl-summary-buffer-elmo-folder + wl-summary-buffer-event-handler)) (unless (eq major-mode 'wl-summary-mode) (wl-summary-mode)) (wl-summary-buffer-set-folder folder) @@ -3015,7 +3039,7 @@ Return non-nil if the mark is updated" (save-excursion (let ((folder wl-summary-buffer-elmo-folder) unread-message number - number-list visible) + number-list) (setq number-list (cond ((numberp number-or-numbers) (setq unread-message (elmo-message-flagged-p @@ -3039,14 +3063,11 @@ Return non-nil if the mark is updated" (if inverse (elmo-folder-set-flag folder number-list 'unread no-folder-mark) (elmo-folder-unset-flag folder number-list 'unread no-folder-mark)) - (dolist (number number-list) - (setq visible (wl-summary-jump-to-msg number)) - (unless inverse - (when unread-message - (run-hooks 'wl-summary-unread-message-hook))) - ;; set mark on buffer - (when visible - (wl-summary-update-persistent-mark))) + (when (and unread-message + (not inverse)) + (dolist (number number-list) + (wl-summary-jump-to-msg number) + (run-hooks 'wl-summary-unread-message-hook))) (unless no-modeline-update ;; Update unread numbers. (wl-summary-count-unread) @@ -3082,7 +3103,7 @@ Return non-nil if the mark is updated" "Set persistent mark." (save-excursion (let ((folder wl-summary-buffer-elmo-folder) - number number-list visible) + number number-list) (setq number-list (cond ((numberp number-or-numbers) (list number-or-numbers)) ((and (not (null number-or-numbers)) @@ -3099,10 +3120,6 @@ Return non-nil if the mark is updated" (if inverse (elmo-folder-unset-flag folder number-list flag no-server) (elmo-folder-set-flag folder number-list flag no-server)) - (dolist (number number-list) - ;; set mark on buffer - (when (wl-summary-jump-to-msg number) - (wl-summary-update-persistent-mark))) (unless no-modeline-update ;; Update unread numbers. ;; should elmo-flag-mark-as-read return unread numbers? @@ -3241,7 +3258,7 @@ Return non-nil if the mark is updated" remove-all) (save-excursion (let ((folder wl-summary-buffer-elmo-folder) - number number-list visible) + number number-list) (setq number-list (cond ((numberp number-or-numbers) (list number-or-numbers)) ((and (not (null number-or-numbers)) @@ -3257,11 +3274,7 @@ Return non-nil if the mark is updated" (if (null number-list) (message "No message.") (dolist (number number-list) - (elmo-message-set-global-flags folder number flags local) - (setq visible (wl-summary-jump-to-msg number)) - ;; set mark on buffer - (when visible - (wl-summary-update-persistent-mark)))) + (elmo-message-set-global-flags folder number flags local))) flags))) (defun wl-summary-set-flags (&optional remove) -- 1.7.10.4