1 ;;; nnheaderxm.el --- making Gnus backends work under XEmacs
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003
4 ;; Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; This file is part of GNU Emacs.
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)
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.
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.
31 (if (condition-case nil
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
43 (setcar ctime (1- (car ctime)))))
45 (itimer (start-itimer "nnheader-run-at-time" 'ignore 5)))
46 (sleep-for 0.1) ;; Accept the timeout interrupt.
48 (> (itimer-value itimer) 0)
49 (delete-itimer itimer))))
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'
56 (apply #'start-itimer "nnheader-run-at-time"
57 function (if time (max time 1e-9) 1e-9)
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'
64 (let ((itimers (list nil)))
67 (apply #'start-itimer "nnheader-run-at-time"
68 (lambda (itimers repeat function &rest args)
69 (let ((itimer (car itimers)))
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
81 (append (list itimer repeat function) args)))
84 (lambda (itimer function &rest args)
85 (delete-itimer itimer)
86 (apply function args)))
87 (set-itimer-function-arguments
89 (append (list itimer function) args)))))
90 1e-9 (if time (max time 1e-9) 1e-9)
91 nil t itimers repeat function args)))))
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)
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))
108 (message "%s(Y/n) No" prompt)
110 (message "%s(Y/n) Yes" prompt)
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)
119 (provide 'nnheaderxm)
121 ;;; nnheaderxm.el ends here