-;;; wl-message.el -- Message displaying modules for Wanderlust.
+;;; wl-message.el --- Message displaying modules for Wanderlust.
;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
;;
;;; Commentary:
-;;
+;;
;;; Code:
-;;
+;;
(require 'wl-vars)
(require 'wl-highlight)
(require 'elmo)
(require 'elmo-mime)
+(require 'timer)
(eval-when-compile
- (if wl-use-semi
- (progn
- (require 'wl-mime)
- (require 'mime-view))
- (require 'tm-wl))
+ (require 'wl-mime)
+ (require 'mime-view)
(defalias-maybe 'event-window 'ignore)
(defalias-maybe 'posn-window 'ignore)
(defalias-maybe 'event-start 'ignore)
- (defalias-maybe 'mime-open-entity 'ignore))
+ (defalias-maybe 'mime-open-entity 'ignore)
+ (defalias-maybe 'itimer-function 'ignore)
+ (defalias-maybe 'delete-itimer 'ignore)
+ (defvar-maybe itimer-list))
-(defconst wl-message-buffer-prefetch-idle-time
- (if (featurep 'lisp-float-type) (/ (float 1) (float 5)) 1))
(defvar wl-message-buffer-prefetch-get-next-function
'wl-summary-default-get-next-msg)
-(defvar wl-message-buffer-prefetch-folder-type-list t)
-
(defvar wl-message-buffer-prefetch-debug nil)
+(defvar wl-message-buffer-prefetch-timer nil)
(defvar wl-message-buffer nil) ; message buffer.
-(defvar wl-message-buffer-cur-summary-buffer nil)
(defvar wl-message-buffer-cur-folder nil)
(defvar wl-message-buffer-cur-number nil)
-(defvar wl-message-buffer-cur-flag nil)
+(defvar wl-message-buffer-cur-display-type nil)
(defvar wl-message-buffer-cur-summary-buffer nil)
+(defvar wl-message-buffer-require-all-header nil)
(defvar wl-message-buffer-original-buffer nil) ; original buffer.
+(defvar wl-message-buffer-mode-line-formatter nil)
+(defvar wl-message-buffer-flag-indicator nil)
(make-variable-buffer-local 'wl-message-buffer-cur-folder)
(make-variable-buffer-local 'wl-message-buffer-cur-number)
-(make-variable-buffer-local 'wl-message-buffer-cur-flag)
+(make-variable-buffer-local 'wl-message-buffer-cur-display-type)
(make-variable-buffer-local 'wl-message-buffer-cur-summary-buffer)
+(make-variable-buffer-local 'wl-message-buffer-require-all-header)
(make-variable-buffer-local 'wl-message-buffer-original-buffer)
+(make-variable-buffer-local 'wl-message-buffer-mode-line-formatter)
+(make-variable-buffer-local 'wl-message-buffer-flag-indicator)
(defvar wl-fixed-window-configuration nil)
; (setcdr pointer (list entry))
; (setq wl-message-buffer-cache (cdr top))))
-(defconst wl-message-buffer-cache-name " *WL:Message*")
(defconst wl-original-message-buffer-name " *Original*")
(defun wl-original-message-mode ()
"A major mode for original message buffer."
(setq major-mode 'wl-original-message-mode)
(setq buffer-read-only t)
- (elmo-set-buffer-multibyte nil)
+ (set-buffer-multibyte nil)
(setq mode-name "Wanderlust original message"))
(defun wl-original-message-buffer-get (name)
(defun wl-message-buffer-create ()
"Create a new message buffer."
- (let* ((buffer (generate-new-buffer wl-message-buffer-cache-name))
+ (let* ((buffer (generate-new-buffer wl-message-buffer-name))
(name (buffer-name buffer)))
(with-current-buffer buffer
(setq wl-message-buffer-original-buffer
- (wl-original-message-buffer-get name)))
+ (wl-original-message-buffer-get name))
+ (when wl-message-use-header-narrowing
+ (wl-message-header-narrowing-setup))
+ (run-hooks 'wl-message-buffer-created-hook))
buffer))
(defun wl-message-buffer-cache-add (key)
(buf nil))
(if (< len wl-message-buffer-cache-size)
(setq buf (wl-message-buffer-create))
- (setq buf (wl-message-buffer-cache-buffer-get
- (nth (1- len) wl-message-buffer-cache)))
- (setcdr (nthcdr (- len 2) wl-message-buffer-cache) nil))
+ (let ((entry (nth (1- len) wl-message-buffer-cache)))
+ (if (buffer-live-p
+ (setq buf (wl-message-buffer-cache-buffer-get entry)))
+ (setcdr (nthcdr (- len 2) wl-message-buffer-cache) nil)
+ (setq wl-message-buffer-cache (delq entry wl-message-buffer-cache))
+ (setq buf (wl-message-buffer-create)))))
(setq wl-message-buffer-cache
(cons (wl-message-buffer-cache-entry-make key buf)
wl-message-buffer-cache))
wl-message-buffer
(get-buffer-window wl-message-buffer))
(delete-window (get-buffer-window wl-message-buffer)))
- (wl-kill-buffers (regexp-quote wl-message-buffer-cache-name))
+ (wl-kill-buffers (regexp-quote wl-message-buffer-name))
(setq wl-message-buffer-cache nil))
;;; Message buffer handling from summary buffer.
(if window
(select-window window)
(when wl-fixed-window-configuration
- (delete-other-windows)
- (and wl-stay-folder-window
- (wl-summary-toggle-disp-folder)))
+ (delete-other-windows)
+ (and wl-stay-folder-window
+ (wl-summary-toggle-disp-folder)))
;; There's no buffer window. Search for message window and snatch it.
(if (setq window (wl-message-buffer-window))
(select-window window)
(setq arg (if arg (prefix-numeric-value arg) 0))
(save-excursion
(condition-case ()
- (forward-page -1) ; Beginning of current page.
+ (forward-page -1) ; Beginning of current page.
(beginning-of-buffer
(goto-char (point-min))))
(forward-char 1) ; for compatibility with emacs-19.28 and emacs-19.29
"Scroll down current message by LINES.
Returns non-nil if top of message."
(interactive)
- (let (cur-buf top real-top)
- (unless (eq major-mode 'mime-view-mode)
- (when (buffer-live-p wl-message-buffer)
- (setq cur-buf (current-buffer))
- (wl-message-select-buffer wl-message-buffer)))
- (move-to-window-line 0)
- (if (and wl-break-pages
- (bobp)
- (not (setq real-top (save-restriction (widen) (bobp)))))
- (progn
- (wl-message-narrow-to-page -1)
- (goto-char (point-max))
- (recenter))
- (if (not (bobp))
- (condition-case nil
- (scroll-down lines)
- (error))
- (setq top t)))
- (if real-top
- (let ((f (assq (mime-preview-original-major-mode)
- mime-preview-over-to-previous-method-alist)))
- (if f (funcall (cdr f))))
- (when cur-buf
- (select-window (get-buffer-window cur-buf))))
+ (let (top real-top)
+ (save-selected-window
+ (unless (eq major-mode 'mime-view-mode)
+ (when (buffer-live-p wl-message-buffer)
+ (wl-message-select-buffer wl-message-buffer)))
+ (move-to-window-line 0)
+ (if (and wl-break-pages
+ (bobp)
+ (not (setq real-top (save-restriction (widen) (bobp)))))
+ (progn
+ (wl-message-narrow-to-page -1)
+ (goto-char (point-max))
+ (recenter))
+ (if (not (bobp))
+ (condition-case nil
+ (scroll-down (or lines wl-message-scroll-amount))
+ (error))
+ (setq top t)))
+ (if real-top
+ (let ((f (assq (mime-preview-original-major-mode)
+ mime-preview-over-to-previous-method-alist)))
+ (if f (funcall (cdr f))))))
top))
(defun wl-message-next-page (&optional lines)
"Scroll up current message by LINES.
Returns non-nil if bottom of message."
(interactive)
- (let (cur-buf bottom)
- (unless (eq major-mode 'mime-view-mode)
- (when (buffer-live-p wl-message-buffer)
- (setq cur-buf (current-buffer))
- (wl-message-select-buffer wl-message-buffer)))
- (move-to-window-line -1)
- (if (save-excursion
- (end-of-line)
- (and (pos-visible-in-window-p)
- (eobp)))
- (if (or (null wl-break-pages)
- (save-excursion
- (save-restriction
- (widen) (forward-line) (eobp))))
- (setq bottom t)
- (wl-message-narrow-to-page 1)
- (setq bottom nil))
- (condition-case ()
- (static-if (boundp 'window-pixel-scroll-increment)
- ;; XEmacs 21.2.20 and later.
- (let (window-pixel-scroll-increment)
- (scroll-up lines))
- (scroll-up lines))
- (end-of-buffer
- (goto-char (point-max))))
- (setq bottom nil))
- (if (eobp)
- (let ((f (assq (mime-preview-original-major-mode)
- mime-preview-over-to-next-method-alist)))
- (if f (funcall (cdr f))))
- (when cur-buf
- (select-window (get-buffer-window cur-buf))))
+ (let (bottom)
+ (save-selected-window
+ (unless (eq major-mode 'mime-view-mode)
+ (when (buffer-live-p wl-message-buffer)
+ (wl-message-select-buffer wl-message-buffer)))
+ (move-to-window-line -1)
+ (if (save-excursion
+ (end-of-line)
+ (and (pos-visible-in-window-p)
+ (eobp)))
+ (if (or (null wl-break-pages)
+ (save-excursion
+ (save-restriction
+ (widen) (forward-line) (eobp))))
+ (setq bottom t)
+ (wl-message-narrow-to-page 1)
+ (setq bottom nil))
+ (condition-case ()
+ (static-if (boundp 'window-pixel-scroll-increment)
+ ;; XEmacs 21.2.20 and later.
+ (let (window-pixel-scroll-increment)
+ (scroll-up (or lines wl-message-scroll-amount)))
+ (scroll-up (or lines wl-message-scroll-amount)))
+ (end-of-buffer
+ (goto-char (point-max))))
+ (setq bottom nil))
+ (if (eobp)
+ (let ((f (assq (mime-preview-original-major-mode)
+ mime-preview-over-to-next-method-alist)))
+ (if f (funcall (cdr f))))))
bottom))
(let ((mail-reply-buffer buffer))
(wl-draft-yank-from-mail-reply-buffer nil)))
-;;
+;;
(defun wl-message-mode ()
"A major mode for message displaying."
(setq mode-name "Message"))
(defun wl-message-exit ()
- "Move to summary buffer."
+ "Move to summary buffer or mother buffer."
(interactive)
- (let (summary-buf summary-win)
- (if (setq summary-buf wl-message-buffer-cur-summary-buffer)
- (if (setq summary-win (get-buffer-window summary-buf))
- (select-window summary-win)
- (switch-to-buffer summary-buf)
- (wl-message-select-buffer wl-message-buffer)
- (select-window (get-buffer-window summary-buf))))
+ (let (summary-buf summary-win mother-buffer)
+ (cond ((setq summary-buf wl-message-buffer-cur-summary-buffer)
+ (if (setq summary-win (get-buffer-window summary-buf))
+ (select-window summary-win)
+ (switch-to-buffer summary-buf)
+ (wl-message-select-buffer wl-message-buffer)
+ (select-window (get-buffer-window summary-buf))))
+ ((setq mother-buffer mime-mother-buffer)
+ (kill-buffer (current-buffer))
+ (switch-to-buffer mother-buffer)))
(run-hooks 'wl-message-exit-hook)))
(defun wl-message-toggle-disp-summary ()
(wl-message-select-buffer wl-message-buffer))
(wl-summary-goto-folder-subr wl-message-buffer-cur-folder 'no-sync
nil nil t)
- ; no summary-buf
+ ; no summary-buf
(let ((sum-buf (current-buffer)))
(wl-message-select-buffer wl-message-buffer)
(setq wl-message-buffer-cur-summary-buffer sum-buf)))))
(defun wl-message-get-original-buffer ()
"Get original buffer for current message buffer."
- wl-message-buffer-original-buffer)
+ (if (buffer-live-p wl-message-buffer-original-buffer)
+ wl-message-buffer-original-buffer
+ (wl-original-message-buffer-get (buffer-name (current-buffer)))))
-(defun wl-message-redisplay (folder number flag &optional force-reload)
+(defun wl-message-add-buttons-to-body (start end)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (let ((case-fold-search t)
+ (alist wl-message-body-button-alist)
+ entry)
+ (while alist
+ (setq entry (car alist)
+ alist (cdr alist))
+ (goto-char (point-min))
+ (while (re-search-forward (car entry) (+ (point) (nth 4 entry)) t)
+ (unless (get-text-property (point) 'keymap)
+ (wl-message-add-button
+ (match-beginning (nth 1 entry))
+ (match-end (nth 1 entry))
+ (nth 2 entry)
+ (match-string (nth 3 entry))))))))))
+
+(defun wl-message-add-buttons-to-header (start end)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (let ((case-fold-search t)
+ (alist wl-message-header-button-alist)
+ entry)
+ (while alist
+ (setq entry (car alist)
+ alist (cdr alist))
+ (goto-char (point-min))
+ (while (re-search-forward (car entry) nil t)
+ (setq start (match-beginning 0)
+ end (if (re-search-forward "^[^ \t]" nil t)
+ (match-beginning 0)
+ (point-max)))
+ (goto-char start)
+ (while (re-search-forward (nth 1 entry) end t)
+ (wl-message-add-button
+ (match-beginning (nth 2 entry))
+ (match-end (nth 2 entry))
+ (nth 3 entry) (match-string (nth 4 entry))))
+ (goto-char end)))))))
+
+;; display-type object definition.
+(defun wl-message-make-display-type (mime header)
+ (let (symbol)
+ (prog1
+ (setq symbol (intern (format "%s-%s-header" mime header)))
+ (put symbol
+ 'wl-message-display-type
+ (list :mime mime :header header)))))
+
+(defun wl-message-display-type-property (display-type prop)
+ (plist-get (get display-type 'wl-message-display-type) prop))
+
+(defun wl-message-mime-analysis-p (display-type &optional header-or-body)
+ (let ((mode (wl-message-display-type-property display-type :mime)))
+ (case header-or-body
+ (header
+ (memq mode '(mime header-only)))
+ (t
+ (eq mode 'mime)))))
+
+(defun wl-message-display-all-header-p (display-type)
+ (eq (wl-message-display-type-property display-type :header) 'all))
+
+(defun wl-message-buffer-display-type (&optional message-buffer)
+ (if message-buffer
+ (with-current-buffer message-buffer
+ wl-message-buffer-cur-display-type)
+ wl-message-buffer-cur-display-type))
+
+(defun wl-message-redisplay (folder number display-type &optional force-reload)
(let* ((default-mime-charset wl-mime-charset)
(buffer-read-only nil)
(summary-buf (current-buffer))
message-buf
strategy entity
cache-used
- header-end real-fld-num summary-win)
+ summary-win delim flags)
(setq buffer-read-only nil)
(setq cache-used (wl-message-buffer-display
- folder number flag force-reload))
+ folder number display-type force-reload))
(setq wl-message-buffer (car cache-used))
(setq message-buf wl-message-buffer)
(wl-message-select-buffer wl-message-buffer)
(set-buffer message-buf)
+ (wl-deactivate-region)
+ (make-local-variable 'truncate-partial-width-windows)
+ (setq truncate-partial-width-windows nil)
+ (setq truncate-lines wl-message-truncate-lines)
(setq buffer-read-only nil)
(setq wl-message-buffer-cur-summary-buffer summary-buf)
(setq wl-message-buffer-cur-folder (elmo-folder-name-internal folder))
(setq wl-message-buffer-cur-number number)
- (wl-message-overload-functions)
+ (setq wl-message-buffer-flag-indicator
+ (if (setq flags (elmo-get-global-flags (elmo-message-flags
+ folder number)))
+ (let ((fl wl-summary-flag-alist)
+ flag-strings flag-string face)
+ (while fl
+ (when (memq (car (car fl)) flags)
+ (setq flag-string (capitalize
+ (symbol-name (car (car fl))))
+ flags (delq (car (car fl)) flags))
+ (when (facep (setq face
+ (intern
+ (format
+ "wl-highlight-summary-%s-flag-face"
+ (car (car fl))))))
+ (put-text-property 0 (length flag-string)
+ 'face face flag-string))
+ (setq flag-strings (nconc flag-strings
+ (list flag-string))))
+ (setq fl (cdr fl)))
+ (setq flag-strings
+ (nconc flag-strings
+ (mapcar (lambda (flag)
+ (capitalize (symbol-name flag)))
+ flags)))
+ (concat " (" (mapconcat 'identity flag-strings ", ") ")"))
+ ""))
+ (wl-line-formatter-setup
+ wl-message-buffer-mode-line-formatter
+ wl-message-mode-line-format
+ wl-message-mode-line-format-spec-alist)
(setq mode-line-buffer-identification
- (format "Wanderlust: << %s / %s >>"
- (if (memq 'modeline wl-use-folder-petname)
- (wl-folder-get-petname (elmo-folder-name-internal
- folder))
- (elmo-folder-name-internal folder)) number))
+ (funcall wl-message-buffer-mode-line-formatter))
;; highlight body
; (when wl-highlight-body-too
; (wl-highlight-body))
- (condition-case ()
- (wl-message-narrow-to-page)
- (error nil)); ignore errors.
+ (ignore-errors (wl-message-narrow-to-page))
(setq cache-used (cdr cache-used))
(goto-char (point-min))
- (unwind-protect
- (save-excursion
- (run-hooks 'wl-message-redisplay-hook))
- ;; go back to summary mode
- (set-buffer-modified-p nil)
- (setq buffer-read-only t)
- (set-buffer summary-buf)
- (setq summary-win (get-buffer-window summary-buf))
- (if (window-live-p summary-win)
- (select-window summary-win)))
+ (when (re-search-forward "^$" nil t)
+ (wl-message-add-buttons-to-header (point-min) (point))
+ (wl-message-add-buttons-to-body (point) (point-max)))
+ (when (and wl-message-use-header-narrowing
+ (not (wl-message-display-all-header-p display-type)))
+ (wl-message-header-narrowing))
+ (goto-char (point-min))
+ (ignore-errors (run-hooks 'wl-message-redisplay-hook))
+ ;; go back to summary mode
+ (set-buffer-modified-p nil)
+ (setq buffer-read-only t)
+ (set-buffer summary-buf)
+ (setq summary-win (get-buffer-window summary-buf))
+ (if (window-live-p summary-win)
+ (select-window summary-win))
cache-used))
;; Use message buffer cache.
-(defun wl-message-buffer-display (folder number flag
+(defun wl-message-buffer-display (folder number display-type
&optional force-reload unread)
- (let* ((msg-id (elmo-message-field folder number 'message-id))
+ (let* ((msg-id (ignore-errors (elmo-message-field folder number
+ 'message-id)))
(fname (elmo-folder-name-internal folder))
(hit (wl-message-buffer-cache-hit (list fname number msg-id)))
(read nil)
;; buffer cache is used.
(setq cache-used t)
(with-current-buffer hit
- (unless (eq wl-message-buffer-cur-flag flag)
+ ;; Rewind to the top page
+ (widen)
+ (goto-char (point-min))
+ (ignore-errors (wl-message-narrow-to-page))
+ (unless (eq wl-message-buffer-cur-display-type display-type)
(setq read t))))
;; delete tail and add new to the top.
(setq hit (wl-message-buffer-cache-add (list fname number msg-id)))
(set-buffer hit)
(setq
cache-used
- (wl-message-display-internal folder number flag
+ (wl-message-display-internal folder number display-type
force-reload unread))
- (setq wl-message-buffer-cur-flag flag))
+ (setq wl-message-buffer-cur-display-type display-type))
(quit
(wl-message-buffer-cache-delete)
(error "Display message %s/%s is quitted" fname number))
nil))) ;; will not be used
(cons hit cache-used)))
-(defun wl-message-display-internal (folder number flag
+(defun wl-message-display-internal (folder number display-type
&optional force-reload unread)
- (let ((elmo-message-ignored-field-list
- (if (eq flag 'all-header)
- nil
- wl-message-ignored-field-list))
- (elmo-message-visible-field-list wl-message-visible-field-list)
- (elmo-message-sorted-field-list wl-message-sort-field-list)
- (elmo-message-fetch-threshold wl-fetch-confirm-threshold))
- (prog1
- (if (eq flag 'as-is)
- (let (wl-highlight-x-face-function)
- (elmo-mime-display-as-is folder number
+ (let ((default-mime-charset wl-mime-charset)
+ (elmo-mime-charset wl-mime-charset))
+ (setq wl-message-buffer-require-all-header
+ (wl-message-display-all-header-p display-type))
+ (prog1
+ (if (wl-message-mime-analysis-p display-type)
+ (elmo-mime-message-display folder number
(current-buffer)
(wl-message-get-original-buffer)
'wl-original-message-mode
force-reload
- unread))
- (elmo-mime-message-display folder number
- (current-buffer)
- (wl-message-get-original-buffer)
- 'wl-original-message-mode
- force-reload
- unread))
+ unread
+ (wl-message-define-keymap))
+ (let* ((elmo-mime-display-header-analysis
+ (wl-message-mime-analysis-p display-type 'header))
+ (wl-highlight-x-face-function
+ (and elmo-mime-display-header-analysis
+ wl-highlight-x-face-function)))
+ (prog1 (elmo-mime-display-as-is folder number
+ (current-buffer)
+ (wl-message-get-original-buffer)
+ 'wl-original-message-mode
+ force-reload
+ unread
+ (wl-message-define-keymap))
+ (let (buffer-read-only)
+ (wl-highlight-message (point-min) (point-max) t)))))
+ (run-hooks 'wl-message-display-internal-hook)
(setq buffer-read-only t))))
-(defsubst wl-message-buffer-prefetch-p (folder &optional number)
- (cond
- ((eq wl-message-buffer-prefetch-folder-type-list t)
- t)
- ((and number wl-message-buffer-prefetch-folder-type-list)
- (memq (elmo-folder-type-internal
- (elmo-message-folder folder number))
- wl-message-buffer-prefetch-folder-type-list))
- (wl-message-buffer-prefetch-folder-type-list
- (let ((list wl-message-buffer-prefetch-folder-type-list)
- type)
- (catch 'done
- (while (setq type (pop list))
- (if (elmo-folder-contains-type folder type)
- (throw 'done t))))))
- ((consp wl-message-buffer-prefetch-folder-type-list)
- (wl-string-match-member (elmo-folder-name-internal folder)
- wl-message-buffer-prefetch-folder-type-list))
- (t wl-message-buffer-prefetch-folder-type-list)))
-
-
-(defvar wl-message-buffer-prefetch-timer nil)
-
-(defun wl-message-buffer-prefetch-next (folder number &optional
- summary charset)
- (if (wl-message-buffer-prefetch-p folder)
- (with-current-buffer (or summary (get-buffer wl-summary-buffer-name))
- (let* ((next (funcall wl-message-buffer-prefetch-get-next-function
- number)))
- (when (and next (wl-message-buffer-prefetch-p folder next))
- (if (not (fboundp 'run-with-idle-timer))
- (when (sit-for wl-message-buffer-prefetch-idle-time)
- (wl-message-buffer-prefetch folder next summary charset))
- (unless wl-message-buffer-prefetch-timer
- (setq wl-message-buffer-prefetch-timer
- (run-with-idle-timer
- wl-message-buffer-prefetch-idle-time
- nil
- 'wl-message-buffer-prefetch
- folder next summary charset)))))))))
-
-(defun wl-message-buffer-prefetch (folder number summary charset)
- (when (buffer-live-p summary)
- (save-excursion
- (set-buffer summary)
- (when (string= (elmo-folder-name-internal folder)
- (wl-summary-buffer-folder-name))
- (let ((message-id (elmo-message-field folder number 'message-id))
- (wl-mime-charset charset)
- (default-mime-charset charset)
- result time1 time2 sec micro)
- (if (not (wl-message-buffer-cache-hit (list folder
- number message-id)))
- (let* ((size (elmo-message-field folder number 'size)))
- (when (or (elmo-message-file-p folder number)
- (not
- (and (integerp size)
- elmo-message-fetch-threshold
- (>= size
- elmo-message-fetch-threshold))))
- ;;(not (elmo-file-cache-exists-p message-id)))))
- (when wl-message-buffer-prefetch-debug
- (setq time1 (current-time))
- (message "Prefetching %d..." number))
- (setq result (wl-message-buffer-display folder number
- 'mime nil 'unread))
- (when wl-message-buffer-prefetch-debug
- (setq time2 (current-time))
- (setq sec (- (nth 1 time2)(nth 1 time1)))
- (setq micro (- (nth 2 time2)(nth 2 time1)))
- (setq micro (+ micro (* 1000000 sec)))
- (message "Prefetching %d...done(%f msec)."
- number
- (/ micro 1000.0))))))))))
- (setq wl-message-buffer-prefetch-timer nil))
+(defun wl-message-buffer-prefetch-p (folder &optional number)
+ (and (or (not number)
+ (elmo-message-file-p folder number)
+ (let ((size (elmo-message-field folder number 'size)))
+ (not (and (integerp size)
+ wl-message-buffer-prefetch-threshold
+ (>= size wl-message-buffer-prefetch-threshold)))))
+ (or (not number)
+ (elmo-folder-plugged-p folder)
+ (elmo-file-cache-exists-p
+ (elmo-message-field folder number 'message-id)))
+ (or (cond
+ ((eq wl-message-buffer-prefetch-folder-type-list t)
+ t)
+ ((and number wl-message-buffer-prefetch-folder-type-list)
+ (memq (elmo-folder-type-internal
+ (elmo-message-folder folder number))
+ wl-message-buffer-prefetch-folder-type-list))
+ (wl-message-buffer-prefetch-folder-type-list
+ (let ((list wl-message-buffer-prefetch-folder-type-list)
+ type)
+ (catch 'done
+ (while (setq type (pop list))
+ (if (elmo-folder-contains-type folder type)
+ (throw 'done t)))))))
+ (cond
+ ((consp wl-message-buffer-prefetch-folder-list)
+ (wl-string-match-member (elmo-folder-name-internal folder)
+ wl-message-buffer-prefetch-folder-list))
+ (t wl-message-buffer-prefetch-folder-list)))))
+
+(defsubst wl-message-buffer-prefetch-clear-timer ()
+;;; cannot use for the bug of fsf-compat package (1.09).
+;;; (cancel-function-timers 'wl-message-buffer-prefetch-subr)
+ (if (fboundp 'run-with-idle-timer)
+ (if (featurep 'xemacs)
+ (let ((p itimer-list))
+ (while (car p)
+ (if (eq 'wl-message-buffer-prefetch-subr
+ (itimer-function (car p)))
+ (delete-itimer (car p)))
+ (setq p (cdr p))))
+ ;; FSF Emacs is correct
+ (cancel-function-timers 'wl-message-buffer-prefetch-subr))))
+
+(defsubst wl-message-buffer-prefetch-set-timer (folder number count
+ summary charset)
+ (if (not (fboundp 'run-with-idle-timer))
+ (when (sit-for wl-message-buffer-prefetch-idle-time)
+ (wl-message-buffer-prefetch-subr
+ folder number count summary charset))
+ (run-with-idle-timer
+ wl-message-buffer-prefetch-idle-time
+ nil
+ 'wl-message-buffer-prefetch-subr
+ folder number count summary charset)))
+
+(defvar wl-message-buffer-prefetch-move-spec-alist nil)
+
+(defun wl-message-buffer-prefetch-get-next (folder number summary)
+ (if (buffer-live-p summary)
+ (with-current-buffer summary
+ (let ((wl-summary-move-spec-alist
+ (or wl-message-buffer-prefetch-move-spec-alist
+ wl-summary-move-spec-alist))
+ (next number))
+ (while (and (setq next (funcall
+ wl-message-buffer-prefetch-get-next-function
+ next))
+ (not (wl-message-buffer-prefetch-p folder next))))
+ next))))
+
+(defun wl-message-buffer-prefetch (folder number count
+ &optional summary charset)
+ (let* ((summary (or summary (get-buffer wl-summary-buffer-name)))
+ (num number))
+ (when (and count
+ (wl-message-buffer-prefetch-p folder))
+ (unless (wl-message-buffer-prefetch-p folder number)
+ (setq num
+ (wl-message-buffer-prefetch-get-next folder number summary)))
+ (when num
+ (wl-message-buffer-prefetch-clear-timer)
+ (wl-message-buffer-prefetch-set-timer
+ folder num count summary charset)))))
+
+(defun wl-message-buffer-prefetch-next (folder number count
+ &optional summary charset)
+ (let* ((summary (or summary (get-buffer wl-summary-buffer-name)))
+ next)
+ (when (and count
+ (wl-message-buffer-prefetch-p folder))
+ (setq next (wl-message-buffer-prefetch-get-next folder number summary))
+ (when next
+ (wl-message-buffer-prefetch-clear-timer)
+ (wl-message-buffer-prefetch-set-timer
+ folder next count summary charset)))))
+
+(defun wl-message-buffer-prefetch-subr (folder number count summary charset)
+ (if (buffer-live-p summary)
+ (with-current-buffer summary
+ (if (and number
+ (numberp count)
+ (>= (setq count (- count 1)) 0)
+ (string= (elmo-folder-name-internal folder)
+ (wl-summary-buffer-folder-name)))
+ (let* ((wl-mime-charset charset)
+ (default-mime-charset charset)
+ (message-id (elmo-message-field folder number 'message-id))
+ (key (list (elmo-folder-name-internal folder)
+ number message-id))
+ (hit (wl-message-buffer-cache-hit key))
+ (display-type (wl-message-make-display-type
+ wl-summary-buffer-display-mime-mode
+ wl-summary-buffer-display-header-mode))
+ result time1 time2 sec micro)
+ (when wl-message-buffer-prefetch-debug
+ (message "%d: count %d, hit %s" number count (buffer-name hit)))
+ (if (and hit (buffer-live-p hit))
+ (progn
+ (wl-message-buffer-cache-sort
+ (wl-message-buffer-cache-entry-make key hit))
+ (wl-message-buffer-prefetch-subr
+ folder
+ (wl-message-buffer-prefetch-get-next
+ folder number summary)
+ count summary charset))
+ ;; prefetching
+ (when wl-message-buffer-prefetch-debug
+ (setq time1 (current-time))
+ (message "Prefetching %d..." number))
+ (setq result (wl-message-buffer-display
+ folder number display-type nil 'unread))
+ (when wl-message-buffer-prefetch-debug
+ (setq time2 (current-time))
+ (setq sec (- (nth 1 time2)(nth 1 time1)))
+ (setq micro (- (nth 2 time2)(nth 2 time1)))
+ (setq micro (+ micro (* 1000000 sec)))
+ (message "Prefetching %d...done(%f msec)."
+ number
+ (/ micro 1000.0))
+ (sit-for 0))
+ ;; set next prefetch
+ (wl-message-buffer-prefetch-set-timer
+ folder
+ (wl-message-buffer-prefetch-get-next
+ folder number summary)
+ count summary charset)
+ (sit-for 0)
+ ;; success prefetch
+ )))
+ ;; finish prefetch
+ (when wl-message-buffer-prefetch-debug
+ (message "Buffer Cached Messages: %s"
+ (mapconcat
+ '(lambda (cache)
+ (if (numberp (nth 1 (car cache)))
+ (if (string=
+ (nth 0 (car cache))
+ (elmo-folder-name-internal folder))
+ (format "%d"
+ (nth 1 (car cache)))
+ (format "*%d" (nth 1 (car cache))))
+ "-"))
+ wl-message-buffer-cache " "))) )))
(defvar wl-message-button-map (make-sparse-keymap))
(if (wl-summary-jump-to-msg-by-message-id data)
(wl-summary-redisplay)))
-(defun wl-message-refer-article-or-url (e)
- "Read article specified by message-id around point.
-If failed, attempt to execute button-dispatcher."
- (interactive "e")
- (let ((window (get-buffer-window (current-buffer)))
- mouse-window point beg end msg-id)
- (unwind-protect
- (progn
- (mouse-set-point e)
- (setq mouse-window (get-buffer-window (current-buffer)))
- (setq point (point))
- (setq beg (save-excursion (beginning-of-line) (point)))
- (setq end (save-excursion (end-of-line) (point)))
- (search-forward ">" end t) ;Move point to end of "<....>".
- (if (and (re-search-backward "\\(<[^<> \t\n]+@[^<> \t\n]+>\\)"
- beg t)
- (not (string-match "mailto:"
- (setq msg-id (wl-match-buffer 1)))))
- (progn
- (goto-char point)
- (switch-to-buffer-other-window
- wl-message-buffer-cur-summary-buffer)
- (if (wl-summary-jump-to-msg-by-message-id msg-id)
- (wl-summary-redisplay)))
- (wl-message-button-dispatcher-internal e)))
- (if (eq mouse-window (get-buffer-window (current-buffer)))
- (select-window window)))))
-
(defun wl-message-uu-substring (buf outbuf &optional first last)
(save-excursion
(set-buffer buf)
(set-buffer buf)
filename))))
+;;; Header narrowing courtesy of Hideyuki Shirai.
+(defun wl-message-header-narrowing ()
+ "Narrowing headers."
+ (unless (eq this-command 'wl-summary-redisplay-all-header)
+ (save-excursion
+ (save-restriction
+ (goto-char (point-min))
+ (if (re-search-forward "^$" nil t)
+ (beginning-of-line)
+ (goto-char (point-max)))
+ (narrow-to-region (point-min) (point))
+ (let ((fields wl-message-header-narrowing-fields))
+ (while fields
+ (wl-message-header-narrowing-1 (concat "^" (car fields) ":"))
+ (setq fields (cdr fields))))))))
+
+(defvar wl-message-header-narrowing-map (make-sparse-keymap))
+(define-key wl-message-header-narrowing-map [mouse-2]
+ 'wl-message-header-narrowing-again-at-mouse)
+
+(defvar wl-message-header-narrowing-widen-map (make-sparse-keymap))
+(define-key wl-message-header-narrowing-widen-map [mouse-2]
+ 'wl-message-header-narrowing-widen-at-mouse)
+
+(defun wl-message-header-narrowing-again-at-mouse (event)
+ (interactive "e")
+ (save-window-excursion
+ (save-excursion
+ (mouse-set-point event)
+ (wl-message-header-narrowing))))
+
+(defun wl-message-header-narrowing-1 (hregexp)
+ (let ((case-fold-search t)
+ ov start end)
+ (goto-char (point-min))
+ (while (re-search-forward hregexp nil t)
+ (setq start (match-beginning 0))
+ (forward-line 1)
+ (setq end (progn (while (looking-at "^[ \t]") (forward-line))
+ (forward-line -1)
+ (line-end-position)))
+ (if (<= (count-lines start end) wl-message-header-narrowing-lines)
+ (forward-line 1)
+ (goto-char start)
+ (forward-line (1- wl-message-header-narrowing-lines))
+ (end-of-line)
+ (setq start (point))
+ (unless (eq (get-char-property start 'invisible)
+ 'wl-message-header-narrowing)
+ (setq ov (or
+ (let ((ovs (overlays-at start))
+ ov)
+ (while (and ovs (not (overlayp ov)))
+ (if (overlay-get (car ovs)
+ 'wl-message-header-narrowing)
+ (setq ov (car ovs)))
+ (setq ovs (cdr ovs)))
+ ov)
+ (make-overlay start end)))
+ (overlay-put ov 'wl-message-header-narrowing t)
+ (overlay-put ov 'evaporate t)
+ (overlay-put ov 'invisible 'wl-message-header-narrowing)
+ (overlay-put ov 'after-string
+ wl-message-header-narrowing-string))))))
+
+(defun wl-message-header-narrowing-widen-at-mouse (event)
+ (interactive "e")
+ (save-selected-window
+ (select-window (posn-window (event-start event)))
+ (let* ((win (selected-window))
+ (wpos (window-start win))
+ (pos (mouse-set-point event))
+ (ovs (overlays-in (1- pos) (1+ pos))) ;; Uum...
+ ov)
+ (while (and ovs (not (overlayp ov)))
+ (when (overlay-get (car ovs) 'wl-message-header-narrowing)
+ (setq ov (car ovs)))
+ (setq ovs (cdr ovs)))
+ (when (overlayp ov)
+ (overlay-put ov 'face 'wl-message-header-narrowing-face)
+ (overlay-put ov 'local-map wl-message-header-narrowing-map)
+ (overlay-put ov 'invisible nil)
+ (overlay-put ov 'after-string nil))
+ (set-window-start win wpos))))
+
+(defun wl-message-header-narrowing-setup ()
+ (when (boundp 'line-move-ignore-invisible)
+ (set (make-local-variable 'line-move-ignore-invisible) t))
+ (set-text-properties 0 (length wl-message-header-narrowing-string)
+ `(face
+ wl-message-header-narrowing-face
+ keymap
+ ,wl-message-header-narrowing-widen-map)
+ wl-message-header-narrowing-string))
+
+(defun wl-message-header-narrowing-toggle ()
+ "Toggle header narrowing."
+ (interactive)
+ (when wl-message-use-header-narrowing
+ (save-excursion
+ (goto-char (point-min))
+ (if (re-search-forward "^$" nil t)
+ (beginning-of-line)
+ (goto-char (point-max)))
+ (let ((ovs (overlays-in (point-min) (point)))
+ ov hn-ovs)
+ (while (setq ov (car ovs))
+ (when (overlay-get ov 'wl-message-header-narrowing)
+ (setq hn-ovs (cons ov hn-ovs)))
+ (setq ovs (cdr ovs)))
+ (if hn-ovs
+ (while hn-ovs
+ (delete-overlay (car hn-ovs))
+ (setq hn-ovs (cdr hn-ovs)))
+ (wl-message-header-narrowing))))))
+
(require 'product)
(product-provide (provide 'wl-message) (require 'wl-version))