Version number is increased to 2.15.7.
[elisp/wanderlust.git] / elmo / elmo-util.el
index 0cf7477..f5191fb 100644 (file)
@@ -29,7 +29,9 @@
 ;;; Code:
 ;;
 
-(eval-when-compile (require 'cl))
+(eval-when-compile
+  (require 'cl)
+  (require 'static))
 (require 'elmo-vars)
 (require 'elmo-date)
 (require 'mcharset)
 (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."
-  (` (save-excursion
-       (set-buffer (get-buffer-create elmo-work-buf-name))
-       (set-buffer-multibyte default-enable-multibyte-characters)
-       (erase-buffer)
-       (,@ body))))
+  `(save-excursion
+     (set-buffer (get-buffer-create elmo-work-buf-name))
+     (set-buffer-multibyte default-enable-multibyte-characters)
+     (erase-buffer)
+     ,@body))
 
 (put 'elmo-set-work-buf 'lisp-indent-function 0)
 (def-edebug-spec elmo-set-work-buf t)
 
 (defmacro elmo-bind-directory (dir &rest body)
   "Set current directory DIR and execute BODY."
-  (` (let ((default-directory (file-name-as-directory (, dir))))
-       (,@ body))))
+  `(let ((default-directory (file-name-as-directory ,dir)))
+     ,@body))
 
 (put 'elmo-bind-directory 'lisp-indent-function 1)
 (def-edebug-spec elmo-bind-directory
 (put 'elmo-with-enable-multibyte 'lisp-indent-function 0)
 (def-edebug-spec elmo-with-enable-multibyte t)
 
+(static-if (condition-case nil
+              (plist-get '(one) 'other)
+            (error t))
+    (defmacro elmo-safe-plist-get (plist prop)
+      `(ignore-errors
+        (plist-get ,plist ,prop)))
+  (defalias 'elmo-safe-plist-get 'plist-get))
+
 (eval-when-compile
   (unless (fboundp 'coding-system-base)
     (defalias 'coding-system-base 'ignore))
@@ -583,7 +594,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
-                         (` (lambda () (elmo-remove-passwd (, key))))))
+                         `(lambda () (elmo-remove-passwd ,key))))
       pass)))
 
 (defun elmo-remove-passwd (key)
@@ -1221,14 +1232,14 @@ If optional DELETE-FUNCTION is speficied, it is used as delete procedure."
       (if (or (elmo-progress-counter-total counter)
              (and (elmo-progress-counter-set-total
                    counter
-                   (plist-get params :total))
+                   (elmo-safe-plist-get params :total))
                   (elmo-progress-call-callback counter 'query)))
          (progn
            (elmo-progress-counter-set-value
             counter
-            (or (plist-get params :set)
+            (or (elmo-safe-plist-get params :set)
                 (+ (elmo-progress-counter-value counter)
-                   (or (plist-get params :inc)
+                   (or (elmo-safe-plist-get params :inc)
                        (car params)
                        1))))
            (elmo-progress-call-callback counter))
@@ -1240,7 +1251,7 @@ SPEC is a list as followed (LABEL TOTAL [VAR]).
 LABEL is an identifier what is specidied by `elmo-progress-notify'.
 If TOTAL is nil, the first `elmo-progress-notify' call must be
 with a `:total' parameter.
-If optional parameter VAR is specified, it is bound a progress counter object.
+If optional parameter VAR is specified, bind it with a progress counter object.
 MESSAGE is a doing part of progress message."
   (let ((label (nth 0 spec))
        (total (nth 1 spec))
@@ -1268,9 +1279,10 @@ MESSAGE is a doing part of progress message."
     (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)))
@@ -1295,9 +1307,9 @@ MESSAGE is a doing part of progress message."
 
 (defmacro elmo-string (string)
   "STRING without text property."
-  (` (let ((obj (copy-sequence (, string))))
-       (and obj (set-text-properties 0 (length obj) nil obj))
-       obj)))
+  `(let ((obj (copy-sequence ,string)))
+     (and obj (set-text-properties 0 (length obj) nil obj))
+     obj))
 
 (defun elmo-flatten (list-of-list)
   "Flatten LIST-OF-LIST."
@@ -1851,15 +1863,15 @@ STATUS is one of 'section, 'entire or nil.
 'section means partial section cache exists.
 'entire means entire cache exists.
 If the cache is partial file-cache, TYPE is 'partial."
-  (` (cons (, path) (, status))))
+  `(cons ,path ,status))
 
 (defmacro elmo-file-cache-path (file-cache)
   "Returns the file path of the FILE-CACHE."
-  (` (car (, file-cache))))
+  `(car ,file-cache))
 
 (defmacro elmo-file-cache-status (file-cache)
   "Returns the status of the FILE-CACHE."
-  (` (cdr (, file-cache))))
+  `(cdr ,file-cache))
 
 (defsubst elmo-cache-to-msgid (filename)
   (concat "<" (elmo-recover-string-from-filename filename) ">"))
@@ -1896,7 +1908,7 @@ If optional argument SECTION is specified, partial cache path is returned."
   "Return file name for the file-cache corresponds to the section.
 PATH is the file-cache path.
 SECTION is the section string."
-  (` (expand-file-name (or (, section) "") (, path))))
+  `(expand-file-name (or ,section "") ,path))
 
 (defun elmo-file-cache-delete (path)
   "Delete a cache on PATH."
@@ -2109,7 +2121,7 @@ Optional argument DAYS specifies the days to expire caches."
        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)))
@@ -2254,7 +2266,8 @@ If ALIST is nil, `elmo-obsolete-variable-alist' is used."
                            file nil beg
                            (incf beg elmo-msgdb-file-header-chop-length))))
                  (prog1 (not (search-forward "\n\n" nil t))
-                   (goto-char (point-max))))))))
+                   (goto-char (point-max)))))
+      (elmo-delete-cr-buffer))))
 
 ;;
 ;; overview handling