Feedback T-gnus 6.16.
[elisp/gnus.git-] / 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 ;;      Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: news
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (if (condition-case nil
32         (progn
33           (unless (or itimer-process itimer-timer)
34             (itimer-driver-start))
35           ;; Check whether there is a bug to which the difference of
36           ;; the present time and the time when the itimer driver was
37           ;; woken up is subtracted from the initial itimer value.
38           (let* ((inhibit-quit t)
39                  (ctime (current-time))
40                  (itimer-timer-last-wakeup
41                   (prog1
42                       ctime
43                     (setcar ctime (1- (car ctime)))))
44                  (itimer-list nil)
45                  (itimer (start-itimer "nnheader-run-at-time" 'ignore 5)))
46             (sleep-for 0.1) ;; Accept the timeout interrupt.
47             (prog1
48                 (> (itimer-value itimer) 0)
49               (delete-itimer itimer))))
50       (error nil))
51     (defun nnheader-xmas-run-at-time (time repeat function &rest args)
52       "Emulating function run as `run-at-time'.
53 TIME should be nil meaning now, or a number of seconds from now.
54 Return an itimer object which can be used in either `delete-itimer'
55 or `cancel-timer'."
56       (apply #'start-itimer "nnheader-run-at-time"
57              function (if time (max time 1e-9) 1e-9)
58              repeat nil t args))
59   (defun nnheader-xmas-run-at-time (time repeat function &rest args)
60     "Emulating function run as `run-at-time' in the right way.
61 TIME should be nil meaning now, or a number of seconds from now.
62 Return an itimer object which can be used in either `delete-itimer'
63 or `cancel-timer'."
64     (let ((itimers (list nil)))
65       (setcar
66        itimers
67        (apply #'start-itimer "nnheader-run-at-time"
68               (lambda (itimers repeat function &rest args)
69                 (let ((itimer (car itimers)))
70                   (if repeat
71                       (progn
72                         (set-itimer-function
73                          itimer
74                          (lambda (itimer repeat function &rest args)
75                            (set-itimer-restart itimer repeat)
76                            (set-itimer-function itimer function)
77                            (set-itimer-function-arguments itimer args)
78                            (apply function args)))
79                         (set-itimer-function-arguments
80                          itimer
81                          (append (list itimer repeat function) args)))
82                     (set-itimer-function
83                      itimer
84                      (lambda (itimer function &rest args)
85                        (delete-itimer itimer)
86                        (apply function args)))
87                     (set-itimer-function-arguments
88                      itimer
89                      (append (list itimer function) args)))))
90               1e-9 (if time (max time 1e-9) 1e-9)
91               nil t itimers repeat function args)))))
92
93 (defun nnheader-xmas-Y-or-n-p (prompt)
94   "Ask user a \"Y/n\" question. Return t if answer is neither \"n\", \"N\" nor \"C-g\"."
95   (if (should-use-dialog-box-p)
96       (yes-or-no-p-dialog-box prompt)
97     (let ((cursor-in-echo-area t)
98           (echo-keystrokes 0)
99           (inhibit-quit t)
100           event)
101       (message "%s(Y/n) " prompt)
102       (while (or (not (key-press-event-p (setq event (next-command-event))))
103                  (not (or (eq (event-key event) 'escape)
104                           (memq (event-to-character event)
105                                 '(?\  ?N ?Y ?\C-g ?\e ?\n ?\r ?n ?y))))))
106       (if (memq (event-key event) '(?\C-g ?N ?n))
107           (progn
108             (message "%s(Y/n) No" prompt)
109             nil)
110         (message "%s(Y/n) Yes" prompt)
111         t))))
112
113 (defalias 'nnheader-run-at-time 'nnheader-xmas-run-at-time)
114 (defalias 'nnheader-cancel-timer 'delete-itimer)
115 (defalias 'nnheader-cancel-function-timers 'ignore)
116 (defalias 'nnheader-string-as-multibyte 'identity)
117 (defalias 'nnheader-Y-or-n-p 'nnheader-xmas-Y-or-n-p)
118
119 (provide 'nnheaderxm)
120
121 ;;; nnheaderxm.el ends here