annotate lisp/gnus/gnus-util.el @ 42:8b8b7f3559a2 r19-15b104

Import from CVS: tag r19-15b104
author cvs
date Mon, 13 Aug 2007 08:54:51 +0200
parents e04119814345
children 8d2a9b52c682
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
1 ;;; gnus-util.el --- utility functions for Gnus
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
3
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
5 ;; Keywords: news
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
6
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
8
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
12 ;; any later version.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
13
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
18
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
23
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
24 ;;; Commentary:
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
25
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
26 ;; Nothing in this file depends on any other parts of Gnus -- all
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
27 ;; functions and macros in this file are utility functions that are
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
28 ;; used by Gnus and may be used by any other package without loading
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
29 ;; Gnus first.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
30
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
31 ;;; Code:
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
32
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
33 (require 'custom)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
34 (require 'cl)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
35 (require 'nnheader)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
36 (require 'timezone)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
37 (require 'message)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
38
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
39 (eval-and-compile
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
40 (autoload 'nnmail-date-to-time "nnmail"))
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
41
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
42 (defun gnus-boundp (variable)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
43 "Return non-nil if VARIABLE is bound and non-nil."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
44 (and (boundp variable)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
45 (symbol-value variable)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
46
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
47 (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
48 "Pop to BUFFER, evaluate FORMS, and then return to the original window."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
49 (let ((tempvar (make-symbol "GnusStartBufferWindow"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
50 (w (make-symbol "w"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
51 (buf (make-symbol "buf")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
52 `(let* ((,tempvar (selected-window))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
53 (,buf ,buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
54 (,w (get-buffer-window ,buf 'visible)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
55 (unwind-protect
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
56 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
57 (if ,w
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
58 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
59 (select-window ,w)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
60 (set-buffer (window-buffer ,w)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
61 (pop-to-buffer ,buf))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
62 ,@forms)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
63 (select-window ,tempvar)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
64
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
65 (put 'gnus-eval-in-buffer-window 'lisp-indent-function 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
66 (put 'gnus-eval-in-buffer-window 'edebug-form-spec '(form body))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
67
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
68 (defmacro gnus-intern-safe (string hashtable)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
69 "Set hash value. Arguments are STRING, VALUE, and HASHTABLE."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
70 `(let ((symbol (intern ,string ,hashtable)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
71 (or (boundp symbol)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
72 (set symbol nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
73 symbol))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
74
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
75 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
76 ;; function `substring' might cut on a middle of multi-octet
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
77 ;; character.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
78 (defun gnus-truncate-string (str width)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
79 (substring str 0 width))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
80
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
81 ;; Added by Geoffrey T. Dairiki <dairiki@u.washington.edu>. A safe way
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
82 ;; to limit the length of a string. This function is necessary since
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
83 ;; `(substr "abc" 0 30)' pukes with "Args out of range".
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
84 (defsubst gnus-limit-string (str width)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
85 (if (> (length str) width)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
86 (substring str 0 width)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
87 str))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
88
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
89 (defsubst gnus-functionp (form)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
90 "Return non-nil if FORM is funcallable."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
91 (or (and (symbolp form) (fboundp form))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
92 (and (listp form) (eq (car form) 'lambda))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
93
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
94 (defsubst gnus-goto-char (point)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
95 (and point (goto-char point)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
96
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
97 (defmacro gnus-buffer-exists-p (buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
98 `(let ((buffer ,buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
99 (when buffer
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
100 (funcall (if (stringp buffer) 'get-buffer 'buffer-name)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
101 buffer))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
102
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
103 (defmacro gnus-kill-buffer (buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
104 `(let ((buf ,buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
105 (when (gnus-buffer-exists-p buf)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
106 (kill-buffer buf))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
107
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
108 (if (fboundp 'point-at-bol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
109 (fset 'gnus-point-at-bol 'point-at-bol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
110 (defun gnus-point-at-bol ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
111 "Return point at the beginning of the line."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
112 (let ((p (point)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
113 (beginning-of-line)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
114 (prog1
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
115 (point)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
116 (goto-char p)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
117
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
118 (if (fboundp 'point-at-eol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
119 (fset 'gnus-point-at-eol 'point-at-eol)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
120 (defun gnus-point-at-eol ()
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
121 "Return point at the end of the line."
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
122 (let ((p (point)))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
123 (end-of-line)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
124 (prog1
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
125 (point)
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
126 (goto-char p)))))
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
127
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
128 (defun gnus-delete-first (elt list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
129 "Delete by side effect the first occurrence of ELT as a member of LIST."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
130 (if (equal (car list) elt)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
131 (cdr list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
132 (let ((total list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
133 (while (and (cdr list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
134 (not (equal (cadr list) elt)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
135 (setq list (cdr list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
136 (when (cdr list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
137 (setcdr list (cddr list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
138 total)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
139
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
140 ;; Delete the current line (and the next N lines).
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
141 (defmacro gnus-delete-line (&optional n)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
142 `(delete-region (progn (beginning-of-line) (point))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
143 (progn (forward-line ,(or n 1)) (point))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
144
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
145 (defun gnus-byte-code (func)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
146 "Return a form that can be `eval'ed based on FUNC."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
147 (let ((fval (symbol-function func)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
148 (if (compiled-function-p fval)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
149 (let ((flist (append fval nil)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
150 (setcar flist 'byte-code)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
151 flist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
152 (cons 'progn (cddr fval)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
153
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
154 (defun gnus-extract-address-components (from)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
155 (let (name address)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
156 ;; First find the address - the thing with the @ in it. This may
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
157 ;; not be accurate in mail addresses, but does the trick most of
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
158 ;; the time in news messages.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
159 (when (string-match "\\b[^@ \t<>]+[!@][^@ \t<>]+\\b" from)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
160 (setq address (substring from (match-beginning 0) (match-end 0))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
161 ;; Then we check whether the "name <address>" format is used.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
162 (and address
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
163 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
164 ;; Linear white space is not required.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
165 (string-match (concat "[ \t]*<" (regexp-quote address) ">") from)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
166 (and (setq name (substring from 0 (match-beginning 0)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
167 ;; Strip any quotes from the name.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
168 (string-match "\".*\"" name)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
169 (setq name (substring name 1 (1- (match-end 0))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
170 ;; If not, then "address (name)" is used.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
171 (or name
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
172 (and (string-match "(.+)" from)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
173 (setq name (substring from (1+ (match-beginning 0))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
174 (1- (match-end 0)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
175 (and (string-match "()" from)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
176 (setq name address))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
177 ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
178 ;; XOVER might not support folded From headers.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
179 (and (string-match "(.*" from)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
180 (setq name (substring from (1+ (match-beginning 0))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
181 (match-end 0)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
182 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
183 (list (or name from) (or address from))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
184
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
185 (defun gnus-fetch-field (field)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
186 "Return the value of the header FIELD of current article."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
187 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
188 (save-restriction
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
189 (let ((case-fold-search t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
190 (inhibit-point-motion-hooks t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
191 (nnheader-narrow-to-headers)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
192 (message-fetch-field field)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
193
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
194 (defun gnus-goto-colon ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
195 (beginning-of-line)
18
d95e72db5c07 Import from CVS: tag r19-15b92
cvs
parents: 16
diff changeset
196 (search-forward ":" (gnus-point-at-eol) t))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
197
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
198 (defun gnus-remove-text-with-property (prop)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
199 "Delete all text in the current buffer with text property PROP."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
200 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
201 (goto-char (point-min))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
202 (while (not (eobp))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
203 (while (get-text-property (point) prop)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
204 (delete-char 1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
205 (goto-char (next-single-property-change (point) prop nil (point-max))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
206
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
207 (defun gnus-newsgroup-directory-form (newsgroup)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
208 "Make hierarchical directory name from NEWSGROUP name."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
209 (let ((newsgroup (gnus-newsgroup-savable-name newsgroup))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
210 (len (length newsgroup))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
211 idx)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
212 ;; If this is a foreign group, we don't want to translate the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
213 ;; entire name.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
214 (if (setq idx (string-match ":" newsgroup))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
215 (aset newsgroup idx ?/)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
216 (setq idx 0))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
217 ;; Replace all occurrences of `.' with `/'.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
218 (while (< idx len)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
219 (when (= (aref newsgroup idx) ?.)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
220 (aset newsgroup idx ?/))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
221 (setq idx (1+ idx)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
222 newsgroup))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
223
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
224 (defun gnus-newsgroup-savable-name (group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
225 ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
226 ;; with dots.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
227 (nnheader-replace-chars-in-string group ?/ ?.))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
228
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
229 (defun gnus-string> (s1 s2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
230 (not (or (string< s1 s2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
231 (string= s1 s2))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
232
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
233 ;;; Time functions.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
234
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
235 (defun gnus-days-between (date1 date2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
236 ;; Return the number of days between date1 and date2.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
237 (- (gnus-day-number date1) (gnus-day-number date2)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
238
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
239 (defun gnus-day-number (date)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
240 (let ((dat (mapcar (lambda (s) (and s (string-to-int s)) )
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
241 (timezone-parse-date date))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
242 (timezone-absolute-from-gregorian
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
243 (nth 1 dat) (nth 2 dat) (car dat))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
244
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
245 (defun gnus-time-to-day (time)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
246 "Convert TIME to day number."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
247 (let ((tim (decode-time time)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
248 (timezone-absolute-from-gregorian
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
249 (nth 4 tim) (nth 3 tim) (nth 5 tim))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
250
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
251 (defun gnus-encode-date (date)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
252 "Convert DATE to internal time."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
253 (let* ((parse (timezone-parse-date date))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
254 (date (mapcar (lambda (d) (and d (string-to-int d))) parse))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
255 (time (mapcar 'string-to-int (timezone-parse-time (aref parse 3)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
256 (encode-time (caddr time) (cadr time) (car time)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
257 (caddr date) (cadr date) (car date) (nth 4 date))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
258
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
259 (defun gnus-time-minus (t1 t2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
260 "Subtract two internal times."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
261 (let ((borrow (< (cadr t1) (cadr t2))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
262 (list (- (car t1) (car t2) (if borrow 1 0))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
263 (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
264
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
265 (defun gnus-time-less (t1 t2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
266 "Say whether time T1 is less than time T2."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
267 (or (< (car t1) (car t2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
268 (and (= (car t1) (car t2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
269 (< (nth 1 t1) (nth 1 t2)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
270
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
271 (defun gnus-file-newer-than (file date)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
272 (let ((fdate (nth 5 (file-attributes file))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
273 (or (> (car fdate) (car date))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
274 (and (= (car fdate) (car date))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
275 (> (nth 1 fdate) (nth 1 date))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
276
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
277 ;;; Keymap macros.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
278
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
279 (defmacro gnus-local-set-keys (&rest plist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
280 "Set the keys in PLIST in the current keymap."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
281 `(gnus-define-keys-1 (current-local-map) ',plist))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
282
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
283 (defmacro gnus-define-keys (keymap &rest plist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
284 "Define all keys in PLIST in KEYMAP."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
285 `(gnus-define-keys-1 (quote ,keymap) (quote ,plist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
286
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
287 (defmacro gnus-define-keys-safe (keymap &rest plist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
288 "Define all keys in PLIST in KEYMAP without overwriting previous definitions."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
289 `(gnus-define-keys-1 (quote ,keymap) (quote ,plist) t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
290
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
291 (put 'gnus-define-keys 'lisp-indent-function 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
292 (put 'gnus-define-keys-safe 'lisp-indent-function 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
293 (put 'gnus-local-set-keys 'lisp-indent-function 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
294
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
295 (defmacro gnus-define-keymap (keymap &rest plist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
296 "Define all keys in PLIST in KEYMAP."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
297 `(gnus-define-keys-1 ,keymap (quote ,plist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
298
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
299 (put 'gnus-define-keymap 'lisp-indent-function 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
300
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
301 (defun gnus-define-keys-1 (keymap plist &optional safe)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
302 (when (null keymap)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
303 (error "Can't set keys in a null keymap"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
304 (cond ((symbolp keymap)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
305 (setq keymap (symbol-value keymap)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
306 ((keymapp keymap))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
307 ((listp keymap)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
308 (set (car keymap) nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
309 (define-prefix-command (car keymap))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
310 (define-key (symbol-value (caddr keymap)) (cadr keymap) (car keymap))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
311 (setq keymap (symbol-value (car keymap)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
312 (let (key)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
313 (while plist
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
314 (when (symbolp (setq key (pop plist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
315 (setq key (symbol-value key)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
316 (if (or (not safe)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
317 (eq (lookup-key keymap key) 'undefined))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
318 (define-key keymap key (pop plist))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
319 (pop plist)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
320
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
321 (defun gnus-completing-read (default prompt &rest args)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
322 ;; Like `completing-read', except that DEFAULT is the default argument.
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
323 (let* ((prompt (if default
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
324 (concat prompt " (default " default ") ")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
325 (concat prompt " ")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
326 (answer (apply 'completing-read prompt args)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
327 (if (or (null answer) (zerop (length answer)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
328 default
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
329 answer)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
330
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
331 ;; Two silly functions to ensure that all `y-or-n-p' questions clear
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
332 ;; the echo area.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
333 (defun gnus-y-or-n-p (prompt)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
334 (prog1
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
335 (y-or-n-p prompt)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
336 (message "")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
337
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
338 (defun gnus-yes-or-no-p (prompt)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
339 (prog1
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
340 (yes-or-no-p prompt)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
341 (message "")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
342
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
343 ;; I suspect there's a better way, but I haven't taken the time to do
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
344 ;; it yet. -erik selberg@cs.washington.edu
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
345 (defun gnus-dd-mmm (messy-date)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
346 "Return a string like DD-MMM from a big messy string"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
347 (let ((datevec (ignore-errors (timezone-parse-date messy-date))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
348 (if (not datevec)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
349 "??-???"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
350 (format "%2s-%s"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
351 (condition-case ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
352 ;; Make sure leading zeroes are stripped.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
353 (number-to-string (string-to-number (aref datevec 2)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
354 (error "??"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
355 (capitalize
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
356 (or (car
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
357 (nth (1- (string-to-number (aref datevec 1)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
358 timezone-months-assoc))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
359 "???"))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
360
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
361 (defmacro gnus-date-get-time (date)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
362 "Convert DATE string to Emacs time.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
363 Cache the result as a text property stored in DATE."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
364 ;; Either return the cached value...
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
365 `(let ((d ,date))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
366 (if (equal "" d)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
367 '(0 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
368 (or (get-text-property 0 'gnus-time d)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
369 ;; or compute the value...
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
370 (let ((time (nnmail-date-to-time d)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
371 ;; and store it back in the string.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
372 (put-text-property 0 1 'gnus-time time d)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
373 time)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
374
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
375 (defsubst gnus-time-iso8601 (time)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
376 "Return a string of TIME in YYMMDDTHHMMSS format."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
377 (format-time-string "%Y%m%dT%H%M%S" time))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
378
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
379 (defun gnus-date-iso8601 (header)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
380 "Convert the date field in HEADER to YYMMDDTHHMMSS"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
381 (condition-case ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
382 (gnus-time-iso8601 (gnus-date-get-time (mail-header-date header)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
383 (error "")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
384
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
385 (defun gnus-mode-string-quote (string)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
386 "Quote all \"%\"'s in STRING."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
387 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
388 (gnus-set-work-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
389 (insert string)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
390 (goto-char (point-min))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
391 (while (search-forward "%" nil t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
392 (insert "%"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
393 (buffer-string)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
394
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
395 ;; Make a hash table (default and minimum size is 256).
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
396 ;; Optional argument HASHSIZE specifies the table size.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
397 (defun gnus-make-hashtable (&optional hashsize)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
398 (make-vector (if hashsize (max (gnus-create-hash-size hashsize) 256) 256) 0))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
399
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
400 ;; Make a number that is suitable for hashing; bigger than MIN and
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
401 ;; equal to some 2^x. Many machines (such as sparcs) do not have a
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
402 ;; hardware modulo operation, so they implement it in software. On
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
403 ;; many sparcs over 50% of the time to intern is spent in the modulo.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
404 ;; Yes, it's slower than actually computing the hash from the string!
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
405 ;; So we use powers of 2 so people can optimize the modulo to a mask.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
406 (defun gnus-create-hash-size (min)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
407 (let ((i 1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
408 (while (< i min)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
409 (setq i (* 2 i)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
410 i))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
411
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
412 (defcustom gnus-verbose 7
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
413 "*Integer that says how verbose Gnus should be.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
414 The higher the number, the more messages Gnus will flash to say what
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
415 it's doing. At zero, Gnus will be totally mute; at five, Gnus will
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
416 display most important messages; and at ten, Gnus will keep on
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
417 jabbering all the time."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
418 :group 'gnus-start
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
419 :type 'integer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
420
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
421 ;; Show message if message has a lower level than `gnus-verbose'.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
422 ;; Guideline for numbers:
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
423 ;; 1 - error messages, 3 - non-serious error messages, 5 - messages
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
424 ;; for things that take a long time, 7 - not very important messages
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
425 ;; on stuff, 9 - messages inside loops.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
426 (defun gnus-message (level &rest args)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
427 (if (<= level gnus-verbose)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
428 (apply 'message args)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
429 ;; We have to do this format thingy here even if the result isn't
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
430 ;; shown - the return value has to be the same as the return value
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
431 ;; from `message'.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
432 (apply 'format args)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
433
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
434 (defun gnus-error (level &rest args)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
435 "Beep an error if LEVEL is equal to or less than `gnus-verbose'."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
436 (when (<= (floor level) gnus-verbose)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
437 (apply 'message args)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
438 (ding)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
439 (let (duration)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
440 (when (and (floatp level)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
441 (not (zerop (setq duration (* 10 (- level (floor level)))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
442 (sit-for duration))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
443 nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
444
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
445 (defun gnus-split-references (references)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
446 "Return a list of Message-IDs in REFERENCES."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
447 (let ((beg 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
448 ids)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
449 (while (string-match "<[^>]+>" references beg)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
450 (push (substring references (match-beginning 0) (setq beg (match-end 0)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
451 ids))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
452 (nreverse ids)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
453
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
454 (defun gnus-parent-id (references &optional n)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
455 "Return the last Message-ID in REFERENCES.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
456 If N, return the Nth ancestor instead."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
457 (when references
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
458 (let ((ids (inline (gnus-split-references references))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
459 (car (last ids (or n 1))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
460
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
461 (defun gnus-horizontal-recenter ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
462 "Recenter the current buffer horizontally."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
463 (if (< (current-column) (/ (window-width) 2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
464 (set-window-hscroll (get-buffer-window (current-buffer) t) 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
465 (let* ((orig (point))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
466 (end (window-end (get-buffer-window (current-buffer) t)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
467 (max 0))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
468 ;; Find the longest line currently displayed in the window.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
469 (goto-char (window-start))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
470 (while (and (not (eobp))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
471 (< (point) end))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
472 (end-of-line)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
473 (setq max (max max (current-column)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
474 (forward-line 1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
475 (goto-char orig)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
476 ;; Scroll horizontally to center (sort of) the point.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
477 (if (> max (window-width))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
478 (set-window-hscroll
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
479 (get-buffer-window (current-buffer) t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
480 (min (- (current-column) (/ (window-width) 3))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
481 (+ 2 (- max (window-width)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
482 (set-window-hscroll (get-buffer-window (current-buffer) t) 0))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
483 max)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
484
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
485 (defun gnus-read-event-char ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
486 "Get the next event."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
487 (let ((event (read-event)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
488 ;; should be gnus-characterp, but this can't be called in XEmacs anyway
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
489 (cons (and (numberp event) event) event)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
490
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
491 (defun gnus-sortable-date (date)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
492 "Make sortable string by string-lessp from DATE.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
493 Timezone package is used."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
494 (condition-case ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
495 (progn
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
496 (setq date (inline (timezone-fix-time
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
497 date nil
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
498 (aref (inline (timezone-parse-date date)) 4))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
499 (inline
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
500 (timezone-make-sortable-date
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
501 (aref date 0) (aref date 1) (aref date 2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
502 (inline
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
503 (timezone-make-time-string
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
504 (aref date 3) (aref date 4) (aref date 5))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
505 (error "")))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
506
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
507 (defun gnus-copy-file (file &optional to)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
508 "Copy FILE to TO."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
509 (interactive
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
510 (list (read-file-name "Copy file: " default-directory)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
511 (read-file-name "Copy file to: " default-directory)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
512 (unless to
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
513 (setq to (read-file-name "Copy file to: " default-directory)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
514 (when (file-directory-p to)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
515 (setq to (concat (file-name-as-directory to)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
516 (file-name-nondirectory file))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
517 (copy-file file to))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
518
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
519 (defun gnus-kill-all-overlays ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
520 "Delete all overlays in the current buffer."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
521 (when (fboundp 'overlay-lists)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
522 (let* ((overlayss (overlay-lists))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
523 (buffer-read-only nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
524 (overlays (nconc (car overlayss) (cdr overlayss))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
525 (while overlays
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
526 (delete-overlay (pop overlays))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
527
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
528 (defvar gnus-work-buffer " *gnus work*")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
529
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
530 (defun gnus-set-work-buffer ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
531 "Put point in the empty Gnus work buffer."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
532 (if (get-buffer gnus-work-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
533 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
534 (set-buffer gnus-work-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
535 (erase-buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
536 (set-buffer (get-buffer-create gnus-work-buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
537 (kill-all-local-variables)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
538 (buffer-disable-undo (current-buffer))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
539
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
540 (defmacro gnus-group-real-name (group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
541 "Find the real name of a foreign newsgroup."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
542 `(let ((gname ,group))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
543 (if (string-match "^[^:]+:" gname)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
544 (substring gname (match-end 0))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
545 gname)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
546
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
547 (defun gnus-make-sort-function (funs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
548 "Return a composite sort condition based on the functions in FUNC."
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
549 (cond
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
550 ((not (listp funs)) funs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
551 ((null funs) funs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
552 ((cdr funs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
553 `(lambda (t1 t2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
554 ,(gnus-make-sort-function-1 (reverse funs))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
555 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
556 (car funs))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
557
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
558 (defun gnus-make-sort-function-1 (funs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
559 "Return a composite sort condition based on the functions in FUNC."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
560 (if (cdr funs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
561 `(or (,(car funs) t1 t2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
562 (and (not (,(car funs) t2 t1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
563 ,(gnus-make-sort-function-1 (cdr funs))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
564 `(,(car funs) t1 t2)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
565
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
566 (defun gnus-turn-off-edit-menu (type)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
567 "Turn off edit menu in `gnus-TYPE-mode-map'."
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
568 (define-key (symbol-value (intern (format "gnus-%s-mode-map" type)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
569 [menu-bar edit] 'undefined))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
570
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
571 (defun gnus-prin1 (form)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
572 "Use `prin1' on FORM in the current buffer.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
573 Bind `print-quoted' to t while printing."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
574 (let ((print-quoted t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
575 print-level print-length)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
576 (prin1 form (current-buffer))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
577
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
578 (defun gnus-prin1-to-string (form)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
579 "The same as `prin1', but but `print-quoted' to t."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
580 (let ((print-quoted t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
581 (prin1-to-string form)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
582
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
583 (defun gnus-make-directory (directory)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
584 "Make DIRECTORY (and all its parents) if it doesn't exist."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
585 (when (and directory
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
586 (not (file-exists-p directory)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
587 (make-directory directory t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
588 t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
589
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
590 (defun gnus-write-buffer (file)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
591 "Write the current buffer's contents to FILE."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
592 ;; Make sure the directory exists.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
593 (gnus-make-directory (file-name-directory file))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
594 ;; Write the buffer.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
595 (write-region (point-min) (point-max) file nil 'quietly))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
596
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
597 (defmacro gnus-delete-assq (key list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
598 `(let ((listval (eval ,list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
599 (setq ,list (delq (assq ,key listval) listval))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
600
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
601 (defmacro gnus-delete-assoc (key list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
602 `(let ((listval ,list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
603 (setq ,list (delq (assoc ,key listval) listval))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
604
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
605 (defun gnus-delete-file (file)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
606 "Delete FILE if it exists."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
607 (when (file-exists-p file)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
608 (delete-file file)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
609
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
610 (defun gnus-strip-whitespace (string)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
611 "Return STRING stripped of all whitespace."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
612 (while (string-match "[\r\n\t ]+" string)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
613 (setq string (replace-match "" t t string)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
614 string)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
615
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
616 (defun gnus-put-text-property-excluding-newlines (beg end prop val)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
617 "The same as `put-text-property', but don't put this prop on any newlines in the region."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
618 (save-match-data
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
619 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
620 (save-restriction
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
621 (goto-char beg)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
622 (while (re-search-forward "[ \t]*\n" end 'move)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
623 (put-text-property beg (match-beginning 0) prop val)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
624 (setq beg (point)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
625 (put-text-property beg (point) prop val)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
626
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
627 ;;; Protected and atomic operations. dmoore@ucsd.edu 21.11.1996
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
628 ;;; The primary idea here is to try to protect internal datastructures
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
629 ;;; from becoming corrupted when the user hits C-g, or if a hook or
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
630 ;;; similar blows up. Often in Gnus multiple tables/lists need to be
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
631 ;;; updated at the same time, or information can be lost.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
632
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
633 (defvar gnus-atomic-be-safe t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
634 "If t, certain operations will be protected from interruption by C-g.")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
635
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
636 (defmacro gnus-atomic-progn (&rest forms)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
637 "Evaluate FORMS atomically, which means to protect the evaluation
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
638 from being interrupted by the user. An error from the forms themselves
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
639 will return without finishing the operation. Since interrupts from
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
640 the user are disabled, it is recommended that only the most minimal
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
641 operations are performed by FORMS. If you wish to assign many
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
642 complicated values atomically, compute the results into temporary
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
643 variables and then do only the assignment atomically."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
644 `(let ((inhibit-quit gnus-atomic-be-safe))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
645 ,@forms))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
646
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
647 (put 'gnus-atomic-progn 'lisp-indent-function 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
648
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
649 (defmacro gnus-atomic-progn-assign (protect &rest forms)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
650 "Evaluate FORMS, but insure that the variables listed in PROTECT
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
651 are not changed if anything in FORMS signals an error or otherwise
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
652 non-locally exits. The variables listed in PROTECT are updated atomically.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
653 It is safe to use gnus-atomic-progn-assign with long computations.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
654
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
655 Note that if any of the symbols in PROTECT were unbound, they will be
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
656 set to nil on a sucessful assignment. In case of an error or other
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
657 non-local exit, it will still be unbound."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
658 (let* ((temp-sym-map (mapcar (lambda (x) (list (make-symbol
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
659 (concat (symbol-name x)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
660 "-tmp"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
661 x))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
662 protect))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
663 (sym-temp-map (mapcar (lambda (x) (list (cadr x) (car x)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
664 temp-sym-map))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
665 (temp-sym-let (mapcar (lambda (x) (list (car x)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
666 `(and (boundp ',(cadr x))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
667 ,(cadr x))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
668 temp-sym-map))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
669 (sym-temp-let sym-temp-map)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
670 (temp-sym-assign (apply 'append temp-sym-map))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
671 (sym-temp-assign (apply 'append sym-temp-map))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
672 (result (make-symbol "result-tmp")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
673 `(let (,@temp-sym-let
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
674 ,result)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
675 (let ,sym-temp-let
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
676 (setq ,result (progn ,@forms))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
677 (setq ,@temp-sym-assign))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
678 (let ((inhibit-quit gnus-atomic-be-safe))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
679 (setq ,@sym-temp-assign))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
680 ,result)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
681
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
682 (put 'gnus-atomic-progn-assign 'lisp-indent-function 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
683 ;(put 'gnus-atomic-progn-assign 'edebug-form-spec '(sexp body))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
684
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
685 (defmacro gnus-atomic-setq (&rest pairs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
686 "Similar to setq, except that the real symbols are only assigned when
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
687 there are no errors. And when the real symbols are assigned, they are
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
688 done so atomically. If other variables might be changed via side-effect,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
689 see gnus-atomic-progn-assign. It is safe to use gnus-atomic-setq
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
690 with potentially long computations."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
691 (let ((tpairs pairs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
692 syms)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
693 (while tpairs
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
694 (push (car tpairs) syms)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
695 (setq tpairs (cddr tpairs)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
696 `(gnus-atomic-progn-assign ,syms
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
697 (setq ,@pairs))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
698
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
699 ;(put 'gnus-atomic-setq 'edebug-form-spec '(body))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
700
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
701
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
702 ;;; Functions for saving to babyl/mail files.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
703
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
704 (defvar rmail-default-rmail-file)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
705 (defun gnus-output-to-rmail (filename &optional ask)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
706 "Append the current article to an Rmail file named FILENAME."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
707 (require 'rmail)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
708 ;; Most of these codes are borrowed from rmailout.el.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
709 (setq filename (expand-file-name filename))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
710 (setq rmail-default-rmail-file filename)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
711 (let ((artbuf (current-buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
712 (tmpbuf (get-buffer-create " *Gnus-output*")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
713 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
714 (or (get-file-buffer filename)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
715 (file-exists-p filename)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
716 (if (or (not ask)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
717 (gnus-yes-or-no-p
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
718 (concat "\"" filename "\" does not exist, create it? ")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
719 (let ((file-buffer (create-file-buffer filename)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
720 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
721 (set-buffer file-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
722 (rmail-insert-rmail-file-header)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
723 (let ((require-final-newline nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
724 (gnus-write-buffer filename)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
725 (kill-buffer file-buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
726 (error "Output file does not exist")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
727 (set-buffer tmpbuf)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
728 (erase-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
729 (insert-buffer-substring artbuf)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
730 (gnus-convert-article-to-rmail)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
731 ;; Decide whether to append to a file or to an Emacs buffer.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
732 (let ((outbuf (get-file-buffer filename)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
733 (if (not outbuf)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
734 (append-to-file (point-min) (point-max) filename)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
735 ;; File has been visited, in buffer OUTBUF.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
736 (set-buffer outbuf)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
737 (let ((buffer-read-only nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
738 (msg (and (boundp 'rmail-current-message)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
739 (symbol-value 'rmail-current-message))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
740 ;; If MSG is non-nil, buffer is in RMAIL mode.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
741 (when msg
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
742 (widen)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
743 (narrow-to-region (point-max) (point-max)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
744 (insert-buffer-substring tmpbuf)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
745 (when msg
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
746 (goto-char (point-min))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
747 (widen)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
748 (search-backward "\^_")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
749 (narrow-to-region (point) (point-max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
750 (goto-char (1+ (point-min)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
751 (rmail-count-new-messages t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
752 (rmail-show-message msg))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
753 (kill-buffer tmpbuf)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
754
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
755 (defun gnus-output-to-mail (filename &optional ask)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
756 "Append the current article to a mail file named FILENAME."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
757 (setq filename (expand-file-name filename))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
758 (let ((artbuf (current-buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
759 (tmpbuf (get-buffer-create " *Gnus-output*")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
760 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
761 ;; Create the file, if it doesn't exist.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
762 (when (and (not (get-file-buffer filename))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
763 (not (file-exists-p filename)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
764 (if (or (not ask)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
765 (gnus-y-or-n-p
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
766 (concat "\"" filename "\" does not exist, create it? ")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
767 (let ((file-buffer (create-file-buffer filename)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
768 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
769 (set-buffer file-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
770 (let ((require-final-newline nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
771 (gnus-write-buffer filename)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
772 (kill-buffer file-buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
773 (error "Output file does not exist")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
774 (set-buffer tmpbuf)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
775 (erase-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
776 (insert-buffer-substring artbuf)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
777 (goto-char (point-min))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 22
diff changeset
778 (if (looking-at "From ")
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 22
diff changeset
779 (forward-line 1)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
780 (insert "From nobody " (current-time-string) "\n"))
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 22
diff changeset
781 (let (case-fold-search)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 22
diff changeset
782 (while (re-search-forward "^From " nil t)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 22
diff changeset
783 (beginning-of-line)
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 22
diff changeset
784 (insert ">")))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
785 ;; Decide whether to append to a file or to an Emacs buffer.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
786 (let ((outbuf (get-file-buffer filename)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
787 (if (not outbuf)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
788 (let ((buffer-read-only nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
789 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
790 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
791 (forward-char -2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
792 (unless (looking-at "\n\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
793 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
794 (unless (bolp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
795 (insert "\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
796 (insert "\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
797 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
798 (append-to-file (point-min) (point-max) filename)))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
799 ;; File has been visited, in buffer OUTBUF.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
800 (set-buffer outbuf)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
801 (let ((buffer-read-only nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
802 (goto-char (point-max))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
803 (unless (eobp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
804 (insert "\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 18
diff changeset
805 (insert "\n")
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
806 (insert-buffer-substring tmpbuf)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
807 (kill-buffer tmpbuf)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
808
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
809 (defun gnus-convert-article-to-rmail ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
810 "Convert article in current buffer to Rmail message format."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
811 (let ((buffer-read-only nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
812 ;; Convert article directly into Babyl format.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
813 (goto-char (point-min))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
814 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
815 (while (search-forward "\n\^_" nil t) ;single char
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
816 (replace-match "\n^_" t t)) ;2 chars: "^" and "_"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
817 (goto-char (point-max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
818 (insert "\^_")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
819
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
820 (provide 'gnus-util)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
821
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
822 ;;; gnus-util.el ends here