[mew-dist 18408] Re: sort by x-* problem

Takashi P.KATOH p-katoh at example.com
2001年 8月 8日 (水) 16:12:34 JST


ようやく Mew 2.0 に移行しました。

From: Koga Youichirou <y-koga at example.com>
Subject: [mew-dist 18126] sort by x-* problem
Date: Wed, 18 Jul 2001 16:05:40 +0900 (JST)
> #昔の Mew にあった mew-summary-sort-region がほしいのはぼくだけだろうか…

これが無くて気が狂いそうになったので作りました。


問題点
  1. あんまりチェックしてない (うまくいってなかったらごめんなさい)
  2. code が綺麗じゃない。
  3. region が全体の途中だけでも、scan は最後までされてしまう
     (まぁ以前もそうだったので許容範囲かとは思うのですが...)

んで、素の 2.0 に対するパッチです。

-- 
かとぺ / 加藤 貴司
久しぶりに elisp で書いた気がする...

-------------- next part --------------
--- mew/mew-sort.el	Wed Jul 18 18:37:36 2001
+++ mew-sort.el	Wed Aug  8 16:12:01 2001
@@ -79,9 +79,9 @@
        (insert (format "move %s to %s\n" src dst)))
     (rename-file src dst)))
 
-(defun mew-summary-sort ()
+(defun mew-summary-sort (&optional prefix)
   "Sort messages and list them up again."
-  (interactive)
+  (interactive "P")
   (mew-summary-only
    (mew-summary-not-in-queue
     (mew-summary-not-in-draft
@@ -100,15 +100,43 @@
 	    (tmp (mew-folder-new-message folder 'num-only))
 	    (i 0)
 	    (tmpbuf (generate-new-buffer mew-buffer-prefix))
-	    ent idx med num value files)
+	    ent idx med num value files
+	    from to (range nil))
        (setq mew-summary-buffer-process t)
-       (message "Sorting %s ... " folder)
+       (message "Sorting %s%s ... " (if prefix "region " "") folder)
+
+       ;; get range if prefix is t
+       (if prefix
+	   (let ((r1 (region-beginning)) (r2 (region-end)))
+	     (save-excursion
+	       (goto-char (min r1 r2))
+	       (setq from
+		     (or (mew-summary-message-number)
+			 (progn
+			   (re-search-backward mew-regex-msg nil t)
+			   (mew-summary-message-number))))
+	       (goto-char (max r1 r2))
+	       (setq to
+		     (or (mew-summary-message-number)
+			 (progn
+			   (re-search-backward mew-regex-msg nil t)
+			   (mew-summary-message-number))))
+	       (goto-char (min r1 r2))
+	       (beginning-of-line)
+	       (setq range (concat from "-" to)))))
+
        (save-excursion
 	 (set-buffer tmpbuf)
 	 (mew-erase-buffer)
-	 (call-process mew-prog-mewls nil t nil
-		       "-b" mew-mail-path "-c" mew-news-path
-		       "-d" key "-l" "0" "-s" folder)
+	 ;;; xxx
+	 ;;; xxx I just want to add range to args...
+	 (if prefix
+	     (call-process mew-prog-mewls nil t nil
+			   "-b" mew-mail-path "-c" mew-news-path
+			   "-d" key "-l" "0" folder range)
+	   (call-process mew-prog-mewls nil t nil
+			 "-b" mew-mail-path "-c" mew-news-path
+			 "-d" key "-l" "0" folder))
 	 (goto-char (point-min))
 	 (while (not (eobp))
 	   (if (not (looking-at "^\\([0-9]+\\)[ \t]*:[ \t]*"))
@@ -132,6 +160,8 @@
 	     ;; message buffer
 	     (mew-elet
 	      (erase-buffer)
+	      (if prefix
+		  (insert "Sort region: " range "\n\n"))
 	      (insert "Sort as follows:\n")))
 	 (mew-window-configure 'summary))
        ;;         sorted        sorted
@@ -182,8 +212,17 @@
 	     (set-buffer-modified-p nil)
 	     (goto-char (point-min))
 	     (mew-pop-to-buffer buf))
-	 (mew-erase-buffer)
-	 (mew-scan (mew-scan-mewls-src folder))))))))
+	 (if prefix
+	     ;; erase buffer after "from"
+	     (save-excursion	;; Is this needed?
+	       (mew-elet
+		(widen)
+		(mew-summary-jump-message from)
+		(delete-region (point) (point-max))))
+	   (mew-erase-buffer))
+	 (mew-scan (mew-scan-mewls-src folder 
+				       (if prefix (concat from "-"))))
+	 ))))))
 
 (provide 'mew-sort)
 


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