Mercurial > hg > xemacs-beta
annotate lisp/itimer-autosave.el @ 4967:0d4c9d0f6a8d
rewrite dynarr code
-------------------- ChangeLog entries follow: --------------------
src/ChangeLog addition:
2010-02-03 Ben Wing <ben@xemacs.org>
* device-x.c (x_get_resource_prefix):
* device-x.c (Fx_get_resource):
* device-x.c (Fx_get_resource_prefix):
* device-x.c (Fx_put_resource):
* dialog-msw.c:
* dialog-msw.c (handle_question_dialog_box):
* dired-msw.c (mswindows_sort_files):
* dired-msw.c (mswindows_get_files):
* extents.c (extent_fragment_sort_by_priority):
* extents.c (Fset_extent_parent):
* file-coding.c (coding_reader):
* file-coding.c (coding_writer):
* file-coding.c (gzip_convert):
* frame.c (generate_title_string):
* gutter.c (calculate_gutter_size_from_display_lines):
* indent.c (vmotion_1):
* lread.c (read_bit_vector):
* mule-coding.c (iso2022_decode):
* rangetab.c:
* rangetab.c (Fcopy_range_table):
* rangetab.c (Fget_range_table):
* rangetab.c (unified_range_table_copy_data):
* redisplay-msw.c (mswindows_output_string):
* redisplay-output.c (output_display_line):
* redisplay-output.c (redisplay_move_cursor):
* redisplay-output.c (redisplay_clear_bottom_of_window):
* redisplay-tty.c (tty_output_ichar_dynarr):
* redisplay-tty.c (set_foreground_to):
* redisplay-tty.c (set_background_to):
* redisplay-xlike-inc.c (XLIKE_output_string):
* redisplay.c (redisplay_window_text_width_string):
* redisplay.c (redisplay_text_width_string):
* redisplay.c (create_text_block):
* redisplay.c (SET_CURRENT_MODE_CHARS_PIXSIZE):
* redisplay.c (generate_fstring_runes):
* redisplay.c (regenerate_modeline):
* redisplay.c (ensure_modeline_generated):
* redisplay.c (real_current_modeline_height):
* redisplay.c (create_string_text_block):
* redisplay.c (regenerate_window):
* redisplay.c (REGEN_INC_FIND_START_END):
* redisplay.c (point_visible):
* redisplay.c (redisplay_window):
* redisplay.c (mark_glyph_block_dynarr):
* redisplay.c (line_start_cache_start):
* redisplay.c (start_with_line_at_pixpos):
* redisplay.c (update_line_start_cache):
* redisplay.c (glyph_to_pixel_translation):
* redisplay.c (pixel_to_glyph_translation):
* sysdep.c (qxe_readdir):
* text.c (dfc_convert_to_external_format):
* text.c (dfc_convert_to_internal_format):
* toolbar-common.c (common_output_toolbar_button):
* window.c (window_modeline_height):
* window.c (Fwindow_last_line_visible_height):
* window.c (window_displayed_height):
* window.c (window_scroll):
* window.c (get_current_pixel_pos):
Use Dynarr_begin() in place of Dynarr_atp (foo, 0).
* dynarr.c (Dynarr_realloc):
* dynarr.c (Dynarr_lisp_realloc):
* dynarr.c (Dynarr_resize):
* dynarr.c (Dynarr_insert_many):
* dynarr.c (Dynarr_delete_many):
* dynarr.c (Dynarr_memory_usage):
* dynarr.c (stack_like_malloc):
* dynarr.c (stack_like_free):
* lisp.h:
* lisp.h (DECLARE_DYNARR_LISP_IMP):
* lisp.h (XD_DYNARR_DESC):
* lisp.h (Dynarr_pop):
* gutter.c (output_gutter):
* redisplay-output.c (sync_rune_structs):
* redisplay-output.c (redisplay_output_window):
Redo the dynarr code, add greater checks.
Rename the `len', `largest' and `max' members to `len_',
`largest_' and `max_' to try and catch existing places that might
directly modify these values. Make new accessors Dynarr_largest()
and Dynarr_max() and make them and existing Dynarr_length() be
non-lvalues by adding '+ 0' to them; fix a couple of places in the
redisplay code that tried to modify the length directly by setting
Dynarr_length(). Use the accessors whenever possible even in the
dynarr code itself. The accessors also verify that 0 <= len <=
largest <= max. Rename settor function Dynarr_set_size() to
Dynarr_set_length() and use it more consistently; also create
lower-level Dynarr_set_length_1(). This latter function should be
the only function that directly modifies the `len_' member of a
Dynarr, and in the process makes sure that the `largest' value is
kept correct.
Consistently use ERROR_CHECK_STRUCTURES instead of
ERROR_CHECK_TYPES for error-checking code. Reintroduce the
temporarily disabled verification code on the positions of
Dynarr_at(), Dynarr_atp() and Dynarr_atp_past_end().
Also create Dynarr_resize_if() in place of a repeated
code fragment. Clean up all the functions that modify Dynarrs to
use the new macros and functions and verify the correctness of the
Dynarr both before and after the change.
Note that there are two kinds of verification -- one for accessing
and one for modifying. The difference is that the modify
verification additionally checks to make sure that the Dynarr
isn't locked. (This is used in redisplay to check for problems
with reentrancy.)
* lrecord.h: Move XD_DYNARR_DESC to lisp.h, grouping with the dynarr code.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 03 Feb 2010 20:51:18 -0600 |
parents | 41ff10fd062f |
children | 308d34e9f07d |
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 | |
10 ;; XEmacs is free software; you can redistribute it and/or modify it | |
11 ;; under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; XEmacs is distributed in the hope that it will be useful, but | |
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 ;; General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
23 ;; 02111-1307, USA. | |
24 | |
25 ;;; Synched up with: Not in FSF. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; This file is dumped with XEmacs. | |
30 | |
31 ;; itimer-driven auto-saves | |
32 | |
33 ;;; Code: | |
34 | |
35 ;jwz: this is preloaded so don't ;;;###autoload | |
36 (defvar auto-save-timeout 960 | |
37 "*Number of seconds idle time before auto-save. | |
38 Zero or nil means disable auto-saving due to idleness. | |
39 | |
40 The actual amount of idle time between auto-saves is logarithmically related | |
41 to the size of the current buffer. This variable is the number of seconds | |
42 after which an auto-save will happen when the current buffer is 50k or less; | |
43 the timeout will be 2 1/4 times this in a 200k buffer, 3 3/4 times this in a | |
44 1000k buffer, and 4 1/2 times this in a 2000k buffer. | |
45 | |
46 See also the variable `auto-save-interval', which controls auto-saving based | |
47 on the number of characters typed.") | |
48 | |
49 ;jwz: this is preloaded so don't ;;;###autoload | |
50 (defvar auto-gc-threshold (/ gc-cons-threshold 3) | |
51 "*GC when this many bytes have been consed since the last GC, | |
52 and the user has been idle for `auto-save-timeout' seconds.") | |
53 | |
54 (defun auto-save-itimer () | |
55 "For use as a itimer callback function. | |
56 Auto-saves and garbage-collects based on the size of the current buffer | |
57 and the value of `auto-save-timeout', `auto-gc-threshold', and the current | |
58 keyboard idle-time." | |
59 (if (or (null auto-save-timeout) | |
60 (<= auto-save-timeout 0) | |
61 (eq (minibuffer-window) (selected-window))) | |
62 nil | |
63 (let ((buf-size (1+ (ash (buffer-size) -8))) | |
64 (delay-level 0) | |
65 (now (current-time)) | |
66 delay) | |
67 (while (> buf-size 64) | |
68 (setq delay-level (1+ delay-level) | |
69 buf-size (- buf-size (ash buf-size -2)))) | |
70 (if (< delay-level 4) | |
71 (setq delay-level 4)) | |
72 ;; delay_level is 4 for files under around 50k, 7 at 100k, 9 at 200k, | |
73 ;; 11 at 300k, and 12 at 500k, 15 at 1 meg, and 17 at 2 meg. | |
74 (setq delay (/ (* delay-level auto-save-timeout) 4)) | |
75 (let ((idle-time (if (or (not (consp last-input-time)) | |
76 (/= (car now) (car last-input-time))) | |
77 (1+ delay) | |
78 (- (car (cdr now)) (cdr last-input-time))))) | |
79 (and (> idle-time delay) | |
80 (do-auto-save)) | |
81 (and (> idle-time auto-save-timeout) | |
82 (> (consing-since-gc) auto-gc-threshold) | |
83 (garbage-collect))))) | |
84 ;; Look at the itimer that's currently running; if the user has changed | |
85 ;; the value of auto-save-timeout, modify this itimer to have the correct | |
86 ;; restart time. There will be some latency between when the user changes | |
87 ;; this variable and when it takes effect, but it will happen eventually. | |
88 (let ((self (get-itimer "auto-save"))) | |
89 (or self (error "auto-save-itimer can't find itself")) | |
90 (if (and auto-save-timeout (> auto-save-timeout 4)) | |
91 (or (= (itimer-restart self) (/ auto-save-timeout 4)) | |
92 (set-itimer-restart self (/ auto-save-timeout 4))))) | |
93 nil) | |
94 | |
95 (defun itimer-init-auto-gc () | |
96 (or noninteractive ; may be being run from after-init-hook in -batch mode. | |
97 (get-itimer "auto-save") | |
98 ;; the time here is just the first interval; if the user changes it | |
99 ;; later, it will adjust. | |
100 (let ((time (max 2 (/ (or auto-save-timeout 30) 4)))) | |
101 (start-itimer "auto-save" 'auto-save-itimer time time)))) | |
102 | |
103 (cond (purify-flag | |
104 ;; This file is being preloaded into an emacs about to be dumped. | |
105 ;; So arrange for the auto-save itimer to be started once emacs | |
106 ;; is launched. | |
107 (add-hook 'after-init-hook 'itimer-init-auto-gc)) | |
108 (t | |
109 ;; Otherwise, this file is being loaded into a normal, interactive | |
110 ;; emacs. Start the auto-save timer now. | |
111 (itimer-init-auto-gc))) | |
112 | |
113 | |
114 ;;; itimer-autosave.el ends here |