* elmo-archive.el (elmo-archive-field-condition-match)
[elisp/wanderlust.git] / elmo / elmo-util.el
index d99b47a..ed5377a 100644 (file)
@@ -29,7 +29,9 @@
 ;;; Code:
 ;;
 
 ;;; Code:
 ;;
 
-(eval-when-compile (require 'cl))
+(eval-when-compile
+  (require 'cl)
+  (require 'static))
 (require 'elmo-vars)
 (require 'elmo-date)
 (require 'mcharset)
 (require 'elmo-vars)
 (require 'elmo-date)
 (require 'mcharset)
 (fset 'elmo-base64-decode-string
       (mel-find-function 'mime-decode-string "base64"))
 
 (fset 'elmo-base64-decode-string
       (mel-find-function 'mime-decode-string "base64"))
 
-(if elmo-use-hardlink
-    (defalias 'elmo-add-name-to-file 'add-name-to-file)
-  (defun elmo-add-name-to-file
-    (filename newname &optional ok-if-already-exists)
-    (copy-file filename newname ok-if-already-exists t)))
+(eval-and-compile
+  (if elmo-use-hardlink
+      (defalias 'elmo-add-name-to-file 'add-name-to-file)
+    (defun elmo-add-name-to-file
+      (filename newname &optional ok-if-already-exists)
+      (copy-file filename newname ok-if-already-exists t))))
 
 (defmacro elmo-set-work-buf (&rest body)
   "Execute BODY on work buffer.  Work buffer remains."
 
 (defmacro elmo-set-work-buf (&rest body)
   "Execute BODY on work buffer.  Work buffer remains."
-  `(save-excursion
-     (set-buffer (get-buffer-create elmo-work-buf-name))
+  `(with-current-buffer (get-buffer-create elmo-work-buf-name)
      (set-buffer-multibyte default-enable-multibyte-characters)
      (erase-buffer)
      ,@body))
      (set-buffer-multibyte default-enable-multibyte-characters)
      (erase-buffer)
      ,@body))
@@ -168,7 +170,7 @@ with FILENAME which defaults to `buffer-file-name'."
              (goto-char (point-min))
              (setq case-fold-search nil)
              (re-search-forward "^;;;coding system: "
              (goto-char (point-min))
              (setq case-fold-search nil)
              (re-search-forward "^;;;coding system: "
-                                ;;(+ (point-min) 3000) t))
+;;;                             (+ (point-min) 3000) t))
                                 nil t))
            (looking-at "[^\t\n\r ]+")
            (find-coding-system
                                 nil t))
            (looking-at "[^\t\n\r ]+")
            (find-coding-system
@@ -482,6 +484,10 @@ Return value is a cons cell of (STRUCTURE . REST)"
       (setq list (cdr list))))
   list)
 
       (setq list (cdr list))))
   list)
 
+(defun elmo-union (l1 l2)
+  "Make a union of two lists"
+  (elmo-uniq-sorted-list (sort (append l1 l2) #'<)))
+
 (defun elmo-list-insert (list element after)
   (let* ((match (memq after list))
         (rest (and match (cdr (memq after list)))))
 (defun elmo-list-insert (list element after)
   (let* ((match (memq after list))
         (rest (and match (cdr (memq after list)))))
@@ -502,7 +508,7 @@ Return value is a cons cell of (STRUCTURE . REST)"
                  (> (buffer-size) 0)
                  (= (char-after (1- (point-max))) ?\n))
         (goto-char (point-max))
                  (> (buffer-size) 0)
                  (= (char-after (1- (point-max))) ?\n))
         (goto-char (point-max))
-        (delete-backward-char 1))
+        (delete-char -1))
        (buffer-string)))))
 
 (defun elmo-save-string (string filename)
        (buffer-string)))))
 
 (defun elmo-save-string (string filename)
@@ -565,7 +571,7 @@ Return value is a cons cell of (STRUCTURE . REST)"
          print-length print-level)
       (prin1 elmo-passwd-alist (current-buffer))
       (princ "\n" (current-buffer))
          print-length print-level)
       (prin1 elmo-passwd-alist (current-buffer))
       (princ "\n" (current-buffer))
-;;;   (if (and (file-exists-p filename)
+;;;      (if (and (file-exists-p filename)
 ;;;           (not (equal 384 (file-modes filename))))
 ;;;      (error "%s is not safe.chmod 600 %s!" filename filename))
       (if (file-writable-p filename)
 ;;;           (not (equal 384 (file-modes filename))))
 ;;;      (error "%s is not safe.chmod 600 %s!" filename filename))
       (if (file-writable-p filename)
@@ -591,7 +597,7 @@ Return value is a cons cell of (STRUCTURE . REST)"
                                (elmo-base64-encode-string pass)))))
       (if elmo-passwd-life-time
          (run-with-timer elmo-passwd-life-time nil
                                (elmo-base64-encode-string pass)))))
       (if elmo-passwd-life-time
          (run-with-timer elmo-passwd-life-time nil
-                         `(lambda nil (elmo-remove-passwd ,key))))
+                         `(lambda () (elmo-remove-passwd ,key))))
       pass)))
 
 (defun elmo-remove-passwd (key)
       pass)))
 
 (defun elmo-remove-passwd (key)
@@ -819,7 +825,7 @@ Return value is a cons cell of (STRUCTURE . REST)"
                             (directory-files path t "^[^\\.]")
                           (error nil)))
                  (result 0.0))
                             (directory-files path t "^[^\\.]")
                           (error nil)))
                  (result 0.0))
-             ;; (result (nth 7 file-attr))) ... directory size
+;;;          (result (nth 7 file-attr))) ; ... directory size
              (while files
                (setq result (+ result (or (elmo-disk-usage (car files)) 0)))
                (setq files (cdr files)))
              (while files
                (setq result (+ result (or (elmo-disk-usage (car files)) 0)))
                (setq files (cdr files)))
@@ -1276,9 +1282,10 @@ MESSAGE is a doing part of progress message."
     (and (eq (car diff) 0)
         (< diff-time (nth 1 diff)))))
 
     (and (eq (car diff) 0)
         (< diff-time (nth 1 diff)))))
 
-(if (fboundp 'std11-fetch-field)
-    (defalias 'elmo-field-body 'std11-fetch-field) ;;no narrow-to-region
-  (defalias 'elmo-field-body 'std11-field-body))
+(eval-and-compile
+  (if (fboundp 'std11-fetch-field)
+      (defalias 'elmo-field-body 'std11-fetch-field) ;;no narrow-to-region
+    (defalias 'elmo-field-body 'std11-field-body)))
 
 (defun elmo-unfold-field-body (name)
   (let ((value (elmo-field-body name)))
 
 (defun elmo-unfold-field-body (name)
   (let ((value (elmo-field-body name)))
@@ -1706,12 +1713,12 @@ NUMBER-SET is altered."
             prev
             (nconc
              (list
             prev
             (nconc
              (list
-              ;; (beg . (1- number))
+;;;           (beg . (1- number))
               (let ((new (cons (car elem) (1- number))))
                 (if (eq (car new) (cdr new))
                     (car new)
                   new))
               (let ((new (cons (car elem) (1- number))))
                 (if (eq (car new) (cdr new))
                     (car new)
                   new))
-              ;; ((1+ number) . end)
+;;;           ((1+ number) . end)
               (let ((new (cons (1+ number) (cdr elem))))
                 (if (eq (car new) (cdr new))
                     (car new)
               (let ((new (cons (1+ number) (cdr elem))))
                 (if (eq (car new) (cdr new))
                     (car new)
@@ -2066,7 +2073,7 @@ If KBYTES is kilo bytes (This value must be float)."
                                   (cons (car (car cfl))
                                         (car flist)))))
       (setq cfl (cdr cfl)))
                                   (cons (car (car cfl))
                                         (car flist)))))
       (setq cfl (cdr cfl)))
-;;; (prin1 firsts)
+;;;    (prin1 firsts)
     (while firsts
       (if (and (not oldest-entity)
               (cdr (cdr (car firsts))))
     (while firsts
       (if (and (not oldest-entity)
               (cdr (cdr (car firsts))))
@@ -2104,12 +2111,12 @@ If KBYTES is kilo bytes (This value must be float)."
   "Expire cache file by age.
 Optional argument DAYS specifies the days to expire caches."
   (interactive)
   "Expire cache file by age.
 Optional argument DAYS specifies the days to expire caches."
   (interactive)
-  (let ((age (or (and days (int-to-string days))
+  (let ((age (or (and days (number-to-string days))
                 (and (interactive-p)
                      (read-from-minibuffer
                       (format "Enter days (%s): "
                               elmo-cache-expire-default-age)))
                 (and (interactive-p)
                      (read-from-minibuffer
                       (format "Enter days (%s): "
                               elmo-cache-expire-default-age)))
-                (int-to-string elmo-cache-expire-default-age)))
+                (number-to-string elmo-cache-expire-default-age)))
        (dirs (directory-files
               elmo-cache-directory
               t "^[^\\.]"))
        (dirs (directory-files
               elmo-cache-directory
               t "^[^\\.]"))
@@ -2117,7 +2124,7 @@ Optional argument DAYS specifies the days to expire caches."
        curtime)
     (if (string= age "")
        (setq age elmo-cache-expire-default-age)
        curtime)
     (if (string= age "")
        (setq age elmo-cache-expire-default-age)
-      (setq age (string-to-int age)))
+      (setq age (string-to-number age)))
     (setq curtime (current-time))
     (setq curtime (+ (* (nth 0 curtime)
                        (float 65536)) (nth 1 curtime)))
     (setq curtime (current-time))
     (setq curtime (+ (* (nth 0 curtime)
                        (float 65536)) (nth 1 curtime)))