annotate lisp/prim/itimer.el @ 12:bcdc7deadc19 r19-15b7

Import from CVS: tag r19-15b7
author cvs
date Mon, 13 Aug 2007 08:48:16 +0200
parents 376386a54a3c
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; Interval timers for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; Copyright (C) 1988, 1991, 1993 Kyle E. Jones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; Modified 5 Feb 91 by Jamie Zawinski <jwz@lucid.com> for Lucid Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; And again, 15 Dec 93.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Send bug reports to kyle@uunet.uu.net.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; The original v18 version of this file worked by having an external program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; wake up once a second to generate an interrupt for emacs; then an emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; process filter was used to schedule timers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; This version works by associating with each timer a "timeout" object,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; since the XEmacs/Lucid Emacs event loop has the concept of timers built
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; in to it. There is no single scheduler function; instead, each timer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; re-sets itself as it is invoked.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; `itimer' feature means Emacs-Lisp programers get:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; itimerp, itimer-value, itimer-restart, itimer-function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; set-itimer-value, set-itimer-restart, set-itimer-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; get-itimer, start-itimer, read-itimer, delete-itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Interactive users get these commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; edit-itimers, list-itimers, start-itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; See the doc strings of these functions for more information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (defvar itimer-version "1.00"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "Version number of the itimer package.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (defvar itimer-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "List of all active itimers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; not needed in XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;(defvar itimer-process nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ; "Process that drives all itimers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; This value is maintained internally; it does not determine itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; granularity. Itimer granularity is 1 second, plus delays due to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; system and Emacs internal activity that delay dealing with process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; not needed in XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;(defvar itimer-process-next-wakeup 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ; "Itimer process will wakeup to service running itimers within this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;many seconds.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar itimer-edit-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "Keymap used when in Itimer Edit mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (if itimer-edit-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (setq itimer-edit-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (define-key itimer-edit-map "s" 'itimer-edit-set-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (define-key itimer-edit-map "d" 'itimer-edit-delete-itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (define-key itimer-edit-map "q" 'itimer-edit-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (define-key itimer-edit-map "\t" 'itimer-edit-next-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (define-key itimer-edit-map " " 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (define-key itimer-edit-map "n" 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (define-key itimer-edit-map "p" 'previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (define-key itimer-edit-map "\C-?" 'itimer-edit-previous-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (define-key itimer-edit-map "x" 'start-itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (define-key itimer-edit-map "?" 'itimer-edit-help))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defvar itimer-edit-start-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; macros must come first... or byte-compile'd code will throw back its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; head and scream.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defmacro itimer-decf (variable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (list 'setq variable (list '1- variable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defmacro itimer-incf (variable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (list 'setq variable (list '1+ variable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defmacro itimer-signum (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (list 'if (list '> n 0) 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (list 'if (list 'zerop n) 0 -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; Itimer access functions should behave as if they were subrs. These
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; macros are used to check the arguments to the itimer functions and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; signal errors appropriately if the arguments are not valid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defmacro check-itimer (var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "If VAR is not bound to an itimer, signal wrong-type-argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 This is a macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (list 'setq var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (list 'if (list 'itimerp var) var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (list 'signal ''wrong-type-argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (list 'list ''itimerp var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (defmacro check-itimer-coerce-string (var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 "If VAR is not bound to a string, look up the itimer that it names and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 bind VAR to it. Otherwise if VAR is not bound to an itimer, signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 wrong-type-argument. This is a macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (list 'setq var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (list 'cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (list (list 'itimerp var) var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (list (list 'stringp var) (list 'get-itimer var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (list t (list 'signal ''wrong-type-argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (list 'list ''string-or-itimer-p var))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defmacro itimer-check-natnum (var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "If VAR is not bound to a non-negative number, signal wrong-type-argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 This is a macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (list 'setq var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (list 'if (list 'natnump var) var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (list 'signal ''wrong-type-argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (list 'list ''natnump var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (defmacro itimer-check-string (var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 "If VAR is not bound to a string, signal wrong-type-argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 This is a macro."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (list 'setq var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (list 'if (list 'stringp var) var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (list 'signal ''wrong-type-argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (list 'list ''stringp var)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; Functions to access and modify itimer attributes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (defun itimerp (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 "Returns non-nil iff OBJ is an itimer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (and (consp obj) (stringp (car obj)) (eq (length obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 5 ; for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;4 ; original version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defun itimer-name (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "Returns the name of ITIMER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (car itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defun itimer-value (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "Returns the number of seconds until ITIMER expires."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (nth 1 itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defun itimer-restart (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "Returns the value to which ITIMER will be set at restart.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 nil is returned if this itimer doesn't restart."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (nth 2 itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (defun itimer-function (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "Returns the function of ITIMER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 This function is called each time ITIMER expires."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (nth 3 itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;; XEmacs-specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (defun itimer-id (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 "Returns the timeout-id of ITIMER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (nth 4 itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defun set-itimer-value (itimer value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; XEmacs doesn't need this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;; &optional nowakeup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "Set the timeout value of ITIMER to be VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 Itimer will expire is this many seconds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 Returns VALUE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; Optional third arg NOWAKEUP non-nil means do not wakeup the itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;; process to recompute a correct wakeup time, even if it means this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;; itimer will expire late. itimer-process-filter uses this option.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;; This is not meant for ordinary usage, which is why it is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; mentioned in the doc string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (itimer-check-natnum value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ; ;; If we're allowed to wakeup the itimer process,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ; ;; and the itimer process's next wakeup needs to be recomputed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ; ;; and the itimer is running, then we wakeup the itimer process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ; (or (and (not nowakeup) (< value itimer-process-next-wakeup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ; (get-itimer (itimer-name itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ; (progn (itimer-process-wakeup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ; (setcar (cdr itimer) value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ; (itimer-process-wakeup)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ; (setcar (cdr itimer) value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; the XEmacs way:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (if (itimer-id itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (deactivate-itimer itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (setcar (cdr itimer) value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (activate-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (defun set-itimer-restart (itimer restart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 "Set the restart value of ITIMER to be RESTART.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 If RESTART is nil, ITIMER will not restart when it expires.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 Returns RESTART."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (if restart (itimer-check-natnum restart))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (and restart (< restart 1) (signal 'args-out-of-range (list restart)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;; (setcar (cdr (cdr itimer)) restart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;; the XEmacs way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (let ((was-active (itimer-id itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (if was-active
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (deactivate-itimer itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (setcar (cdr (cdr itimer)) restart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (if was-active
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (setcar (cdr itimer) restart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (if restart
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (activate-itimer itimer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 restart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (defun set-itimer-function (itimer function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 "Set the function of ITIMER to be FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 FUNCTION will be called when itimer expires.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 Returns FUNCTION."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (setcar (cdr (cdr (cdr itimer))) function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; XEmacs-specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (defun set-itimer-id (itimer id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (check-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setcar (cdr (cdr (cdr (cdr itimer)))) id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defun get-itimer (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 "Return itimer named NAME, or nil if there is none."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (itimer-check-string name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (assoc name itimer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (defun read-itimer (prompt &optional initial-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 "Read the name of an itimer from the minibuffer and return the itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 associated with that name. The user is prompted with PROMPT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 Optional second arg INITIAL-INPUT non-nil is inserted into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 minibuffer as initial user input."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (get-itimer (completing-read prompt itimer-list nil 'confirm initial-input)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (defun delete-itimer (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 "Deletes ITIMER. ITIMER may be an itimer or the name of one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (check-itimer-coerce-string itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (deactivate-itimer itimer) ;; for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (setq itimer-list (delq itimer itimer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;jwz: this is preloaded so don't ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defun start-itimer (name function value &optional restart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 "Start an itimer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 Args are NAME, FUNCTION, VALUE &optional RESTART.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 NAME is an identifier for the itimer. It must be a string. If an itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 already exists with this name, NAME will be modified slightly to until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 it is unique.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 FUNCTION should be a function (or symbol naming one) of no arguments. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 will be called each time the itimer expires. The function can access
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 itimer that invoked it through the variable `current-itimer'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 VALUE is the number of seconds until this itimer expires.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 Optional fourth arg RESTART non-nil means that this itimer should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 restarted automatically after its function is called. Normally an itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 is deleted at expiration after its function has returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 If non-nil RESTART should be a number indicating the value at which the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 itimer should be set at restart time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 Returns the newly created itimer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (list (completing-read "Start itimer: " itimer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (read (completing-read "Itimer function: " obarray 'fboundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (let (value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (while (not (natnump value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (setq value (read-from-minibuffer "Itimer value: " nil nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (let ((restart t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (while (and restart (not (natnump restart)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (setq restart (read-from-minibuffer "Itimer restart: " nil nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 restart)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (itimer-check-string name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (itimer-check-natnum value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if restart (itimer-check-natnum restart))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ;; Make proposed itimer name unique if it's not already.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (let ((oname name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (num 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (while (get-itimer name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (setq name (concat oname "<" num ">"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (itimer-incf num)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ; ;; If there's no itimer process, start one now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ; ;; Otherwise wake up the itimer process so that seconds slept before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ; ;; the new itimer is created won't be counted against it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ; (if itimer-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ; (itimer-process-wakeup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ; (itimer-process-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; add the itimer to the global list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (setq itimer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (cons (list name value restart function nil) ; extra slot for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 itimer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ; ;; If the itimer process is scheduled to wake up too late for the itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ; ;; we wake it up to calculate a correct wakeup value giving consideration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ; ;; to the newly added itimer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ; (if (< value itimer-process-next-wakeup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ; (itimer-process-wakeup)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (activate-itimer (car itimer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (car itimer-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;; User level functions to list and modify existing itimers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ;; Itimer Edit major mode, and the editing commands thereof.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (defun list-itimers ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 "Pop up a buffer containing a list of all itimers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 The major mode of the buffer is Itimer Edit mode. This major mode provides
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 commands to manipulate itimers; see the documentation for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 `itimer-edit-mode' for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (let* ((buf (get-buffer-create "*Itimer List*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (standard-output buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (itimers (reverse itimer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (itimer-edit-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (setq buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (insert "Name Value Restart Function\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 "---- ----- ------- --------")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (if (null itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (setq itimer-edit-start-marker (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (while itimers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (newline 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (prin1 (itimer-name (car itimers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (prin1 (itimer-value (car itimers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (prin1 (itimer-restart (car itimers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (tab-to-tab-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (prin1 (itimer-function (car itimers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (setq itimers (cdr itimers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ;; restore point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (if (< (point) itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (goto-char itimer-edit-start-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (display-buffer buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (defun edit-itimers ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 "Display a list of all itimers and select it for editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 The major mode of the buffer containing the listing is Itimer Edit mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 This major mode provides commands to manipulate itimers; see the documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 for `itimer-edit-mode' for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;; since user is editing, make sure displayed data is reasonably up-to-date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ; (if itimer-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ; (itimer-process-wakeup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (list-itimers)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (select-window (get-buffer-window "*Itimer List*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (goto-char itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (if itimer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (forward-sexp 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (backward-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (message "type q to quit, ? for help"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;; no point in making this interactive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (defun itimer-edit-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 "Major mode for manipulating itimers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 Atrributes of running itimers are changed by moving the cursor to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 desired field and typing `s' to set that field. The field will then be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 set to the value read from the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 TAB move forward a field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 DEL move backward a field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 s set a field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 d delete the selected itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 x start a new itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ? help"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (make-local-variable 'tab-stop-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (setq major-mode 'itimer-edit-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 mode-name "Itimer Edit"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 truncate-lines t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 tab-stop-list '(22 32 42))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (abbrev-mode 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (auto-fill-mode 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (buffer-disable-undo (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (use-local-map itimer-edit-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (and lisp-mode-syntax-table (set-syntax-table lisp-mode-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (put 'itimer-edit-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (defun itimer-edit-help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 "Help function for Itimer Edit."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (if (eq last-command 'itimer-edit-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (message "TAB, DEL select fields, (s)et field, (d)elete itimer (type ? for more help)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (defun itimer-edit-quit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 "End Itimer Edit."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (bury-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (if (one-window-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (switch-to-buffer (other-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (delete-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (defun itimer-edit-set-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 ;; First two lines in list buffer are headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 ;; Cry out against the luser who attempts to change a field there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (if (<= (point) itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ;; field-value must be initialized to be something other than a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;; number, symbol, or list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (let (itimer field (field-value ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (setq itimer (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; read the name of the itimer from the beginning of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ;; the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (get-itimer (read (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 field (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (itimer-edit-beginning-of-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;; count the number of sexprs until we reach the cursor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ;; and use this info to determine which field the user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ;; wants to modify.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (while (and (>= opoint (point)) (< n 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (forward-sexp 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (itimer-incf n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (cond ((eq n 1) (error "Cannot change itimer name."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ((eq n 2) 'value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ((eq n 3) 'restart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ((eq n 4) 'function)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (cond ((eq field 'value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;; XEmacs: rewritten for I18N3 snarfing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (while (not (natnump field-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (setq field-value (read-from-minibuffer "Set itimer value: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 nil nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ((eq field 'restart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (while (and field-value (not (natnump field-value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (setq field-value (read-from-minibuffer "Set itimer restart: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 nil nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ((eq field 'function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (while (not (or (and (symbolp field-value) (fboundp field-value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (and (consp field-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (memq (car field-value) '(lambda macro)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (setq field-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (read (completing-read "Set itimer function: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 obarray 'fboundp nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ;; set the itimer field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (funcall (intern (concat "set-itimer-" (symbol-name field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 itimer field-value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ;; move to beginning of field to be changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (itimer-edit-beginning-of-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; modify the list buffer to reflect the change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (let (buffer-read-only kill-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (kill-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (kill-region (point) (progn (skip-chars-forward " \t") (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (prin1 field-value (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (if (not (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (tab-to-tab-stop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (backward-sexp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (defun itimer-edit-delete-itimer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ;; First two lines in list buffer are headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;; Cry out against the luser who attempts to change a field there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (if (<= (point) itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (delete-itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (read-itimer "Delete itimer: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (save-excursion (beginning-of-line) (read (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; update list information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (list-itimers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (defun itimer-edit-next-field (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (itimer-edit-beginning-of-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (cond ((> (itimer-signum count) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (while (not (zerop count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;; wrap from eob to itimer-edit-start-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (goto-char itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (forward-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 ;; treat fields at beginning of line as if they weren't there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (forward-sexp 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (backward-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (itimer-decf count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 ((< (itimer-signum count) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (while (not (zerop count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;; treat fields at beginning of line as if they weren't there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (backward-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;; wrap from itimer-edit-start-marker to field at eob.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (if (<= (point) itimer-edit-start-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (backward-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (itimer-incf count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (defun itimer-edit-previous-field (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (itimer-edit-next-field (- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (defun itimer-edit-beginning-of-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (let ((forw-back (save-excursion (forward-sexp) (backward-sexp) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (back (save-excursion (backward-sexp) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (cond ((eq forw-back back) (backward-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ((eq forw-back (point)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (t (backward-sexp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; internals of the itimer implementation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (defun itimer-process-filter (process string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (error "itimer-process-filter is not used in XEmacs")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 ; ;; If the itimer process dies and generates output while doing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ; ;; so, we may be called before the process-sentinel. Sanity
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ; ;; check the output just in case...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ; (if (not (string-match "^[0-9]" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ; (progn (message "itimer process gave odd output: %s" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ; ;; it may be still alive and waiting for input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ; (process-send-string itimer-process "3\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ; ;; if there are no active itimers, return quickly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ; (if itimer-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ; (let ((time-elapsed (string-to-int string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 ; (itimers itimer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ; (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ; ;; process filters can be hit by stray C-g's from the user,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ; ;; so we must protect this stuff appropriately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ; ;; Quit's are allowed from within itimer functions, but we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ; ;; catch them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 ; (inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ; (setq itimer-process-next-wakeup 600)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ; (while itimers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ; (setq itimer (car itimers))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ; (set-itimer-value itimer (max 0 (- (itimer-value itimer) time-elapsed)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ; (if (> (itimer-value itimer) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ; (setq itimer-process-next-wakeup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ; (min itimer-process-next-wakeup (itimer-value itimer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 ; ;; itimer has expired, we must call its function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ; ;; protect our local vars from the itimer function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 ; ;; allow keyboard quit to occur, but catch and report it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ; ;; provide the variable `current-itimer' in case the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ; ;; is interested.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ; (condition-case condition-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 ; (let* ((current-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 ; itimer itimers time-elapsed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 ; quit-flag inhibit-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ; (funcall (itimer-function current-itimer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 ; (error (message "itimer \"%s\" signaled: %s" (itimer-name itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 ; (prin1-to-string condition-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ; (quit (message "itimer \"%s\" quit" (itimer-name itimer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 ; ;; restart the itimer if we should, otherwise delete it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ; (if (null (itimer-restart itimer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 ; (delete-itimer itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 ; (set-itimer-value itimer (itimer-restart itimer) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ; (setq itimer-process-next-wakeup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ; (min itimer-process-next-wakeup (itimer-value itimer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ; (setq itimers (cdr itimers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ; ;; if user is editing itimers, update displayed info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 ; (if (eq major-mode 'itimer-edit-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ; (list-itimers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 ; (setq itimer-process-next-wakeup 600))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 ; ;; tell itimer-process when to wakeup again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 ; (process-send-string itimer-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ; (concat (int-to-string itimer-process-next-wakeup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ; "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (defun itimer-process-sentinel (process message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (error "itimer-process-sentinel is not used in XEmacs")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ; (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ; (if (eq (process-status process) 'stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 ; (continue-process process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 ; ;; not stopped, so it must have died.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ; ;; cleanup first...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ; (delete-process process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 ; (setq itimer-process nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 ; ;; now, if there are any active itimers then we need to immediately
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 ; ;; start another itimer process, otherwise we can wait until the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 ; ;; start-itimer call, which will start one automatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ; (if (null itimer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 ; ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ; ;; there may have been an error message in the echo area;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 ; ;; give the user at least a little time to read it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 ; (sit-for 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 ; (message "itimer process %s... respawning." (substring message 0 -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 ; (itimer-process-start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (defun itimer-process-start ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (error "itimer-process-start is not used in XEmacs")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 ; (let ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 ; (process-connection-type nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 ; (setq itimer-process (start-process "itimer" nil "itimer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 ; (process-kill-without-query itimer-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 ; (set-process-filter itimer-process 'itimer-process-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 ; (set-process-sentinel itimer-process 'itimer-process-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 ; ;; Tell itimer process to wake up quickly, so that a correct wakeup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 ; ;; time can be computed. Zero instead of one here loses because of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 ; ;; underlying itimer implementations that use 0 to mean `disable the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ; ;; itimer'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 ; (setq itimer-process-next-wakeup 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 ; (process-send-string itimer-process "1\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (defun itimer-process-wakeup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (error "itimer-process-wakeup is not used in XEmacs")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 ; (interrupt-process itimer-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ; (accept-process-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ;; XEmacs-specific code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (defun activate-itimer (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (set-itimer-id itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (add-timeout (itimer-value itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 'itimer-callback
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 itimer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (itimer-restart itimer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (defun deactivate-itimer (itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (let ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (id (itimer-id itimer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (and id (disable-timeout id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (set-itimer-id itimer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (defun itimer-callback (current-itimer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (funcall (itimer-function current-itimer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ;;; itimer-driven auto-saves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 ;jwz: this is preloaded so don't ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (defvar auto-save-timeout 30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 "*Number of seconds idle time before auto-save.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 Zero or nil means disable auto-saving due to idleness.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 The actual amount of idle time between auto-saves is logarithmically related
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 to the size of the current buffer. This variable is the number of seconds
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 after which an auto-save will happen when the current buffer is 50k or less;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 the timeout will be 2 1/4 times this in a 200k buffer, 3 3/4 times this in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 1000k buffer, and 4 1/2 times this in a 2000k buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 See also the variable `auto-save-interval', which controls auto-saving based
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 on the number of characters typed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 ;jwz: this is preloaded so don't ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (defvar auto-gc-threshold (/ gc-cons-threshold 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 "*GC when this many bytes have been consed since the last GC,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 and the user has been idle for `auto-save-timeout' seconds.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (defun auto-save-itimer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 "For use as a itimer callback function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 Auto-saves and garbage-collects based on the size of the current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 and the value of `auto-save-timeout', `auto-gc-threshold', and the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 keyboard idle-time."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (if (or (null auto-save-timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (<= auto-save-timeout 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (eq (minibuffer-window) (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (let ((buf-size (1+ (ash (buffer-size) -8)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (delay-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (now (current-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 delay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (while (> buf-size 64)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (setq delay-level (1+ delay-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 buf-size (- buf-size (ash buf-size -2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (if (< delay-level 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (setq delay-level 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ;; delay_level is 4 for files under around 50k, 7 at 100k, 9 at 200k,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 ;; 11 at 300k, and 12 at 500k, 15 at 1 meg, and 17 at 2 meg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (setq delay (/ (* delay-level auto-save-timeout) 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (let ((idle-time (if (or (not (consp last-input-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (/= (car now) (car last-input-time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (1+ delay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (- (car (cdr now)) (cdr last-input-time)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (and (> idle-time delay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (do-auto-save))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (and (> idle-time auto-save-timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (> (consing-since-gc) auto-gc-threshold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (garbage-collect)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 ;; Look at the itimer that's currently running; if the user has changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 ;; the value of auto-save-timeout, modify this itimer to have the correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 ;; restart time. There will be some latency between when the user changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 ;; this variable and when it takes effect, but it will happen eventually.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (let ((self (get-itimer "auto-save")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (or self (error "auto-save-itimer can't find itself"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (if (and auto-save-timeout (> auto-save-timeout 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (or (= (itimer-restart self) (/ auto-save-timeout 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (set-itimer-restart self (/ auto-save-timeout 4)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (defun itimer-init-auto-gc ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (or noninteractive ; may be being run from after-init-hook in -batch mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (get-itimer "auto-save")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ;; the time here is just the first interval; if the user changes it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 ;; later, it will adjust.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (let ((time (max 2 (/ (or auto-save-timeout 30) 4))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (start-itimer "auto-save" 'auto-save-itimer time time))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (cond (purify-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 ;; This file is being preloaded into an emacs about to be dumped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 ;; So arrange for the auto-save itimer to be started once emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;; is launched.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (add-hook 'after-init-hook 'itimer-init-auto-gc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ;; Otherwise, this file is being loaded into a normal, interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;; emacs. Start the auto-save timer now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (itimer-init-auto-gc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (provide 'itimer)