annotate lisp/prim/itimer.el @ 73:e2d7a37b7c8d

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