Mercurial > hg > xemacs-beta
annotate lisp/itimer-autosave.el @ 5602:c9e5612f5424
Support the MP library on recent FreeBSD, have it pass relevant tests.
src/ChangeLog addition:
2011-11-26 Aidan Kehoe <kehoea@parhasard.net>
* number-mp.c (bignum_to_string):
Don't overwrite the accumulator we've just set up for this
function.
* number-mp.c (BIGNUM_TO_TYPE):
mp_itom() doesn't necessarily do what this code used to think with
negative numbers, it can treat them as unsigned ints. Subtract
numbers from bignum_zero instead of multiplying them by -1 to
convert them to their negative equivalents.
* number-mp.c (bignum_to_int):
* number-mp.c (bignum_to_uint):
* number-mp.c (bignum_to_long):
* number-mp.c (bignum_to_ulong):
* number-mp.c (bignum_to_double):
Use the changed BIGNUM_TO_TYPE() in these functions.
* number-mp.c (bignum_ceil):
* number-mp.c (bignum_floor):
In these functions, be more careful about rounding to positive and
negative infinity, respectively. Don't use the sign of QUOTIENT
when working out out whether to add or subtract one, rather use
the sign QUOTIENT would have if arbitrary-precision division were
done.
* number-mp.h:
* number-mp.h (MP_GCD):
Wrap #include <mp.h> in BEGIN_C_DECLS/END_C_DECLS.
* number.c (Fbigfloat_get_precision):
* number.c (Fbigfloat_set_precision):
Don't attempt to call XBIGFLOAT_GET_PREC if this build doesn't
support big floats.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 26 Nov 2011 17:59:14 +0000 |
parents | 308d34e9f07d |
children |
rev | line source |
---|---|
209 | 1 ;;; itimer-autosave.el --- Autosave functions with itimers |
2 | |
3 ;; Copyright status unknown | |
4 | |
5 ;; Maintainer: XEmacs Development Team | |
6 ;; Keywords: internal, dumped | |
7 | |
8 ;; This file is part of XEmacs. | |
9 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
209
diff
changeset
|
10 ;; XEmacs is free software: you can redistribute it and/or modify it |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
209
diff
changeset
|
11 ;; under the terms of the GNU General Public License as published by the |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
209
diff
changeset
|
12 ;; Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
209
diff
changeset
|
13 ;; option) any later version. |
209 | 14 |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
209
diff
changeset
|
15 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
209
diff
changeset
|
16 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
209
diff
changeset
|
17 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
209
diff
changeset
|
18 ;; for more details. |
209 | 19 |
20 ;; You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
209
diff
changeset
|
21 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
209 | 22 |
23 ;;; Synched up with: Not in FSF. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; This file is dumped with XEmacs. | |
28 | |
29 ;; itimer-driven auto-saves | |
30 | |
31 ;;; Code: | |
32 | |
33 ;jwz: this is preloaded so don't ;;;###autoload | |
34 (defvar auto-save-timeout 960 | |
35 "*Number of seconds idle time before auto-save. | |
36 Zero or nil means disable auto-saving due to idleness. | |
37 | |
38 The actual amount of idle time between auto-saves is logarithmically related | |
39 to the size of the current buffer. This variable is the number of seconds | |
40 after which an auto-save will happen when the current buffer is 50k or less; | |
41 the timeout will be 2 1/4 times this in a 200k buffer, 3 3/4 times this in a | |
42 1000k buffer, and 4 1/2 times this in a 2000k buffer. | |
43 | |
44 See also the variable `auto-save-interval', which controls auto-saving based | |
45 on the number of characters typed.") | |
46 | |
47 ;jwz: this is preloaded so don't ;;;###autoload | |
48 (defvar auto-gc-threshold (/ gc-cons-threshold 3) | |
49 "*GC when this many bytes have been consed since the last GC, | |
50 and the user has been idle for `auto-save-timeout' seconds.") | |
51 | |
52 (defun auto-save-itimer () | |
53 "For use as a itimer callback function. | |
54 Auto-saves and garbage-collects based on the size of the current buffer | |
55 and the value of `auto-save-timeout', `auto-gc-threshold', and the current | |
56 keyboard idle-time." | |
57 (if (or (null auto-save-timeout) | |
58 (<= auto-save-timeout 0) | |
59 (eq (minibuffer-window) (selected-window))) | |
60 nil | |
61 (let ((buf-size (1+ (ash (buffer-size) -8))) | |
62 (delay-level 0) | |
63 (now (current-time)) | |
64 delay) | |
65 (while (> buf-size 64) | |
66 (setq delay-level (1+ delay-level) | |
67 buf-size (- buf-size (ash buf-size -2)))) | |
68 (if (< delay-level 4) | |
69 (setq delay-level 4)) | |
70 ;; delay_level is 4 for files under around 50k, 7 at 100k, 9 at 200k, | |
71 ;; 11 at 300k, and 12 at 500k, 15 at 1 meg, and 17 at 2 meg. | |
72 (setq delay (/ (* delay-level auto-save-timeout) 4)) | |
73 (let ((idle-time (if (or (not (consp last-input-time)) | |
74 (/= (car now) (car last-input-time))) | |
75 (1+ delay) | |
76 (- (car (cdr now)) (cdr last-input-time))))) | |
77 (and (> idle-time delay) | |
78 (do-auto-save)) | |
79 (and (> idle-time auto-save-timeout) | |
80 (> (consing-since-gc) auto-gc-threshold) | |
81 (garbage-collect))))) | |
82 ;; Look at the itimer that's currently running; if the user has changed | |
83 ;; the value of auto-save-timeout, modify this itimer to have the correct | |
84 ;; restart time. There will be some latency between when the user changes | |
85 ;; this variable and when it takes effect, but it will happen eventually. | |
86 (let ((self (get-itimer "auto-save"))) | |
87 (or self (error "auto-save-itimer can't find itself")) | |
88 (if (and auto-save-timeout (> auto-save-timeout 4)) | |
89 (or (= (itimer-restart self) (/ auto-save-timeout 4)) | |
90 (set-itimer-restart self (/ auto-save-timeout 4))))) | |
91 nil) | |
92 | |
93 (defun itimer-init-auto-gc () | |
94 (or noninteractive ; may be being run from after-init-hook in -batch mode. | |
95 (get-itimer "auto-save") | |
96 ;; the time here is just the first interval; if the user changes it | |
97 ;; later, it will adjust. | |
98 (let ((time (max 2 (/ (or auto-save-timeout 30) 4)))) | |
99 (start-itimer "auto-save" 'auto-save-itimer time time)))) | |
100 | |
101 (cond (purify-flag | |
102 ;; This file is being preloaded into an emacs about to be dumped. | |
103 ;; So arrange for the auto-save itimer to be started once emacs | |
104 ;; is launched. | |
105 (add-hook 'after-init-hook 'itimer-init-auto-gc)) | |
106 (t | |
107 ;; Otherwise, this file is being loaded into a normal, interactive | |
108 ;; emacs. Start the auto-save timer now. | |
109 (itimer-init-auto-gc))) | |
110 | |
111 | |
112 ;;; itimer-autosave.el ends here |