comparison src/buffer.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 41dbb7a9d5f2
children
comparison
equal deleted inserted replaced
423:28d9c139be4c 424:11054d720c21
94 The default value occupies the same slot in this structure 94 The default value occupies the same slot in this structure
95 as an individual buffer's value occupies in that buffer. 95 as an individual buffer's value occupies in that buffer.
96 Setting the default value also goes through the alist of buffers 96 Setting the default value also goes through the alist of buffers
97 and stores into each buffer that does not say it has a local value. */ 97 and stores into each buffer that does not say it has a local value. */
98 Lisp_Object Vbuffer_defaults; 98 Lisp_Object Vbuffer_defaults;
99 static void *buffer_defaults_saved_slots;
99 100
100 /* This structure marks which slots in a buffer have corresponding 101 /* This structure marks which slots in a buffer have corresponding
101 default values in Vbuffer_defaults. 102 default values in Vbuffer_defaults.
102 Each such slot has a nonzero value in this structure. 103 Each such slot has a nonzero value in this structure.
103 The value has only one nonzero bit. 104 The value has only one nonzero bit.
131 char initial_directory[MAXPATHLEN+1]; 132 char initial_directory[MAXPATHLEN+1];
132 133
133 /* This structure holds the names of symbols whose values may be 134 /* This structure holds the names of symbols whose values may be
134 buffer-local. It is indexed and accessed in the same way as the above. */ 135 buffer-local. It is indexed and accessed in the same way as the above. */
135 static Lisp_Object Vbuffer_local_symbols; 136 static Lisp_Object Vbuffer_local_symbols;
137 static void *buffer_local_symbols_saved_slots;
136 138
137 /* Alist of all buffer names vs the buffers. */ 139 /* Alist of all buffer names vs the buffers. */
138 /* This used to be a variable, but is no longer, 140 /* This used to be a variable, but is no longer,
139 to prevent lossage due to user rplac'ing this alist or its elements. 141 to prevent lossage due to user rplac'ing this alist or its elements.
140 Note that there is a per-frame copy of this as well; the frame slot 142 Note that there is a per-frame copy of this as well; the frame slot
187 Lisp_Object QSFundamental; /* A string "Fundamental" */ 189 Lisp_Object QSFundamental; /* A string "Fundamental" */
188 Lisp_Object QSscratch; /* "*scratch*" */ 190 Lisp_Object QSscratch; /* "*scratch*" */
189 Lisp_Object Qdefault_directory; 191 Lisp_Object Qdefault_directory;
190 192
191 Lisp_Object Qkill_buffer_hook; 193 Lisp_Object Qkill_buffer_hook;
192 Lisp_Object Qbuffer_file_name, Qbuffer_undo_list; 194 Lisp_Object Qrecord_buffer_hook;
193 195
194 Lisp_Object Qrename_auto_save_file; 196 Lisp_Object Qrename_auto_save_file;
195 197
196 Lisp_Object Qget_file_buffer; 198 Lisp_Object Qget_file_buffer;
197 Lisp_Object Qchange_major_mode_hook, Vchange_major_mode_hook; 199 Lisp_Object Qchange_major_mode_hook, Vchange_major_mode_hook;
218 XSETBUFFER (obj, buf); 220 XSETBUFFER (obj, buf);
219 return obj; 221 return obj;
220 } 222 }
221 223
222 static Lisp_Object 224 static Lisp_Object
223 mark_buffer (Lisp_Object obj, void (*markobj) (Lisp_Object)) 225 mark_buffer (Lisp_Object obj)
224 { 226 {
225 struct buffer *buf = XBUFFER (obj); 227 struct buffer *buf = XBUFFER (obj);
226 228
227 /* Truncate undo information. */ 229 /* Truncate undo information. */
228 buf->undo_list = truncate_undo_list (buf->undo_list, 230 buf->undo_list = truncate_undo_list (buf->undo_list,
229 undo_threshold, 231 undo_threshold,
230 undo_high_threshold); 232 undo_high_threshold);
231 233
232 #define MARKED_SLOT(x) ((void) (markobj (buf->x))); 234 #define MARKED_SLOT(x) mark_object (buf->x)
233 #include "bufslots.h" 235 #include "bufslots.h"
234 #undef MARKED_SLOT 236 #undef MARKED_SLOT
235 237
236 markobj (buf->extent_info); 238 mark_object (buf->extent_info);
237 if (buf->text) 239 if (buf->text)
238 markobj (buf->text->line_number_cache); 240 mark_object (buf->text->line_number_cache);
239 241
240 /* Don't mark normally through the children slot. 242 /* Don't mark normally through the children slot.
241 (Actually, in this case, it doesn't matter.) */ 243 (Actually, in this case, it doesn't matter.) */
242 if (! EQ (buf->indirect_children, Qnull_pointer)) 244 if (! EQ (buf->indirect_children, Qnull_pointer))
243 mark_conses_in_list (buf->indirect_children); 245 mark_conses_in_list (buf->indirect_children);
1404 f->buffer_alist = XCDR (f->buffer_alist); 1406 f->buffer_alist = XCDR (f->buffer_alist);
1405 else 1407 else
1406 XCDR (prev) = XCDR (XCDR (prev)); 1408 XCDR (prev) = XCDR (XCDR (prev));
1407 XCDR (lynk) = f->buffer_alist; 1409 XCDR (lynk) = f->buffer_alist;
1408 f->buffer_alist = lynk; 1410 f->buffer_alist = lynk;
1411
1412 va_run_hook_with_args (Qrecord_buffer_hook, 1, buffer);
1413
1409 return Qnil; 1414 return Qnil;
1410 } 1415 }
1411 1416
1412 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, 1, 1, 0, /* 1417 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, 1, 1, 0, /*
1413 Set an appropriate major mode for BUFFER, according to `default-major-mode'. 1418 Set an appropriate major mode for BUFFER, according to `default-major-mode'.
1804 defsymbol (&Qbuffer_live_p, "buffer-live-p"); 1809 defsymbol (&Qbuffer_live_p, "buffer-live-p");
1805 defsymbol (&Qbuffer_or_string_p, "buffer-or-string-p"); 1810 defsymbol (&Qbuffer_or_string_p, "buffer-or-string-p");
1806 defsymbol (&Qmode_class, "mode-class"); 1811 defsymbol (&Qmode_class, "mode-class");
1807 defsymbol (&Qrename_auto_save_file, "rename-auto-save-file"); 1812 defsymbol (&Qrename_auto_save_file, "rename-auto-save-file");
1808 defsymbol (&Qkill_buffer_hook, "kill-buffer-hook"); 1813 defsymbol (&Qkill_buffer_hook, "kill-buffer-hook");
1814 defsymbol (&Qrecord_buffer_hook, "record-buffer-hook");
1809 defsymbol (&Qpermanent_local, "permanent-local"); 1815 defsymbol (&Qpermanent_local, "permanent-local");
1810 1816
1811 defsymbol (&Qfirst_change_hook, "first-change-hook"); 1817 defsymbol (&Qfirst_change_hook, "first-change-hook");
1812 defsymbol (&Qbefore_change_functions, "before-change-functions"); 1818 defsymbol (&Qbefore_change_functions, "before-change-functions");
1813 defsymbol (&Qafter_change_functions, "after-change-functions"); 1819 defsymbol (&Qafter_change_functions, "after-change-functions");
1814 1820
1815 /* #### Obsolete, for compatibility */ 1821 /* #### Obsolete, for compatibility */
1816 defsymbol (&Qbefore_change_function, "before-change-function"); 1822 defsymbol (&Qbefore_change_function, "before-change-function");
1817 defsymbol (&Qafter_change_function, "after-change-function"); 1823 defsymbol (&Qafter_change_function, "after-change-function");
1818 1824
1819 defsymbol (&Qbuffer_file_name, "buffer-file-name");
1820 defsymbol (&Qbuffer_undo_list, "buffer-undo-list");
1821 defsymbol (&Qdefault_directory, "default-directory"); 1825 defsymbol (&Qdefault_directory, "default-directory");
1822 1826
1823 defsymbol (&Qget_file_buffer, "get-file-buffer"); 1827 defsymbol (&Qget_file_buffer, "get-file-buffer");
1824 defsymbol (&Qchange_major_mode_hook, "change-major-mode-hook"); 1828 defsymbol (&Qchange_major_mode_hook, "change-major-mode-hook");
1825 1829
1868 1872
1869 deferror (&Qprotected_field, "protected-field", 1873 deferror (&Qprotected_field, "protected-field",
1870 "Attempt to modify a protected field", Qerror); 1874 "Attempt to modify a protected field", Qerror);
1871 } 1875 }
1872 1876
1877 void
1878 reinit_vars_of_buffer (void)
1879 {
1880 staticpro_nodump (&Vbuffer_alist);
1881 Vbuffer_alist = Qnil;
1882 current_buffer = 0;
1883 }
1884
1873 /* initialize the buffer routines */ 1885 /* initialize the buffer routines */
1874 void 1886 void
1875 vars_of_buffer (void) 1887 vars_of_buffer (void)
1876 { 1888 {
1877 /* This function can GC */ 1889 /* This function can GC */
1890 reinit_vars_of_buffer ();
1891
1878 staticpro (&QSFundamental); 1892 staticpro (&QSFundamental);
1879 staticpro (&QSscratch); 1893 staticpro (&QSscratch);
1880 staticpro (&Vbuffer_alist); 1894
1881 1895 QSFundamental = build_string ("Fundamental");
1882 QSFundamental = Fpurecopy (build_string ("Fundamental")); 1896 QSscratch = build_string (DEFER_GETTEXT ("*scratch*"));
1883 QSscratch = Fpurecopy (build_string (DEFER_GETTEXT ("*scratch*")));
1884
1885 Vbuffer_alist = Qnil;
1886 current_buffer = 0;
1887 1897
1888 DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook /* 1898 DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook /*
1889 List of hooks to be run before killing local variables in a buffer. 1899 List of hooks to be run before killing local variables in a buffer.
1890 This should be used by any mode that temporarily alters the contents or 1900 This should be used by any mode that temporarily alters the contents or
1891 the read-only state of the buffer. See also `kill-all-local-variables'. 1901 the read-only state of the buffer. See also `kill-all-local-variables'.
2061 2071
2062 b->extent_info = Qnil; 2072 b->extent_info = Qnil;
2063 b->indirect_children = Qnil; 2073 b->indirect_children = Qnil;
2064 b->own_text.line_number_cache = Qnil; 2074 b->own_text.line_number_cache = Qnil;
2065 2075
2066 #define MARKED_SLOT(x) b->x = (zap); 2076 #define MARKED_SLOT(x) b->x = zap
2067 #include "bufslots.h" 2077 #include "bufslots.h"
2068 #undef MARKED_SLOT 2078 #undef MARKED_SLOT
2069 } 2079 }
2070 2080
2071 void 2081 static void
2072 complex_vars_of_buffer (void) 2082 common_init_complex_vars_of_buffer (void)
2073 { 2083 {
2074 /* Make sure all markable slots in buffer_defaults 2084 /* Make sure all markable slots in buffer_defaults
2075 are initialized reasonably, so mark_buffer won't choke. */ 2085 are initialized reasonably, so mark_buffer won't choke. */
2076 struct buffer *defs = alloc_lcrecord_type (struct buffer, &lrecord_buffer); 2086 struct buffer *defs = alloc_lcrecord_type (struct buffer, &lrecord_buffer);
2077 struct buffer *syms = alloc_lcrecord_type (struct buffer, &lrecord_buffer); 2087 struct buffer *syms = alloc_lcrecord_type (struct buffer, &lrecord_buffer);
2078 2088
2079 staticpro (&Vbuffer_defaults); 2089 staticpro_nodump (&Vbuffer_defaults);
2080 staticpro (&Vbuffer_local_symbols); 2090 staticpro_nodump (&Vbuffer_local_symbols);
2081 XSETBUFFER (Vbuffer_defaults, defs); 2091 XSETBUFFER (Vbuffer_defaults, defs);
2082 XSETBUFFER (Vbuffer_local_symbols, syms); 2092 XSETBUFFER (Vbuffer_local_symbols, syms);
2083 2093
2084 nuke_all_buffer_slots (syms, Qnil); 2094 nuke_all_buffer_slots (syms, Qnil);
2085 nuke_all_buffer_slots (defs, Qnil); 2095 nuke_all_buffer_slots (defs, Qnil);
2191 #endif 2201 #endif
2192 #ifdef FILE_CODING 2202 #ifdef FILE_CODING
2193 buffer_local_flags.buffer_file_coding_system = make_int (1<<14); 2203 buffer_local_flags.buffer_file_coding_system = make_int (1<<14);
2194 #endif 2204 #endif
2195 2205
2196 /* #### Warning: 1<<28 is the largest number currently allowable 2206 /* #### Warning: 1<<31 is the largest number currently allowable
2197 due to the XINT() handling of this value. With some 2207 due to the XINT() handling of this value. With some
2198 rearrangement you can get 3 more bits. */ 2208 rearrangement you can get 3 more bits. */
2199 } 2209 }
2200 2210 }
2211
2212 #define BUFFER_SLOTS_SIZE (offsetof (struct buffer, BUFFER_SLOTS_LAST_NAME) - offsetof (struct buffer, BUFFER_SLOTS_FIRST_NAME) + sizeof (Lisp_Object))
2213 #define BUFFER_SLOTS_COUNT (BUFFER_SLOTS_SIZE / sizeof (Lisp_Object))
2214
2215 void
2216 reinit_complex_vars_of_buffer (void)
2217 {
2218 struct buffer *defs, *syms;
2219
2220 common_init_complex_vars_of_buffer ();
2221
2222 defs = XBUFFER (Vbuffer_defaults);
2223 syms = XBUFFER (Vbuffer_local_symbols);
2224 memcpy (&defs->BUFFER_SLOTS_FIRST_NAME,
2225 buffer_defaults_saved_slots,
2226 BUFFER_SLOTS_SIZE);
2227 memcpy (&syms->BUFFER_SLOTS_FIRST_NAME,
2228 buffer_local_symbols_saved_slots,
2229 BUFFER_SLOTS_SIZE);
2230 }
2231
2232
2233 static const struct lrecord_description buffer_slots_description_1[] = {
2234 { XD_LISP_OBJECT, 0, BUFFER_SLOTS_COUNT },
2235 { XD_END }
2236 };
2237
2238 static const struct struct_description buffer_slots_description = {
2239 BUFFER_SLOTS_SIZE,
2240 buffer_slots_description_1
2241 };
2242
2243 void
2244 complex_vars_of_buffer (void)
2245 {
2246 struct buffer *defs, *syms;
2247
2248 common_init_complex_vars_of_buffer ();
2249
2250 defs = XBUFFER (Vbuffer_defaults);
2251 syms = XBUFFER (Vbuffer_local_symbols);
2252 buffer_defaults_saved_slots = &defs->BUFFER_SLOTS_FIRST_NAME;
2253 buffer_local_symbols_saved_slots = &syms->BUFFER_SLOTS_FIRST_NAME;
2254 dumpstruct (&buffer_defaults_saved_slots, &buffer_slots_description);
2255 dumpstruct (&buffer_local_symbols_saved_slots, &buffer_slots_description);
2256
2201 DEFVAR_BUFFER_DEFAULTS ("default-modeline-format", modeline_format /* 2257 DEFVAR_BUFFER_DEFAULTS ("default-modeline-format", modeline_format /*
2202 Default value of `modeline-format' for buffers that don't override it. 2258 Default value of `modeline-format' for buffers that don't override it.
2203 This is the same as (default-value 'modeline-format). 2259 This is the same as (default-value 'modeline-format).
2204 */ ); 2260 */ );
2205 2261