[Mew-dist 15257] another visualisation of thread

Shun-ichi TAHARA ( 田原 俊一 ) jado at example.com
2000年 12月 2日 (土) 02:22:55 JST


threadの描画を、よくあるツリーっぽい感じにするパッチを作ってみました。
b84に当ててください。

mew-thread-indent-string の代わりに、string 4つからなる vector の、
mew-thread-indent-strings を定義します。

デフォルトは [ " +" " +" " |" "  " ] ですが、日本語が使えるなら、
[ "├" "└" "│" " " ] などとすると、かなりそれっぽいです。

なんとなくわかると思いますが、それぞれ、thread の描画に使われるパーツ
になります(docstringの英語がかなりアヤシイですが)。

なお、vector の各要素の length が同じでないと、^ や C-p や C-n で誤動
作するので、起動時にチェックしてエラーにするようにしています。ですので、
JISの罫線を設定するときは、4つめを(いわゆる)全角スペースにする必要があ
ります。

まだとりあえず動くだけで、かなり遅いような気もしますが、これから頑張っ
てみます。
_______________________________
田原 俊一   jado at example.com, shunichi_tahara at example.com
                                  http://flowernet.gr.jp/jado/
FingerPrint: 16 9E 70 3B 05 86 5D 08 - B8 4C 47 3A E7 E9 8E D9
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
-------------- next part --------------
*** mew-thread.el.orig	Thu Nov 30 18:54:53 2000
--- mew-thread.el	Sat Dec  2 02:03:56 2000
***************
*** 47,57 ****
  Mew doesn't provide any loop detection/avoidance mechanism. So, you
  should understand this risk.")
  
! (defvar mew-thread-indent-string "  "
!   "*A string to be inserted for indentation of thread.")
  
! (defvar mew-thread-indent-array nil)
! (defvar mew-thread-indent-array-size 33) ;; devide by 32
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;
--- 47,76 ----
  Mew doesn't provide any loop detection/avoidance mechanism. So, you
  should understand this risk.")
  
! (defvar mew-thread-indent-strings
!   [" +" " +" " |" "  "]
!   "*Vector of string to be used for indentation of thread.
! This is consist of four members; 1st member is to prefix the child
! message that is not the last one, 2nd is to prefix the last child, 3rd
! and 4th are to prefix grand-child thread tree, 4th is for the child
! tree of the last chile message.
! For example, [ \" +\" \" +\" \" |\" \"  \" ] makes thread view below.
! 
!     Message 1
!      +Message 2
!      | +Message 3
!      +Message 4
!        +Message 5
! 
! All members must have same lengths.")
! (defvar mew-thread-indent-regex nil)
! (defvar mew-thread-indent-lregex nil)
  
! ;(defvar mew-thread-indent-string "  "
! ;  "*A string to be inserted for indentation of thread.")
! 
! ;(defvar mew-thread-indent-array nil)
! ;(defvar mew-thread-indent-array-size 33) ;; devide by 32
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;
***************
*** 98,112 ****
  ;;;
  
  (defun mew-thread-setup ()
!   (let* ((i 0)
! 	 (size mew-thread-indent-array-size)
! 	 (array (make-vector size nil))
! 	 (indent ""))
!     (while (< i size)
!       (aset array i indent)
!       (setq i (1+ i))
!       (setq indent (concat indent mew-thread-indent-string)))
!     (setq mew-thread-indent-array array)))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;
--- 117,147 ----
  ;;;
  
  (defun mew-thread-setup ()
!   (let ((idt1 (aref mew-thread-indent-strings 0))
! 	(idt2 (aref mew-thread-indent-strings 1))
! 	(idt3 (aref mew-thread-indent-strings 2))
! 	(idt4 (aref mew-thread-indent-strings 3)))
!     (if (not (= (length idt1) (length idt2) (length idt3) (length idt4)))
! 	(error
! 	 "All members of mew-thread-indent-strings must have same lengths."))
!     (setq mew-thread-indent-regex
! 	  (concat "\\(" (regexp-quote idt1) "\\|" (regexp-quote idt2)
! 		  "\\|" (regexp-quote idt3) "\\|" (regexp-quote idt4) "\\)"))
!     (setq mew-thread-indent-lregex
! 	  (concat "[^"
! 		  (regexp-quote
! 		   (format "%c%c%c%c"
! 			   (aref idt1 0) (aref idt2 0)
! 			   (aref idt3 0) (aref idt4 0))) "]"))))
! ;  (let* ((i 0)
! ;	 (size mew-thread-indent-array-size)
! ;	 (array (make-vector size nil))
! ;	 (indent ""))
! ;    (while (< i size)
! ;      (aset array i indent)
! ;      (setq i (1+ i))
! ;      (setq indent (concat indent mew-thread-indent-string)))
! ;    (setq mew-thread-indent-array array)))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;
***************
*** 253,259 ****
       (setq tm5 (current-time))
       (mew-summary-thread-print-loop
        mew-virtual-buffer-thread-top 0 folder
!       (mew-summary-scan-form folder 'column))
       (setq tm6 (current-time))
       ;;
       (if mark (mew-mark-undo-marks (list mew-mark-review)))
--- 288,294 ----
       (setq tm5 (current-time))
       (mew-summary-thread-print-loop
        mew-virtual-buffer-thread-top 0 folder
!       (mew-summary-scan-form folder 'column) "")
       (setq tm6 (current-time))
       ;;
       (if mark (mew-mark-undo-marks (list mew-mark-review)))
***************
*** 274,294 ****
  ;;; Visualizing thread
  ;;;
  
! (defun mew-summary-thread-print-loop (top level folder column)
    (while top
!     (mew-summary-thread-print (car top) level folder column)
!     (setq top (cdr top))))
  
! (defun mew-summary-thread-print (me level folder column)
    (let (cld)
      (mew-elet
       (insert (mew-thread-get-line me))
       (forward-line -1)
       (move-to-column column)
!      (let ((i 0))
!        (while (< i level)
! 	 (insert mew-thread-indent-string)
! 	 (setq i (1+ i))))
  ;     (if (< level mew-thread-indent-array-size)
  ;	 (insert (aref mew-thread-indent-array level))
  ;       (let* ((i 0)
--- 309,341 ----
  ;;; Visualizing thread
  ;;;
  
! (defun mew-summary-thread-print-loop (top level folder column prefix)
    (while top
!     (let ((next (cdr top))
! 	  i idt1 idt2)
!       (if next
! 	  (setq i 0)
! 	(setq i 1))
!       (cond ((= level 0)
! 	     (setq idt1 "")
! 	     (setq idt2 ""))
! 	    (t
! 	     (setq idt1 (aref mew-thread-indent-strings i))
! 	     (setq idt2 (aref mew-thread-indent-strings (+ i 2)))))
!       (mew-summary-thread-print (car top) level folder column idt1 idt2 prefix)
!       (setq top next))))
  
! (defun mew-summary-thread-print (me level folder column idt1 idt2 prefix)
    (let (cld)
      (mew-elet
       (insert (mew-thread-get-line me))
       (forward-line -1)
       (move-to-column column)
!      (insert prefix idt1)
! ;     (let ((i 0))
! ;       (while (< i level)
! ;	 (insert mew-thread-indent-string)
! ;	 (setq i (1+ i))))
  ;     (if (< level mew-thread-indent-array-size)
  ;	 (insert (aref mew-thread-indent-array level))
  ;       (let* ((i 0)
***************
*** 304,310 ****
         (insert " " folder " " (mew-thread-get-msg me)))
       (forward-line))
      (setq cld (mew-thread-get-child me))
!     (if cld (mew-summary-thread-print-loop cld (1+ level) folder column))))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;
--- 351,359 ----
         (insert " " folder " " (mew-thread-get-msg me)))
       (forward-line))
      (setq cld (mew-thread-get-child me))
!     (if cld
! 	(mew-summary-thread-print-loop
! 	 cld (1+ level) folder column (concat prefix idt2)))))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ;;;
***************
*** 316,331 ****
    (interactive)
    (let* ((folder (mew-summary-folder-name))
  	 (column (mew-summary-scan-form folder 'column))
! 	 (len (length mew-thread-indent-string))
! 	 (fregex (regexp-quote mew-thread-indent-string))
  	 (regex ""))
      (save-excursion
        (move-to-column column)
!       (while (looking-at fregex)
! 	(setq regex (concat regex mew-thread-indent-string))
  	(forward-char len))
!       (setq regex (concat regex mew-thread-indent-string))
!       (setq regex (regexp-quote regex))
        (mew-summary-review-one)
        (forward-line)
        (catch 'loop
--- 365,378 ----
    (interactive)
    (let* ((folder (mew-summary-folder-name))
  	 (column (mew-summary-scan-form folder 'column))
! 	 (len (length (aref mew-thread-indent-strings 0)))
  	 (regex ""))
      (save-excursion
        (move-to-column column)
!       (while (looking-at mew-thread-indent-regex)
! 	(setq regex (concat regex mew-thread-indent-regex))
  	(forward-char len))
!       (setq regex (concat regex mew-thread-indent-regex))
        (mew-summary-review-one)
        (forward-line)
        (catch 'loop
***************
*** 343,356 ****
    (mew-virtual-only
     (let* ((folder (substring (mew-summary-folder-name 'ext) 1))
  	  (column (mew-summary-scan-form folder 'column))
- 	  (regex (regexp-quote mew-thread-indent-string))
  	  here)
       (save-excursion
         (forward-line -1)
         (catch 'loop
  	 (while (not (bobp))
  	   (move-to-column column)
! 	   (if (looking-at regex)
  	       (forward-line -1)
  	     (throw 'loop (setq here (point)))))))
       (if here
--- 390,402 ----
    (mew-virtual-only
     (let* ((folder (substring (mew-summary-folder-name 'ext) 1))
  	  (column (mew-summary-scan-form folder 'column))
  	  here)
       (save-excursion
         (forward-line -1)
         (catch 'loop
  	 (while (not (bobp))
  	   (move-to-column column)
! 	   (if (looking-at mew-thread-indent-regex)
  	       (forward-line -1)
  	     (throw 'loop (setq here (point)))))))
       (if here
***************
*** 366,379 ****
    (mew-virtual-only
     (let* ((folder (substring (mew-summary-folder-name 'ext) 1))
  	  (column (mew-summary-scan-form folder 'column))
- 	  (regex (regexp-quote mew-thread-indent-string))
  	  here)
       (save-excursion
         (forward-line)
         (catch 'loop
  	 (while (not (eobp))
  	   (move-to-column column)
! 	   (if (looking-at regex)
  	       (forward-line)
  	     (throw 'loop (setq here (point)))))))
       (if here
--- 412,424 ----
    (mew-virtual-only
     (let* ((folder (substring (mew-summary-folder-name 'ext) 1))
  	  (column (mew-summary-scan-form folder 'column))
  	  here)
       (save-excursion
         (forward-line)
         (catch 'loop
  	 (while (not (eobp))
  	   (move-to-column column)
! 	   (if (looking-at mew-thread-indent-regex)
  	       (forward-line)
  	     (throw 'loop (setq here (point)))))))
       (if here
***************
*** 389,409 ****
    (mew-virtual-only
     (let* ((folder (mew-summary-folder-name))
  	  (column (mew-summary-scan-form folder 'column))
! 	  (len (length mew-thread-indent-string))
! 	  (fregex (regexp-quote mew-thread-indent-string))
  	  (regex "") lregex movep)
       (save-excursion
         (move-to-column column)
!        (if (not (looking-at fregex))
  	   ()
  	 (setq movep t)
  	 (forward-char len)
! 	 (while (looking-at fregex)
! 	   (setq regex (concat regex mew-thread-indent-string))
  	   (forward-char len))))
!      (setq lregex (concat (regexp-quote regex)
! 			  (format "[^%c]" (aref mew-thread-indent-string 0))))
!      (setq regex (regexp-quote regex))
       (if movep
  	 (catch 'loop
  	   (while t
--- 434,451 ----
    (mew-virtual-only
     (let* ((folder (mew-summary-folder-name))
  	  (column (mew-summary-scan-form folder 'column))
! 	  (len (length (aref mew-thread-indent-strings 0)))
  	  (regex "") lregex movep)
       (save-excursion
         (move-to-column column)
!        (if (not (looking-at mew-thread-indent-regex))
  	   ()
  	 (setq movep t)
  	 (forward-char len)
! 	 (while (looking-at mew-thread-indent-regex)
! 	   (setq regex (concat regex mew-thread-indent-regex))
  	   (forward-char len))))
!      (setq lregex (concat regex mew-thread-indent-lregex))
       (if movep
  	 (catch 'loop
  	   (while t


Mew-dist メーリングリストの案内