* nnheaderxm.el (nnheader-xmas-run-at-time): Make it work
[gnus] / lisp / nnheaderxm.el
1 ;;; nnheaderxm.el --- making Gnus backends work under XEmacs
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003
4 ;;      Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (defun nnheader-xmas-run-at-time (time repeat function &rest args)
31   "Emulating function run as `run-at-time' in the right way.
32 TIME should be nil meaning now or a number of seconds from now.
33 Return an itimer object which can be used in either `delete-itimer'
34 or `cancel-timer'."
35   (let ((itimers (list nil)))
36     (setcar
37      itimers
38      (apply #'start-itimer "nnheader-run-at-time"
39             (lambda (itimers repeat function &rest args)
40               (let ((itimer (car itimers)))
41                 (if repeat
42                     (progn
43                       (set-itimer-function
44                        itimer
45                        (lambda (itimer repeat function &rest args)
46                          (set-itimer-restart itimer repeat)
47                          (set-itimer-function itimer function)
48                          (set-itimer-function-arguments itimer args)
49                          (apply function args)))
50                       (set-itimer-function-arguments
51                        itimer
52                        (append (list itimer repeat function) args)))
53                   (set-itimer-function
54                    itimer
55                    (lambda (itimer function &rest args)
56                      (delete-itimer itimer)
57                      (apply function args)))
58                   (set-itimer-function-arguments
59                    itimer
60                    (append (list itimer function) args)))))
61             1e-9 (if time (max time 1e-9) 1e-9)
62             nil t itimers repeat function args))))
63
64 (defalias 'nnheader-run-at-time 'nnheader-xmas-run-at-time)
65 (defalias 'nnheader-cancel-timer 'delete-itimer)
66 (defalias 'nnheader-cancel-function-timers 'ignore)
67 (defalias 'nnheader-string-as-multibyte 'identity)
68
69 (provide 'nnheaderxm)
70
71 ;;; nnheaderxm.el ends here