* nnheader.el (nnheader-find-file-noselect): Use
[elisp/gnus.git-] / lisp / gnus-util.el
index ff0176b..9371650 100644 (file)
@@ -503,11 +503,16 @@ If N, return the Nth ancestor instead."
        (first 't1)
        (last 't2))
     (when (consp function)
-      (if (eq (car function) 'not)
-         (setq function (cadr function)
-               first 't2
-               last 't1)
-       (error "Invalid sort spec: %s" function)))
+      (cond
+       ;; Reversed spec.
+       ((eq (car function) 'not)
+       (setq function (cadr function)
+             first 't2
+             last 't1))
+       ((gnus-functionp function)
+       )
+       (t
+       (error "Invalid sort spec: %s" function))))if
     (if (cdr funs)
        `(or (,function ,first ,last)
             (and (not (,function ,last ,first))
@@ -548,6 +553,21 @@ Bind `print-quoted' and `print-readably' to t while printing."
   ;; Write the buffer.
   (write-region (point-min) (point-max) file nil 'quietly))
 
+(defun gnus-write-buffer-as-binary (file)
+  "Write the current buffer's contents to FILE without code conversion."
+  ;; Make sure the directory exists.
+  (gnus-make-directory (file-name-directory file))
+  ;; Write the buffer.
+  (write-region-as-binary (point-min) (point-max) file nil 'quietly))
+
+(defun gnus-write-buffer-as-coding-system (file coding-system)
+  "Write the current buffer's contents to FILE with code conversion."
+  ;; Make sure the directory exists.
+  (gnus-make-directory (file-name-directory file))
+  ;; Write the buffer.
+  (write-region-as-coding-system
+   (point-min) (point-max) file coding-system nil 'quietly))
+
 (defun gnus-delete-file (file)
   "Delete FILE if it exists."
   (when (file-exists-p file)
@@ -729,9 +749,8 @@ with potentially long computations."
            (let ((file-buffer (create-file-buffer filename)))
              (save-excursion
                (set-buffer file-buffer)
-               (let ((require-final-newline nil)
-                     (coding-system-for-write 'binary))
-                 (gnus-write-buffer filename)))
+               (let ((require-final-newline nil))
+                 (gnus-write-buffer-as-binary filename)))
              (kill-buffer file-buffer))
          (error "Output file does not exist")))
       (set-buffer tmpbuf)
@@ -748,8 +767,7 @@ with potentially long computations."
       ;; Decide whether to append to a file or to an Emacs buffer.
       (let ((outbuf (get-file-buffer filename)))
        (if (not outbuf)
-           (let ((buffer-read-only nil)
-                 (coding-system-for-write 'binary))
+           (let ((buffer-read-only nil))
              (save-excursion
                (goto-char (point-max))
                (forward-char -2)
@@ -759,7 +777,8 @@ with potentially long computations."
                    (insert "\n"))
                  (insert "\n"))
                (goto-char (point-max))
-               (append-to-file (point-min) (point-max) filename)))
+               (write-region-as-binary (point-min) (point-max)
+                                       filename 'append)))
          ;; File has been visited, in buffer OUTBUF.
          (set-buffer outbuf)
          (let ((buffer-read-only nil))
@@ -937,6 +956,11 @@ ARG is passed to the first function."
     (when win
       (set-window-start win (or point (point))))))
 
+(defun gnus-annotation-in-region-p (b e)
+  (if (= b e)
+      (eq (cadr (memq 'gnus-undeletable (text-properties-at b))) t) 
+    (text-property-any b e 'gnus-undeletable t)))
+
 (provide 'gnus-util)
 
 ;;; gnus-util.el ends here