;;; wl-localdir-sort.el --- sort files in localdir by current summary order ;; Copyright (C) 2003 Yoichi NAKAYAMA ;; Author: Yoichi NAKAYAMA ;; Keywords: mail, net news ;; This file is not yet part of Wanderlust. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;; ;;; Commentary: ;; ;; This gives a function to sort localdir files. ;; ;; If it fails with error, please invoke wl-summary-sync with "all" range ;; to recover summary view. ;; ;; example: ;; ;; --> steps ;; 111111 ;; 3-2222 ;; 4444-3 ;; 555-44 ;; 22-555 ;; ------ following are temporary ;; .3333. ;; ;; ----> steps ;; 2-111111 ;; 333-2222 ;; 11-33333 ;; 55555-44 ;; 444444-5 ;; -------- following are temporary ;; .222.... ;; .....55. ;;; Code: ;; (defun wl-localdir-sort-and-pack-number () "Sort files in localdir by current summary order." (interactive) (let ((folder wl-summary-buffer-elmo-folder)) (cond ((not folder) ;; do nothing ) ((eq (elmo-folder-type-internal folder) 'localdir) (when (eq wl-summary-buffer-view 'sequence) (wl-summary-pack-number) (let ((dir (elmo-localdir-folder-directory-internal folder)) map-list (new-num 1)) ;; Here wl-summary-buffer-number-list is assumed to be occupied from ;; the lowest number. If not, putting back tmp-num can generate a ;; hole and possibly cause error when new message is added. (dolist (old-num wl-summary-buffer-number-list) (setq map-list (append map-list (list (cons old-num new-num)))) (setq new-num (1+ new-num))) (setq map-list (sort map-list (lambda (x y) (< (car x) (car y))))) (while map-list (if (eq (car (car map-list)) (cdr (car map-list))) (setq map-list (cdr map-list)) (let ((tmp-num (1+ (car (elmo-folder-status wl-summary-buffer-elmo-folder)))) (old-num1 (car (car map-list))) (new-num1 (cdr (car map-list))) map map1) (elmo-bind-directory dir (rename-file (int-to-string old-num1) (int-to-string tmp-num))) (setq map-list (cdr map-list)) (setq map1 (cons tmp-num new-num1)) (while (setq map (rassq old-num1 map-list)) (elmo-bind-directory dir (rename-file (int-to-string (car map)) (int-to-string (cdr map)))) (setq map-list (delq map map-list)) (setq old-num1 (car map))) (elmo-bind-directory dir (rename-file (int-to-string (car map1)) (int-to-string (cdr map1)))))))) (wl-summary-sync 'unset-cursor "all"))) (t (message "Not supported folder type")))))