comparison src/buffer.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
82 #include "lstream.h" 82 #include "lstream.h"
83 #include "process.h" /* for kill_buffer_processes */ 83 #include "process.h" /* for kill_buffer_processes */
84 #ifdef REGION_CACHE_NEEDS_WORK 84 #ifdef REGION_CACHE_NEEDS_WORK
85 #include "region-cache.h" 85 #include "region-cache.h"
86 #endif 86 #endif
87 #include "select.h" /* for select_notify_buffer_kill */
87 #include "specifier.h" 88 #include "specifier.h"
88 #include "syntax.h" 89 #include "syntax.h"
89 #include "sysdep.h" /* for getwd */ 90 #include "sysdep.h" /* for getwd */
90 #include "window.h" 91 #include "window.h"
91 92
193 Lisp_Object QSFundamental; /* A string "Fundamental" */ 194 Lisp_Object QSFundamental; /* A string "Fundamental" */
194 Lisp_Object QSscratch; /* "*scratch*" */ 195 Lisp_Object QSscratch; /* "*scratch*" */
195 Lisp_Object Qdefault_directory; 196 Lisp_Object Qdefault_directory;
196 197
197 Lisp_Object Qkill_buffer_hook; 198 Lisp_Object Qkill_buffer_hook;
198 Lisp_Object Qrecord_buffer_hook;
199 199
200 Lisp_Object Qrename_auto_save_file; 200 Lisp_Object Qrename_auto_save_file;
201 201
202 Lisp_Object Qget_file_buffer; 202 Lisp_Object Qget_file_buffer;
203 Lisp_Object Qchange_major_mode_hook, Vchange_major_mode_hook; 203 Lisp_Object Qchange_major_mode_hook, Vchange_major_mode_hook;
437 FILENAME will be converted to its truename and used for searching, but 437 FILENAME will be converted to its truename and used for searching, but
438 the search will still be done on `buffer-file-name'. 438 the search will still be done on `buffer-file-name'.
439 */ 439 */
440 (filename)) 440 (filename))
441 { 441 {
442 /* This function can GC. GC checked 1997.04.06. */ 442 /* This function can GC. GC checked and fixed 7-11-2000 ben. */
443 REGISTER Lisp_Object buf; 443 REGISTER Lisp_Object buf;
444 struct gcpro gcpro1; 444 struct gcpro gcpro1;
445 445
446 #ifdef I18N3 446 #ifdef I18N3
447 /* DO NOT translate the filename. */ 447 /* DO NOT translate the filename. */
472 if (NILP (fn)) 472 if (NILP (fn))
473 { 473 {
474 dn = Ffile_name_directory (filename); 474 dn = Ffile_name_directory (filename);
475 fn = Ffile_truename (dn, Qnil); 475 fn = Ffile_truename (dn, Qnil);
476 if (! NILP (fn)) dn = fn; 476 if (! NILP (fn)) dn = fn;
477 fn = Fexpand_file_name (Ffile_name_nondirectory (filename), 477 /* Formerly the two calls below were combined, but that is
478 dn); 478 not GC-safe because the first call returns unprotected
479 data and the second call can GC. --ben */
480 fn = Ffile_name_nondirectory (filename);
481 fn = Fexpand_file_name (fn, dn);
479 } 482 }
480 filename = fn; 483 filename = fn;
481 NUNGCPRO; 484 NUNGCPRO;
482 } 485 }
483 486
484 { 487 {
485 Lisp_Object elt;
486 LIST_LOOP_2 (elt, Vbuffer_alist) 488 LIST_LOOP_2 (elt, Vbuffer_alist)
487 { 489 {
488 buf = Fcdr (elt); 490 buf = Fcdr (elt);
489 if (!BUFFERP (buf)) continue; 491 if (!BUFFERP (buf)) continue;
490 if (!STRINGP (XBUFFER (buf)->filename)) continue; 492 if (!STRINGP (XBUFFER (buf)->filename)) continue;
532 } 534 }
533 535
534 Lisp_Object 536 Lisp_Object
535 get_truename_buffer (REGISTER Lisp_Object filename) 537 get_truename_buffer (REGISTER Lisp_Object filename)
536 { 538 {
539 /* This function can GC. GC correct 7-11-00 ben */
537 /* FSFmacs has its own code here and doesn't call get-file-buffer. 540 /* FSFmacs has its own code here and doesn't call get-file-buffer.
538 That's because their equivalent of find-file-compare-truenames 541 That's because their equivalent of find-file-compare-truenames
539 (find-file-existing-other-name) isn't looked at in get-file-buffer. 542 (find-file-existing-other-name) isn't looked at in get-file-buffer.
540 This way is more correct. */ 543 This way is more correct. */
541 int count = specpdl_depth (); 544 int count = specpdl_depth ();
565 /* #### This really does not need to be called. We already 568 /* #### This really does not need to be called. We already
566 initialized the buffer-local variables in allocate_buffer(). 569 initialized the buffer-local variables in allocate_buffer().
567 local_var_alist is set to Qnil at the same point, in 570 local_var_alist is set to Qnil at the same point, in
568 nuke_all_buffer_slots(). */ 571 nuke_all_buffer_slots(). */
569 reset_buffer_local_variables (b, 1); 572 reset_buffer_local_variables (b, 1);
570 b->directory = ((current_buffer) ? current_buffer->directory : Qnil); 573 b->directory = current_buffer ? current_buffer->directory : Qnil;
571 574
572 b->last_window_start = 1; 575 b->last_window_start = 1;
573 576
574 b->name = name; 577 b->name = name;
575 if (string_byte (XSTRING (name), 0) != ' ') 578 if (string_byte (XSTRING (name), 0) != ' ')
867 #undef MARKED_SLOT 870 #undef MARKED_SLOT
868 } 871 }
869 return result; 872 return result;
870 } 873 }
871 874
872 DEFUN ("buffer-dedicated-frame", Fbuffer_dedicated_frame, 0, 1, 0, /*
873 Return the frame dedicated to this BUFFER, or nil if there is none.
874 No argument or nil as argument means use current buffer as BUFFER.
875 */
876 (buffer))
877 {
878 struct buffer *buf = decode_buffer (buffer, 0);
879
880 /* XEmacs addition: if the frame is dead, silently make it go away. */
881 if (!NILP (buf->dedicated_frame) &&
882 !FRAME_LIVE_P (XFRAME (buf->dedicated_frame)))
883 buf->dedicated_frame = Qnil;
884
885 return buf->dedicated_frame;
886 }
887
888 DEFUN ("set-buffer-dedicated-frame", Fset_buffer_dedicated_frame, 2, 2, 0, /*
889 For this BUFFER, set the FRAME dedicated to it.
890 FRAME must be a frame or nil.
891 */
892 (buffer, frame))
893 {
894 struct buffer *buf = decode_buffer (buffer, 0);
895
896 if (!NILP (frame))
897 CHECK_LIVE_FRAME (frame); /* XEmacs change */
898
899 return buf->dedicated_frame = frame;
900 }
901
902
903 875
904 DEFUN ("buffer-modified-p", Fbuffer_modified_p, 0, 1, 0, /* 876 DEFUN ("buffer-modified-p", Fbuffer_modified_p, 0, 1, 0, /*
905 Return t if BUFFER was modified since its file was last read or saved. 877 Return t if BUFFER was modified since its file was last read or saved.
906 No argument or nil as argument means use current buffer as BUFFER. 878 No argument or nil as argument means use current buffer as BUFFER.
907 */ 879 */
1025 buf = Fcurrent_buffer (); 997 buf = Fcurrent_buffer ();
1026 998
1027 /* The aconses in the Vbuffer_alist are shared with frame->buffer_alist, 999 /* The aconses in the Vbuffer_alist are shared with frame->buffer_alist,
1028 so this will change it in the per-frame ordering as well. */ 1000 so this will change it in the per-frame ordering as well. */
1029 Fsetcar (Frassq (buf, Vbuffer_alist), newname); 1001 Fsetcar (Frassq (buf, Vbuffer_alist), newname);
1002
1030 if (NILP (current_buffer->filename) 1003 if (NILP (current_buffer->filename)
1031 && !NILP (current_buffer->auto_save_file_name)) 1004 && !NILP (current_buffer->auto_save_file_name))
1032 call0 (Qrename_auto_save_file); 1005 call0 (Qrename_auto_save_file);
1033 /* refetch since that last call may have done GC */ 1006 /* refetch since that last call may have done GC */
1034 /* (hypothetical relocating GC) */ 1007 /* (hypothetical relocating GC) */
1184 Lisp_Object killp; 1157 Lisp_Object killp;
1185 GCPRO1 (buf); 1158 GCPRO1 (buf);
1186 killp = call1 1159 killp = call1
1187 (Qyes_or_no_p, 1160 (Qyes_or_no_p,
1188 (emacs_doprnt_string_c 1161 (emacs_doprnt_string_c
1189 ((CONST Bufbyte *) GETTEXT ("Buffer %s modified; kill anyway? "), 1162 ((const Bufbyte *) GETTEXT ("Buffer %s modified; kill anyway? "),
1190 Qnil, -1, XSTRING_DATA (b->name)))); 1163 Qnil, -1, XSTRING_DATA (b->name))));
1191 UNGCPRO; 1164 UNGCPRO;
1192 if (NILP (killp)) 1165 if (NILP (killp))
1193 return Qnil; 1166 return Qnil;
1194 b = XBUFFER (buf); /* Hypothetical relocating GC. */ 1167 b = XBUFFER (buf); /* Hypothetical relocating GC. */
1218 } 1191 }
1219 } 1192 }
1220 1193
1221 /* Then run the hooks. */ 1194 /* Then run the hooks. */
1222 run_hook (Qkill_buffer_hook); 1195 run_hook (Qkill_buffer_hook);
1223 #ifdef HAVE_X_WINDOWS 1196
1224 /* If an X selection was in this buffer, disown it. 1197 /* Inform the selection code that a buffer just got killed.
1225 We could have done this by simply adding this function to the 1198 We do this in C because (a) it's faster, and (b) it needs
1226 kill-buffer-hook, but the user might mess that up. 1199 to access data internal to select.c that can't be seen from
1227 */ 1200 Lisp (so the Lisp code would just call into C anyway. */
1228 if (EQ (Vwindow_system, Qx)) 1201 select_notify_buffer_kill (buf);
1229 call0 (intern ("xselect-kill-buffer-hook")); 1202
1230 /* #### generalize me! */
1231 #endif /* HAVE_X_WINDOWS */
1232 unbind_to (speccount, Qnil); 1203 unbind_to (speccount, Qnil);
1233 UNGCPRO; 1204 UNGCPRO;
1234 b = XBUFFER (buf); /* Hypothetical relocating GC. */ 1205 b = XBUFFER (buf); /* Hypothetical relocating GC. */
1235 } 1206 }
1236 1207
1302 int speccount = specpdl_depth (); 1273 int speccount = specpdl_depth ();
1303 specbind (Qinhibit_quit, Qt); 1274 specbind (Qinhibit_quit, Qt);
1304 1275
1305 kill_buffer_processes (buf); 1276 kill_buffer_processes (buf);
1306 1277
1278 delete_from_buffer_alist (buf);
1279
1307 /* #### This is a problem if this buffer is in a dedicated window. 1280 /* #### This is a problem if this buffer is in a dedicated window.
1308 Need to undedicate any windows of this buffer first (and delete them?) 1281 Need to undedicate any windows of this buffer first (and delete them?)
1309 */ 1282 */
1310 Freplace_buffer_in_windows (buf); 1283 Freplace_buffer_in_windows (buf);
1311
1312 delete_from_buffer_alist (buf);
1313 1284
1314 font_lock_buffer_was_killed (b); 1285 font_lock_buffer_was_killed (b);
1315 1286
1316 /* Delete any auto-save file, if we saved it in this session. */ 1287 /* Delete any auto-save file, if we saved it in this session. */
1317 if (STRINGP (b->auto_save_file_name) 1288 if (STRINGP (b->auto_save_file_name)
1411 else 1382 else
1412 XCDR (prev) = XCDR (XCDR (prev)); 1383 XCDR (prev) = XCDR (XCDR (prev));
1413 XCDR (lynk) = f->buffer_alist; 1384 XCDR (lynk) = f->buffer_alist;
1414 f->buffer_alist = lynk; 1385 f->buffer_alist = lynk;
1415 1386
1416 va_run_hook_with_args (Qrecord_buffer_hook, 1, buffer);
1417
1418 return Qnil; 1387 return Qnil;
1419 } 1388 }
1420 1389
1421 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, 1, 1, 0, /* 1390 DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, 1, 1, 0, /*
1422 Set an appropriate major mode for BUFFER, according to `default-major-mode'. 1391 Set an appropriate major mode for BUFFER, according to `default-major-mode'.
1480 INVALIDATE_PIXEL_TO_GLYPH_CACHE; 1449 INVALIDATE_PIXEL_TO_GLYPH_CACHE;
1481 1450
1482 old_buf = current_buffer; 1451 old_buf = current_buffer;
1483 current_buffer = b; 1452 current_buffer = b;
1484 invalidate_current_column (); /* invalidate indentation cache */ 1453 invalidate_current_column (); /* invalidate indentation cache */
1485
1486 #ifdef HAVE_FEP
1487 if (!noninteractive && initialized)
1488 {
1489 extern Lisp_Object Ffep_force_on (), Ffep_force_off (), Ffep_get_mode ();
1490
1491 old_buf->fep_mode = Ffep_get_mode ();
1492
1493 if (!NILP (current_buffer->fep_mode))
1494 Ffep_force_on ();
1495 else
1496 Ffep_force_off ();
1497 }
1498 #endif /* HAVE_FEP */
1499 1454
1500 if (old_buf) 1455 if (old_buf)
1501 { 1456 {
1502 /* Put the undo list back in the base buffer, so that it appears 1457 /* Put the undo list back in the base buffer, so that it appears
1503 that an indirect buffer shares the undo list of its base. */ 1458 that an indirect buffer shares the undo list of its base. */
1830 } 1785 }
1831 #else 1786 #else
1832 #define coding_system_is_binary(coding_system) 1 1787 #define coding_system_is_binary(coding_system) 1
1833 #endif 1788 #endif
1834 1789
1835 static Extbyte_dynarr *conversion_out_dynarr; 1790 typedef struct
1836 static Bufbyte_dynarr *conversion_in_dynarr; 1791 {
1792 Dynarr_declare (Bufbyte_dynarr *);
1793 } Bufbyte_dynarr_dynarr;
1794
1795 typedef struct
1796 {
1797 Dynarr_declare (Extbyte_dynarr *);
1798 } Extbyte_dynarr_dynarr;
1799
1800 static Extbyte_dynarr_dynarr *conversion_out_dynarr_list;
1801 static Bufbyte_dynarr_dynarr *conversion_in_dynarr_list;
1837 1802
1838 static int dfc_convert_to_external_format_in_use; 1803 static int dfc_convert_to_external_format_in_use;
1839 static int dfc_convert_to_internal_format_in_use; 1804 static int dfc_convert_to_internal_format_in_use;
1840 1805
1841 static Lisp_Object 1806 static Lisp_Object
1860 #endif 1825 #endif
1861 dfc_conversion_type sink_type, 1826 dfc_conversion_type sink_type,
1862 dfc_conversion_data *sink) 1827 dfc_conversion_data *sink)
1863 { 1828 {
1864 int count = specpdl_depth (); 1829 int count = specpdl_depth ();
1830 Extbyte_dynarr *conversion_out_dynarr;
1865 1831
1866 type_checking_assert 1832 type_checking_assert
1867 (((source_type == DFC_TYPE_DATA) || 1833 (((source_type == DFC_TYPE_DATA) ||
1868 (source_type == DFC_TYPE_LISP_LSTREAM && LSTREAMP (source->lisp_object)) || 1834 (source_type == DFC_TYPE_LISP_LSTREAM && LSTREAMP (source->lisp_object)) ||
1869 (source_type == DFC_TYPE_LISP_STRING && STRINGP (source->lisp_object))) 1835 (source_type == DFC_TYPE_LISP_STRING && STRINGP (source->lisp_object)))
1870 && 1836 &&
1871 ((sink_type == DFC_TYPE_DATA) || 1837 ((sink_type == DFC_TYPE_DATA) ||
1872 (sink_type == DFC_TYPE_LISP_LSTREAM && LSTREAMP (source->lisp_object)))); 1838 (sink_type == DFC_TYPE_LISP_LSTREAM && LSTREAMP (source->lisp_object))));
1873 1839
1874 if (dfc_convert_to_external_format_in_use != 0)
1875 error ("Can't call a conversion function from a conversion function");
1876 else
1877 dfc_convert_to_external_format_in_use = 1;
1878
1879 record_unwind_protect (dfc_convert_to_external_format_reset_in_use, 1840 record_unwind_protect (dfc_convert_to_external_format_reset_in_use,
1880 Qzero); 1841 make_int (dfc_convert_to_external_format_in_use));
1842 if (Dynarr_length (conversion_out_dynarr_list) <=
1843 dfc_convert_to_external_format_in_use)
1844 Dynarr_add (conversion_out_dynarr_list, Dynarr_new (Extbyte));
1845 conversion_out_dynarr = Dynarr_at (conversion_out_dynarr_list,
1846 dfc_convert_to_external_format_in_use);
1847 dfc_convert_to_external_format_in_use++;
1848 Dynarr_reset (conversion_out_dynarr);
1881 1849
1882 #ifdef FILE_CODING 1850 #ifdef FILE_CODING
1883 coding_system = Fget_coding_system (coding_system); 1851 coding_system = Fget_coding_system (coding_system);
1884 #endif 1852 #endif
1885
1886 Dynarr_reset (conversion_out_dynarr);
1887 1853
1888 /* Here we optimize in the case where the coding system does no 1854 /* Here we optimize in the case where the coding system does no
1889 conversion. However, we don't want to optimize in case the source 1855 conversion. However, we don't want to optimize in case the source
1890 or sink is an lstream, since writing to an lstream can cause a 1856 or sink is an lstream, since writing to an lstream can cause a
1891 garbage collection, and this could be problematic if the source 1857 garbage collection, and this could be problematic if the source
2015 #endif 1981 #endif
2016 dfc_conversion_type sink_type, 1982 dfc_conversion_type sink_type,
2017 dfc_conversion_data *sink) 1983 dfc_conversion_data *sink)
2018 { 1984 {
2019 int count = specpdl_depth (); 1985 int count = specpdl_depth ();
1986 Bufbyte_dynarr *conversion_in_dynarr;
2020 1987
2021 type_checking_assert 1988 type_checking_assert
2022 ((source_type == DFC_TYPE_DATA || 1989 ((source_type == DFC_TYPE_DATA ||
2023 source_type == DFC_TYPE_LISP_LSTREAM) 1990 source_type == DFC_TYPE_LISP_LSTREAM)
2024 && 1991 &&
2025 (sink_type == DFC_TYPE_DATA || 1992 (sink_type == DFC_TYPE_DATA ||
2026 sink_type == DFC_TYPE_LISP_LSTREAM)); 1993 sink_type == DFC_TYPE_LISP_LSTREAM));
2027 1994
2028 if (dfc_convert_to_internal_format_in_use != 0)
2029 error ("Can't call a conversion function from a conversion function");
2030 else
2031 dfc_convert_to_internal_format_in_use = 1;
2032
2033 record_unwind_protect (dfc_convert_to_internal_format_reset_in_use, 1995 record_unwind_protect (dfc_convert_to_internal_format_reset_in_use,
2034 Qzero); 1996 make_int (dfc_convert_to_internal_format_in_use));
1997 if (Dynarr_length (conversion_in_dynarr_list) <=
1998 dfc_convert_to_internal_format_in_use)
1999 Dynarr_add (conversion_in_dynarr_list, Dynarr_new (Bufbyte));
2000 conversion_in_dynarr = Dynarr_at (conversion_in_dynarr_list,
2001 dfc_convert_to_internal_format_in_use);
2002 dfc_convert_to_internal_format_in_use++;
2003 Dynarr_reset (conversion_in_dynarr);
2035 2004
2036 #ifdef FILE_CODING 2005 #ifdef FILE_CODING
2037 coding_system = Fget_coding_system (coding_system); 2006 coding_system = Fget_coding_system (coding_system);
2038 #endif 2007 #endif
2039
2040 Dynarr_reset (conversion_in_dynarr);
2041 2008
2042 if (source_type != DFC_TYPE_LISP_LSTREAM && 2009 if (source_type != DFC_TYPE_LISP_LSTREAM &&
2043 sink_type != DFC_TYPE_LISP_LSTREAM && 2010 sink_type != DFC_TYPE_LISP_LSTREAM &&
2044 coding_system_is_binary (coding_system)) 2011 coding_system_is_binary (coding_system))
2045 { 2012 {
2146 2113
2147 2114
2148 void 2115 void
2149 syms_of_buffer (void) 2116 syms_of_buffer (void)
2150 { 2117 {
2118 INIT_LRECORD_IMPLEMENTATION (buffer);
2119
2151 defsymbol (&Qbuffer_live_p, "buffer-live-p"); 2120 defsymbol (&Qbuffer_live_p, "buffer-live-p");
2152 defsymbol (&Qbuffer_or_string_p, "buffer-or-string-p"); 2121 defsymbol (&Qbuffer_or_string_p, "buffer-or-string-p");
2153 defsymbol (&Qmode_class, "mode-class"); 2122 defsymbol (&Qmode_class, "mode-class");
2154 defsymbol (&Qrename_auto_save_file, "rename-auto-save-file"); 2123 defsymbol (&Qrename_auto_save_file, "rename-auto-save-file");
2155 defsymbol (&Qkill_buffer_hook, "kill-buffer-hook"); 2124 defsymbol (&Qkill_buffer_hook, "kill-buffer-hook");
2156 defsymbol (&Qrecord_buffer_hook, "record-buffer-hook");
2157 defsymbol (&Qpermanent_local, "permanent-local"); 2125 defsymbol (&Qpermanent_local, "permanent-local");
2158 2126
2159 defsymbol (&Qfirst_change_hook, "first-change-hook"); 2127 defsymbol (&Qfirst_change_hook, "first-change-hook");
2160 defsymbol (&Qbefore_change_functions, "before-change-functions"); 2128 defsymbol (&Qbefore_change_functions, "before-change-functions");
2161 defsymbol (&Qafter_change_functions, "after-change-functions"); 2129 defsymbol (&Qafter_change_functions, "after-change-functions");
2188 DEFSUBR (Fbuffer_name); 2156 DEFSUBR (Fbuffer_name);
2189 DEFSUBR (Fbuffer_file_name); 2157 DEFSUBR (Fbuffer_file_name);
2190 DEFSUBR (Fbuffer_base_buffer); 2158 DEFSUBR (Fbuffer_base_buffer);
2191 DEFSUBR (Fbuffer_indirect_children); 2159 DEFSUBR (Fbuffer_indirect_children);
2192 DEFSUBR (Fbuffer_local_variables); 2160 DEFSUBR (Fbuffer_local_variables);
2193 DEFSUBR (Fbuffer_dedicated_frame);
2194 DEFSUBR (Fset_buffer_dedicated_frame);
2195 DEFSUBR (Fbuffer_modified_p); 2161 DEFSUBR (Fbuffer_modified_p);
2196 DEFSUBR (Fset_buffer_modified_p); 2162 DEFSUBR (Fset_buffer_modified_p);
2197 DEFSUBR (Fbuffer_modified_tick); 2163 DEFSUBR (Fbuffer_modified_tick);
2198 DEFSUBR (Frename_buffer); 2164 DEFSUBR (Frename_buffer);
2199 DEFSUBR (Fother_buffer); 2165 DEFSUBR (Fother_buffer);
2210 DEFSUBR (Fkill_all_local_variables); 2176 DEFSUBR (Fkill_all_local_variables);
2211 #ifdef MEMORY_USAGE_STATS 2177 #ifdef MEMORY_USAGE_STATS
2212 DEFSUBR (Fbuffer_memory_usage); 2178 DEFSUBR (Fbuffer_memory_usage);
2213 #endif 2179 #endif
2214 2180
2215 deferror (&Qprotected_field, "protected-field", 2181 DEFERROR (Qprotected_field, "Attempt to modify a protected field",
2216 "Attempt to modify a protected field", Qerror); 2182 Qinvalid_change);
2217 } 2183 }
2218 2184
2219 void 2185 void
2220 reinit_vars_of_buffer (void) 2186 reinit_vars_of_buffer (void)
2221 { 2187 {
2222 conversion_in_dynarr = Dynarr_new (Bufbyte); 2188 conversion_in_dynarr_list = Dynarr_new2 (Bufbyte_dynarr_dynarr,
2223 conversion_out_dynarr = Dynarr_new (Extbyte); 2189 Bufbyte_dynarr *);
2190 conversion_out_dynarr_list = Dynarr_new2 (Extbyte_dynarr_dynarr,
2191 Extbyte_dynarr *);
2224 2192
2225 staticpro_nodump (&Vbuffer_alist); 2193 staticpro_nodump (&Vbuffer_alist);
2226 Vbuffer_alist = Qnil; 2194 Vbuffer_alist = Qnil;
2227 current_buffer = 0; 2195 current_buffer = 0;
2228 } 2196 }
2371 2339
2372 /* The docstrings for DEFVAR_* are recorded externally by make-docfile. */ 2340 /* The docstrings for DEFVAR_* are recorded externally by make-docfile. */
2373 2341
2374 /* Renamed from DEFVAR_PER_BUFFER because FSFmacs D_P_B takes 2342 /* Renamed from DEFVAR_PER_BUFFER because FSFmacs D_P_B takes
2375 a bogus extra arg, which confuses an otherwise identical make-docfile.c */ 2343 a bogus extra arg, which confuses an otherwise identical make-docfile.c */
2376
2377 /* Declaring this stuff as const produces 'Cannot reinitialize' messages
2378 from SunPro C's fix-and-continue feature (a way neato feature that
2379 makes debugging unbelievably more bearable) */
2380 #define DEFVAR_BUFFER_LOCAL_1(lname, field_name, forward_type, magicfun) do { \ 2344 #define DEFVAR_BUFFER_LOCAL_1(lname, field_name, forward_type, magicfun) do { \
2381 static CONST_IF_NOT_DEBUG struct symbol_value_forward I_hate_C \ 2345 static const struct symbol_value_forward I_hate_C = \
2382 = { { { symbol_value_forward_lheader_initializer, \ 2346 { /* struct symbol_value_forward */ \
2383 (struct lcrecord_header *) &(buffer_local_flags.field_name), 69 }, \ 2347 { /* struct symbol_value_magic */ \
2384 forward_type }, magicfun }; \ 2348 { /* struct lcrecord_header */ \
2349 { /* struct lrecord_header */ \
2350 lrecord_type_symbol_value_forward, /* lrecord_type_index */ \
2351 1, /* mark bit */ \
2352 1, /* c_readonly bit */ \
2353 1 /* lisp_readonly bit */ \
2354 }, \
2355 0, /* next */ \
2356 0, /* uid */ \
2357 0 /* free */ \
2358 }, \
2359 &(buffer_local_flags.field_name), \
2360 forward_type \
2361 }, \
2362 magicfun \
2363 }; \
2364 \
2385 { \ 2365 { \
2386 int offset = ((char *)symbol_value_forward_forward (&I_hate_C) - \ 2366 int offset = ((char *)symbol_value_forward_forward (&I_hate_C) - \
2387 (char *)&buffer_local_flags); \ 2367 (char *)&buffer_local_flags); \
2388 defvar_magic (lname, &I_hate_C); \ 2368 defvar_magic (lname, &I_hate_C); \
2389 \ 2369 \
2648 */ ); 2628 */ );
2649 2629
2650 DEFVAR_BUFFER_LOCAL ("modeline-format", modeline_format /* 2630 DEFVAR_BUFFER_LOCAL ("modeline-format", modeline_format /*
2651 Template for displaying modeline for current buffer. 2631 Template for displaying modeline for current buffer.
2652 Each buffer has its own value of this variable. 2632 Each buffer has its own value of this variable.
2653 Value may be a string, a symbol or a list or cons cell. 2633 Value may be a string, symbol, glyph, generic specifier, list or cons cell.
2654 For a symbol, its value is used (but it is ignored if t or nil). 2634 For a symbol, its value is processed (but it is ignored if t or nil).
2655 A string appearing directly as the value of a symbol is processed verbatim 2635 A string appearing directly as the value of a symbol is processed verbatim
2656 in that the %-constructs below are not recognized. 2636 in that the %-constructs below are not recognized.
2657 For a glyph, it is inserted as is. 2637 For a glyph, it is inserted as is.
2638 For a generic specifier (i.e. a specifier of type `generic'), its instance
2639 is computed in the current window using the equivalent of `specifier-instance'
2640 and the value is processed.
2658 For a list whose car is a symbol, the symbol's value is taken, 2641 For a list whose car is a symbol, the symbol's value is taken,
2659 and if that is non-nil, the cadr of the list is processed recursively. 2642 and if that is non-nil, the cadr of the list is processed recursively.
2660 Otherwise, the caddr of the list (if there is one) is processed. 2643 Otherwise, the caddr of the list (if there is one) is processed.
2661 For a list whose car is a string or list, each element is processed 2644 For a list whose car is a string or list, each element is processed
2662 recursively and the results are effectively concatenated. 2645 recursively and the results are effectively concatenated.
2663 For a list whose car is an integer, the cdr of the list is processed 2646 For a list whose car is an integer, the cdr of the list is processed
2664 and padded (if the number is positive) or truncated (if negative) 2647 and padded (if the number is positive) or truncated (if negative)
2665 to the width specified by that number. 2648 to the width specified by that number.
2666 For a list whose car is an extent, the cdr of the list is processed 2649 For a list whose car is an extent, the cdr of the list is processed
2667 normally but the results are displayed using the face of the 2650 normally but the results are displayed using the face of the
2668 extent, and mouse clicks over this section are processed using the 2651 extent, and mouse clicks over this section are processed using the
2669 keymap of the extent. (In addition, if the extent has a help-echo 2652 keymap of the extent. (In addition, if the extent has a help-echo
2670 property, that string will be echoed when the mouse moves over this 2653 property, that string will be echoed when the mouse moves over this
2671 section.) See `generated-modeline-string' for more information. 2654 section.) If extents are nested, all keymaps are properly consulted
2672 For a list whose car is a face, the cdr of the list is processed 2655 when processing mouse clicks, but multiple faces are not correctly
2673 normally but the results will be displayed using the face in the car. 2656 merged (only the first face is used), and lists of faces are not
2674 For a list whose car is a keymap, the cdr of the list is processed 2657 correctly handled. See `generated-modeline-string' for more information.
2675 normally but the keymap will apply for mouse clicks over the results,
2676 in addition to `modeline-map'. Nested keymap specifications are
2677 handled properly.
2678 A string is printed verbatim in the modeline except for %-constructs: 2658 A string is printed verbatim in the modeline except for %-constructs:
2679 (%-constructs are processed when the string is the entire modeline-format 2659 (%-constructs are processed when the string is the entire modeline-format
2680 or when it is found in a cons-cell or a list) 2660 or when it is found in a cons-cell or a list)
2681 %b -- print buffer name. %c -- print the current column number. 2661 %b -- print buffer name. %c -- print the current column number.
2682 %f -- print visited file name. 2662 %f -- print visited file name.
3087 /* Want no undo records for *scratch* until after Emacs is dumped */ 3067 /* Want no undo records for *scratch* until after Emacs is dumped */
3088 Fbuffer_disable_undo (scratch); 3068 Fbuffer_disable_undo (scratch);
3089 } 3069 }
3090 } 3070 }
3091 3071
3072 #ifndef WIN32_NATIVE
3092 /* Is PWD another name for `.' ? */ 3073 /* Is PWD another name for `.' ? */
3093 static int 3074 static int
3094 directory_is_current_directory (Extbyte *pwd) 3075 directory_is_current_directory (Extbyte *pwd)
3095 { 3076 {
3096 Bufbyte *pwd_internal; 3077 Bufbyte *pwd_internal;
3100 TO_INTERNAL_FORMAT (DATA, (pwd, strlen ((char *)pwd) + 1), 3081 TO_INTERNAL_FORMAT (DATA, (pwd, strlen ((char *)pwd) + 1),
3101 ALLOCA, (pwd_internal, pwd_internal_len), 3082 ALLOCA, (pwd_internal, pwd_internal_len),
3102 Qfile_name); 3083 Qfile_name);
3103 3084
3104 return (IS_DIRECTORY_SEP (*pwd_internal) 3085 return (IS_DIRECTORY_SEP (*pwd_internal)
3105 && stat ((char *) pwd_internal, &pwdstat) == 0 3086 && xemacs_stat ((char *) pwd_internal, &pwdstat) == 0
3106 && stat (".", &dotstat) == 0 3087 && xemacs_stat (".", &dotstat) == 0
3107 && dotstat.st_ino == pwdstat.st_ino 3088 && dotstat.st_ino == pwdstat.st_ino
3108 && dotstat.st_dev == pwdstat.st_dev 3089 && dotstat.st_dev == pwdstat.st_dev
3109 && pwd_internal_len < MAXPATHLEN); 3090 && pwd_internal_len < MAXPATHLEN);
3110 } 3091 }
3092 #endif
3111 3093
3112 void 3094 void
3113 init_initial_directory (void) 3095 init_initial_directory (void)
3114 { 3096 {
3115 /* This function can GC */ 3097 /* This function can GC */
3116 3098
3099 #ifndef WIN32_NATIVE
3117 Extbyte *pwd; 3100 Extbyte *pwd;
3101 #endif
3118 3102
3119 initial_directory[0] = 0; 3103 initial_directory[0] = 0;
3120 3104
3121 /* If PWD is accurate, use it instead of calling getcwd. This is faster 3105 /* If PWD is accurate, use it instead of calling getcwd. This is faster
3122 when PWD is right, and may avoid a fatal error. */ 3106 when PWD is right, and may avoid a fatal error. */
3107 #ifndef WIN32_NATIVE
3123 if ((pwd = (Extbyte *) getenv ("PWD")) != NULL 3108 if ((pwd = (Extbyte *) getenv ("PWD")) != NULL
3124 && directory_is_current_directory (pwd)) 3109 && directory_is_current_directory (pwd))
3125 strcpy (initial_directory, (char *) pwd); 3110 strcpy (initial_directory, (char *) pwd);
3126 else if (getcwd (initial_directory, MAXPATHLEN) == NULL) 3111 else
3127 fatal ("`getcwd' failed: %s\n", strerror (errno)); 3112 #endif
3113 if (getcwd (initial_directory, MAXPATHLEN) == NULL)
3114 fatal ("`getcwd' failed: %s\n", strerror (errno));
3128 3115
3129 /* Make sure pwd is DIRECTORY_SEP-terminated. 3116 /* Make sure pwd is DIRECTORY_SEP-terminated.
3130 Maybe this should really use some standard subroutine 3117 Maybe this should really use some standard subroutine
3131 whose definition is filename syntax dependent. */ 3118 whose definition is filename syntax dependent. */
3132 { 3119 {
3137 initial_directory[len] = DIRECTORY_SEP; 3124 initial_directory[len] = DIRECTORY_SEP;
3138 initial_directory[len + 1] = '\0'; 3125 initial_directory[len + 1] = '\0';
3139 } 3126 }
3140 } 3127 }
3141 3128
3142 /* XEmacs change: store buffer's default directory 3129 #ifdef CORRECT_DIR_SEPS
3143 using preferred (i.e. as defined at compile-time) 3130 CORRECT_DIR_SEPS (initial_directory);
3144 directory separator. --marcpa */
3145 #ifdef DOS_NT
3146 #define CORRECT_DIR_SEPS(s) \
3147 do { if ('/' == DIRECTORY_SEP) dostounix_filename (s); \
3148 else unixtodos_filename (s); \
3149 } while (0)
3150
3151 CORRECT_DIR_SEPS(initial_directory);
3152 #endif 3131 #endif
3153 } 3132 }
3154 3133
3155 void 3134 void
3156 init_buffer (void) 3135 init_buffer (void)