comparison src/buffer.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 56c54cf7c5b6
children c7528f8e288d
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
67 67
68 #include <config.h> 68 #include <config.h>
69 #include "lisp.h" 69 #include "lisp.h"
70 70
71 #include "buffer.h" 71 #include "buffer.h"
72 #include "chartab.h"
72 #include "commands.h" 73 #include "commands.h"
73 #include "elhash.h" 74 #include "elhash.h"
74 #include "extents.h" 75 #include "extents.h"
75 #include "faces.h" 76 #include "faces.h"
76 #include "frame.h" 77 #include "frame.h"
458 FILENAME will be converted to its truename and used for searching, but 459 FILENAME will be converted to its truename and used for searching, but
459 the search will still be done on `buffer-file-name'. 460 the search will still be done on `buffer-file-name'.
460 */ 461 */
461 (filename)) 462 (filename))
462 { 463 {
463 /* This function can GC. GC checked 1997.04.06. */ 464 /* This function can GC */
464 REGISTER Lisp_Object tail, buf, tem; 465 REGISTER Lisp_Object tail, buf, tem;
465 struct gcpro gcpro1; 466 struct gcpro gcpro1;
466 467
467 #ifdef I18N3 468 #ifdef I18N3
468 /* DO NOT translate the filename. */ 469 /* DO NOT translate the filename. */
663 664
664 #if 0 /* #### implement this! Need various changes in insdel.c */ 665 #if 0 /* #### implement this! Need various changes in insdel.c */
665 Lisp_Object buf; 666 Lisp_Object buf;
666 REGISTER struct buffer *b; 667 REGISTER struct buffer *b;
667 668
669 #ifdef I18N3
670 /* #### Doc string should indicate that the buffer name will get
671 translated. */
672 #endif
673
668 name = LISP_GETTEXT (name); 674 name = LISP_GETTEXT (name);
669 buf = Fget_buffer (name); 675 buf = Fget_buffer (name);
670 if (!NILP (buf)) 676 if (!NILP (buf))
671 error ("Buffer name `%s' is in use", XSTRING_DATA (name)); 677 error ("Buffer name `%s' is in use", XSTRING_DATA (name));
672 678
978 int already = BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf); 984 int already = BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf);
979 if (already == NILP (flag)) 985 if (already == NILP (flag))
980 { 986 {
981 int count = specpdl_depth (); 987 int count = specpdl_depth ();
982 /* lock_file() and unlock_file() currently use current_buffer */ 988 /* lock_file() and unlock_file() currently use current_buffer */
983 /* #### - dmoore, what if lock_file or unlock_file kill
984 the current buffer? */
985 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 989 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
986 set_buffer_internal (buf); 990 set_buffer_internal (buf);
987 if (!already && !NILP (flag)) 991 if (!already && !NILP (flag))
988 lock_file (fn); 992 lock_file (fn);
989 else if (already && NILP (flag)) 993 else if (already && NILP (flag))
996 /* This is often called when the buffer contents are altered but we 1000 /* This is often called when the buffer contents are altered but we
997 don't want to treat the changes that way (e.g. selective 1001 don't want to treat the changes that way (e.g. selective
998 display). We still need to make sure redisplay realizes that the 1002 display). We still need to make sure redisplay realizes that the
999 contents have potentially altered and it needs to do some 1003 contents have potentially altered and it needs to do some
1000 work. */ 1004 work. */
1001 buf = decode_buffer(buffer, 0);
1002 BUF_MODIFF (buf)++; 1005 BUF_MODIFF (buf)++;
1003 BUF_SAVE_MODIFF (buf) = NILP (flag) ? BUF_MODIFF (buf) : 0; 1006 BUF_SAVE_MODIFF (buf) = NILP (flag) ? BUF_MODIFF (buf) : 0;
1004 MARK_MODELINE_CHANGED; 1007 MARK_MODELINE_CHANGED;
1005 1008
1006 #ifdef ENERGIZE 1009 #ifdef ENERGIZE
1164 if (!NILP (notsogood)) 1167 if (!NILP (notsogood))
1165 return notsogood; 1168 return notsogood;
1166 return Fget_buffer_create (QSscratch); 1169 return Fget_buffer_create (QSscratch);
1167 } 1170 }
1168 1171
1169 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, 0, 1, "", /* 1172 /* XEmacs change: Make this argument required because this is a dangerous
1173 function. */
1174 DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, 1, 1, "", /*
1170 Make BUFFER stop keeping undo information. 1175 Make BUFFER stop keeping undo information.
1171 Any undo records it already has are discarded. 1176 Any undo records it already has are discarded.
1172 No argument or nil as argument means do this for the current buffer.
1173 */ 1177 */
1174 (buffer)) 1178 (buffer))
1175 { 1179 {
1176 /* Allowing nil is an RMSism */ 1180 /* Allowing nil is an RMSism */
1177 struct buffer *real_buf = decode_buffer (buffer, 1); 1181 struct buffer *real_buf = decode_buffer (buffer, 1);
1208 Any processes that have this buffer as the `process-buffer' are killed 1212 Any processes that have this buffer as the `process-buffer' are killed
1209 with `delete-process'. 1213 with `delete-process'.
1210 */ 1214 */
1211 (bufname)) 1215 (bufname))
1212 { 1216 {
1213 /* This function can call lisp */ 1217 /* This function can GC */
1214 Lisp_Object buf; 1218 Lisp_Object buf;
1215 REGISTER struct buffer *b; 1219 REGISTER struct buffer *b;
1216 struct gcpro gcpro1, gcpro2; 1220 struct gcpro gcpro1, gcpro2;
1217 1221
1218 if (NILP (bufname)) 1222 if (NILP (bufname))
1235 if (EQ (buf, Vminibuffer_zero)) 1239 if (EQ (buf, Vminibuffer_zero))
1236 return Qnil; 1240 return Qnil;
1237 1241
1238 /* Or the echo area. */ 1242 /* Or the echo area. */
1239 if (EQ (buf, Vecho_area_buffer)) 1243 if (EQ (buf, Vecho_area_buffer))
1240 return Qnil;
1241
1242 /* Or the special invisible internal prin1 buffer. */
1243 if (EQ (buf, Vprin1_to_string_buffer))
1244 return Qnil; 1244 return Qnil;
1245 1245
1246 /* Query if the buffer is still modified. */ 1246 /* Query if the buffer is still modified. */
1247 if (INTERACTIVE && !NILP (b->filename) 1247 if (INTERACTIVE && !NILP (b->filename)
1248 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) 1248 && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
1304 1304
1305 /* We have no more questions to ask. Verify that it is valid 1305 /* We have no more questions to ask. Verify that it is valid
1306 to kill the buffer. This must be done after the questions 1306 to kill the buffer. This must be done after the questions
1307 since anything can happen within yes-or-no-p. */ 1307 since anything can happen within yes-or-no-p. */
1308 1308
1309 /* Don't kill the minibuffer now current. */
1310 if (EQ (buf, XWINDOW (minibuf_window)->buffer))
1311 return Qnil;
1312
1309 /* Might have been deleted during the last question above */ 1313 /* Might have been deleted during the last question above */
1310 if (!BUFFER_LIVE_P (b)) 1314 if (!BUFFER_LIVE_P (b))
1311 return Qnil;
1312
1313 /* Don't kill the minibuffer now current. */
1314 if (EQ (buf, XWINDOW (minibuf_window)->buffer))
1315 return Qnil; 1315 return Qnil;
1316 1316
1317 /* When we kill a base buffer, kill all its indirect buffers. 1317 /* When we kill a base buffer, kill all its indirect buffers.
1318 We do it at this stage so nothing terrible happens if they 1318 We do it at this stage so nothing terrible happens if they
1319 ask questions or their hooks get errors. */ 1319 ask questions or their hooks get errors. */
1340 } 1340 }
1341 1341
1342 /* Now there is no question: we can kill the buffer. */ 1342 /* Now there is no question: we can kill the buffer. */
1343 1343
1344 #ifdef CLASH_DETECTION 1344 #ifdef CLASH_DETECTION
1345 /* Unlock this buffer's file, if it is locked. unlock_buffer 1345 /* Unlock this buffer's file, if it is locked. */
1346 can both GC and kill the current buffer, and wreak general
1347 havok by running lisp code. */
1348 GCPRO1 (buf);
1349 unlock_buffer (b); 1346 unlock_buffer (b);
1350 UNGCPRO;
1351 b = XBUFFER (buf);
1352
1353 if (!BUFFER_LIVE_P (b))
1354 return Qnil;
1355
1356 if (b == current_buffer)
1357 {
1358 Fset_buffer (Fother_buffer (buf, Qnil, Qnil));
1359 if (b == current_buffer)
1360 return Qnil;
1361 }
1362 #endif /* CLASH_DETECTION */ 1347 #endif /* CLASH_DETECTION */
1363 1348
1364 { 1349 {
1365 int speccount = specpdl_depth (); 1350 int speccount = specpdl_depth ();
1366 specbind (Qinhibit_quit, Qt); 1351 specbind (Qinhibit_quit, Qt);
1380 if (STRINGP (b->auto_save_file_name) 1365 if (STRINGP (b->auto_save_file_name)
1381 && b->auto_save_modified != 0 1366 && b->auto_save_modified != 0
1382 && BUF_SAVE_MODIFF (b) < b->auto_save_modified) 1367 && BUF_SAVE_MODIFF (b) < b->auto_save_modified)
1383 { 1368 {
1384 if (!NILP (Vdelete_auto_save_files)) 1369 if (!NILP (Vdelete_auto_save_files))
1385 { 1370 internal_delete_file (b->auto_save_file_name);
1386 /* deleting the auto save file might kill b! */
1387 /* #### dmoore - fix this crap, we do this same gcpro and
1388 buffer liveness check multiple times. Let's get a
1389 macro or something for it. */
1390 GCPRO1 (buf);
1391 internal_delete_file (b->auto_save_file_name);
1392 UNGCPRO;
1393 b = XBUFFER (buf);
1394
1395 if (!BUFFER_LIVE_P (b))
1396 return Qnil;
1397
1398 if (b == current_buffer)
1399 {
1400 Fset_buffer (Fother_buffer (buf, Qnil, Qnil));
1401 if (b == current_buffer)
1402 return Qnil;
1403 }
1404 }
1405 } 1371 }
1406 1372
1407 uninit_buffer_markers (b); 1373 uninit_buffer_markers (b);
1408 1374
1409 kill_buffer_local_variables (b); 1375 kill_buffer_local_variables (b);
1580 Lisp_Object valcontents = XSYMBOL (sym)->value; 1546 Lisp_Object valcontents = XSYMBOL (sym)->value;
1581 if (SYMBOL_VALUE_MAGIC_P (valcontents)) 1547 if (SYMBOL_VALUE_MAGIC_P (valcontents))
1582 { 1548 {
1583 /* Just reference the variable 1549 /* Just reference the variable
1584 to cause it to become set for this buffer. */ 1550 to cause it to become set for this buffer. */
1585 /* Use find_symbol_value_quickly to avoid an unnecessary O(n) 1551 (void) find_symbol_value (sym);
1586 lookup. */
1587 (void) find_symbol_value_quickly (XCAR (tail), 1);
1588 } 1552 }
1589 } 1553 }
1590 1554
1591 /* Do the same with any others that were local to the previous buffer */ 1555 /* Do the same with any others that were local to the previous buffer */
1592 1556
1593 if (old_buf) 1557 if (old_buf)
1594 { 1558 {
1595 LIST_LOOP (tail, old_buf->local_var_alist) 1559 for (tail = old_buf->local_var_alist;
1560 !NILP (tail);
1561 tail = XCDR (tail))
1596 { 1562 {
1597 Lisp_Object sym = XCAR (XCAR (tail)); 1563 Lisp_Object sym = XCAR (XCAR (tail));
1598 Lisp_Object valcontents = XSYMBOL (sym)->value; 1564 Lisp_Object valcontents = XSYMBOL (sym)->value;
1599 1565
1600 if (SYMBOL_VALUE_MAGIC_P (valcontents)) 1566 if (SYMBOL_VALUE_MAGIC_P (valcontents))
1601 { 1567 {
1602 /* Just reference the variable 1568 /* Just reference the variable
1603 to cause it to become set for this buffer. */ 1569 to cause it to become set for this buffer. */
1604 /* Use find_symbol_value_quickly with find_it_p as 0 to avoid an 1570 (void) find_symbol_value (sym);
1605 unnecessary O(n) lookup which is guaranteed to be worst case.
1606 Any symbols which are local are guaranteed to have been
1607 handled in the previous loop, above. */
1608 (void) find_symbol_value_quickly (sym, 0);
1609 } 1571 }
1610 } 1572 }
1611 } 1573 }
1612 } 1574 }
1613 1575
1756 1718
1757 DEFUN ("kill-all-local-variables", Fkill_all_local_variables, 0, 0, 0, /* 1719 DEFUN ("kill-all-local-variables", Fkill_all_local_variables, 0, 0, 0, /*
1758 Switch to Fundamental mode by killing current buffer's local variables. 1720 Switch to Fundamental mode by killing current buffer's local variables.
1759 Most local variable bindings are eliminated so that the default values 1721 Most local variable bindings are eliminated so that the default values
1760 become effective once more. Also, the syntax table is set from 1722 become effective once more. Also, the syntax table is set from
1761 `standard-syntax-table', local keymap is set to nil, 1723 `standard-syntax-table', the category table is set from
1762 the abbrev table is set from `fundamental-mode-abbrev-table', 1724 `standard-category-table' (if support for Mule exists), local keymap is set
1725 to nil, the abbrev table is set from `fundamental-mode-abbrev-table',
1763 and all specifier specifications whose locale is the current buffer 1726 and all specifier specifications whose locale is the current buffer
1764 are removed. This function also forces redisplay of the modeline. 1727 are removed. This function also forces redisplay of the modeline.
1765 1728
1766 Every function to select a new major mode starts by 1729 Every function to select a new major mode starts by
1767 calling this function. 1730 calling this function.
2197 defs->abbrev_table = Qnil; /* real default setup by Lisp code */ 2160 defs->abbrev_table = Qnil; /* real default setup by Lisp code */
2198 defs->downcase_table = Vascii_downcase_table; 2161 defs->downcase_table = Vascii_downcase_table;
2199 defs->upcase_table = Vascii_upcase_table; 2162 defs->upcase_table = Vascii_upcase_table;
2200 defs->case_canon_table = Vascii_canon_table; 2163 defs->case_canon_table = Vascii_canon_table;
2201 defs->case_eqv_table = Vascii_eqv_table; 2164 defs->case_eqv_table = Vascii_eqv_table;
2165 #ifdef MULE
2166 defs->mirror_downcase_table = Vmirror_ascii_downcase_table;
2167 defs->mirror_upcase_table = Vmirror_ascii_upcase_table;
2168 defs->mirror_case_canon_table = Vmirror_ascii_canon_table;
2169 defs->mirror_case_eqv_table = Vmirror_ascii_eqv_table;
2170 #endif
2202 defs->syntax_table = Vstandard_syntax_table; 2171 defs->syntax_table = Vstandard_syntax_table;
2203 2172 defs->mirror_syntax_table =
2173 XCHAR_TABLE (Vstandard_syntax_table)->mirror_table;
2174 #ifdef MULE
2175 defs->category_table = Vstandard_category_table;
2176 #endif
2204 defs->modeline_format = build_string ("%-"); /* reset in loaddefs.el */ 2177 defs->modeline_format = build_string ("%-"); /* reset in loaddefs.el */
2205 defs->case_fold_search = Qt; 2178 defs->case_fold_search = Qt;
2206 defs->selective_display_ellipses = Qt; 2179 defs->selective_display_ellipses = Qt;
2207 defs->tab_width = make_int (8); 2180 defs->tab_width = make_int (8);
2208 defs->ctl_arrow = Qt; 2181 defs->ctl_arrow = Qt;
2258 buffer_local_flags.downcase_table = resettable; 2231 buffer_local_flags.downcase_table = resettable;
2259 buffer_local_flags.upcase_table = resettable; 2232 buffer_local_flags.upcase_table = resettable;
2260 buffer_local_flags.case_canon_table = resettable; 2233 buffer_local_flags.case_canon_table = resettable;
2261 buffer_local_flags.case_eqv_table = resettable; 2234 buffer_local_flags.case_eqv_table = resettable;
2262 buffer_local_flags.syntax_table = resettable; 2235 buffer_local_flags.syntax_table = resettable;
2236 #ifdef MULE
2237 buffer_local_flags.category_table = resettable;
2238 #endif
2263 2239
2264 buffer_local_flags.modeline_format = make_int (1); 2240 buffer_local_flags.modeline_format = make_int (1);
2265 buffer_local_flags.abbrev_mode = make_int (2); 2241 buffer_local_flags.abbrev_mode = make_int (2);
2266 buffer_local_flags.overwrite_mode = make_int (4); 2242 buffer_local_flags.overwrite_mode = make_int (4);
2267 buffer_local_flags.case_fold_search = make_int (8); 2243 buffer_local_flags.case_fold_search = make_int (8);
2276 buffer_local_flags.abbrev_table = make_int (0x1000); 2252 buffer_local_flags.abbrev_table = make_int (0x1000);
2277 #ifdef REGION_CACHE_NEEDS_WORK 2253 #ifdef REGION_CACHE_NEEDS_WORK
2278 buffer_local_flags.cache_long_line_scans = make_int (0x2000); 2254 buffer_local_flags.cache_long_line_scans = make_int (0x2000);
2279 #endif 2255 #endif
2280 buffer_local_flags.buffer_file_type = make_int (0x4000); 2256 buffer_local_flags.buffer_file_type = make_int (0x4000);
2257 #ifdef MULE
2258 buffer_local_flags.file_coding_system = make_int (0x8000);
2259 #endif
2281 2260
2282 /* #### Warning, 0x4000000 (that's six zeroes) is the largest number 2261 /* #### Warning, 0x4000000 (that's six zeroes) is the largest number
2283 currently allowable due to the XINT() handling of this value. 2262 currently allowable due to the XINT() handling of this value.
2284 With some rearrangement you can get 4 more bits. */ 2263 With some rearrangement you can get 4 more bits. */
2285 } 2264 }
2379 %p -- print percent of buffer above top of window, or Top, Bot or All. 2358 %p -- print percent of buffer above top of window, or Top, Bot or All.
2380 %P -- print percent of buffer above bottom of window, perhaps plus Top, 2359 %P -- print percent of buffer above bottom of window, perhaps plus Top,
2381 or print Bottom or All. 2360 or print Bottom or All.
2382 %n -- print Narrow if appropriate. 2361 %n -- print Narrow if appropriate.
2383 %t -- Under MS-DOS, print T if files is text, B if binary. 2362 %t -- Under MS-DOS, print T if files is text, B if binary.
2363 %C -- under XEmacs/Mule, print the mnemonic for `file-coding-system'.
2384 %[ -- print one [ for each recursive editing level. %] similar. 2364 %[ -- print one [ for each recursive editing level. %] similar.
2385 %% -- print %. %- -- print infinitely many dashes. 2365 %% -- print %. %- -- print infinitely many dashes.
2386 Decimal digits after the % specify field width to which to pad. 2366 Decimal digits after the % specify field width to which to pad.
2387 */ ); 2367 */ );
2388 2368
2409 */ ); 2389 */ );
2410 2390
2411 DEFVAR_BUFFER_LOCAL ("case-fold-search", case_fold_search /* 2391 DEFVAR_BUFFER_LOCAL ("case-fold-search", case_fold_search /*
2412 *Non-nil if searches should ignore case. 2392 *Non-nil if searches should ignore case.
2413 Automatically becomes buffer-local when set in any fashion. 2393 Automatically becomes buffer-local when set in any fashion.
2394
2395 BUG: Under XEmacs/Mule, translations to or from non-ASCII characters
2396 (this includes chars in the range 128 - 255) are ignored by
2397 the string/buffer-searching routines. Thus, `case-fold-search'
2398 will not correctly conflate a-umlaut and A-umlaut even if the
2399 case tables call for this.
2414 */ ); 2400 */ );
2415 2401
2416 DEFVAR_BUFFER_LOCAL ("fill-column", fill_column /* 2402 DEFVAR_BUFFER_LOCAL ("fill-column", fill_column /*
2417 *Column beyond which automatic line-wrapping should happen. 2403 *Column beyond which automatic line-wrapping should happen.
2418 Automatically becomes buffer-local when set in any fashion. 2404 Automatically becomes buffer-local when set in any fashion.
2472 "Non-nil if the visited file is a binary file. 2458 "Non-nil if the visited file is a binary file.
2473 This variable is meaningful on MS-DOG and Windows NT. 2459 This variable is meaningful on MS-DOG and Windows NT.
2474 On those systems, it is automatically local in every buffer. 2460 On those systems, it is automatically local in every buffer.
2475 On other systems, this variable is normally always nil. 2461 On other systems, this variable is normally always nil.
2476 */ ); 2462 */ );
2463
2464 #ifdef MULE
2465 DEFVAR_BUFFER_DEFAULTS ("default-file-coding-system", file_coding_system /*
2466 Default value of `file-coding-system' for buffers that do not override it.
2467 This is the same as (default-value 'file-coding-system).
2468 This value is used both for buffers without associated files and
2469 for buffers whose files do not have any apparent coding system.
2470 See `file-coding-system'.
2471 */ );
2472
2473 DEFVAR_BUFFER_LOCAL ("file-coding-system", file_coding_system /*
2474 *Current coding system for the current buffer.
2475 When the buffer is written out into a file, this coding system will
2476 be used for the encoding. Automatically buffer-local when set in
2477 any fashion. This is normally set automatically when a file is loaded
2478 in based on the determined coding system of the file (assuming that
2479 `file-coding-system-for-read' is set to `autodetect', which calls
2480 for automatic determination of the file's coding system). Normally the
2481 modeline indicates the current file coding system using its mnemonic
2482 abbreviation.
2483
2484 The default value for this variable (which is normally used for
2485 buffers without associated files) is also used when automatic
2486 detection of a file's encoding is called for and there was no
2487 discernable encoding in the file (i.e. it was entirely or almost
2488 entirely ASCII). The default value should generally *not* be set to
2489 nil (equivalent to `no-conversion'), because if extended characters
2490 are ever inserted into the buffer, they will be lost when the file is
2491 written out. A good choice is `iso-2022-8' (the simple ISO 2022 8-bit
2492 encoding), which will write out ASCII and Latin-1 characters in the
2493 standard (and highly portable) fashion and use standard escape
2494 sequences for other charsets. Another reasonable choice is
2495 `escape-quoted', which is equivalent to `iso-2022-8' but prefixes
2496 certain control characters with ESC to make sure they are not
2497 interpreted as escape sequences when read in. This latter coding
2498 system results in more \"correct\" output in the presence of control
2499 characters in the buffer, in the sense that when read in again using
2500 the same coding system, the result will virtually always match the
2501 original contents of the buffer, which is not the case with
2502 `iso-2022-8'; but the output is less portable when dealing with binary
2503 data -- there may be stray ESC characters when the file is read by
2504 another program.
2505
2506 `file-coding-system' does *not* control the coding system used when
2507 a file is read in. Use the variables `file-coding-system-for-read'
2508 and `file-coding-system-alist' for that. From a Lisp program, if
2509 you wish to unilaterally specify the coding system used for one
2510 particular operation, you should bind the variable
2511 `overriding-file-coding-system' rather than changing the other two
2512 variables just mentioned, which are intended to be used for
2513 global environment specification. */ );
2514 #endif /* MULE */
2477 2515
2478 DEFVAR_BUFFER_LOCAL ("auto-fill-function", auto_fill_function /* 2516 DEFVAR_BUFFER_LOCAL ("auto-fill-function", auto_fill_function /*
2479 Function called (if non-nil) to perform auto-fill. 2517 Function called (if non-nil) to perform auto-fill.
2480 It is called after self-inserting a space at a column beyond `fill-column'. 2518 It is called after self-inserting a space at a column beyond `fill-column'.
2481 Each buffer has its own value of this variable. 2519 Each buffer has its own value of this variable.