diff options
| author | Eli Zaretskii | 2013-09-05 11:01:04 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2013-09-05 11:01:04 +0300 |
| commit | 41306318777a942420bc4feadbfacf662ea179dc (patch) | |
| tree | 669e5cca02f95d6064ce73c0d3fbbf91b8c8b563 /src/buffer.c | |
| parent | 141f1ff7a40cda10f0558e891dd196a943a5082e (diff) | |
| parent | 257b3b03cb1cff917e0b3b7832ad3eab5b59f257 (diff) | |
| download | emacs-41306318777a942420bc4feadbfacf662ea179dc.tar.gz emacs-41306318777a942420bc4feadbfacf662ea179dc.zip | |
Merge from trunk after a lot of time.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 1861 |
1 files changed, 1086 insertions, 775 deletions
diff --git a/src/buffer.c b/src/buffer.c index 20260d5a5d8..0bcb608dbd3 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | /* Buffer manipulation primitives for GNU Emacs. | 1 | /* Buffer manipulation primitives for GNU Emacs. |
| 2 | 2 | ||
| 3 | Copyright (C) 1985-1989, 1993-1995, 1997-2012 Free Software Foundation, Inc. | 3 | Copyright (C) 1985-1989, 1993-1995, 1997-2013 Free Software Foundation, |
| 4 | Inc. | ||
| 4 | 5 | ||
| 5 | This file is part of GNU Emacs. | 6 | This file is part of GNU Emacs. |
| 6 | 7 | ||
| @@ -19,12 +20,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 19 | 20 | ||
| 20 | #include <config.h> | 21 | #include <config.h> |
| 21 | 22 | ||
| 23 | #define BUFFER_INLINE EXTERN_INLINE | ||
| 24 | |||
| 22 | #include <sys/types.h> | 25 | #include <sys/types.h> |
| 23 | #include <sys/stat.h> | 26 | #include <sys/stat.h> |
| 24 | #include <sys/param.h> | 27 | #include <sys/param.h> |
| 25 | #include <errno.h> | 28 | #include <errno.h> |
| 26 | #include <stdio.h> | 29 | #include <stdio.h> |
| 27 | #include <setjmp.h> | ||
| 28 | #include <unistd.h> | 30 | #include <unistd.h> |
| 29 | 31 | ||
| 30 | #include <verify.h> | 32 | #include <verify.h> |
| @@ -33,8 +35,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 33 | #include "intervals.h" | 35 | #include "intervals.h" |
| 34 | #include "window.h" | 36 | #include "window.h" |
| 35 | #include "commands.h" | 37 | #include "commands.h" |
| 36 | #include "buffer.h" | ||
| 37 | #include "character.h" | 38 | #include "character.h" |
| 39 | #include "buffer.h" | ||
| 38 | #include "region-cache.h" | 40 | #include "region-cache.h" |
| 39 | #include "indent.h" | 41 | #include "indent.h" |
| 40 | #include "blockinput.h" | 42 | #include "blockinput.h" |
| @@ -42,7 +44,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 42 | #include "keymap.h" | 44 | #include "keymap.h" |
| 43 | #include "frame.h" | 45 | #include "frame.h" |
| 44 | 46 | ||
| 45 | struct buffer *current_buffer; /* the current buffer */ | 47 | struct buffer *current_buffer; /* The current buffer. */ |
| 46 | 48 | ||
| 47 | /* First buffer in chain of all buffers (in reverse order of creation). | 49 | /* First buffer in chain of all buffers (in reverse order of creation). |
| 48 | Threaded through ->header.next.buffer. */ | 50 | Threaded through ->header.next.buffer. */ |
| @@ -56,11 +58,7 @@ struct buffer *all_buffers; | |||
| 56 | Setting the default value also goes through the alist of buffers | 58 | Setting the default value also goes through the alist of buffers |
| 57 | and stores into each buffer that does not say it has a local value. */ | 59 | and stores into each buffer that does not say it has a local value. */ |
| 58 | 60 | ||
| 59 | DECL_ALIGN (struct buffer, buffer_defaults); | 61 | struct buffer alignas (GCALIGNMENT) buffer_defaults; |
| 60 | |||
| 61 | /* A Lisp_Object pointer to the above, used for staticpro */ | ||
| 62 | |||
| 63 | static Lisp_Object Vbuffer_defaults; | ||
| 64 | 62 | ||
| 65 | /* This structure marks which slots in a buffer have corresponding | 63 | /* This structure marks which slots in a buffer have corresponding |
| 66 | default values in buffer_defaults. | 64 | default values in buffer_defaults. |
| @@ -76,17 +74,14 @@ static Lisp_Object Vbuffer_defaults; | |||
| 76 | and the corresponding slot in buffer_defaults is not used. | 74 | and the corresponding slot in buffer_defaults is not used. |
| 77 | 75 | ||
| 78 | If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is | 76 | If a slot in this structure corresponding to a DEFVAR_PER_BUFFER is |
| 79 | zero, that is a bug */ | 77 | zero, that is a bug. */ |
| 80 | 78 | ||
| 81 | struct buffer buffer_local_flags; | 79 | struct buffer buffer_local_flags; |
| 82 | 80 | ||
| 83 | /* This structure holds the names of symbols whose values may be | 81 | /* This structure holds the names of symbols whose values may be |
| 84 | buffer-local. It is indexed and accessed in the same way as the above. */ | 82 | buffer-local. It is indexed and accessed in the same way as the above. */ |
| 85 | |||
| 86 | DECL_ALIGN (struct buffer, buffer_local_symbols); | ||
| 87 | 83 | ||
| 88 | /* A Lisp_Object pointer to the above, used for staticpro */ | 84 | struct buffer alignas (GCALIGNMENT) buffer_local_symbols; |
| 89 | static Lisp_Object Vbuffer_local_symbols; | ||
| 90 | 85 | ||
| 91 | /* Return the symbol of the per-buffer variable at offset OFFSET in | 86 | /* Return the symbol of the per-buffer variable at offset OFFSET in |
| 92 | the buffer structure. */ | 87 | the buffer structure. */ |
| @@ -97,7 +92,7 @@ static Lisp_Object Vbuffer_local_symbols; | |||
| 97 | /* Maximum length of an overlay vector. */ | 92 | /* Maximum length of an overlay vector. */ |
| 98 | #define OVERLAY_COUNT_MAX \ | 93 | #define OVERLAY_COUNT_MAX \ |
| 99 | ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, \ | 94 | ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, \ |
| 100 | min (PTRDIFF_MAX, SIZE_MAX) / sizeof (Lisp_Object))) | 95 | min (PTRDIFF_MAX, SIZE_MAX) / word_size)) |
| 101 | 96 | ||
| 102 | /* Flags indicating which built-in buffer-local variables | 97 | /* Flags indicating which built-in buffer-local variables |
| 103 | are permanent locals. */ | 98 | are permanent locals. */ |
| @@ -107,17 +102,15 @@ static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS]; | |||
| 107 | 102 | ||
| 108 | int last_per_buffer_idx; | 103 | int last_per_buffer_idx; |
| 109 | 104 | ||
| 110 | static Lisp_Object Fset_buffer_major_mode (Lisp_Object); | ||
| 111 | static Lisp_Object Fdelete_overlay (Lisp_Object); | ||
| 112 | static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, | 105 | static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, |
| 113 | int after, Lisp_Object arg1, | 106 | bool after, Lisp_Object arg1, |
| 114 | Lisp_Object arg2, Lisp_Object arg3); | 107 | Lisp_Object arg2, Lisp_Object arg3); |
| 115 | static void swap_out_buffer_local_variables (struct buffer *b); | 108 | static void swap_out_buffer_local_variables (struct buffer *b); |
| 116 | static void reset_buffer_local_variables (struct buffer *b, int permanent_too); | 109 | static void reset_buffer_local_variables (struct buffer *, bool); |
| 117 | 110 | ||
| 118 | /* Alist of all buffer names vs the buffers. */ | 111 | /* Alist of all buffer names vs the buffers. This used to be |
| 119 | /* This used to be a variable, but is no longer, | 112 | a Lisp-visible variable, but is no longer, to prevent lossage |
| 120 | to prevent lossage due to user rplac'ing this alist or its elements. */ | 113 | due to user rplac'ing this alist or its elements. */ |
| 121 | Lisp_Object Vbuffer_alist; | 114 | Lisp_Object Vbuffer_alist; |
| 122 | 115 | ||
| 123 | static Lisp_Object Qkill_buffer_query_functions; | 116 | static Lisp_Object Qkill_buffer_query_functions; |
| @@ -134,7 +127,7 @@ static Lisp_Object Qpermanent_local_hook; | |||
| 134 | 127 | ||
| 135 | static Lisp_Object Qprotected_field; | 128 | static Lisp_Object Qprotected_field; |
| 136 | 129 | ||
| 137 | static Lisp_Object QSFundamental; /* A string "Fundamental" */ | 130 | static Lisp_Object QSFundamental; /* A string "Fundamental". */ |
| 138 | 131 | ||
| 139 | static Lisp_Object Qkill_buffer_hook; | 132 | static Lisp_Object Qkill_buffer_hook; |
| 140 | static Lisp_Object Qbuffer_list_update_hook; | 133 | static Lisp_Object Qbuffer_list_update_hook; |
| @@ -155,10 +148,235 @@ static void alloc_buffer_text (struct buffer *, ptrdiff_t); | |||
| 155 | static void free_buffer_text (struct buffer *b); | 148 | static void free_buffer_text (struct buffer *b); |
| 156 | static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); | 149 | static struct Lisp_Overlay * copy_overlays (struct buffer *, struct Lisp_Overlay *); |
| 157 | static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t); | 150 | static void modify_overlay (struct buffer *, ptrdiff_t, ptrdiff_t); |
| 158 | static Lisp_Object buffer_lisp_local_variables (struct buffer *); | 151 | static Lisp_Object buffer_lisp_local_variables (struct buffer *, bool); |
| 159 | 152 | ||
| 160 | /* For debugging; temporary. See set_buffer_internal. */ | 153 | static void |
| 161 | /* Lisp_Object Qlisp_mode, Vcheck_symbol; */ | 154 | CHECK_OVERLAY (Lisp_Object x) |
| 155 | { | ||
| 156 | CHECK_TYPE (OVERLAYP (x), Qoverlayp, x); | ||
| 157 | } | ||
| 158 | |||
| 159 | /* These setters are used only in this file, so they can be private. */ | ||
| 160 | static void | ||
| 161 | bset_abbrev_mode (struct buffer *b, Lisp_Object val) | ||
| 162 | { | ||
| 163 | b->INTERNAL_FIELD (abbrev_mode) = val; | ||
| 164 | } | ||
| 165 | static void | ||
| 166 | bset_abbrev_table (struct buffer *b, Lisp_Object val) | ||
| 167 | { | ||
| 168 | b->INTERNAL_FIELD (abbrev_table) = val; | ||
| 169 | } | ||
| 170 | static void | ||
| 171 | bset_auto_fill_function (struct buffer *b, Lisp_Object val) | ||
| 172 | { | ||
| 173 | b->INTERNAL_FIELD (auto_fill_function) = val; | ||
| 174 | } | ||
| 175 | static void | ||
| 176 | bset_auto_save_file_format (struct buffer *b, Lisp_Object val) | ||
| 177 | { | ||
| 178 | b->INTERNAL_FIELD (auto_save_file_format) = val; | ||
| 179 | } | ||
| 180 | static void | ||
| 181 | bset_auto_save_file_name (struct buffer *b, Lisp_Object val) | ||
| 182 | { | ||
| 183 | b->INTERNAL_FIELD (auto_save_file_name) = val; | ||
| 184 | } | ||
| 185 | static void | ||
| 186 | bset_backed_up (struct buffer *b, Lisp_Object val) | ||
| 187 | { | ||
| 188 | b->INTERNAL_FIELD (backed_up) = val; | ||
| 189 | } | ||
| 190 | static void | ||
| 191 | bset_begv_marker (struct buffer *b, Lisp_Object val) | ||
| 192 | { | ||
| 193 | b->INTERNAL_FIELD (begv_marker) = val; | ||
| 194 | } | ||
| 195 | static void | ||
| 196 | bset_bidi_display_reordering (struct buffer *b, Lisp_Object val) | ||
| 197 | { | ||
| 198 | b->INTERNAL_FIELD (bidi_display_reordering) = val; | ||
| 199 | } | ||
| 200 | static void | ||
| 201 | bset_buffer_file_coding_system (struct buffer *b, Lisp_Object val) | ||
| 202 | { | ||
| 203 | b->INTERNAL_FIELD (buffer_file_coding_system) = val; | ||
| 204 | } | ||
| 205 | static void | ||
| 206 | bset_cache_long_scans (struct buffer *b, Lisp_Object val) | ||
| 207 | { | ||
| 208 | b->INTERNAL_FIELD (cache_long_scans) = val; | ||
| 209 | } | ||
| 210 | static void | ||
| 211 | bset_case_fold_search (struct buffer *b, Lisp_Object val) | ||
| 212 | { | ||
| 213 | b->INTERNAL_FIELD (case_fold_search) = val; | ||
| 214 | } | ||
| 215 | static void | ||
| 216 | bset_ctl_arrow (struct buffer *b, Lisp_Object val) | ||
| 217 | { | ||
| 218 | b->INTERNAL_FIELD (ctl_arrow) = val; | ||
| 219 | } | ||
| 220 | static void | ||
| 221 | bset_cursor_in_non_selected_windows (struct buffer *b, Lisp_Object val) | ||
| 222 | { | ||
| 223 | b->INTERNAL_FIELD (cursor_in_non_selected_windows) = val; | ||
| 224 | } | ||
| 225 | static void | ||
| 226 | bset_cursor_type (struct buffer *b, Lisp_Object val) | ||
| 227 | { | ||
| 228 | b->INTERNAL_FIELD (cursor_type) = val; | ||
| 229 | } | ||
| 230 | static void | ||
| 231 | bset_display_table (struct buffer *b, Lisp_Object val) | ||
| 232 | { | ||
| 233 | b->INTERNAL_FIELD (display_table) = val; | ||
| 234 | } | ||
| 235 | static void | ||
| 236 | bset_extra_line_spacing (struct buffer *b, Lisp_Object val) | ||
| 237 | { | ||
| 238 | b->INTERNAL_FIELD (extra_line_spacing) = val; | ||
| 239 | } | ||
| 240 | static void | ||
| 241 | bset_file_format (struct buffer *b, Lisp_Object val) | ||
| 242 | { | ||
| 243 | b->INTERNAL_FIELD (file_format) = val; | ||
| 244 | } | ||
| 245 | static void | ||
| 246 | bset_file_truename (struct buffer *b, Lisp_Object val) | ||
| 247 | { | ||
| 248 | b->INTERNAL_FIELD (file_truename) = val; | ||
| 249 | } | ||
| 250 | static void | ||
| 251 | bset_fringe_cursor_alist (struct buffer *b, Lisp_Object val) | ||
| 252 | { | ||
| 253 | b->INTERNAL_FIELD (fringe_cursor_alist) = val; | ||
| 254 | } | ||
| 255 | static void | ||
| 256 | bset_fringe_indicator_alist (struct buffer *b, Lisp_Object val) | ||
| 257 | { | ||
| 258 | b->INTERNAL_FIELD (fringe_indicator_alist) = val; | ||
| 259 | } | ||
| 260 | static void | ||
| 261 | bset_fringes_outside_margins (struct buffer *b, Lisp_Object val) | ||
| 262 | { | ||
| 263 | b->INTERNAL_FIELD (fringes_outside_margins) = val; | ||
| 264 | } | ||
| 265 | static void | ||
| 266 | bset_header_line_format (struct buffer *b, Lisp_Object val) | ||
| 267 | { | ||
| 268 | b->INTERNAL_FIELD (header_line_format) = val; | ||
| 269 | } | ||
| 270 | static void | ||
| 271 | bset_indicate_buffer_boundaries (struct buffer *b, Lisp_Object val) | ||
| 272 | { | ||
| 273 | b->INTERNAL_FIELD (indicate_buffer_boundaries) = val; | ||
| 274 | } | ||
| 275 | static void | ||
| 276 | bset_indicate_empty_lines (struct buffer *b, Lisp_Object val) | ||
| 277 | { | ||
| 278 | b->INTERNAL_FIELD (indicate_empty_lines) = val; | ||
| 279 | } | ||
| 280 | static void | ||
| 281 | bset_invisibility_spec (struct buffer *b, Lisp_Object val) | ||
| 282 | { | ||
| 283 | b->INTERNAL_FIELD (invisibility_spec) = val; | ||
| 284 | } | ||
| 285 | static void | ||
| 286 | bset_left_fringe_width (struct buffer *b, Lisp_Object val) | ||
| 287 | { | ||
| 288 | b->INTERNAL_FIELD (left_fringe_width) = val; | ||
| 289 | } | ||
| 290 | static void | ||
| 291 | bset_major_mode (struct buffer *b, Lisp_Object val) | ||
| 292 | { | ||
| 293 | b->INTERNAL_FIELD (major_mode) = val; | ||
| 294 | } | ||
| 295 | static void | ||
| 296 | bset_mark (struct buffer *b, Lisp_Object val) | ||
| 297 | { | ||
| 298 | b->INTERNAL_FIELD (mark) = val; | ||
| 299 | } | ||
| 300 | static void | ||
| 301 | bset_minor_modes (struct buffer *b, Lisp_Object val) | ||
| 302 | { | ||
| 303 | b->INTERNAL_FIELD (minor_modes) = val; | ||
| 304 | } | ||
| 305 | static void | ||
| 306 | bset_mode_line_format (struct buffer *b, Lisp_Object val) | ||
| 307 | { | ||
| 308 | b->INTERNAL_FIELD (mode_line_format) = val; | ||
| 309 | } | ||
| 310 | static void | ||
| 311 | bset_mode_name (struct buffer *b, Lisp_Object val) | ||
| 312 | { | ||
| 313 | b->INTERNAL_FIELD (mode_name) = val; | ||
| 314 | } | ||
| 315 | static void | ||
| 316 | bset_name (struct buffer *b, Lisp_Object val) | ||
| 317 | { | ||
| 318 | b->INTERNAL_FIELD (name) = val; | ||
| 319 | } | ||
| 320 | static void | ||
| 321 | bset_overwrite_mode (struct buffer *b, Lisp_Object val) | ||
| 322 | { | ||
| 323 | b->INTERNAL_FIELD (overwrite_mode) = val; | ||
| 324 | } | ||
| 325 | static void | ||
| 326 | bset_pt_marker (struct buffer *b, Lisp_Object val) | ||
| 327 | { | ||
| 328 | b->INTERNAL_FIELD (pt_marker) = val; | ||
| 329 | } | ||
| 330 | static void | ||
| 331 | bset_right_fringe_width (struct buffer *b, Lisp_Object val) | ||
| 332 | { | ||
| 333 | b->INTERNAL_FIELD (right_fringe_width) = val; | ||
| 334 | } | ||
| 335 | static void | ||
| 336 | bset_save_length (struct buffer *b, Lisp_Object val) | ||
| 337 | { | ||
| 338 | b->INTERNAL_FIELD (save_length) = val; | ||
| 339 | } | ||
| 340 | static void | ||
| 341 | bset_scroll_bar_width (struct buffer *b, Lisp_Object val) | ||
| 342 | { | ||
| 343 | b->INTERNAL_FIELD (scroll_bar_width) = val; | ||
| 344 | } | ||
| 345 | static void | ||
| 346 | bset_scroll_down_aggressively (struct buffer *b, Lisp_Object val) | ||
| 347 | { | ||
| 348 | b->INTERNAL_FIELD (scroll_down_aggressively) = val; | ||
| 349 | } | ||
| 350 | static void | ||
| 351 | bset_scroll_up_aggressively (struct buffer *b, Lisp_Object val) | ||
| 352 | { | ||
| 353 | b->INTERNAL_FIELD (scroll_up_aggressively) = val; | ||
| 354 | } | ||
| 355 | static void | ||
| 356 | bset_selective_display (struct buffer *b, Lisp_Object val) | ||
| 357 | { | ||
| 358 | b->INTERNAL_FIELD (selective_display) = val; | ||
| 359 | } | ||
| 360 | static void | ||
| 361 | bset_selective_display_ellipses (struct buffer *b, Lisp_Object val) | ||
| 362 | { | ||
| 363 | b->INTERNAL_FIELD (selective_display_ellipses) = val; | ||
| 364 | } | ||
| 365 | static void | ||
| 366 | bset_vertical_scroll_bar_type (struct buffer *b, Lisp_Object val) | ||
| 367 | { | ||
| 368 | b->INTERNAL_FIELD (vertical_scroll_bar_type) = val; | ||
| 369 | } | ||
| 370 | static void | ||
| 371 | bset_word_wrap (struct buffer *b, Lisp_Object val) | ||
| 372 | { | ||
| 373 | b->INTERNAL_FIELD (word_wrap) = val; | ||
| 374 | } | ||
| 375 | static void | ||
| 376 | bset_zv_marker (struct buffer *b, Lisp_Object val) | ||
| 377 | { | ||
| 378 | b->INTERNAL_FIELD (zv_marker) = val; | ||
| 379 | } | ||
| 162 | 380 | ||
| 163 | void | 381 | void |
| 164 | nsberror (Lisp_Object spec) | 382 | nsberror (Lisp_Object spec) |
| @@ -173,7 +391,7 @@ DEFUN ("buffer-live-p", Fbuffer_live_p, Sbuffer_live_p, 1, 1, 0, | |||
| 173 | Value is nil if OBJECT is not a buffer or if it has been killed. */) | 391 | Value is nil if OBJECT is not a buffer or if it has been killed. */) |
| 174 | (Lisp_Object object) | 392 | (Lisp_Object object) |
| 175 | { | 393 | { |
| 176 | return ((BUFFERP (object) && ! NILP (BVAR (XBUFFER (object), name))) | 394 | return ((BUFFERP (object) && BUFFER_LIVE_P (XBUFFER (object))) |
| 177 | ? Qt : Qnil); | 395 | ? Qt : Qnil); |
| 178 | } | 396 | } |
| 179 | 397 | ||
| @@ -192,7 +410,6 @@ followed by the rest of the buffers. */) | |||
| 192 | Lisp_Object framelist, prevlist, tail; | 410 | Lisp_Object framelist, prevlist, tail; |
| 193 | Lisp_Object args[3]; | 411 | Lisp_Object args[3]; |
| 194 | 412 | ||
| 195 | CHECK_FRAME (frame); | ||
| 196 | framelist = Fcopy_sequence (XFRAME (frame)->buffer_list); | 413 | framelist = Fcopy_sequence (XFRAME (frame)->buffer_list); |
| 197 | prevlist = Fnreverse (Fcopy_sequence | 414 | prevlist = Fnreverse (Fcopy_sequence |
| 198 | (XFRAME (frame)->buried_buffer_list)); | 415 | (XFRAME (frame)->buried_buffer_list)); |
| @@ -261,8 +478,7 @@ If there is no such live buffer, return nil. | |||
| 261 | See also `find-buffer-visiting'. */) | 478 | See also `find-buffer-visiting'. */) |
| 262 | (register Lisp_Object filename) | 479 | (register Lisp_Object filename) |
| 263 | { | 480 | { |
| 264 | register Lisp_Object tail, buf, tem; | 481 | register Lisp_Object tail, buf, handler; |
| 265 | Lisp_Object handler; | ||
| 266 | 482 | ||
| 267 | CHECK_STRING (filename); | 483 | CHECK_STRING (filename); |
| 268 | filename = Fexpand_file_name (filename, Qnil); | 484 | filename = Fexpand_file_name (filename, Qnil); |
| @@ -277,13 +493,10 @@ See also `find-buffer-visiting'. */) | |||
| 277 | return BUFFERP (handled_buf) ? handled_buf : Qnil; | 493 | return BUFFERP (handled_buf) ? handled_buf : Qnil; |
| 278 | } | 494 | } |
| 279 | 495 | ||
| 280 | for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) | 496 | FOR_EACH_LIVE_BUFFER (tail, buf) |
| 281 | { | 497 | { |
| 282 | buf = Fcdr (XCAR (tail)); | ||
| 283 | if (!BUFFERP (buf)) continue; | ||
| 284 | if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue; | 498 | if (!STRINGP (BVAR (XBUFFER (buf), filename))) continue; |
| 285 | tem = Fstring_equal (BVAR (XBUFFER (buf), filename), filename); | 499 | if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), filename), filename))) |
| 286 | if (!NILP (tem)) | ||
| 287 | return buf; | 500 | return buf; |
| 288 | } | 501 | } |
| 289 | return Qnil; | 502 | return Qnil; |
| @@ -292,15 +505,12 @@ See also `find-buffer-visiting'. */) | |||
| 292 | Lisp_Object | 505 | Lisp_Object |
| 293 | get_truename_buffer (register Lisp_Object filename) | 506 | get_truename_buffer (register Lisp_Object filename) |
| 294 | { | 507 | { |
| 295 | register Lisp_Object tail, buf, tem; | 508 | register Lisp_Object tail, buf; |
| 296 | 509 | ||
| 297 | for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) | 510 | FOR_EACH_LIVE_BUFFER (tail, buf) |
| 298 | { | 511 | { |
| 299 | buf = Fcdr (XCAR (tail)); | ||
| 300 | if (!BUFFERP (buf)) continue; | ||
| 301 | if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue; | 512 | if (!STRINGP (BVAR (XBUFFER (buf), file_truename))) continue; |
| 302 | tem = Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename); | 513 | if (!NILP (Fstring_equal (BVAR (XBUFFER (buf), file_truename), filename))) |
| 303 | if (!NILP (tem)) | ||
| 304 | return buf; | 514 | return buf; |
| 305 | } | 515 | } |
| 306 | return Qnil; | 516 | return Qnil; |
| @@ -331,14 +541,18 @@ even if it is dead. The return value is never nil. */) | |||
| 331 | 541 | ||
| 332 | /* An ordinary buffer uses its own struct buffer_text. */ | 542 | /* An ordinary buffer uses its own struct buffer_text. */ |
| 333 | b->text = &b->own_text; | 543 | b->text = &b->own_text; |
| 334 | b->base_buffer = 0; | 544 | b->base_buffer = NULL; |
| 545 | /* No one shares the text with us now. */ | ||
| 546 | b->indirections = 0; | ||
| 547 | /* No one shows us now. */ | ||
| 548 | b->window_count = 0; | ||
| 335 | 549 | ||
| 336 | BUF_GAP_SIZE (b) = 20; | 550 | BUF_GAP_SIZE (b) = 20; |
| 337 | BLOCK_INPUT; | 551 | block_input (); |
| 338 | /* We allocate extra 1-byte at the tail and keep it always '\0' for | 552 | /* We allocate extra 1-byte at the tail and keep it always '\0' for |
| 339 | anchoring a search. */ | 553 | anchoring a search. */ |
| 340 | alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1); | 554 | alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1); |
| 341 | UNBLOCK_INPUT; | 555 | unblock_input (); |
| 342 | if (! BUF_BEG_ADDR (b)) | 556 | if (! BUF_BEG_ADDR (b)) |
| 343 | buffer_memory_full (BUF_GAP_SIZE (b) + 1); | 557 | buffer_memory_full (BUF_GAP_SIZE (b) + 1); |
| 344 | 558 | ||
| @@ -358,7 +572,8 @@ even if it is dead. The return value is never nil. */) | |||
| 358 | BUF_CHARS_MODIFF (b) = 1; | 572 | BUF_CHARS_MODIFF (b) = 1; |
| 359 | BUF_OVERLAY_MODIFF (b) = 1; | 573 | BUF_OVERLAY_MODIFF (b) = 1; |
| 360 | BUF_SAVE_MODIFF (b) = 1; | 574 | BUF_SAVE_MODIFF (b) = 1; |
| 361 | BUF_INTERVALS (b) = 0; | 575 | BUF_COMPACT (b) = 1; |
| 576 | set_buffer_intervals (b, NULL); | ||
| 362 | BUF_UNCHANGED_MODIFIED (b) = 1; | 577 | BUF_UNCHANGED_MODIFIED (b) = 1; |
| 363 | BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1; | 578 | BUF_OVERLAY_UNCHANGED_MODIFIED (b) = 1; |
| 364 | BUF_END_UNCHANGED (b) = 0; | 579 | BUF_END_UNCHANGED (b) = 0; |
| @@ -368,34 +583,31 @@ even if it is dead. The return value is never nil. */) | |||
| 368 | 583 | ||
| 369 | b->newline_cache = 0; | 584 | b->newline_cache = 0; |
| 370 | b->width_run_cache = 0; | 585 | b->width_run_cache = 0; |
| 371 | BVAR (b, width_table) = Qnil; | 586 | b->bidi_paragraph_cache = 0; |
| 587 | bset_width_table (b, Qnil); | ||
| 372 | b->prevent_redisplay_optimizations_p = 1; | 588 | b->prevent_redisplay_optimizations_p = 1; |
| 373 | 589 | ||
| 374 | /* Put this on the chain of all buffers including killed ones. */ | ||
| 375 | b->header.next.buffer = all_buffers; | ||
| 376 | all_buffers = b; | ||
| 377 | |||
| 378 | /* An ordinary buffer normally doesn't need markers | 590 | /* An ordinary buffer normally doesn't need markers |
| 379 | to handle BEGV and ZV. */ | 591 | to handle BEGV and ZV. */ |
| 380 | BVAR (b, pt_marker) = Qnil; | 592 | bset_pt_marker (b, Qnil); |
| 381 | BVAR (b, begv_marker) = Qnil; | 593 | bset_begv_marker (b, Qnil); |
| 382 | BVAR (b, zv_marker) = Qnil; | 594 | bset_zv_marker (b, Qnil); |
| 383 | 595 | ||
| 384 | name = Fcopy_sequence (buffer_or_name); | 596 | name = Fcopy_sequence (buffer_or_name); |
| 385 | STRING_SET_INTERVALS (name, NULL_INTERVAL); | 597 | set_string_intervals (name, NULL); |
| 386 | BVAR (b, name) = name; | 598 | bset_name (b, name); |
| 387 | 599 | ||
| 388 | BVAR (b, undo_list) = (SREF (name, 0) != ' ') ? Qnil : Qt; | 600 | bset_undo_list (b, SREF (name, 0) != ' ' ? Qnil : Qt); |
| 389 | 601 | ||
| 390 | reset_buffer (b); | 602 | reset_buffer (b); |
| 391 | reset_buffer_local_variables (b, 1); | 603 | reset_buffer_local_variables (b, 1); |
| 392 | 604 | ||
| 393 | BVAR (b, mark) = Fmake_marker (); | 605 | bset_mark (b, Fmake_marker ()); |
| 394 | BUF_MARKERS (b) = NULL; | 606 | BUF_MARKERS (b) = NULL; |
| 395 | 607 | ||
| 396 | /* Put this in the alist of all live buffers. */ | 608 | /* Put this in the alist of all live buffers. */ |
| 397 | XSETBUFFER (buffer, b); | 609 | XSETBUFFER (buffer, b); |
| 398 | Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buffer), Qnil)); | 610 | Vbuffer_alist = nconc2 (Vbuffer_alist, list1 (Fcons (name, buffer))); |
| 399 | /* And run buffer-list-update-hook. */ | 611 | /* And run buffer-list-update-hook. */ |
| 400 | if (!NILP (Vrun_hooks)) | 612 | if (!NILP (Vrun_hooks)) |
| 401 | call1 (Vrun_hooks, Qbuffer_list_update_hook); | 613 | call1 (Vrun_hooks, Qbuffer_list_update_hook); |
| @@ -410,36 +622,24 @@ even if it is dead. The return value is never nil. */) | |||
| 410 | static struct Lisp_Overlay * | 622 | static struct Lisp_Overlay * |
| 411 | copy_overlays (struct buffer *b, struct Lisp_Overlay *list) | 623 | copy_overlays (struct buffer *b, struct Lisp_Overlay *list) |
| 412 | { | 624 | { |
| 413 | Lisp_Object buffer; | ||
| 414 | struct Lisp_Overlay *result = NULL, *tail = NULL; | 625 | struct Lisp_Overlay *result = NULL, *tail = NULL; |
| 415 | 626 | ||
| 416 | XSETBUFFER (buffer, b); | ||
| 417 | |||
| 418 | for (; list; list = list->next) | 627 | for (; list; list = list->next) |
| 419 | { | 628 | { |
| 420 | Lisp_Object overlay, start, end, old_overlay; | 629 | Lisp_Object overlay, start, end; |
| 421 | ptrdiff_t charpos; | 630 | struct Lisp_Marker *m; |
| 422 | 631 | ||
| 423 | XSETMISC (old_overlay, list); | 632 | eassert (MARKERP (list->start)); |
| 424 | charpos = marker_position (OVERLAY_START (old_overlay)); | 633 | m = XMARKER (list->start); |
| 425 | start = Fmake_marker (); | 634 | start = build_marker (b, m->charpos, m->bytepos); |
| 426 | Fset_marker (start, make_number (charpos), buffer); | 635 | XMARKER (start)->insertion_type = m->insertion_type; |
| 427 | XMARKER (start)->insertion_type | 636 | |
| 428 | = XMARKER (OVERLAY_START (old_overlay))->insertion_type; | 637 | eassert (MARKERP (list->end)); |
| 429 | 638 | m = XMARKER (list->end); | |
| 430 | charpos = marker_position (OVERLAY_END (old_overlay)); | 639 | end = build_marker (b, m->charpos, m->bytepos); |
| 431 | end = Fmake_marker (); | 640 | XMARKER (end)->insertion_type = m->insertion_type; |
| 432 | Fset_marker (end, make_number (charpos), buffer); | ||
| 433 | XMARKER (end)->insertion_type | ||
| 434 | = XMARKER (OVERLAY_END (old_overlay))->insertion_type; | ||
| 435 | |||
| 436 | overlay = allocate_misc (); | ||
| 437 | XMISCTYPE (overlay) = Lisp_Misc_Overlay; | ||
| 438 | OVERLAY_START (overlay) = start; | ||
| 439 | OVERLAY_END (overlay) = end; | ||
| 440 | OVERLAY_PLIST (overlay) = Fcopy_sequence (OVERLAY_PLIST (old_overlay)); | ||
| 441 | XOVERLAY (overlay)->next = NULL; | ||
| 442 | 641 | ||
| 642 | overlay = build_overlay (start, end, Fcopy_sequence (list->plist)); | ||
| 443 | if (tail) | 643 | if (tail) |
| 444 | tail = tail->next = XOVERLAY (overlay); | 644 | tail = tail->next = XOVERLAY (overlay); |
| 445 | else | 645 | else |
| @@ -449,6 +649,19 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list) | |||
| 449 | return result; | 649 | return result; |
| 450 | } | 650 | } |
| 451 | 651 | ||
| 652 | /* Set an appropriate overlay of B. */ | ||
| 653 | |||
| 654 | static void | ||
| 655 | set_buffer_overlays_before (struct buffer *b, struct Lisp_Overlay *o) | ||
| 656 | { | ||
| 657 | b->overlays_before = o; | ||
| 658 | } | ||
| 659 | |||
| 660 | static void | ||
| 661 | set_buffer_overlays_after (struct buffer *b, struct Lisp_Overlay *o) | ||
| 662 | { | ||
| 663 | b->overlays_after = o; | ||
| 664 | } | ||
| 452 | 665 | ||
| 453 | /* Clone per-buffer values of buffer FROM. | 666 | /* Clone per-buffer values of buffer FROM. |
| 454 | 667 | ||
| @@ -460,16 +673,9 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list) | |||
| 460 | static void | 673 | static void |
| 461 | clone_per_buffer_values (struct buffer *from, struct buffer *to) | 674 | clone_per_buffer_values (struct buffer *from, struct buffer *to) |
| 462 | { | 675 | { |
| 463 | Lisp_Object to_buffer; | ||
| 464 | int offset; | 676 | int offset; |
| 465 | 677 | ||
| 466 | XSETBUFFER (to_buffer, to); | 678 | FOR_EACH_PER_BUFFER_OBJECT_AT (offset) |
| 467 | |||
| 468 | /* buffer-local Lisp variables start at `undo_list', | ||
| 469 | tho only the ones from `name' on are GC'd normally. */ | ||
| 470 | for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER); | ||
| 471 | offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER); | ||
| 472 | offset += sizeof (Lisp_Object)) | ||
| 473 | { | 679 | { |
| 474 | Lisp_Object obj; | 680 | Lisp_Object obj; |
| 475 | 681 | ||
| @@ -477,26 +683,26 @@ clone_per_buffer_values (struct buffer *from, struct buffer *to) | |||
| 477 | if (offset == PER_BUFFER_VAR_OFFSET (name)) | 683 | if (offset == PER_BUFFER_VAR_OFFSET (name)) |
| 478 | continue; | 684 | continue; |
| 479 | 685 | ||
| 480 | obj = PER_BUFFER_VALUE (from, offset); | 686 | obj = per_buffer_value (from, offset); |
| 481 | if (MARKERP (obj) && XMARKER (obj)->buffer == from) | 687 | if (MARKERP (obj) && XMARKER (obj)->buffer == from) |
| 482 | { | 688 | { |
| 483 | struct Lisp_Marker *m = XMARKER (obj); | 689 | struct Lisp_Marker *m = XMARKER (obj); |
| 484 | obj = Fmake_marker (); | 690 | |
| 691 | obj = build_marker (to, m->charpos, m->bytepos); | ||
| 485 | XMARKER (obj)->insertion_type = m->insertion_type; | 692 | XMARKER (obj)->insertion_type = m->insertion_type; |
| 486 | set_marker_both (obj, to_buffer, m->charpos, m->bytepos); | ||
| 487 | } | 693 | } |
| 488 | 694 | ||
| 489 | PER_BUFFER_VALUE (to, offset) = obj; | 695 | set_per_buffer_value (to, offset, obj); |
| 490 | } | 696 | } |
| 491 | 697 | ||
| 492 | memcpy (to->local_flags, from->local_flags, sizeof to->local_flags); | 698 | memcpy (to->local_flags, from->local_flags, sizeof to->local_flags); |
| 493 | 699 | ||
| 494 | to->overlays_before = copy_overlays (to, from->overlays_before); | 700 | set_buffer_overlays_before (to, copy_overlays (to, from->overlays_before)); |
| 495 | to->overlays_after = copy_overlays (to, from->overlays_after); | 701 | set_buffer_overlays_after (to, copy_overlays (to, from->overlays_after)); |
| 496 | 702 | ||
| 497 | /* Get (a copy of) the alist of Lisp-level local variables of FROM | 703 | /* Get (a copy of) the alist of Lisp-level local variables of FROM |
| 498 | and install that in TO. */ | 704 | and install that in TO. */ |
| 499 | BVAR (to, local_var_alist) = buffer_lisp_local_variables (from); | 705 | bset_local_var_alist (to, buffer_lisp_local_variables (from, 1)); |
| 500 | } | 706 | } |
| 501 | 707 | ||
| 502 | 708 | ||
| @@ -569,7 +775,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */) | |||
| 569 | base_buffer = Fget_buffer (base_buffer); | 775 | base_buffer = Fget_buffer (base_buffer); |
| 570 | if (NILP (base_buffer)) | 776 | if (NILP (base_buffer)) |
| 571 | error ("No such buffer: `%s'", SDATA (tem)); | 777 | error ("No such buffer: `%s'", SDATA (tem)); |
| 572 | if (NILP (BVAR (XBUFFER (base_buffer), name))) | 778 | if (!BUFFER_LIVE_P (XBUFFER (base_buffer))) |
| 573 | error ("Base buffer has been killed"); | 779 | error ("Base buffer has been killed"); |
| 574 | 780 | ||
| 575 | if (SCHARS (name) == 0) | 781 | if (SCHARS (name) == 0) |
| @@ -577,12 +783,20 @@ CLONE nil means the indirect buffer's state is reset to default values. */) | |||
| 577 | 783 | ||
| 578 | b = allocate_buffer (); | 784 | b = allocate_buffer (); |
| 579 | 785 | ||
| 786 | /* No double indirection - if base buffer is indirect, | ||
| 787 | new buffer becomes an indirect to base's base. */ | ||
| 580 | b->base_buffer = (XBUFFER (base_buffer)->base_buffer | 788 | b->base_buffer = (XBUFFER (base_buffer)->base_buffer |
| 581 | ? XBUFFER (base_buffer)->base_buffer | 789 | ? XBUFFER (base_buffer)->base_buffer |
| 582 | : XBUFFER (base_buffer)); | 790 | : XBUFFER (base_buffer)); |
| 583 | 791 | ||
| 584 | /* Use the base buffer's text object. */ | 792 | /* Use the base buffer's text object. */ |
| 585 | b->text = b->base_buffer->text; | 793 | b->text = b->base_buffer->text; |
| 794 | /* We have no own text. */ | ||
| 795 | b->indirections = -1; | ||
| 796 | /* Notify base buffer that we share the text now. */ | ||
| 797 | b->base_buffer->indirections++; | ||
| 798 | /* Always -1 for an indirect buffer. */ | ||
| 799 | b->window_count = -1; | ||
| 586 | 800 | ||
| 587 | b->pt = b->base_buffer->pt; | 801 | b->pt = b->base_buffer->pt; |
| 588 | b->begv = b->base_buffer->begv; | 802 | b->begv = b->base_buffer->begv; |
| @@ -593,27 +807,25 @@ CLONE nil means the indirect buffer's state is reset to default values. */) | |||
| 593 | 807 | ||
| 594 | b->newline_cache = 0; | 808 | b->newline_cache = 0; |
| 595 | b->width_run_cache = 0; | 809 | b->width_run_cache = 0; |
| 596 | BVAR (b, width_table) = Qnil; | 810 | b->bidi_paragraph_cache = 0; |
| 597 | 811 | bset_width_table (b, Qnil); | |
| 598 | /* Put this on the chain of all buffers including killed ones. */ | ||
| 599 | b->header.next.buffer = all_buffers; | ||
| 600 | all_buffers = b; | ||
| 601 | 812 | ||
| 602 | name = Fcopy_sequence (name); | 813 | name = Fcopy_sequence (name); |
| 603 | STRING_SET_INTERVALS (name, NULL_INTERVAL); | 814 | set_string_intervals (name, NULL); |
| 604 | BVAR (b, name) = name; | 815 | bset_name (b, name); |
| 605 | 816 | ||
| 606 | reset_buffer (b); | 817 | reset_buffer (b); |
| 607 | reset_buffer_local_variables (b, 1); | 818 | reset_buffer_local_variables (b, 1); |
| 608 | 819 | ||
| 609 | /* Put this in the alist of all live buffers. */ | 820 | /* Put this in the alist of all live buffers. */ |
| 610 | XSETBUFFER (buf, b); | 821 | XSETBUFFER (buf, b); |
| 611 | Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil)); | 822 | Vbuffer_alist = nconc2 (Vbuffer_alist, list1 (Fcons (name, buf))); |
| 612 | 823 | ||
| 613 | BVAR (b, mark) = Fmake_marker (); | 824 | bset_mark (b, Fmake_marker ()); |
| 614 | 825 | ||
| 615 | /* The multibyte status belongs to the base buffer. */ | 826 | /* The multibyte status belongs to the base buffer. */ |
| 616 | BVAR (b, enable_multibyte_characters) = BVAR (b->base_buffer, enable_multibyte_characters); | 827 | bset_enable_multibyte_characters |
| 828 | (b, BVAR (b->base_buffer, enable_multibyte_characters)); | ||
| 617 | 829 | ||
| 618 | /* Make sure the base buffer has markers for its narrowing. */ | 830 | /* Make sure the base buffer has markers for its narrowing. */ |
| 619 | if (NILP (BVAR (b->base_buffer, pt_marker))) | 831 | if (NILP (BVAR (b->base_buffer, pt_marker))) |
| @@ -621,32 +833,27 @@ CLONE nil means the indirect buffer's state is reset to default values. */) | |||
| 621 | eassert (NILP (BVAR (b->base_buffer, begv_marker))); | 833 | eassert (NILP (BVAR (b->base_buffer, begv_marker))); |
| 622 | eassert (NILP (BVAR (b->base_buffer, zv_marker))); | 834 | eassert (NILP (BVAR (b->base_buffer, zv_marker))); |
| 623 | 835 | ||
| 624 | BVAR (b->base_buffer, pt_marker) = Fmake_marker (); | 836 | bset_pt_marker (b->base_buffer, |
| 625 | set_marker_both (BVAR (b->base_buffer, pt_marker), base_buffer, | 837 | build_marker (b->base_buffer, b->base_buffer->pt, |
| 626 | b->base_buffer->pt, | 838 | b->base_buffer->pt_byte)); |
| 627 | b->base_buffer->pt_byte); | 839 | |
| 840 | bset_begv_marker (b->base_buffer, | ||
| 841 | build_marker (b->base_buffer, b->base_buffer->begv, | ||
| 842 | b->base_buffer->begv_byte)); | ||
| 628 | 843 | ||
| 629 | BVAR (b->base_buffer, begv_marker) = Fmake_marker (); | 844 | bset_zv_marker (b->base_buffer, |
| 630 | set_marker_both (BVAR (b->base_buffer, begv_marker), base_buffer, | 845 | build_marker (b->base_buffer, b->base_buffer->zv, |
| 631 | b->base_buffer->begv, | 846 | b->base_buffer->zv_byte)); |
| 632 | b->base_buffer->begv_byte); | ||
| 633 | 847 | ||
| 634 | BVAR (b->base_buffer, zv_marker) = Fmake_marker (); | ||
| 635 | set_marker_both (BVAR (b->base_buffer, zv_marker), base_buffer, | ||
| 636 | b->base_buffer->zv, | ||
| 637 | b->base_buffer->zv_byte); | ||
| 638 | XMARKER (BVAR (b->base_buffer, zv_marker))->insertion_type = 1; | 848 | XMARKER (BVAR (b->base_buffer, zv_marker))->insertion_type = 1; |
| 639 | } | 849 | } |
| 640 | 850 | ||
| 641 | if (NILP (clone)) | 851 | if (NILP (clone)) |
| 642 | { | 852 | { |
| 643 | /* Give the indirect buffer markers for its narrowing. */ | 853 | /* Give the indirect buffer markers for its narrowing. */ |
| 644 | BVAR (b, pt_marker) = Fmake_marker (); | 854 | bset_pt_marker (b, build_marker (b, b->pt, b->pt_byte)); |
| 645 | set_marker_both (BVAR (b, pt_marker), buf, b->pt, b->pt_byte); | 855 | bset_begv_marker (b, build_marker (b, b->begv, b->begv_byte)); |
| 646 | BVAR (b, begv_marker) = Fmake_marker (); | 856 | bset_zv_marker (b, build_marker (b, b->zv, b->zv_byte)); |
| 647 | set_marker_both (BVAR (b, begv_marker), buf, b->begv, b->begv_byte); | ||
| 648 | BVAR (b, zv_marker) = Fmake_marker (); | ||
| 649 | set_marker_both (BVAR (b, zv_marker), buf, b->zv, b->zv_byte); | ||
| 650 | XMARKER (BVAR (b, zv_marker))->insertion_type = 1; | 857 | XMARKER (BVAR (b, zv_marker))->insertion_type = 1; |
| 651 | } | 858 | } |
| 652 | else | 859 | else |
| @@ -654,11 +861,11 @@ CLONE nil means the indirect buffer's state is reset to default values. */) | |||
| 654 | struct buffer *old_b = current_buffer; | 861 | struct buffer *old_b = current_buffer; |
| 655 | 862 | ||
| 656 | clone_per_buffer_values (b->base_buffer, b); | 863 | clone_per_buffer_values (b->base_buffer, b); |
| 657 | BVAR (b, filename) = Qnil; | 864 | bset_filename (b, Qnil); |
| 658 | BVAR (b, file_truename) = Qnil; | 865 | bset_file_truename (b, Qnil); |
| 659 | BVAR (b, display_count) = make_number (0); | 866 | bset_display_count (b, make_number (0)); |
| 660 | BVAR (b, backed_up) = Qnil; | 867 | bset_backed_up (b, Qnil); |
| 661 | BVAR (b, auto_save_file_name) = Qnil; | 868 | bset_auto_save_file_name (b, Qnil); |
| 662 | set_buffer_internal_1 (b); | 869 | set_buffer_internal_1 (b); |
| 663 | Fset (intern ("buffer-save-without-query"), Qnil); | 870 | Fset (intern ("buffer-save-without-query"), Qnil); |
| 664 | Fset (intern ("buffer-file-number"), Qnil); | 871 | Fset (intern ("buffer-file-number"), Qnil); |
| @@ -673,27 +880,44 @@ CLONE nil means the indirect buffer's state is reset to default values. */) | |||
| 673 | return buf; | 880 | return buf; |
| 674 | } | 881 | } |
| 675 | 882 | ||
| 883 | /* Mark OV as no longer associated with B. */ | ||
| 884 | |||
| 885 | static void | ||
| 886 | drop_overlay (struct buffer *b, struct Lisp_Overlay *ov) | ||
| 887 | { | ||
| 888 | eassert (b == XBUFFER (Fmarker_buffer (ov->start))); | ||
| 889 | modify_overlay (b, marker_position (ov->start), | ||
| 890 | marker_position (ov->end)); | ||
| 891 | unchain_marker (XMARKER (ov->start)); | ||
| 892 | unchain_marker (XMARKER (ov->end)); | ||
| 893 | |||
| 894 | } | ||
| 895 | |||
| 896 | /* Delete all overlays of B and reset it's overlay lists. */ | ||
| 897 | |||
| 676 | void | 898 | void |
| 677 | delete_all_overlays (struct buffer *b) | 899 | delete_all_overlays (struct buffer *b) |
| 678 | { | 900 | { |
| 679 | Lisp_Object overlay; | 901 | struct Lisp_Overlay *ov, *next; |
| 680 | 902 | ||
| 681 | /* `reset_buffer' blindly sets the list of overlays to NULL, so we | 903 | /* FIXME: Since each drop_overlay will scan BUF_MARKERS to unlink its |
| 682 | have to empty the list, otherwise we end up with overlays that | 904 | markers, we have an unneeded O(N^2) behavior here. */ |
| 683 | think they belong to this buffer while the buffer doesn't know about | 905 | for (ov = b->overlays_before; ov; ov = next) |
| 684 | them any more. */ | ||
| 685 | while (b->overlays_before) | ||
| 686 | { | 906 | { |
| 687 | XSETMISC (overlay, b->overlays_before); | 907 | drop_overlay (b, ov); |
| 688 | Fdelete_overlay (overlay); | 908 | next = ov->next; |
| 909 | ov->next = NULL; | ||
| 689 | } | 910 | } |
| 690 | while (b->overlays_after) | 911 | |
| 912 | for (ov = b->overlays_after; ov; ov = next) | ||
| 691 | { | 913 | { |
| 692 | XSETMISC (overlay, b->overlays_after); | 914 | drop_overlay (b, ov); |
| 693 | Fdelete_overlay (overlay); | 915 | next = ov->next; |
| 916 | ov->next = NULL; | ||
| 694 | } | 917 | } |
| 695 | eassert (b->overlays_before == NULL); | 918 | |
| 696 | eassert (b->overlays_after == NULL); | 919 | set_buffer_overlays_before (b, NULL); |
| 920 | set_buffer_overlays_after (b, NULL); | ||
| 697 | } | 921 | } |
| 698 | 922 | ||
| 699 | /* Reinitialize everything about a buffer except its name and contents | 923 | /* Reinitialize everything about a buffer except its name and contents |
| @@ -706,34 +930,35 @@ delete_all_overlays (struct buffer *b) | |||
| 706 | void | 930 | void |
| 707 | reset_buffer (register struct buffer *b) | 931 | reset_buffer (register struct buffer *b) |
| 708 | { | 932 | { |
| 709 | BVAR (b, filename) = Qnil; | 933 | bset_filename (b, Qnil); |
| 710 | BVAR (b, file_truename) = Qnil; | 934 | bset_file_truename (b, Qnil); |
| 711 | BVAR (b, directory) = (current_buffer) ? BVAR (current_buffer, directory) : Qnil; | 935 | bset_directory (b, current_buffer ? BVAR (current_buffer, directory) : Qnil); |
| 712 | b->modtime = 0; | 936 | b->modtime = make_timespec (0, UNKNOWN_MODTIME_NSECS); |
| 713 | b->modtime_size = -1; | 937 | b->modtime_size = -1; |
| 714 | XSETFASTINT (BVAR (b, save_length), 0); | 938 | XSETFASTINT (BVAR (b, save_length), 0); |
| 715 | b->last_window_start = 1; | 939 | b->last_window_start = 1; |
| 716 | /* It is more conservative to start out "changed" than "unchanged". */ | 940 | /* It is more conservative to start out "changed" than "unchanged". */ |
| 717 | b->clip_changed = 0; | 941 | b->clip_changed = 0; |
| 718 | b->prevent_redisplay_optimizations_p = 1; | 942 | b->prevent_redisplay_optimizations_p = 1; |
| 719 | BVAR (b, backed_up) = Qnil; | 943 | bset_backed_up (b, Qnil); |
| 720 | BUF_AUTOSAVE_MODIFF (b) = 0; | 944 | BUF_AUTOSAVE_MODIFF (b) = 0; |
| 721 | b->auto_save_failure_time = 0; | 945 | b->auto_save_failure_time = 0; |
| 722 | BVAR (b, auto_save_file_name) = Qnil; | 946 | bset_auto_save_file_name (b, Qnil); |
| 723 | BVAR (b, read_only) = Qnil; | 947 | bset_read_only (b, Qnil); |
| 724 | b->overlays_before = NULL; | 948 | set_buffer_overlays_before (b, NULL); |
| 725 | b->overlays_after = NULL; | 949 | set_buffer_overlays_after (b, NULL); |
| 726 | b->overlay_center = BEG; | 950 | b->overlay_center = BEG; |
| 727 | BVAR (b, mark_active) = Qnil; | 951 | bset_mark_active (b, Qnil); |
| 728 | BVAR (b, point_before_scroll) = Qnil; | 952 | bset_point_before_scroll (b, Qnil); |
| 729 | BVAR (b, file_format) = Qnil; | 953 | bset_file_format (b, Qnil); |
| 730 | BVAR (b, auto_save_file_format) = Qt; | 954 | bset_auto_save_file_format (b, Qt); |
| 731 | BVAR (b, last_selected_window) = Qnil; | 955 | bset_last_selected_window (b, Qnil); |
| 732 | XSETINT (BVAR (b, display_count), 0); | 956 | bset_display_count (b, make_number (0)); |
| 733 | BVAR (b, display_time) = Qnil; | 957 | bset_display_time (b, Qnil); |
| 734 | BVAR (b, enable_multibyte_characters) = BVAR (&buffer_defaults, enable_multibyte_characters); | 958 | bset_enable_multibyte_characters |
| 735 | BVAR (b, cursor_type) = BVAR (&buffer_defaults, cursor_type); | 959 | (b, BVAR (&buffer_defaults, enable_multibyte_characters)); |
| 736 | BVAR (b, extra_line_spacing) = BVAR (&buffer_defaults, extra_line_spacing); | 960 | bset_cursor_type (b, BVAR (&buffer_defaults, cursor_type)); |
| 961 | bset_extra_line_spacing (b, BVAR (&buffer_defaults, extra_line_spacing)); | ||
| 737 | 962 | ||
| 738 | b->display_error_modiff = 0; | 963 | b->display_error_modiff = 0; |
| 739 | } | 964 | } |
| @@ -743,24 +968,22 @@ reset_buffer (register struct buffer *b) | |||
| 743 | it does not treat permanent locals consistently. | 968 | it does not treat permanent locals consistently. |
| 744 | Instead, use Fkill_all_local_variables. | 969 | Instead, use Fkill_all_local_variables. |
| 745 | 970 | ||
| 746 | If PERMANENT_TOO is 1, then we reset permanent | 971 | If PERMANENT_TOO, reset permanent buffer-local variables. |
| 747 | buffer-local variables. If PERMANENT_TOO is 0, | 972 | If not, preserve those. */ |
| 748 | we preserve those. */ | ||
| 749 | 973 | ||
| 750 | static void | 974 | static void |
| 751 | reset_buffer_local_variables (register struct buffer *b, int permanent_too) | 975 | reset_buffer_local_variables (struct buffer *b, bool permanent_too) |
| 752 | { | 976 | { |
| 753 | register int offset; | 977 | int offset, i; |
| 754 | int i; | ||
| 755 | 978 | ||
| 756 | /* Reset the major mode to Fundamental, together with all the | 979 | /* Reset the major mode to Fundamental, together with all the |
| 757 | things that depend on the major mode. | 980 | things that depend on the major mode. |
| 758 | default-major-mode is handled at a higher level. | 981 | default-major-mode is handled at a higher level. |
| 759 | We ignore it here. */ | 982 | We ignore it here. */ |
| 760 | BVAR (b, major_mode) = Qfundamental_mode; | 983 | bset_major_mode (b, Qfundamental_mode); |
| 761 | BVAR (b, keymap) = Qnil; | 984 | bset_keymap (b, Qnil); |
| 762 | BVAR (b, mode_name) = QSFundamental; | 985 | bset_mode_name (b, QSFundamental); |
| 763 | BVAR (b, minor_modes) = Qnil; | 986 | bset_minor_modes (b, Qnil); |
| 764 | 987 | ||
| 765 | /* If the standard case table has been altered and invalidated, | 988 | /* If the standard case table has been altered and invalidated, |
| 766 | fix up its insides first. */ | 989 | fix up its insides first. */ |
| @@ -769,15 +992,15 @@ reset_buffer_local_variables (register struct buffer *b, int permanent_too) | |||
| 769 | && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table)->extras[2]))) | 992 | && CHAR_TABLE_P (XCHAR_TABLE (Vascii_downcase_table)->extras[2]))) |
| 770 | Fset_standard_case_table (Vascii_downcase_table); | 993 | Fset_standard_case_table (Vascii_downcase_table); |
| 771 | 994 | ||
| 772 | BVAR (b, downcase_table) = Vascii_downcase_table; | 995 | bset_downcase_table (b, Vascii_downcase_table); |
| 773 | BVAR (b, upcase_table) = XCHAR_TABLE (Vascii_downcase_table)->extras[0]; | 996 | bset_upcase_table (b, XCHAR_TABLE (Vascii_downcase_table)->extras[0]); |
| 774 | BVAR (b, case_canon_table) = XCHAR_TABLE (Vascii_downcase_table)->extras[1]; | 997 | bset_case_canon_table (b, XCHAR_TABLE (Vascii_downcase_table)->extras[1]); |
| 775 | BVAR (b, case_eqv_table) = XCHAR_TABLE (Vascii_downcase_table)->extras[2]; | 998 | bset_case_eqv_table (b, XCHAR_TABLE (Vascii_downcase_table)->extras[2]); |
| 776 | BVAR (b, invisibility_spec) = Qt; | 999 | bset_invisibility_spec (b, Qt); |
| 777 | 1000 | ||
| 778 | /* Reset all (or most) per-buffer variables to their defaults. */ | 1001 | /* Reset all (or most) per-buffer variables to their defaults. */ |
| 779 | if (permanent_too) | 1002 | if (permanent_too) |
| 780 | BVAR (b, local_var_alist) = Qnil; | 1003 | bset_local_var_alist (b, Qnil); |
| 781 | else | 1004 | else |
| 782 | { | 1005 | { |
| 783 | Lisp_Object tmp, prop, last = Qnil; | 1006 | Lisp_Object tmp, prop, last = Qnil; |
| @@ -811,7 +1034,7 @@ reset_buffer_local_variables (register struct buffer *b, int permanent_too) | |||
| 811 | } | 1034 | } |
| 812 | /* Delete this local variable. */ | 1035 | /* Delete this local variable. */ |
| 813 | else if (NILP (last)) | 1036 | else if (NILP (last)) |
| 814 | BVAR (b, local_var_alist) = XCDR (tmp); | 1037 | bset_local_var_alist (b, XCDR (tmp)); |
| 815 | else | 1038 | else |
| 816 | XSETCDR (last, XCDR (tmp)); | 1039 | XSETCDR (last, XCDR (tmp)); |
| 817 | } | 1040 | } |
| @@ -820,20 +1043,14 @@ reset_buffer_local_variables (register struct buffer *b, int permanent_too) | |||
| 820 | if (permanent_too || buffer_permanent_local_flags[i] == 0) | 1043 | if (permanent_too || buffer_permanent_local_flags[i] == 0) |
| 821 | SET_PER_BUFFER_VALUE_P (b, i, 0); | 1044 | SET_PER_BUFFER_VALUE_P (b, i, 0); |
| 822 | 1045 | ||
| 823 | /* For each slot that has a default value, | 1046 | /* For each slot that has a default value, copy that into the slot. */ |
| 824 | copy that into the slot. */ | 1047 | FOR_EACH_PER_BUFFER_OBJECT_AT (offset) |
| 825 | |||
| 826 | /* buffer-local Lisp variables start at `undo_list', | ||
| 827 | tho only the ones from `name' on are GC'd normally. */ | ||
| 828 | for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER); | ||
| 829 | offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER); | ||
| 830 | offset += sizeof (Lisp_Object)) | ||
| 831 | { | 1048 | { |
| 832 | int idx = PER_BUFFER_IDX (offset); | 1049 | int idx = PER_BUFFER_IDX (offset); |
| 833 | if ((idx > 0 | 1050 | if ((idx > 0 |
| 834 | && (permanent_too | 1051 | && (permanent_too |
| 835 | || buffer_permanent_local_flags[idx] == 0))) | 1052 | || buffer_permanent_local_flags[idx] == 0))) |
| 836 | PER_BUFFER_VALUE (b, offset) = PER_BUFFER_DEFAULT (offset); | 1053 | set_per_buffer_value (b, offset, per_buffer_default (offset)); |
| 837 | } | 1054 | } |
| 838 | } | 1055 | } |
| 839 | 1056 | ||
| @@ -848,10 +1065,14 @@ If there is no live buffer named NAME, then return NAME. | |||
| 848 | Otherwise modify name by appending `<NUMBER>', incrementing NUMBER | 1065 | Otherwise modify name by appending `<NUMBER>', incrementing NUMBER |
| 849 | \(starting at 2) until an unused name is found, and then return that name. | 1066 | \(starting at 2) until an unused name is found, and then return that name. |
| 850 | Optional second argument IGNORE specifies a name that is okay to use (if | 1067 | Optional second argument IGNORE specifies a name that is okay to use (if |
| 851 | it is in the sequence to be tried) even if a buffer with that name exists. */) | 1068 | it is in the sequence to be tried) even if a buffer with that name exists. |
| 1069 | |||
| 1070 | If NAME begins with a space (i.e., a buffer that is not normally | ||
| 1071 | visible to users), then if buffer NAME already exists a random number | ||
| 1072 | is first appended to NAME, to speed up finding a non-existent buffer. */) | ||
| 852 | (register Lisp_Object name, Lisp_Object ignore) | 1073 | (register Lisp_Object name, Lisp_Object ignore) |
| 853 | { | 1074 | { |
| 854 | register Lisp_Object gentemp, tem; | 1075 | register Lisp_Object gentemp, tem, tem2; |
| 855 | ptrdiff_t count; | 1076 | ptrdiff_t count; |
| 856 | char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"]; | 1077 | char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"]; |
| 857 | 1078 | ||
| @@ -864,11 +1085,24 @@ it is in the sequence to be tried) even if a buffer with that name exists. */) | |||
| 864 | if (NILP (tem)) | 1085 | if (NILP (tem)) |
| 865 | return name; | 1086 | return name; |
| 866 | 1087 | ||
| 1088 | if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */ | ||
| 1089 | { | ||
| 1090 | /* Note fileio.c:make_temp_name does random differently. */ | ||
| 1091 | tem2 = concat2 (name, make_formatted_string | ||
| 1092 | (number, "-%"pI"d", | ||
| 1093 | XFASTINT (Frandom (make_number (999999))))); | ||
| 1094 | tem = Fget_buffer (tem2); | ||
| 1095 | if (NILP (tem)) | ||
| 1096 | return tem2; | ||
| 1097 | } | ||
| 1098 | else | ||
| 1099 | tem2 = name; | ||
| 1100 | |||
| 867 | count = 1; | 1101 | count = 1; |
| 868 | while (1) | 1102 | while (1) |
| 869 | { | 1103 | { |
| 870 | sprintf (number, "<%"pD"d>", ++count); | 1104 | gentemp = concat2 (tem2, make_formatted_string |
| 871 | gentemp = concat2 (name, build_string (number)); | 1105 | (number, "<%"pD"d>", ++count)); |
| 872 | tem = Fstring_equal (gentemp, ignore); | 1106 | tem = Fstring_equal (gentemp, ignore); |
| 873 | if (!NILP (tem)) | 1107 | if (!NILP (tem)) |
| 874 | return gentemp; | 1108 | return gentemp; |
| @@ -933,6 +1167,21 @@ If VARIABLE does not have a buffer-local binding in BUFFER, the value | |||
| 933 | is the default binding of the variable. */) | 1167 | is the default binding of the variable. */) |
| 934 | (register Lisp_Object variable, register Lisp_Object buffer) | 1168 | (register Lisp_Object variable, register Lisp_Object buffer) |
| 935 | { | 1169 | { |
| 1170 | register Lisp_Object result = buffer_local_value_1 (variable, buffer); | ||
| 1171 | |||
| 1172 | if (EQ (result, Qunbound)) | ||
| 1173 | xsignal1 (Qvoid_variable, variable); | ||
| 1174 | |||
| 1175 | return result; | ||
| 1176 | } | ||
| 1177 | |||
| 1178 | |||
| 1179 | /* Like Fbuffer_local_value, but return Qunbound if the variable is | ||
| 1180 | locally unbound. */ | ||
| 1181 | |||
| 1182 | Lisp_Object | ||
| 1183 | buffer_local_value_1 (Lisp_Object variable, Lisp_Object buffer) | ||
| 1184 | { | ||
| 936 | register struct buffer *buf; | 1185 | register struct buffer *buf; |
| 937 | register Lisp_Object result; | 1186 | register Lisp_Object result; |
| 938 | struct Lisp_Symbol *sym; | 1187 | struct Lisp_Symbol *sym; |
| @@ -977,29 +1226,28 @@ is the default binding of the variable. */) | |||
| 977 | { | 1226 | { |
| 978 | union Lisp_Fwd *fwd = SYMBOL_FWD (sym); | 1227 | union Lisp_Fwd *fwd = SYMBOL_FWD (sym); |
| 979 | if (BUFFER_OBJFWDP (fwd)) | 1228 | if (BUFFER_OBJFWDP (fwd)) |
| 980 | result = PER_BUFFER_VALUE (buf, XBUFFER_OBJFWD (fwd)->offset); | 1229 | result = per_buffer_value (buf, XBUFFER_OBJFWD (fwd)->offset); |
| 981 | else | 1230 | else |
| 982 | result = Fdefault_value (variable); | 1231 | result = Fdefault_value (variable); |
| 983 | break; | 1232 | break; |
| 984 | } | 1233 | } |
| 985 | default: abort (); | 1234 | default: emacs_abort (); |
| 986 | } | 1235 | } |
| 987 | 1236 | ||
| 988 | if (!EQ (result, Qunbound)) | 1237 | return result; |
| 989 | return result; | ||
| 990 | |||
| 991 | xsignal1 (Qvoid_variable, variable); | ||
| 992 | } | 1238 | } |
| 993 | 1239 | ||
| 994 | /* Return an alist of the Lisp-level buffer-local bindings of | 1240 | /* Return an alist of the Lisp-level buffer-local bindings of |
| 995 | buffer BUF. That is, don't include the variables maintained | 1241 | buffer BUF. That is, don't include the variables maintained |
| 996 | in special slots in the buffer object. */ | 1242 | in special slots in the buffer object. |
| 1243 | If not CLONE, replace elements of the form (VAR . unbound) | ||
| 1244 | by VAR. */ | ||
| 997 | 1245 | ||
| 998 | static Lisp_Object | 1246 | static Lisp_Object |
| 999 | buffer_lisp_local_variables (struct buffer *buf) | 1247 | buffer_lisp_local_variables (struct buffer *buf, bool clone) |
| 1000 | { | 1248 | { |
| 1001 | Lisp_Object result = Qnil; | 1249 | Lisp_Object result = Qnil; |
| 1002 | register Lisp_Object tail; | 1250 | Lisp_Object tail; |
| 1003 | for (tail = BVAR (buf, local_var_alist); CONSP (tail); tail = XCDR (tail)) | 1251 | for (tail = BVAR (buf, local_var_alist); CONSP (tail); tail = XCDR (tail)) |
| 1004 | { | 1252 | { |
| 1005 | Lisp_Object val, elt; | 1253 | Lisp_Object val, elt; |
| @@ -1016,7 +1264,7 @@ buffer_lisp_local_variables (struct buffer *buf) | |||
| 1016 | if (buf != current_buffer) | 1264 | if (buf != current_buffer) |
| 1017 | val = XCDR (elt); | 1265 | val = XCDR (elt); |
| 1018 | 1266 | ||
| 1019 | result = Fcons (EQ (val, Qunbound) | 1267 | result = Fcons (!clone && EQ (val, Qunbound) |
| 1020 | ? XCAR (elt) | 1268 | ? XCAR (elt) |
| 1021 | : Fcons (XCAR (elt), val), | 1269 | : Fcons (XCAR (elt), val), |
| 1022 | result); | 1270 | result); |
| @@ -1045,25 +1293,20 @@ No argument or nil as argument means use current buffer as BUFFER. */) | |||
| 1045 | buf = XBUFFER (buffer); | 1293 | buf = XBUFFER (buffer); |
| 1046 | } | 1294 | } |
| 1047 | 1295 | ||
| 1048 | result = buffer_lisp_local_variables (buf); | 1296 | result = buffer_lisp_local_variables (buf, 0); |
| 1049 | 1297 | ||
| 1050 | /* Add on all the variables stored in special slots. */ | 1298 | /* Add on all the variables stored in special slots. */ |
| 1051 | { | 1299 | { |
| 1052 | int offset, idx; | 1300 | int offset, idx; |
| 1053 | 1301 | ||
| 1054 | /* buffer-local Lisp variables start at `undo_list', | 1302 | FOR_EACH_PER_BUFFER_OBJECT_AT (offset) |
| 1055 | tho only the ones from `name' on are GC'd normally. */ | ||
| 1056 | for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER); | ||
| 1057 | offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER); | ||
| 1058 | /* sizeof EMACS_INT == sizeof Lisp_Object */ | ||
| 1059 | offset += (sizeof (EMACS_INT))) | ||
| 1060 | { | 1303 | { |
| 1061 | idx = PER_BUFFER_IDX (offset); | 1304 | idx = PER_BUFFER_IDX (offset); |
| 1062 | if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) | 1305 | if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) |
| 1063 | && SYMBOLP (PER_BUFFER_SYMBOL (offset))) | 1306 | && SYMBOLP (PER_BUFFER_SYMBOL (offset))) |
| 1064 | { | 1307 | { |
| 1065 | Lisp_Object sym = PER_BUFFER_SYMBOL (offset); | 1308 | Lisp_Object sym = PER_BUFFER_SYMBOL (offset); |
| 1066 | Lisp_Object val = PER_BUFFER_VALUE (buf, offset); | 1309 | Lisp_Object val = per_buffer_value (buf, offset); |
| 1067 | result = Fcons (EQ (val, Qunbound) ? sym : Fcons (sym, val), | 1310 | result = Fcons (EQ (val, Qunbound) ? sym : Fcons (sym, val), |
| 1068 | result); | 1311 | result); |
| 1069 | } | 1312 | } |
| @@ -1095,21 +1338,23 @@ DEFUN ("set-buffer-modified-p", Fset_buffer_modified_p, Sset_buffer_modified_p, | |||
| 1095 | 1, 1, 0, | 1338 | 1, 1, 0, |
| 1096 | doc: /* Mark current buffer as modified or unmodified according to FLAG. | 1339 | doc: /* Mark current buffer as modified or unmodified according to FLAG. |
| 1097 | A non-nil FLAG means mark the buffer modified. */) | 1340 | A non-nil FLAG means mark the buffer modified. */) |
| 1098 | (register Lisp_Object flag) | 1341 | (Lisp_Object flag) |
| 1099 | { | 1342 | { |
| 1100 | register int already; | 1343 | Lisp_Object fn; |
| 1101 | register Lisp_Object fn; | ||
| 1102 | Lisp_Object buffer, window; | ||
| 1103 | 1344 | ||
| 1104 | #ifdef CLASH_DETECTION | 1345 | #ifdef CLASH_DETECTION |
| 1105 | /* If buffer becoming modified, lock the file. | 1346 | /* If buffer becoming modified, lock the file. |
| 1106 | If buffer becoming unmodified, unlock the file. */ | 1347 | If buffer becoming unmodified, unlock the file. */ |
| 1107 | 1348 | ||
| 1108 | fn = BVAR (current_buffer, file_truename); | 1349 | struct buffer *b = current_buffer->base_buffer |
| 1350 | ? current_buffer->base_buffer | ||
| 1351 | : current_buffer; | ||
| 1352 | |||
| 1353 | fn = BVAR (b, file_truename); | ||
| 1109 | /* Test buffer-file-name so that binding it to nil is effective. */ | 1354 | /* Test buffer-file-name so that binding it to nil is effective. */ |
| 1110 | if (!NILP (fn) && ! NILP (BVAR (current_buffer, filename))) | 1355 | if (!NILP (fn) && ! NILP (BVAR (b, filename))) |
| 1111 | { | 1356 | { |
| 1112 | already = SAVE_MODIFF < MODIFF; | 1357 | bool already = SAVE_MODIFF < MODIFF; |
| 1113 | if (!already && !NILP (flag)) | 1358 | if (!already && !NILP (flag)) |
| 1114 | lock_file (fn); | 1359 | lock_file (fn); |
| 1115 | else if (already && NILP (flag)) | 1360 | else if (already && NILP (flag)) |
| @@ -1148,9 +1393,7 @@ A non-nil FLAG means mark the buffer modified. */) | |||
| 1148 | Ideally, I think there should be another mechanism for fontifying | 1393 | Ideally, I think there should be another mechanism for fontifying |
| 1149 | buffers without "modifying" buffers, or redisplay should be | 1394 | buffers without "modifying" buffers, or redisplay should be |
| 1150 | smarter about updating the `*' in mode lines. --gerd */ | 1395 | smarter about updating the `*' in mode lines. --gerd */ |
| 1151 | XSETBUFFER (buffer, current_buffer); | 1396 | if (buffer_window_count (current_buffer)) |
| 1152 | window = Fget_buffer_window (buffer, Qt); | ||
| 1153 | if (WINDOWP (window)) | ||
| 1154 | { | 1397 | { |
| 1155 | ++update_mode_lines; | 1398 | ++update_mode_lines; |
| 1156 | current_buffer->prevent_redisplay_optimizations_p = 1; | 1399 | current_buffer->prevent_redisplay_optimizations_p = 1; |
| @@ -1176,7 +1419,7 @@ state of the current buffer. Use with care. */) | |||
| 1176 | /* Test buffer-file-name so that binding it to nil is effective. */ | 1419 | /* Test buffer-file-name so that binding it to nil is effective. */ |
| 1177 | if (!NILP (fn) && ! NILP (BVAR (current_buffer, filename))) | 1420 | if (!NILP (fn) && ! NILP (BVAR (current_buffer, filename))) |
| 1178 | { | 1421 | { |
| 1179 | int already = SAVE_MODIFF < MODIFF; | 1422 | bool already = SAVE_MODIFF < MODIFF; |
| 1180 | if (!already && !NILP (flag)) | 1423 | if (!already && !NILP (flag)) |
| 1181 | lock_file (fn); | 1424 | lock_file (fn); |
| 1182 | else if (already && NILP (flag)) | 1425 | else if (already && NILP (flag)) |
| @@ -1268,7 +1511,7 @@ This does not change the name of the visited file (if any). */) | |||
| 1268 | error ("Buffer name `%s' is in use", SDATA (newname)); | 1511 | error ("Buffer name `%s' is in use", SDATA (newname)); |
| 1269 | } | 1512 | } |
| 1270 | 1513 | ||
| 1271 | BVAR (current_buffer, name) = newname; | 1514 | bset_name (current_buffer, newname); |
| 1272 | 1515 | ||
| 1273 | /* Catch redisplay's attention. Unless we do this, the mode lines for | 1516 | /* Catch redisplay's attention. Unless we do this, the mode lines for |
| 1274 | any windows displaying current_buffer will stay unchanged. */ | 1517 | any windows displaying current_buffer will stay unchanged. */ |
| @@ -1288,6 +1531,16 @@ This does not change the name of the visited file (if any). */) | |||
| 1288 | return BVAR (current_buffer, name); | 1531 | return BVAR (current_buffer, name); |
| 1289 | } | 1532 | } |
| 1290 | 1533 | ||
| 1534 | /* True if B can be used as 'other-than-BUFFER' buffer. */ | ||
| 1535 | |||
| 1536 | static bool | ||
| 1537 | candidate_buffer (Lisp_Object b, Lisp_Object buffer) | ||
| 1538 | { | ||
| 1539 | return (BUFFERP (b) && !EQ (b, buffer) | ||
| 1540 | && BUFFER_LIVE_P (XBUFFER (b)) | ||
| 1541 | && !BUFFER_HIDDEN_P (XBUFFER (b))); | ||
| 1542 | } | ||
| 1543 | |||
| 1291 | DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0, | 1544 | DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 3, 0, |
| 1292 | doc: /* Return most recently selected buffer other than BUFFER. | 1545 | doc: /* Return most recently selected buffer other than BUFFER. |
| 1293 | Buffers not visible in windows are preferred to visible buffers, unless | 1546 | Buffers not visible in windows are preferred to visible buffers, unless |
| @@ -1301,24 +1554,15 @@ list first, followed by the list of all buffers. If no other buffer | |||
| 1301 | exists, return the buffer `*scratch*' (creating it if necessary). */) | 1554 | exists, return the buffer `*scratch*' (creating it if necessary). */) |
| 1302 | (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame) | 1555 | (register Lisp_Object buffer, Lisp_Object visible_ok, Lisp_Object frame) |
| 1303 | { | 1556 | { |
| 1304 | Lisp_Object Fset_buffer_major_mode (Lisp_Object buffer); | 1557 | struct frame *f = decode_any_frame (frame); |
| 1305 | Lisp_Object tail, buf, pred; | 1558 | Lisp_Object tail = f->buffer_list, pred = f->buffer_predicate; |
| 1306 | Lisp_Object notsogood = Qnil; | 1559 | Lisp_Object buf, notsogood = Qnil; |
| 1307 | 1560 | ||
| 1308 | if (NILP (frame)) | ||
| 1309 | frame = selected_frame; | ||
| 1310 | |||
| 1311 | CHECK_FRAME (frame); | ||
| 1312 | |||
| 1313 | pred = frame_buffer_predicate (frame); | ||
| 1314 | /* Consider buffers that have been seen in the frame first. */ | 1561 | /* Consider buffers that have been seen in the frame first. */ |
| 1315 | tail = XFRAME (frame)->buffer_list; | ||
| 1316 | for (; CONSP (tail); tail = XCDR (tail)) | 1562 | for (; CONSP (tail); tail = XCDR (tail)) |
| 1317 | { | 1563 | { |
| 1318 | buf = XCAR (tail); | 1564 | buf = XCAR (tail); |
| 1319 | if (BUFFERP (buf) && !EQ (buf, buffer) | 1565 | if (candidate_buffer (buf, buffer) |
| 1320 | && !NILP (BVAR (XBUFFER (buf), name)) | ||
| 1321 | && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ') | ||
| 1322 | /* If the frame has a buffer_predicate, disregard buffers that | 1566 | /* If the frame has a buffer_predicate, disregard buffers that |
| 1323 | don't fit the predicate. */ | 1567 | don't fit the predicate. */ |
| 1324 | && (NILP (pred) || !NILP (call1 (pred, buf)))) | 1568 | && (NILP (pred) || !NILP (call1 (pred, buf)))) |
| @@ -1332,13 +1576,9 @@ exists, return the buffer `*scratch*' (creating it if necessary). */) | |||
| 1332 | } | 1576 | } |
| 1333 | 1577 | ||
| 1334 | /* Consider alist of all buffers next. */ | 1578 | /* Consider alist of all buffers next. */ |
| 1335 | tail = Vbuffer_alist; | 1579 | FOR_EACH_LIVE_BUFFER (tail, buf) |
| 1336 | for (; CONSP (tail); tail = XCDR (tail)) | ||
| 1337 | { | 1580 | { |
| 1338 | buf = Fcdr (XCAR (tail)); | 1581 | if (candidate_buffer (buf, buffer) |
| 1339 | if (BUFFERP (buf) && !EQ (buf, buffer) | ||
| 1340 | && !NILP (BVAR (XBUFFER (buf), name)) | ||
| 1341 | && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ') | ||
| 1342 | /* If the frame has a buffer_predicate, disregard buffers that | 1582 | /* If the frame has a buffer_predicate, disregard buffers that |
| 1343 | don't fit the predicate. */ | 1583 | don't fit the predicate. */ |
| 1344 | && (NILP (pred) || !NILP (call1 (pred, buf)))) | 1584 | && (NILP (pred) || !NILP (call1 (pred, buf)))) |
| @@ -1372,18 +1612,11 @@ exists, return the buffer `*scratch*' (creating it if necessary). */) | |||
| 1372 | Lisp_Object | 1612 | Lisp_Object |
| 1373 | other_buffer_safely (Lisp_Object buffer) | 1613 | other_buffer_safely (Lisp_Object buffer) |
| 1374 | { | 1614 | { |
| 1375 | Lisp_Object Fset_buffer_major_mode (Lisp_Object buffer); | ||
| 1376 | Lisp_Object tail, buf; | 1615 | Lisp_Object tail, buf; |
| 1377 | 1616 | ||
| 1378 | tail = Vbuffer_alist; | 1617 | FOR_EACH_LIVE_BUFFER (tail, buf) |
| 1379 | for (; CONSP (tail); tail = XCDR (tail)) | 1618 | if (candidate_buffer (buf, buffer)) |
| 1380 | { | 1619 | return buf; |
| 1381 | buf = Fcdr (XCAR (tail)); | ||
| 1382 | if (BUFFERP (buf) && !EQ (buf, buffer) | ||
| 1383 | && !NILP (BVAR (XBUFFER (buf), name)) | ||
| 1384 | && (SREF (BVAR (XBUFFER (buf), name), 0) != ' ')) | ||
| 1385 | return buf; | ||
| 1386 | } | ||
| 1387 | 1620 | ||
| 1388 | buf = Fget_buffer (build_string ("*scratch*")); | 1621 | buf = Fget_buffer (build_string ("*scratch*")); |
| 1389 | if (NILP (buf)) | 1622 | if (NILP (buf)) |
| @@ -1413,33 +1646,63 @@ No argument or nil as argument means do this for the current buffer. */) | |||
| 1413 | } | 1646 | } |
| 1414 | 1647 | ||
| 1415 | if (EQ (BVAR (XBUFFER (real_buffer), undo_list), Qt)) | 1648 | if (EQ (BVAR (XBUFFER (real_buffer), undo_list), Qt)) |
| 1416 | BVAR (XBUFFER (real_buffer), undo_list) = Qnil; | 1649 | bset_undo_list (XBUFFER (real_buffer), Qnil); |
| 1417 | 1650 | ||
| 1418 | return Qnil; | 1651 | return Qnil; |
| 1419 | } | 1652 | } |
| 1420 | 1653 | ||
| 1421 | /* | 1654 | /* Truncate undo list and shrink the gap of BUFFER. */ |
| 1422 | DEFVAR_LISP ("kill-buffer-hook", ..., "\ | 1655 | |
| 1423 | Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\ | 1656 | void |
| 1424 | The buffer being killed will be current while the hook is running.\n\ | 1657 | compact_buffer (struct buffer *buffer) |
| 1425 | See `kill-buffer'." | 1658 | { |
| 1426 | */ | 1659 | BUFFER_CHECK_INDIRECTION (buffer); |
| 1660 | |||
| 1661 | /* Skip dead buffers, indirect buffers and buffers | ||
| 1662 | which aren't changed since last compaction. */ | ||
| 1663 | if (BUFFER_LIVE_P (buffer) | ||
| 1664 | && (buffer->base_buffer == NULL) | ||
| 1665 | && (BUF_COMPACT (buffer) != BUF_MODIFF (buffer))) | ||
| 1666 | { | ||
| 1667 | /* If a buffer's undo list is Qt, that means that undo is | ||
| 1668 | turned off in that buffer. Calling truncate_undo_list on | ||
| 1669 | Qt tends to return NULL, which effectively turns undo back on. | ||
| 1670 | So don't call truncate_undo_list if undo_list is Qt. */ | ||
| 1671 | if (!EQ (buffer->INTERNAL_FIELD (undo_list), Qt)) | ||
| 1672 | truncate_undo_list (buffer); | ||
| 1673 | |||
| 1674 | /* Shrink buffer gaps. */ | ||
| 1675 | if (!buffer->text->inhibit_shrinking) | ||
| 1676 | { | ||
| 1677 | /* If a buffer's gap size is more than 10% of the buffer | ||
| 1678 | size, or larger than GAP_BYTES_DFL bytes, then shrink it | ||
| 1679 | accordingly. Keep a minimum size of GAP_BYTES_MIN bytes. */ | ||
| 1680 | ptrdiff_t size = clip_to_bounds (GAP_BYTES_MIN, | ||
| 1681 | BUF_Z_BYTE (buffer) / 10, | ||
| 1682 | GAP_BYTES_DFL); | ||
| 1683 | if (BUF_GAP_SIZE (buffer) > size) | ||
| 1684 | make_gap_1 (buffer, -(BUF_GAP_SIZE (buffer) - size)); | ||
| 1685 | } | ||
| 1686 | BUF_COMPACT (buffer) = BUF_MODIFF (buffer); | ||
| 1687 | } | ||
| 1688 | } | ||
| 1689 | |||
| 1427 | DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ", | 1690 | DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ", |
| 1428 | doc: /* Kill buffer BUFFER-OR-NAME. | 1691 | doc: /* Kill the buffer specified by BUFFER-OR-NAME. |
| 1429 | The argument may be a buffer or the name of an existing buffer. | 1692 | The argument may be a buffer or the name of an existing buffer. |
| 1430 | Argument nil or omitted means kill the current buffer. Return t if the | 1693 | Argument nil or omitted means kill the current buffer. Return t if the |
| 1431 | buffer is actually killed, nil otherwise. | 1694 | buffer is actually killed, nil otherwise. |
| 1432 | 1695 | ||
| 1433 | This function calls `replace-buffer-in-windows' for cleaning up all | 1696 | The functions in `kill-buffer-query-functions' are called with the |
| 1434 | windows currently displaying the buffer to be killed. The functions in | 1697 | buffer to be killed as the current buffer. If any of them returns nil, |
| 1435 | `kill-buffer-query-functions' are called with the buffer to be killed as | 1698 | the buffer is not killed. The hook `kill-buffer-hook' is run before the |
| 1436 | the current buffer. If any of them returns nil, the buffer is not | 1699 | buffer is actually killed. The buffer being killed will be current |
| 1437 | killed. The hook `kill-buffer-hook' is run before the buffer is | 1700 | while the hook is running. Functions called by any of these hooks are |
| 1438 | actually killed. The buffer being killed will be current while the hook | 1701 | supposed to not change the current buffer. |
| 1439 | is running. | ||
| 1440 | 1702 | ||
| 1441 | Any processes that have this buffer as the `process-buffer' are killed | 1703 | Any processes that have this buffer as the `process-buffer' are killed |
| 1442 | with SIGHUP. */) | 1704 | with SIGHUP. This function calls `replace-buffer-in-windows' for |
| 1705 | cleaning up all windows currently displaying the buffer to be killed. */) | ||
| 1443 | (Lisp_Object buffer_or_name) | 1706 | (Lisp_Object buffer_or_name) |
| 1444 | { | 1707 | { |
| 1445 | Lisp_Object buffer; | 1708 | Lisp_Object buffer; |
| @@ -1458,21 +1721,9 @@ with SIGHUP. */) | |||
| 1458 | b = XBUFFER (buffer); | 1721 | b = XBUFFER (buffer); |
| 1459 | 1722 | ||
| 1460 | /* Avoid trouble for buffer already dead. */ | 1723 | /* Avoid trouble for buffer already dead. */ |
| 1461 | if (NILP (BVAR (b, name))) | 1724 | if (!BUFFER_LIVE_P (b)) |
| 1462 | return Qnil; | 1725 | return Qnil; |
| 1463 | 1726 | ||
| 1464 | /* Query if the buffer is still modified. */ | ||
| 1465 | if (INTERACTIVE && !NILP (BVAR (b, filename)) | ||
| 1466 | && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | ||
| 1467 | { | ||
| 1468 | GCPRO1 (buffer); | ||
| 1469 | tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ", | ||
| 1470 | BVAR (b, name), make_number (0))); | ||
| 1471 | UNGCPRO; | ||
| 1472 | if (NILP (tem)) | ||
| 1473 | return Qnil; | ||
| 1474 | } | ||
| 1475 | |||
| 1476 | /* Run hooks with the buffer to be killed the current buffer. */ | 1727 | /* Run hooks with the buffer to be killed the current buffer. */ |
| 1477 | { | 1728 | { |
| 1478 | ptrdiff_t count = SPECPDL_INDEX (); | 1729 | ptrdiff_t count = SPECPDL_INDEX (); |
| @@ -1488,35 +1739,51 @@ with SIGHUP. */) | |||
| 1488 | if (NILP (tem)) | 1739 | if (NILP (tem)) |
| 1489 | return unbind_to (count, Qnil); | 1740 | return unbind_to (count, Qnil); |
| 1490 | 1741 | ||
| 1742 | /* Query if the buffer is still modified. */ | ||
| 1743 | if (INTERACTIVE && !NILP (BVAR (b, filename)) | ||
| 1744 | && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | ||
| 1745 | { | ||
| 1746 | GCPRO1 (buffer); | ||
| 1747 | tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ", | ||
| 1748 | BVAR (b, name), make_number (0))); | ||
| 1749 | UNGCPRO; | ||
| 1750 | if (NILP (tem)) | ||
| 1751 | return unbind_to (count, Qnil); | ||
| 1752 | } | ||
| 1753 | |||
| 1754 | /* If the hooks have killed the buffer, exit now. */ | ||
| 1755 | if (!BUFFER_LIVE_P (b)) | ||
| 1756 | return unbind_to (count, Qt); | ||
| 1757 | |||
| 1491 | /* Then run the hooks. */ | 1758 | /* Then run the hooks. */ |
| 1492 | Frun_hooks (1, &Qkill_buffer_hook); | 1759 | Frun_hooks (1, &Qkill_buffer_hook); |
| 1493 | unbind_to (count, Qnil); | 1760 | unbind_to (count, Qnil); |
| 1494 | } | 1761 | } |
| 1495 | 1762 | ||
| 1763 | /* If the hooks have killed the buffer, exit now. */ | ||
| 1764 | if (!BUFFER_LIVE_P (b)) | ||
| 1765 | return Qt; | ||
| 1766 | |||
| 1496 | /* We have no more questions to ask. Verify that it is valid | 1767 | /* We have no more questions to ask. Verify that it is valid |
| 1497 | to kill the buffer. This must be done after the questions | 1768 | to kill the buffer. This must be done after the questions |
| 1498 | since anything can happen within do_yes_or_no_p. */ | 1769 | since anything can happen within do_yes_or_no_p. */ |
| 1499 | 1770 | ||
| 1500 | /* Don't kill the minibuffer now current. */ | 1771 | /* Don't kill the minibuffer now current. */ |
| 1501 | if (EQ (buffer, XWINDOW (minibuf_window)->buffer)) | 1772 | if (EQ (buffer, XWINDOW (minibuf_window)->contents)) |
| 1502 | return Qnil; | 1773 | return Qnil; |
| 1503 | 1774 | ||
| 1504 | if (NILP (BVAR (b, name))) | 1775 | /* When we kill an ordinary buffer which shares it's buffer text |
| 1505 | return Qnil; | 1776 | with indirect buffer(s), we must kill indirect buffer(s) too. |
| 1506 | |||
| 1507 | /* When we kill a base buffer, kill all its indirect buffers. | ||
| 1508 | We do it at this stage so nothing terrible happens if they | 1777 | We do it at this stage so nothing terrible happens if they |
| 1509 | ask questions or their hooks get errors. */ | 1778 | ask questions or their hooks get errors. */ |
| 1510 | if (! b->base_buffer) | 1779 | if (!b->base_buffer && b->indirections > 0) |
| 1511 | { | 1780 | { |
| 1512 | struct buffer *other; | 1781 | struct buffer *other; |
| 1513 | 1782 | ||
| 1514 | GCPRO1 (buffer); | 1783 | GCPRO1 (buffer); |
| 1515 | 1784 | ||
| 1516 | for (other = all_buffers; other; other = other->header.next.buffer) | 1785 | FOR_EACH_BUFFER (other) |
| 1517 | /* all_buffers contains dead buffers too; | 1786 | if (other->base_buffer == b) |
| 1518 | don't re-kill them. */ | ||
| 1519 | if (other->base_buffer == b && !NILP (BVAR (other, name))) | ||
| 1520 | { | 1787 | { |
| 1521 | Lisp_Object buf; | 1788 | Lisp_Object buf; |
| 1522 | XSETBUFFER (buf, other); | 1789 | XSETBUFFER (buf, other); |
| @@ -1524,6 +1791,10 @@ with SIGHUP. */) | |||
| 1524 | } | 1791 | } |
| 1525 | 1792 | ||
| 1526 | UNGCPRO; | 1793 | UNGCPRO; |
| 1794 | |||
| 1795 | /* Exit if we now have killed the base buffer (Bug#11665). */ | ||
| 1796 | if (!BUFFER_LIVE_P (b)) | ||
| 1797 | return Qt; | ||
| 1527 | } | 1798 | } |
| 1528 | 1799 | ||
| 1529 | /* Run replace_buffer_in_windows before making another buffer current | 1800 | /* Run replace_buffer_in_windows before making another buffer current |
| @@ -1532,9 +1803,12 @@ with SIGHUP. */) | |||
| 1532 | buffer. (Bug#10114) */ | 1803 | buffer. (Bug#10114) */ |
| 1533 | replace_buffer_in_windows (buffer); | 1804 | replace_buffer_in_windows (buffer); |
| 1534 | 1805 | ||
| 1535 | /* Make this buffer not be current. | 1806 | /* Exit if replacing the buffer in windows has killed our buffer. */ |
| 1536 | In the process, notice if this is the sole visible buffer | 1807 | if (!BUFFER_LIVE_P (b)) |
| 1537 | and give up if so. */ | 1808 | return Qt; |
| 1809 | |||
| 1810 | /* Make this buffer not be current. Exit if it is the sole visible | ||
| 1811 | buffer. */ | ||
| 1538 | if (b == current_buffer) | 1812 | if (b == current_buffer) |
| 1539 | { | 1813 | { |
| 1540 | tem = Fother_buffer (buffer, Qnil, Qnil); | 1814 | tem = Fother_buffer (buffer, Qnil, Qnil); |
| @@ -1543,15 +1817,12 @@ with SIGHUP. */) | |||
| 1543 | return Qnil; | 1817 | return Qnil; |
| 1544 | } | 1818 | } |
| 1545 | 1819 | ||
| 1546 | /* Notice if the buffer to kill is the sole visible buffer | 1820 | /* If the buffer now current is shown in the minibuffer and our buffer |
| 1547 | when we're currently in the mini-buffer, and give up if so. */ | 1821 | is the sole other buffer give up. */ |
| 1548 | XSETBUFFER (tem, current_buffer); | 1822 | XSETBUFFER (tem, current_buffer); |
| 1549 | if (EQ (tem, XWINDOW (minibuf_window)->buffer)) | 1823 | if (EQ (tem, XWINDOW (minibuf_window)->contents) |
| 1550 | { | 1824 | && EQ (buffer, Fother_buffer (buffer, Qnil, Qnil))) |
| 1551 | tem = Fother_buffer (buffer, Qnil, Qnil); | 1825 | return Qnil; |
| 1552 | if (EQ (buffer, tem)) | ||
| 1553 | return Qnil; | ||
| 1554 | } | ||
| 1555 | 1826 | ||
| 1556 | /* Now there is no question: we can kill the buffer. */ | 1827 | /* Now there is no question: we can kill the buffer. */ |
| 1557 | 1828 | ||
| @@ -1564,11 +1835,10 @@ with SIGHUP. */) | |||
| 1564 | kill_buffer_processes (buffer); | 1835 | kill_buffer_processes (buffer); |
| 1565 | UNGCPRO; | 1836 | UNGCPRO; |
| 1566 | 1837 | ||
| 1567 | /* Killing buffer processes may run sentinels which may | 1838 | /* Killing buffer processes may run sentinels which may have killed |
| 1568 | have called kill-buffer. */ | 1839 | our buffer. */ |
| 1569 | 1840 | if (!BUFFER_LIVE_P (b)) | |
| 1570 | if (NILP (BVAR (b, name))) | 1841 | return Qt; |
| 1571 | return Qnil; | ||
| 1572 | 1842 | ||
| 1573 | /* These may run Lisp code and into infinite loops (if someone | 1843 | /* These may run Lisp code and into infinite loops (if someone |
| 1574 | insisted on circular lists) so allow quitting here. */ | 1844 | insisted on circular lists) so allow quitting here. */ |
| @@ -1580,8 +1850,7 @@ with SIGHUP. */) | |||
| 1580 | Vinhibit_quit = Qt; | 1850 | Vinhibit_quit = Qt; |
| 1581 | /* Remove the buffer from the list of all buffers. */ | 1851 | /* Remove the buffer from the list of all buffers. */ |
| 1582 | Vbuffer_alist = Fdelq (Frassq (buffer, Vbuffer_alist), Vbuffer_alist); | 1852 | Vbuffer_alist = Fdelq (Frassq (buffer, Vbuffer_alist), Vbuffer_alist); |
| 1583 | /* If replace_buffer_in_windows didn't do its job correctly fix that | 1853 | /* If replace_buffer_in_windows didn't do its job fix that now. */ |
| 1584 | now. */ | ||
| 1585 | replace_buffer_in_windows_safely (buffer); | 1854 | replace_buffer_in_windows_safely (buffer); |
| 1586 | Vinhibit_quit = tem; | 1855 | Vinhibit_quit = tem; |
| 1587 | 1856 | ||
| @@ -1599,17 +1868,25 @@ with SIGHUP. */) | |||
| 1599 | internal_delete_file (BVAR (b, auto_save_file_name)); | 1868 | internal_delete_file (BVAR (b, auto_save_file_name)); |
| 1600 | } | 1869 | } |
| 1601 | 1870 | ||
| 1871 | /* Deleting an auto-save file could have killed our buffer. */ | ||
| 1872 | if (!BUFFER_LIVE_P (b)) | ||
| 1873 | return Qt; | ||
| 1874 | |||
| 1602 | if (b->base_buffer) | 1875 | if (b->base_buffer) |
| 1603 | { | 1876 | { |
| 1604 | /* Unchain all markers that belong to this indirect buffer. | 1877 | /* Unchain all markers that belong to this indirect buffer. |
| 1605 | Don't unchain the markers that belong to the base buffer | 1878 | Don't unchain the markers that belong to the base buffer |
| 1606 | or its other indirect buffers. */ | 1879 | or its other indirect buffers. */ |
| 1607 | for (m = BUF_MARKERS (b); m; ) | 1880 | struct Lisp_Marker **mp = &BUF_MARKERS (b); |
| 1881 | while ((m = *mp)) | ||
| 1608 | { | 1882 | { |
| 1609 | struct Lisp_Marker *next = m->next; | ||
| 1610 | if (m->buffer == b) | 1883 | if (m->buffer == b) |
| 1611 | unchain_marker (m); | 1884 | { |
| 1612 | m = next; | 1885 | m->buffer = NULL; |
| 1886 | *mp = m->next; | ||
| 1887 | } | ||
| 1888 | else | ||
| 1889 | mp = &m->next; | ||
| 1613 | } | 1890 | } |
| 1614 | } | 1891 | } |
| 1615 | else | 1892 | else |
| @@ -1624,10 +1901,14 @@ with SIGHUP. */) | |||
| 1624 | m = next; | 1901 | m = next; |
| 1625 | } | 1902 | } |
| 1626 | BUF_MARKERS (b) = NULL; | 1903 | BUF_MARKERS (b) = NULL; |
| 1627 | BUF_INTERVALS (b) = NULL_INTERVAL; | 1904 | set_buffer_intervals (b, NULL); |
| 1628 | 1905 | ||
| 1629 | /* Perhaps we should explicitly free the interval tree here... */ | 1906 | /* Perhaps we should explicitly free the interval tree here... */ |
| 1630 | } | 1907 | } |
| 1908 | /* Since we've unlinked the markers, the overlays can't be here any more | ||
| 1909 | either. */ | ||
| 1910 | b->overlays_before = NULL; | ||
| 1911 | b->overlays_after = NULL; | ||
| 1631 | 1912 | ||
| 1632 | /* Reset the local variables, so that this buffer's local values | 1913 | /* Reset the local variables, so that this buffer's local values |
| 1633 | won't be protected from GC. They would be protected | 1914 | won't be protected from GC. They would be protected |
| @@ -1636,11 +1917,25 @@ with SIGHUP. */) | |||
| 1636 | swap_out_buffer_local_variables (b); | 1917 | swap_out_buffer_local_variables (b); |
| 1637 | reset_buffer_local_variables (b, 1); | 1918 | reset_buffer_local_variables (b, 1); |
| 1638 | 1919 | ||
| 1639 | BVAR (b, name) = Qnil; | 1920 | bset_name (b, Qnil); |
| 1640 | 1921 | ||
| 1641 | BLOCK_INPUT; | 1922 | block_input (); |
| 1642 | if (! b->base_buffer) | 1923 | if (b->base_buffer) |
| 1643 | free_buffer_text (b); | 1924 | { |
| 1925 | /* Notify our base buffer that we don't share the text anymore. */ | ||
| 1926 | eassert (b->indirections == -1); | ||
| 1927 | b->base_buffer->indirections--; | ||
| 1928 | eassert (b->base_buffer->indirections >= 0); | ||
| 1929 | /* Make sure that we wasn't confused. */ | ||
| 1930 | eassert (b->window_count == -1); | ||
| 1931 | } | ||
| 1932 | else | ||
| 1933 | { | ||
| 1934 | /* Make sure that no one shows us. */ | ||
| 1935 | eassert (b->window_count == 0); | ||
| 1936 | /* No one shares our buffer text, can free it. */ | ||
| 1937 | free_buffer_text (b); | ||
| 1938 | } | ||
| 1644 | 1939 | ||
| 1645 | if (b->newline_cache) | 1940 | if (b->newline_cache) |
| 1646 | { | 1941 | { |
| @@ -1652,9 +1947,14 @@ with SIGHUP. */) | |||
| 1652 | free_region_cache (b->width_run_cache); | 1947 | free_region_cache (b->width_run_cache); |
| 1653 | b->width_run_cache = 0; | 1948 | b->width_run_cache = 0; |
| 1654 | } | 1949 | } |
| 1655 | BVAR (b, width_table) = Qnil; | 1950 | if (b->bidi_paragraph_cache) |
| 1656 | UNBLOCK_INPUT; | 1951 | { |
| 1657 | BVAR (b, undo_list) = Qnil; | 1952 | free_region_cache (b->bidi_paragraph_cache); |
| 1953 | b->bidi_paragraph_cache = 0; | ||
| 1954 | } | ||
| 1955 | bset_width_table (b, Qnil); | ||
| 1956 | unblock_input (); | ||
| 1957 | bset_undo_list (b, Qnil); | ||
| 1658 | 1958 | ||
| 1659 | /* Run buffer-list-update-hook. */ | 1959 | /* Run buffer-list-update-hook. */ |
| 1660 | if (!NILP (Vrun_hooks)) | 1960 | if (!NILP (Vrun_hooks)) |
| @@ -1695,8 +1995,8 @@ record_buffer (Lisp_Object buffer) | |||
| 1695 | Vinhibit_quit = tem; | 1995 | Vinhibit_quit = tem; |
| 1696 | 1996 | ||
| 1697 | /* Update buffer list of selected frame. */ | 1997 | /* Update buffer list of selected frame. */ |
| 1698 | f->buffer_list = Fcons (buffer, Fdelq (buffer, f->buffer_list)); | 1998 | fset_buffer_list (f, Fcons (buffer, Fdelq (buffer, f->buffer_list))); |
| 1699 | f->buried_buffer_list = Fdelq (buffer, f->buried_buffer_list); | 1999 | fset_buried_buffer_list (f, Fdelq (buffer, f->buried_buffer_list)); |
| 1700 | 2000 | ||
| 1701 | /* Run buffer-list-update-hook. */ | 2001 | /* Run buffer-list-update-hook. */ |
| 1702 | if (!NILP (Vrun_hooks)) | 2002 | if (!NILP (Vrun_hooks)) |
| @@ -1733,8 +2033,9 @@ DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal, | |||
| 1733 | Vinhibit_quit = tem; | 2033 | Vinhibit_quit = tem; |
| 1734 | 2034 | ||
| 1735 | /* Update buffer lists of selected frame. */ | 2035 | /* Update buffer lists of selected frame. */ |
| 1736 | f->buffer_list = Fdelq (buffer, f->buffer_list); | 2036 | fset_buffer_list (f, Fdelq (buffer, f->buffer_list)); |
| 1737 | f->buried_buffer_list = Fcons (buffer, Fdelq (buffer, f->buried_buffer_list)); | 2037 | fset_buried_buffer_list |
| 2038 | (f, Fcons (buffer, Fdelq (buffer, f->buried_buffer_list))); | ||
| 1738 | 2039 | ||
| 1739 | /* Run buffer-list-update-hook. */ | 2040 | /* Run buffer-list-update-hook. */ |
| 1740 | if (!NILP (Vrun_hooks)) | 2041 | if (!NILP (Vrun_hooks)) |
| @@ -1746,7 +2047,7 @@ DEFUN ("bury-buffer-internal", Fbury_buffer_internal, Sbury_buffer_internal, | |||
| 1746 | DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0, | 2047 | DEFUN ("set-buffer-major-mode", Fset_buffer_major_mode, Sset_buffer_major_mode, 1, 1, 0, |
| 1747 | doc: /* Set an appropriate major mode for BUFFER. | 2048 | doc: /* Set an appropriate major mode for BUFFER. |
| 1748 | For the *scratch* buffer, use `initial-major-mode', otherwise choose a mode | 2049 | For the *scratch* buffer, use `initial-major-mode', otherwise choose a mode |
| 1749 | according to `default-major-mode'. | 2050 | according to the default value of `major-mode'. |
| 1750 | Use this function before selecting the buffer, since it may need to inspect | 2051 | Use this function before selecting the buffer, since it may need to inspect |
| 1751 | the current buffer's major mode. */) | 2052 | the current buffer's major mode. */) |
| 1752 | (Lisp_Object buffer) | 2053 | (Lisp_Object buffer) |
| @@ -1756,8 +2057,10 @@ the current buffer's major mode. */) | |||
| 1756 | 2057 | ||
| 1757 | CHECK_BUFFER (buffer); | 2058 | CHECK_BUFFER (buffer); |
| 1758 | 2059 | ||
| 1759 | if (STRINGP (BVAR (XBUFFER (buffer), name)) | 2060 | if (!BUFFER_LIVE_P (XBUFFER (buffer))) |
| 1760 | && strcmp (SSDATA (BVAR (XBUFFER (buffer), name)), "*scratch*") == 0) | 2061 | error ("Attempt to set major mode for a dead buffer"); |
| 2062 | |||
| 2063 | if (strcmp (SSDATA (BVAR (XBUFFER (buffer), name)), "*scratch*") == 0) | ||
| 1761 | function = find_symbol_value (intern ("initial-major-mode")); | 2064 | function = find_symbol_value (intern ("initial-major-mode")); |
| 1762 | else | 2065 | else |
| 1763 | { | 2066 | { |
| @@ -1791,22 +2094,6 @@ DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0, | |||
| 1791 | XSETBUFFER (buf, current_buffer); | 2094 | XSETBUFFER (buf, current_buffer); |
| 1792 | return buf; | 2095 | return buf; |
| 1793 | } | 2096 | } |
| 1794 | |||
| 1795 | /* Set the current buffer to B. | ||
| 1796 | |||
| 1797 | We previously set windows_or_buffers_changed here to invalidate | ||
| 1798 | global unchanged information in beg_unchanged and end_unchanged. | ||
| 1799 | This is no longer necessary because we now compute unchanged | ||
| 1800 | information on a buffer-basis. Every action affecting other | ||
| 1801 | windows than the selected one requires a select_window at some | ||
| 1802 | time, and that increments windows_or_buffers_changed. */ | ||
| 1803 | |||
| 1804 | void | ||
| 1805 | set_buffer_internal (register struct buffer *b) | ||
| 1806 | { | ||
| 1807 | if (current_buffer != b) | ||
| 1808 | set_buffer_internal_1 (b); | ||
| 1809 | } | ||
| 1810 | 2097 | ||
| 1811 | /* Set the current buffer to B, and do not set windows_or_buffers_changed. | 2098 | /* Set the current buffer to B, and do not set windows_or_buffers_changed. |
| 1812 | This is used by redisplay. */ | 2099 | This is used by redisplay. */ |
| @@ -1825,6 +2112,8 @@ set_buffer_internal_1 (register struct buffer *b) | |||
| 1825 | if (current_buffer == b) | 2112 | if (current_buffer == b) |
| 1826 | return; | 2113 | return; |
| 1827 | 2114 | ||
| 2115 | BUFFER_CHECK_INDIRECTION (b); | ||
| 2116 | |||
| 1828 | old_buf = current_buffer; | 2117 | old_buf = current_buffer; |
| 1829 | current_buffer = b; | 2118 | current_buffer = b; |
| 1830 | last_known_column_point = -1; /* invalidate indentation cache */ | 2119 | last_known_column_point = -1; /* invalidate indentation cache */ |
| @@ -1834,7 +2123,7 @@ set_buffer_internal_1 (register struct buffer *b) | |||
| 1834 | /* Put the undo list back in the base buffer, so that it appears | 2123 | /* Put the undo list back in the base buffer, so that it appears |
| 1835 | that an indirect buffer shares the undo list of its base. */ | 2124 | that an indirect buffer shares the undo list of its base. */ |
| 1836 | if (old_buf->base_buffer) | 2125 | if (old_buf->base_buffer) |
| 1837 | BVAR (old_buf->base_buffer, undo_list) = BVAR (old_buf, undo_list); | 2126 | bset_undo_list (old_buf->base_buffer, BVAR (old_buf, undo_list)); |
| 1838 | 2127 | ||
| 1839 | /* If the old current buffer has markers to record PT, BEGV and ZV | 2128 | /* If the old current buffer has markers to record PT, BEGV and ZV |
| 1840 | when it is not current, update them now. */ | 2129 | when it is not current, update them now. */ |
| @@ -1844,7 +2133,7 @@ set_buffer_internal_1 (register struct buffer *b) | |||
| 1844 | /* Get the undo list from the base buffer, so that it appears | 2133 | /* Get the undo list from the base buffer, so that it appears |
| 1845 | that an indirect buffer shares the undo list of its base. */ | 2134 | that an indirect buffer shares the undo list of its base. */ |
| 1846 | if (b->base_buffer) | 2135 | if (b->base_buffer) |
| 1847 | BVAR (b, undo_list) = BVAR (b->base_buffer, undo_list); | 2136 | bset_undo_list (b, BVAR (b->base_buffer, undo_list)); |
| 1848 | 2137 | ||
| 1849 | /* If the new current buffer has markers to record PT, BEGV and ZV | 2138 | /* If the new current buffer has markers to record PT, BEGV and ZV |
| 1850 | when it is not current, fetch them now. */ | 2139 | when it is not current, fetch them now. */ |
| @@ -1896,7 +2185,7 @@ set_buffer_temp (struct buffer *b) | |||
| 1896 | DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0, | 2185 | DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0, |
| 1897 | doc: /* Make buffer BUFFER-OR-NAME current for editing operations. | 2186 | doc: /* Make buffer BUFFER-OR-NAME current for editing operations. |
| 1898 | BUFFER-OR-NAME may be a buffer or the name of an existing buffer. See | 2187 | BUFFER-OR-NAME may be a buffer or the name of an existing buffer. See |
| 1899 | also `save-excursion' when you want to make a buffer current | 2188 | also `with-current-buffer' when you want to make a buffer current |
| 1900 | temporarily. This function does not display the buffer, so its effect | 2189 | temporarily. This function does not display the buffer, so its effect |
| 1901 | ends when the current command terminates. Use `switch-to-buffer' or | 2190 | ends when the current command terminates. Use `switch-to-buffer' or |
| 1902 | `pop-to-buffer' to switch buffers permanently. */) | 2191 | `pop-to-buffer' to switch buffers permanently. */) |
| @@ -1906,20 +2195,25 @@ ends when the current command terminates. Use `switch-to-buffer' or | |||
| 1906 | buffer = Fget_buffer (buffer_or_name); | 2195 | buffer = Fget_buffer (buffer_or_name); |
| 1907 | if (NILP (buffer)) | 2196 | if (NILP (buffer)) |
| 1908 | nsberror (buffer_or_name); | 2197 | nsberror (buffer_or_name); |
| 1909 | if (NILP (BVAR (XBUFFER (buffer), name))) | 2198 | if (!BUFFER_LIVE_P (XBUFFER (buffer))) |
| 1910 | error ("Selecting deleted buffer"); | 2199 | error ("Selecting deleted buffer"); |
| 1911 | set_buffer_internal (XBUFFER (buffer)); | 2200 | set_buffer_internal (XBUFFER (buffer)); |
| 1912 | return buffer; | 2201 | return buffer; |
| 1913 | } | 2202 | } |
| 1914 | 2203 | ||
| 1915 | /* Set the current buffer to BUFFER provided it is alive. */ | 2204 | void |
| 2205 | restore_buffer (Lisp_Object buffer_or_name) | ||
| 2206 | { | ||
| 2207 | Fset_buffer (buffer_or_name); | ||
| 2208 | } | ||
| 1916 | 2209 | ||
| 1917 | Lisp_Object | 2210 | /* Set the current buffer to BUFFER provided if it is alive. */ |
| 2211 | |||
| 2212 | void | ||
| 1918 | set_buffer_if_live (Lisp_Object buffer) | 2213 | set_buffer_if_live (Lisp_Object buffer) |
| 1919 | { | 2214 | { |
| 1920 | if (! NILP (BVAR (XBUFFER (buffer), name))) | 2215 | if (BUFFER_LIVE_P (XBUFFER (buffer))) |
| 1921 | Fset_buffer (buffer); | 2216 | set_buffer_internal (XBUFFER (buffer)); |
| 1922 | return Qnil; | ||
| 1923 | } | 2217 | } |
| 1924 | 2218 | ||
| 1925 | DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, | 2219 | DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, |
| @@ -2012,7 +2306,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text, | |||
| 2012 | CHECK_BUFFER (buffer); | 2306 | CHECK_BUFFER (buffer); |
| 2013 | other_buffer = XBUFFER (buffer); | 2307 | other_buffer = XBUFFER (buffer); |
| 2014 | 2308 | ||
| 2015 | if (NILP (BVAR (other_buffer, name))) | 2309 | if (!BUFFER_LIVE_P (other_buffer)) |
| 2016 | error ("Cannot swap a dead buffer's text"); | 2310 | error ("Cannot swap a dead buffer's text"); |
| 2017 | 2311 | ||
| 2018 | /* Actually, it probably works just fine. | 2312 | /* Actually, it probably works just fine. |
| @@ -2027,7 +2321,7 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text, | |||
| 2027 | 2321 | ||
| 2028 | { /* This is probably harder to make work. */ | 2322 | { /* This is probably harder to make work. */ |
| 2029 | struct buffer *other; | 2323 | struct buffer *other; |
| 2030 | for (other = all_buffers; other; other = other->header.next.buffer) | 2324 | FOR_EACH_BUFFER (other) |
| 2031 | if (other->base_buffer == other_buffer | 2325 | if (other->base_buffer == other_buffer |
| 2032 | || other->base_buffer == current_buffer) | 2326 | || other->base_buffer == current_buffer) |
| 2033 | error ("One of the buffers to swap has indirect buffers"); | 2327 | error ("One of the buffers to swap has indirect buffers"); |
| @@ -2042,8 +2336,8 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text, | |||
| 2042 | #define swapfield_(field, type) \ | 2336 | #define swapfield_(field, type) \ |
| 2043 | do { \ | 2337 | do { \ |
| 2044 | type tmp##field = BVAR (other_buffer, field); \ | 2338 | type tmp##field = BVAR (other_buffer, field); \ |
| 2045 | BVAR (other_buffer, field) = BVAR (current_buffer, field); \ | 2339 | bset_##field (other_buffer, BVAR (current_buffer, field)); \ |
| 2046 | BVAR (current_buffer, field) = tmp##field; \ | 2340 | bset_##field (current_buffer, tmp##field); \ |
| 2047 | } while (0) | 2341 | } while (0) |
| 2048 | 2342 | ||
| 2049 | swapfield (own_text, struct buffer_text); | 2343 | swapfield (own_text, struct buffer_text); |
| @@ -2064,9 +2358,11 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text, | |||
| 2064 | swapfield (zv_byte, ptrdiff_t); | 2358 | swapfield (zv_byte, ptrdiff_t); |
| 2065 | eassert (!current_buffer->base_buffer); | 2359 | eassert (!current_buffer->base_buffer); |
| 2066 | eassert (!other_buffer->base_buffer); | 2360 | eassert (!other_buffer->base_buffer); |
| 2361 | swapfield (indirections, ptrdiff_t); | ||
| 2067 | current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; | 2362 | current_buffer->clip_changed = 1; other_buffer->clip_changed = 1; |
| 2068 | swapfield (newline_cache, struct region_cache *); | 2363 | swapfield (newline_cache, struct region_cache *); |
| 2069 | swapfield (width_run_cache, struct region_cache *); | 2364 | swapfield (width_run_cache, struct region_cache *); |
| 2365 | swapfield (bidi_paragraph_cache, struct region_cache *); | ||
| 2070 | current_buffer->prevent_redisplay_optimizations_p = 1; | 2366 | current_buffer->prevent_redisplay_optimizations_p = 1; |
| 2071 | other_buffer->prevent_redisplay_optimizations_p = 1; | 2367 | other_buffer->prevent_redisplay_optimizations_p = 1; |
| 2072 | swapfield (overlays_before, struct Lisp_Overlay *); | 2368 | swapfield (overlays_before, struct Lisp_Overlay *); |
| @@ -2082,8 +2378,8 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text, | |||
| 2082 | swapfield_ (pt_marker, Lisp_Object); | 2378 | swapfield_ (pt_marker, Lisp_Object); |
| 2083 | swapfield_ (begv_marker, Lisp_Object); | 2379 | swapfield_ (begv_marker, Lisp_Object); |
| 2084 | swapfield_ (zv_marker, Lisp_Object); | 2380 | swapfield_ (zv_marker, Lisp_Object); |
| 2085 | BVAR (current_buffer, point_before_scroll) = Qnil; | 2381 | bset_point_before_scroll (current_buffer, Qnil); |
| 2086 | BVAR (other_buffer, point_before_scroll) = Qnil; | 2382 | bset_point_before_scroll (other_buffer, Qnil); |
| 2087 | 2383 | ||
| 2088 | current_buffer->text->modiff++; other_buffer->text->modiff++; | 2384 | current_buffer->text->modiff++; other_buffer->text->modiff++; |
| 2089 | current_buffer->text->chars_modiff++; other_buffer->text->chars_modiff++; | 2385 | current_buffer->text->chars_modiff++; other_buffer->text->chars_modiff++; |
| @@ -2109,10 +2405,11 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text, | |||
| 2109 | BUF_MARKERS(buf) should either be for `buf' or dead. */ | 2405 | BUF_MARKERS(buf) should either be for `buf' or dead. */ |
| 2110 | eassert (!m->buffer); | 2406 | eassert (!m->buffer); |
| 2111 | } | 2407 | } |
| 2112 | { /* Some of the C code expects that w->buffer == w->pointm->buffer. | 2408 | { /* Some of the C code expects that both window markers of a |
| 2113 | So since we just swapped the markers between the two buffers, we need | 2409 | live window points to that window's buffer. So since we |
| 2410 | just swapped the markers between the two buffers, we need | ||
| 2114 | to undo the effect of this swap for window markers. */ | 2411 | to undo the effect of this swap for window markers. */ |
| 2115 | Lisp_Object w = Fselected_window (), ws = Qnil; | 2412 | Lisp_Object w = selected_window, ws = Qnil; |
| 2116 | Lisp_Object buf1, buf2; | 2413 | Lisp_Object buf1, buf2; |
| 2117 | XSETBUFFER (buf1, current_buffer); XSETBUFFER (buf2, other_buffer); | 2414 | XSETBUFFER (buf1, current_buffer); XSETBUFFER (buf2, other_buffer); |
| 2118 | 2415 | ||
| @@ -2120,11 +2417,19 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text, | |||
| 2120 | { | 2417 | { |
| 2121 | ws = Fcons (w, ws); | 2418 | ws = Fcons (w, ws); |
| 2122 | if (MARKERP (XWINDOW (w)->pointm) | 2419 | if (MARKERP (XWINDOW (w)->pointm) |
| 2123 | && (EQ (XWINDOW (w)->buffer, buf1) | 2420 | && (EQ (XWINDOW (w)->contents, buf1) |
| 2124 | || EQ (XWINDOW (w)->buffer, buf2))) | 2421 | || EQ (XWINDOW (w)->contents, buf2))) |
| 2125 | Fset_marker (XWINDOW (w)->pointm, | 2422 | Fset_marker (XWINDOW (w)->pointm, |
| 2126 | make_number (BUF_BEGV (XBUFFER (XWINDOW (w)->buffer))), | 2423 | make_number |
| 2127 | XWINDOW (w)->buffer); | 2424 | (BUF_BEGV (XBUFFER (XWINDOW (w)->contents))), |
| 2425 | XWINDOW (w)->contents); | ||
| 2426 | if (MARKERP (XWINDOW (w)->start) | ||
| 2427 | && (EQ (XWINDOW (w)->contents, buf1) | ||
| 2428 | || EQ (XWINDOW (w)->contents, buf2))) | ||
| 2429 | Fset_marker (XWINDOW (w)->start, | ||
| 2430 | make_number | ||
| 2431 | (XBUFFER (XWINDOW (w)->contents)->last_window_start), | ||
| 2432 | XWINDOW (w)->contents); | ||
| 2128 | w = Fnext_window (w, Qt, Qt); | 2433 | w = Fnext_window (w, Qt, Qt); |
| 2129 | } | 2434 | } |
| 2130 | } | 2435 | } |
| @@ -2155,8 +2460,8 @@ current buffer is cleared. */) | |||
| 2155 | struct Lisp_Marker *tail, *markers; | 2460 | struct Lisp_Marker *tail, *markers; |
| 2156 | struct buffer *other; | 2461 | struct buffer *other; |
| 2157 | ptrdiff_t begv, zv; | 2462 | ptrdiff_t begv, zv; |
| 2158 | int narrowed = (BEG != BEGV || Z != ZV); | 2463 | bool narrowed = (BEG != BEGV || Z != ZV); |
| 2159 | int modified_p = !NILP (Fbuffer_modified_p (Qnil)); | 2464 | bool modified_p = !NILP (Fbuffer_modified_p (Qnil)); |
| 2160 | Lisp_Object old_undo = BVAR (current_buffer, undo_list); | 2465 | Lisp_Object old_undo = BVAR (current_buffer, undo_list); |
| 2161 | struct gcpro gcpro1; | 2466 | struct gcpro gcpro1; |
| 2162 | 2467 | ||
| @@ -2171,7 +2476,7 @@ current buffer is cleared. */) | |||
| 2171 | 2476 | ||
| 2172 | /* Don't record these buffer changes. We will put a special undo entry | 2477 | /* Don't record these buffer changes. We will put a special undo entry |
| 2173 | instead. */ | 2478 | instead. */ |
| 2174 | BVAR (current_buffer, undo_list) = Qt; | 2479 | bset_undo_list (current_buffer, Qt); |
| 2175 | 2480 | ||
| 2176 | /* If the cached position is for this buffer, clear it out. */ | 2481 | /* If the cached position is for this buffer, clear it out. */ |
| 2177 | clear_charpos_cache (current_buffer); | 2482 | clear_charpos_cache (current_buffer); |
| @@ -2182,7 +2487,7 @@ current buffer is cleared. */) | |||
| 2182 | begv = BEGV, zv = ZV; | 2487 | begv = BEGV, zv = ZV; |
| 2183 | 2488 | ||
| 2184 | if (narrowed) | 2489 | if (narrowed) |
| 2185 | Fwiden (); | 2490 | error ("Changing multibyteness in a narrowed buffer"); |
| 2186 | 2491 | ||
| 2187 | if (NILP (flag)) | 2492 | if (NILP (flag)) |
| 2188 | { | 2493 | { |
| @@ -2193,7 +2498,7 @@ current buffer is cleared. */) | |||
| 2193 | to calculate the old correspondences. */ | 2498 | to calculate the old correspondences. */ |
| 2194 | set_intervals_multibyte (0); | 2499 | set_intervals_multibyte (0); |
| 2195 | 2500 | ||
| 2196 | BVAR (current_buffer, enable_multibyte_characters) = Qnil; | 2501 | bset_enable_multibyte_characters (current_buffer, Qnil); |
| 2197 | 2502 | ||
| 2198 | Z = Z_BYTE; | 2503 | Z = Z_BYTE; |
| 2199 | BEGV = BEGV_BYTE; | 2504 | BEGV = BEGV_BYTE; |
| @@ -2331,7 +2636,7 @@ current buffer is cleared. */) | |||
| 2331 | 2636 | ||
| 2332 | /* Do this first, so that chars_in_text asks the right question. | 2637 | /* Do this first, so that chars_in_text asks the right question. |
| 2333 | set_intervals_multibyte needs it too. */ | 2638 | set_intervals_multibyte needs it too. */ |
| 2334 | BVAR (current_buffer, enable_multibyte_characters) = Qt; | 2639 | bset_enable_multibyte_characters (current_buffer, Qt); |
| 2335 | 2640 | ||
| 2336 | GPT_BYTE = advance_to_char_boundary (GPT_BYTE); | 2641 | GPT_BYTE = advance_to_char_boundary (GPT_BYTE); |
| 2337 | GPT = chars_in_text (BEG_ADDR, GPT_BYTE - BEG_BYTE) + BEG; | 2642 | GPT = chars_in_text (BEG_ADDR, GPT_BYTE - BEG_BYTE) + BEG; |
| @@ -2377,7 +2682,7 @@ current buffer is cleared. */) | |||
| 2377 | /* Make sure no markers were put on the chain | 2682 | /* Make sure no markers were put on the chain |
| 2378 | while the chain value was incorrect. */ | 2683 | while the chain value was incorrect. */ |
| 2379 | if (BUF_MARKERS (current_buffer)) | 2684 | if (BUF_MARKERS (current_buffer)) |
| 2380 | abort (); | 2685 | emacs_abort (); |
| 2381 | 2686 | ||
| 2382 | BUF_MARKERS (current_buffer) = markers; | 2687 | BUF_MARKERS (current_buffer) = markers; |
| 2383 | 2688 | ||
| @@ -2389,23 +2694,25 @@ current buffer is cleared. */) | |||
| 2389 | if (!EQ (old_undo, Qt)) | 2694 | if (!EQ (old_undo, Qt)) |
| 2390 | { | 2695 | { |
| 2391 | /* Represent all the above changes by a special undo entry. */ | 2696 | /* Represent all the above changes by a special undo entry. */ |
| 2392 | BVAR (current_buffer, undo_list) = Fcons (list3 (Qapply, | 2697 | bset_undo_list (current_buffer, |
| 2393 | intern ("set-buffer-multibyte"), | 2698 | Fcons (list3 (Qapply, |
| 2394 | NILP (flag) ? Qt : Qnil), | 2699 | intern ("set-buffer-multibyte"), |
| 2395 | old_undo); | 2700 | NILP (flag) ? Qt : Qnil), |
| 2701 | old_undo)); | ||
| 2396 | } | 2702 | } |
| 2397 | 2703 | ||
| 2398 | UNGCPRO; | 2704 | UNGCPRO; |
| 2399 | 2705 | ||
| 2400 | /* Changing the multibyteness of a buffer means that all windows | ||
| 2401 | showing that buffer must be updated thoroughly. */ | ||
| 2402 | current_buffer->prevent_redisplay_optimizations_p = 1; | 2706 | current_buffer->prevent_redisplay_optimizations_p = 1; |
| 2403 | ++windows_or_buffers_changed; | 2707 | |
| 2708 | /* If buffer is shown in a window, let redisplay consider other windows. */ | ||
| 2709 | if (buffer_window_count (current_buffer)) | ||
| 2710 | ++windows_or_buffers_changed; | ||
| 2404 | 2711 | ||
| 2405 | /* Copy this buffer's new multibyte status | 2712 | /* Copy this buffer's new multibyte status |
| 2406 | into all of its indirect buffers. */ | 2713 | into all of its indirect buffers. */ |
| 2407 | for (other = all_buffers; other; other = other->header.next.buffer) | 2714 | FOR_EACH_BUFFER (other) |
| 2408 | if (other->base_buffer == current_buffer && !NILP (BVAR (other, name))) | 2715 | if (other->base_buffer == current_buffer && BUFFER_LIVE_P (other)) |
| 2409 | { | 2716 | { |
| 2410 | BVAR (other, enable_multibyte_characters) | 2717 | BVAR (other, enable_multibyte_characters) |
| 2411 | = BVAR (current_buffer, enable_multibyte_characters); | 2718 | = BVAR (current_buffer, enable_multibyte_characters); |
| @@ -2504,19 +2811,19 @@ swap_out_buffer_local_variables (struct buffer *b) | |||
| 2504 | *VEC_PTR and *LEN_PTR should contain a valid vector and size | 2811 | *VEC_PTR and *LEN_PTR should contain a valid vector and size |
| 2505 | when this function is called. | 2812 | when this function is called. |
| 2506 | 2813 | ||
| 2507 | If EXTEND is non-zero, we make the vector bigger if necessary. | 2814 | If EXTEND, make the vector bigger if necessary. |
| 2508 | If EXTEND is zero, we never extend the vector, | 2815 | If not, never extend the vector, |
| 2509 | and we store only as many overlays as will fit. | 2816 | and store only as many overlays as will fit. |
| 2510 | But we still return the total number of overlays. | 2817 | But still return the total number of overlays. |
| 2511 | 2818 | ||
| 2512 | If CHANGE_REQ is true, then any position written into *PREV_PTR or | 2819 | If CHANGE_REQ, any position written into *PREV_PTR or |
| 2513 | *NEXT_PTR is guaranteed to be not equal to POS, unless it is the | 2820 | *NEXT_PTR is guaranteed to be not equal to POS, unless it is the |
| 2514 | default (BEGV or ZV). */ | 2821 | default (BEGV or ZV). */ |
| 2515 | 2822 | ||
| 2516 | ptrdiff_t | 2823 | ptrdiff_t |
| 2517 | overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, | 2824 | overlays_at (EMACS_INT pos, bool extend, Lisp_Object **vec_ptr, |
| 2518 | ptrdiff_t *len_ptr, | 2825 | ptrdiff_t *len_ptr, |
| 2519 | ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr, int change_req) | 2826 | ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr, bool change_req) |
| 2520 | { | 2827 | { |
| 2521 | Lisp_Object overlay, start, end; | 2828 | Lisp_Object overlay, start, end; |
| 2522 | struct Lisp_Overlay *tail; | 2829 | struct Lisp_Overlay *tail; |
| @@ -2525,7 +2832,7 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, | |||
| 2525 | Lisp_Object *vec = *vec_ptr; | 2832 | Lisp_Object *vec = *vec_ptr; |
| 2526 | ptrdiff_t next = ZV; | 2833 | ptrdiff_t next = ZV; |
| 2527 | ptrdiff_t prev = BEGV; | 2834 | ptrdiff_t prev = BEGV; |
| 2528 | int inhibit_storing = 0; | 2835 | bool inhibit_storing = 0; |
| 2529 | 2836 | ||
| 2530 | for (tail = current_buffer->overlays_before; tail; tail = tail->next) | 2837 | for (tail = current_buffer->overlays_before; tail; tail = tail->next) |
| 2531 | { | 2838 | { |
| @@ -2642,13 +2949,13 @@ overlays_at (EMACS_INT pos, int extend, Lisp_Object **vec_ptr, | |||
| 2642 | *VEC_PTR and *LEN_PTR should contain a valid vector and size | 2949 | *VEC_PTR and *LEN_PTR should contain a valid vector and size |
| 2643 | when this function is called. | 2950 | when this function is called. |
| 2644 | 2951 | ||
| 2645 | If EXTEND is non-zero, we make the vector bigger if necessary. | 2952 | If EXTEND, make the vector bigger if necessary. |
| 2646 | If EXTEND is zero, we never extend the vector, | 2953 | If not, never extend the vector, |
| 2647 | and we store only as many overlays as will fit. | 2954 | and store only as many overlays as will fit. |
| 2648 | But we still return the total number of overlays. */ | 2955 | But still return the total number of overlays. */ |
| 2649 | 2956 | ||
| 2650 | static ptrdiff_t | 2957 | static ptrdiff_t |
| 2651 | overlays_in (EMACS_INT beg, EMACS_INT end, int extend, | 2958 | overlays_in (EMACS_INT beg, EMACS_INT end, bool extend, |
| 2652 | Lisp_Object **vec_ptr, ptrdiff_t *len_ptr, | 2959 | Lisp_Object **vec_ptr, ptrdiff_t *len_ptr, |
| 2653 | ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr) | 2960 | ptrdiff_t *next_ptr, ptrdiff_t *prev_ptr) |
| 2654 | { | 2961 | { |
| @@ -2659,8 +2966,8 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend, | |||
| 2659 | Lisp_Object *vec = *vec_ptr; | 2966 | Lisp_Object *vec = *vec_ptr; |
| 2660 | ptrdiff_t next = ZV; | 2967 | ptrdiff_t next = ZV; |
| 2661 | ptrdiff_t prev = BEGV; | 2968 | ptrdiff_t prev = BEGV; |
| 2662 | int inhibit_storing = 0; | 2969 | bool inhibit_storing = 0; |
| 2663 | int end_is_Z = end == Z; | 2970 | bool end_is_Z = end == Z; |
| 2664 | 2971 | ||
| 2665 | for (tail = current_buffer->overlays_before; tail; tail = tail->next) | 2972 | for (tail = current_buffer->overlays_before; tail; tail = tail->next) |
| 2666 | { | 2973 | { |
| @@ -2761,10 +3068,10 @@ overlays_in (EMACS_INT beg, EMACS_INT end, int extend, | |||
| 2761 | } | 3068 | } |
| 2762 | 3069 | ||
| 2763 | 3070 | ||
| 2764 | /* Return non-zero if there exists an overlay with a non-nil | 3071 | /* Return true if there exists an overlay with a non-nil |
| 2765 | `mouse-face' property overlapping OVERLAY. */ | 3072 | `mouse-face' property overlapping OVERLAY. */ |
| 2766 | 3073 | ||
| 2767 | int | 3074 | bool |
| 2768 | mouse_face_overlay_overlaps (Lisp_Object overlay) | 3075 | mouse_face_overlay_overlaps (Lisp_Object overlay) |
| 2769 | { | 3076 | { |
| 2770 | ptrdiff_t start = OVERLAY_POSITION (OVERLAY_START (overlay)); | 3077 | ptrdiff_t start = OVERLAY_POSITION (OVERLAY_START (overlay)); |
| @@ -2773,11 +3080,11 @@ mouse_face_overlay_overlaps (Lisp_Object overlay) | |||
| 2773 | Lisp_Object *v, tem; | 3080 | Lisp_Object *v, tem; |
| 2774 | 3081 | ||
| 2775 | size = 10; | 3082 | size = 10; |
| 2776 | v = (Lisp_Object *) alloca (size * sizeof *v); | 3083 | v = alloca (size * sizeof *v); |
| 2777 | n = overlays_in (start, end, 0, &v, &size, NULL, NULL); | 3084 | n = overlays_in (start, end, 0, &v, &size, NULL, NULL); |
| 2778 | if (n > size) | 3085 | if (n > size) |
| 2779 | { | 3086 | { |
| 2780 | v = (Lisp_Object *) alloca (n * sizeof *v); | 3087 | v = alloca (n * sizeof *v); |
| 2781 | overlays_in (start, end, 0, &v, &n, NULL, NULL); | 3088 | overlays_in (start, end, 0, &v, &n, NULL, NULL); |
| 2782 | } | 3089 | } |
| 2783 | 3090 | ||
| @@ -2793,7 +3100,7 @@ mouse_face_overlay_overlaps (Lisp_Object overlay) | |||
| 2793 | 3100 | ||
| 2794 | 3101 | ||
| 2795 | /* Fast function to just test if we're at an overlay boundary. */ | 3102 | /* Fast function to just test if we're at an overlay boundary. */ |
| 2796 | int | 3103 | bool |
| 2797 | overlay_touches_p (ptrdiff_t pos) | 3104 | overlay_touches_p (ptrdiff_t pos) |
| 2798 | { | 3105 | { |
| 2799 | Lisp_Object overlay; | 3106 | Lisp_Object overlay; |
| @@ -2804,8 +3111,7 @@ overlay_touches_p (ptrdiff_t pos) | |||
| 2804 | ptrdiff_t endpos; | 3111 | ptrdiff_t endpos; |
| 2805 | 3112 | ||
| 2806 | XSETMISC (overlay ,tail); | 3113 | XSETMISC (overlay ,tail); |
| 2807 | if (!OVERLAYP (overlay)) | 3114 | eassert (OVERLAYP (overlay)); |
| 2808 | abort (); | ||
| 2809 | 3115 | ||
| 2810 | endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); | 3116 | endpos = OVERLAY_POSITION (OVERLAY_END (overlay)); |
| 2811 | if (endpos < pos) | 3117 | if (endpos < pos) |
| @@ -2819,8 +3125,7 @@ overlay_touches_p (ptrdiff_t pos) | |||
| 2819 | ptrdiff_t startpos; | 3125 | ptrdiff_t startpos; |
| 2820 | 3126 | ||
| 2821 | XSETMISC (overlay, tail); | 3127 | XSETMISC (overlay, tail); |
| 2822 | if (!OVERLAYP (overlay)) | 3128 | eassert (OVERLAYP (overlay)); |
| 2823 | abort (); | ||
| 2824 | 3129 | ||
| 2825 | startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); | 3130 | startpos = OVERLAY_POSITION (OVERLAY_START (overlay)); |
| 2826 | if (pos < startpos) | 3131 | if (pos < startpos) |
| @@ -2841,8 +3146,8 @@ struct sortvec | |||
| 2841 | static int | 3146 | static int |
| 2842 | compare_overlays (const void *v1, const void *v2) | 3147 | compare_overlays (const void *v1, const void *v2) |
| 2843 | { | 3148 | { |
| 2844 | const struct sortvec *s1 = (const struct sortvec *) v1; | 3149 | const struct sortvec *s1 = v1; |
| 2845 | const struct sortvec *s2 = (const struct sortvec *) v2; | 3150 | const struct sortvec *s2 = v2; |
| 2846 | if (s1->priority != s2->priority) | 3151 | if (s1->priority != s2->priority) |
| 2847 | return s1->priority < s2->priority ? -1 : 1; | 3152 | return s1->priority < s2->priority ? -1 : 1; |
| 2848 | if (s1->beg != s2->beg) | 3153 | if (s1->beg != s2->beg) |
| @@ -2853,8 +3158,8 @@ compare_overlays (const void *v1, const void *v2) | |||
| 2853 | between "equal" overlays. The result can still change between | 3158 | between "equal" overlays. The result can still change between |
| 2854 | invocations of Emacs, but it won't change in the middle of | 3159 | invocations of Emacs, but it won't change in the middle of |
| 2855 | `find_field' (bug#6830). */ | 3160 | `find_field' (bug#6830). */ |
| 2856 | if (XHASH (s1->overlay) != XHASH (s2->overlay)) | 3161 | if (!EQ (s1->overlay, s2->overlay)) |
| 2857 | return XHASH (s1->overlay) < XHASH (s2->overlay) ? -1 : 1; | 3162 | return XLI (s1->overlay) < XLI (s2->overlay) ? -1 : 1; |
| 2858 | return 0; | 3163 | return 0; |
| 2859 | } | 3164 | } |
| 2860 | 3165 | ||
| @@ -2865,8 +3170,10 @@ ptrdiff_t | |||
| 2865 | sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) | 3170 | sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) |
| 2866 | { | 3171 | { |
| 2867 | ptrdiff_t i, j; | 3172 | ptrdiff_t i, j; |
| 3173 | USE_SAFE_ALLOCA; | ||
| 2868 | struct sortvec *sortvec; | 3174 | struct sortvec *sortvec; |
| 2869 | sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec)); | 3175 | |
| 3176 | SAFE_NALLOCA (sortvec, 1, noverlays); | ||
| 2870 | 3177 | ||
| 2871 | /* Put the valid and relevant overlays into sortvec. */ | 3178 | /* Put the valid and relevant overlays into sortvec. */ |
| 2872 | 3179 | ||
| @@ -2876,7 +3183,7 @@ sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) | |||
| 2876 | Lisp_Object overlay; | 3183 | Lisp_Object overlay; |
| 2877 | 3184 | ||
| 2878 | overlay = overlay_vec[i]; | 3185 | overlay = overlay_vec[i]; |
| 2879 | if (OVERLAY_VALID (overlay) | 3186 | if (OVERLAYP (overlay) |
| 2880 | && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0 | 3187 | && OVERLAY_POSITION (OVERLAY_START (overlay)) > 0 |
| 2881 | && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0) | 3188 | && OVERLAY_POSITION (OVERLAY_END (overlay)) > 0) |
| 2882 | { | 3189 | { |
| @@ -2912,6 +3219,8 @@ sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) | |||
| 2912 | 3219 | ||
| 2913 | for (i = 0; i < noverlays; i++) | 3220 | for (i = 0; i < noverlays; i++) |
| 2914 | overlay_vec[i] = sortvec[i].overlay; | 3221 | overlay_vec[i] = sortvec[i].overlay; |
| 3222 | |||
| 3223 | SAFE_FREE (); | ||
| 2915 | return (noverlays); | 3224 | return (noverlays); |
| 2916 | } | 3225 | } |
| 2917 | 3226 | ||
| @@ -2944,8 +3253,8 @@ static ptrdiff_t overlay_str_len; | |||
| 2944 | static int | 3253 | static int |
| 2945 | cmp_for_strings (const void *as1, const void *as2) | 3254 | cmp_for_strings (const void *as1, const void *as2) |
| 2946 | { | 3255 | { |
| 2947 | struct sortstr *s1 = (struct sortstr *)as1; | 3256 | struct sortstr const *s1 = as1; |
| 2948 | struct sortstr *s2 = (struct sortstr *)as2; | 3257 | struct sortstr const *s2 = as2; |
| 2949 | if (s1->size != s2->size) | 3258 | if (s1->size != s2->size) |
| 2950 | return s2->size < s1->size ? -1 : 1; | 3259 | return s2->size < s1->size ? -1 : 1; |
| 2951 | if (s1->priority != s2->priority) | 3260 | if (s1->priority != s2->priority) |
| @@ -3013,7 +3322,7 @@ overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr) | |||
| 3013 | Lisp_Object overlay, window, str; | 3322 | Lisp_Object overlay, window, str; |
| 3014 | struct Lisp_Overlay *ov; | 3323 | struct Lisp_Overlay *ov; |
| 3015 | ptrdiff_t startpos, endpos; | 3324 | ptrdiff_t startpos, endpos; |
| 3016 | int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); | 3325 | bool multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); |
| 3017 | 3326 | ||
| 3018 | overlay_heads.used = overlay_heads.bytes = 0; | 3327 | overlay_heads.used = overlay_heads.bytes = 0; |
| 3019 | overlay_tails.used = overlay_tails.bytes = 0; | 3328 | overlay_tails.used = overlay_tails.bytes = 0; |
| @@ -3121,7 +3430,7 @@ overlay_strings (ptrdiff_t pos, struct window *w, unsigned char **pstr) | |||
| 3121 | } | 3430 | } |
| 3122 | } | 3431 | } |
| 3123 | if (p != overlay_str_buf + total) | 3432 | if (p != overlay_str_buf + total) |
| 3124 | abort (); | 3433 | emacs_abort (); |
| 3125 | if (pstr) | 3434 | if (pstr) |
| 3126 | *pstr = overlay_str_buf; | 3435 | *pstr = overlay_str_buf; |
| 3127 | return total; | 3436 | return total; |
| @@ -3147,22 +3456,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos) | |||
| 3147 | { | 3456 | { |
| 3148 | next = tail->next; | 3457 | next = tail->next; |
| 3149 | XSETMISC (overlay, tail); | 3458 | XSETMISC (overlay, tail); |
| 3150 | 3459 | eassert (OVERLAYP (overlay)); | |
| 3151 | /* If the overlay is not valid, get rid of it. */ | ||
| 3152 | if (!OVERLAY_VALID (overlay)) | ||
| 3153 | #if 1 | ||
| 3154 | abort (); | ||
| 3155 | #else | ||
| 3156 | { | ||
| 3157 | /* Splice the cons cell TAIL out of overlays_before. */ | ||
| 3158 | if (!NILP (prev)) | ||
| 3159 | XCDR (prev) = next; | ||
| 3160 | else | ||
| 3161 | buf->overlays_before = next; | ||
| 3162 | tail = prev; | ||
| 3163 | continue; | ||
| 3164 | } | ||
| 3165 | #endif | ||
| 3166 | 3460 | ||
| 3167 | beg = OVERLAY_START (overlay); | 3461 | beg = OVERLAY_START (overlay); |
| 3168 | end = OVERLAY_END (overlay); | 3462 | end = OVERLAY_END (overlay); |
| @@ -3177,7 +3471,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos) | |||
| 3177 | if (prev) | 3471 | if (prev) |
| 3178 | prev->next = next; | 3472 | prev->next = next; |
| 3179 | else | 3473 | else |
| 3180 | buf->overlays_before = next; | 3474 | set_buffer_overlays_before (buf, next); |
| 3181 | 3475 | ||
| 3182 | /* Search thru overlays_after for where to put it. */ | 3476 | /* Search thru overlays_after for where to put it. */ |
| 3183 | other_prev = NULL; | 3477 | other_prev = NULL; |
| @@ -3187,7 +3481,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos) | |||
| 3187 | Lisp_Object otherbeg, otheroverlay; | 3481 | Lisp_Object otherbeg, otheroverlay; |
| 3188 | 3482 | ||
| 3189 | XSETMISC (otheroverlay, other); | 3483 | XSETMISC (otheroverlay, other); |
| 3190 | eassert (OVERLAY_VALID (otheroverlay)); | 3484 | eassert (OVERLAYP (otheroverlay)); |
| 3191 | 3485 | ||
| 3192 | otherbeg = OVERLAY_START (otheroverlay); | 3486 | otherbeg = OVERLAY_START (otheroverlay); |
| 3193 | if (OVERLAY_POSITION (otherbeg) >= where) | 3487 | if (OVERLAY_POSITION (otherbeg) >= where) |
| @@ -3199,7 +3493,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos) | |||
| 3199 | if (other_prev) | 3493 | if (other_prev) |
| 3200 | other_prev->next = tail; | 3494 | other_prev->next = tail; |
| 3201 | else | 3495 | else |
| 3202 | buf->overlays_after = tail; | 3496 | set_buffer_overlays_after (buf, tail); |
| 3203 | tail = prev; | 3497 | tail = prev; |
| 3204 | } | 3498 | } |
| 3205 | else | 3499 | else |
| @@ -3215,22 +3509,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos) | |||
| 3215 | { | 3509 | { |
| 3216 | next = tail->next; | 3510 | next = tail->next; |
| 3217 | XSETMISC (overlay, tail); | 3511 | XSETMISC (overlay, tail); |
| 3218 | 3512 | eassert (OVERLAYP (overlay)); | |
| 3219 | /* If the overlay is not valid, get rid of it. */ | ||
| 3220 | if (!OVERLAY_VALID (overlay)) | ||
| 3221 | #if 1 | ||
| 3222 | abort (); | ||
| 3223 | #else | ||
| 3224 | { | ||
| 3225 | /* Splice the cons cell TAIL out of overlays_after. */ | ||
| 3226 | if (!NILP (prev)) | ||
| 3227 | XCDR (prev) = next; | ||
| 3228 | else | ||
| 3229 | buf->overlays_after = next; | ||
| 3230 | tail = prev; | ||
| 3231 | continue; | ||
| 3232 | } | ||
| 3233 | #endif | ||
| 3234 | 3513 | ||
| 3235 | beg = OVERLAY_START (overlay); | 3514 | beg = OVERLAY_START (overlay); |
| 3236 | end = OVERLAY_END (overlay); | 3515 | end = OVERLAY_END (overlay); |
| @@ -3250,7 +3529,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos) | |||
| 3250 | if (prev) | 3529 | if (prev) |
| 3251 | prev->next = next; | 3530 | prev->next = next; |
| 3252 | else | 3531 | else |
| 3253 | buf->overlays_after = next; | 3532 | set_buffer_overlays_after (buf, next); |
| 3254 | 3533 | ||
| 3255 | /* Search thru overlays_before for where to put it. */ | 3534 | /* Search thru overlays_before for where to put it. */ |
| 3256 | other_prev = NULL; | 3535 | other_prev = NULL; |
| @@ -3260,7 +3539,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos) | |||
| 3260 | Lisp_Object otherend, otheroverlay; | 3539 | Lisp_Object otherend, otheroverlay; |
| 3261 | 3540 | ||
| 3262 | XSETMISC (otheroverlay, other); | 3541 | XSETMISC (otheroverlay, other); |
| 3263 | eassert (OVERLAY_VALID (otheroverlay)); | 3542 | eassert (OVERLAYP (otheroverlay)); |
| 3264 | 3543 | ||
| 3265 | otherend = OVERLAY_END (otheroverlay); | 3544 | otherend = OVERLAY_END (otheroverlay); |
| 3266 | if (OVERLAY_POSITION (otherend) <= where) | 3545 | if (OVERLAY_POSITION (otherend) <= where) |
| @@ -3272,7 +3551,7 @@ recenter_overlay_lists (struct buffer *buf, ptrdiff_t pos) | |||
| 3272 | if (other_prev) | 3551 | if (other_prev) |
| 3273 | other_prev->next = tail; | 3552 | other_prev->next = tail; |
| 3274 | else | 3553 | else |
| 3275 | buf->overlays_before = tail; | 3554 | set_buffer_overlays_before (buf, tail); |
| 3276 | tail = prev; | 3555 | tail = prev; |
| 3277 | } | 3556 | } |
| 3278 | } | 3557 | } |
| @@ -3377,7 +3656,7 @@ fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end) | |||
| 3377 | beforep = tail; | 3656 | beforep = tail; |
| 3378 | } | 3657 | } |
| 3379 | if (!parent) | 3658 | if (!parent) |
| 3380 | current_buffer->overlays_before = tail->next; | 3659 | set_buffer_overlays_before (current_buffer, tail->next); |
| 3381 | else | 3660 | else |
| 3382 | parent->next = tail->next; | 3661 | parent->next = tail->next; |
| 3383 | tail = tail->next; | 3662 | tail = tail->next; |
| @@ -3423,7 +3702,7 @@ fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end) | |||
| 3423 | beforep = tail; | 3702 | beforep = tail; |
| 3424 | } | 3703 | } |
| 3425 | if (!parent) | 3704 | if (!parent) |
| 3426 | current_buffer->overlays_after = tail->next; | 3705 | set_buffer_overlays_after (current_buffer, tail->next); |
| 3427 | else | 3706 | else |
| 3428 | parent->next = tail->next; | 3707 | parent->next = tail->next; |
| 3429 | tail = tail->next; | 3708 | tail = tail->next; |
| @@ -3437,14 +3716,13 @@ fix_start_end_in_overlays (register ptrdiff_t start, register ptrdiff_t end) | |||
| 3437 | if (beforep) | 3716 | if (beforep) |
| 3438 | { | 3717 | { |
| 3439 | beforep->next = current_buffer->overlays_before; | 3718 | beforep->next = current_buffer->overlays_before; |
| 3440 | current_buffer->overlays_before = before_list; | 3719 | set_buffer_overlays_before (current_buffer, before_list); |
| 3441 | } | 3720 | } |
| 3442 | recenter_overlay_lists (current_buffer, current_buffer->overlay_center); | ||
| 3443 | 3721 | ||
| 3444 | if (afterp) | 3722 | if (afterp) |
| 3445 | { | 3723 | { |
| 3446 | afterp->next = current_buffer->overlays_after; | 3724 | afterp->next = current_buffer->overlays_after; |
| 3447 | current_buffer->overlays_after = after_list; | 3725 | set_buffer_overlays_after (current_buffer, after_list); |
| 3448 | } | 3726 | } |
| 3449 | recenter_overlay_lists (current_buffer, current_buffer->overlay_center); | 3727 | recenter_overlay_lists (current_buffer, current_buffer->overlay_center); |
| 3450 | } | 3728 | } |
| @@ -3521,7 +3799,7 @@ fix_overlays_before (struct buffer *bp, ptrdiff_t prev, ptrdiff_t pos) | |||
| 3521 | if (!right_pair) | 3799 | if (!right_pair) |
| 3522 | { | 3800 | { |
| 3523 | found->next = bp->overlays_before; | 3801 | found->next = bp->overlays_before; |
| 3524 | bp->overlays_before = found; | 3802 | set_buffer_overlays_before (bp, found); |
| 3525 | } | 3803 | } |
| 3526 | else | 3804 | else |
| 3527 | { | 3805 | { |
| @@ -3556,7 +3834,8 @@ for the front of the overlay advance when text is inserted there | |||
| 3556 | The fifth arg REAR-ADVANCE, if non-nil, makes the marker | 3834 | The fifth arg REAR-ADVANCE, if non-nil, makes the marker |
| 3557 | for the rear of the overlay advance when text is inserted there | 3835 | for the rear of the overlay advance when text is inserted there |
| 3558 | \(which means the text *is* included in the overlay). */) | 3836 | \(which means the text *is* included in the overlay). */) |
| 3559 | (Lisp_Object beg, Lisp_Object end, Lisp_Object buffer, Lisp_Object front_advance, Lisp_Object rear_advance) | 3837 | (Lisp_Object beg, Lisp_Object end, Lisp_Object buffer, |
| 3838 | Lisp_Object front_advance, Lisp_Object rear_advance) | ||
| 3560 | { | 3839 | { |
| 3561 | Lisp_Object overlay; | 3840 | Lisp_Object overlay; |
| 3562 | struct buffer *b; | 3841 | struct buffer *b; |
| @@ -3565,12 +3844,11 @@ for the rear of the overlay advance when text is inserted there | |||
| 3565 | XSETBUFFER (buffer, current_buffer); | 3844 | XSETBUFFER (buffer, current_buffer); |
| 3566 | else | 3845 | else |
| 3567 | CHECK_BUFFER (buffer); | 3846 | CHECK_BUFFER (buffer); |
| 3568 | if (MARKERP (beg) | 3847 | |
| 3569 | && ! EQ (Fmarker_buffer (beg), buffer)) | 3848 | if (MARKERP (beg) && !EQ (Fmarker_buffer (beg), buffer)) |
| 3570 | error ("Marker points into wrong buffer"); | 3849 | signal_error ("Marker points into wrong buffer", beg); |
| 3571 | if (MARKERP (end) | 3850 | if (MARKERP (end) && !EQ (Fmarker_buffer (end), buffer)) |
| 3572 | && ! EQ (Fmarker_buffer (end), buffer)) | 3851 | signal_error ("Marker points into wrong buffer", end); |
| 3573 | error ("Marker points into wrong buffer"); | ||
| 3574 | 3852 | ||
| 3575 | CHECK_NUMBER_COERCE_MARKER (beg); | 3853 | CHECK_NUMBER_COERCE_MARKER (beg); |
| 3576 | CHECK_NUMBER_COERCE_MARKER (end); | 3854 | CHECK_NUMBER_COERCE_MARKER (end); |
| @@ -3591,28 +3869,22 @@ for the rear of the overlay advance when text is inserted there | |||
| 3591 | if (!NILP (rear_advance)) | 3869 | if (!NILP (rear_advance)) |
| 3592 | XMARKER (end)->insertion_type = 1; | 3870 | XMARKER (end)->insertion_type = 1; |
| 3593 | 3871 | ||
| 3594 | overlay = allocate_misc (); | 3872 | overlay = build_overlay (beg, end, Qnil); |
| 3595 | XMISCTYPE (overlay) = Lisp_Misc_Overlay; | ||
| 3596 | XOVERLAY (overlay)->start = beg; | ||
| 3597 | XOVERLAY (overlay)->end = end; | ||
| 3598 | XOVERLAY (overlay)->plist = Qnil; | ||
| 3599 | XOVERLAY (overlay)->next = NULL; | ||
| 3600 | 3873 | ||
| 3601 | /* Put the new overlay on the wrong list. */ | 3874 | /* Put the new overlay on the wrong list. */ |
| 3602 | end = OVERLAY_END (overlay); | 3875 | end = OVERLAY_END (overlay); |
| 3603 | if (OVERLAY_POSITION (end) < b->overlay_center) | 3876 | if (OVERLAY_POSITION (end) < b->overlay_center) |
| 3604 | { | 3877 | { |
| 3605 | if (b->overlays_after) | 3878 | eassert (b->overlays_after || (XOVERLAY (overlay)->next == NULL)); |
| 3606 | XOVERLAY (overlay)->next = b->overlays_after; | 3879 | XOVERLAY (overlay)->next = b->overlays_after; |
| 3607 | b->overlays_after = XOVERLAY (overlay); | 3880 | set_buffer_overlays_after (b, XOVERLAY (overlay)); |
| 3608 | } | 3881 | } |
| 3609 | else | 3882 | else |
| 3610 | { | 3883 | { |
| 3611 | if (b->overlays_before) | 3884 | eassert (b->overlays_before || (XOVERLAY (overlay)->next == NULL)); |
| 3612 | XOVERLAY (overlay)->next = b->overlays_before; | 3885 | XOVERLAY (overlay)->next = b->overlays_before; |
| 3613 | b->overlays_before = XOVERLAY (overlay); | 3886 | set_buffer_overlays_before (b, XOVERLAY (overlay)); |
| 3614 | } | 3887 | } |
| 3615 | |||
| 3616 | /* This puts it in the right list, and in the right order. */ | 3888 | /* This puts it in the right list, and in the right order. */ |
| 3617 | recenter_overlay_lists (b, b->overlay_center); | 3889 | recenter_overlay_lists (b, b->overlay_center); |
| 3618 | 3890 | ||
| @@ -3636,39 +3908,50 @@ modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end) | |||
| 3636 | 3908 | ||
| 3637 | BUF_COMPUTE_UNCHANGED (buf, start, end); | 3909 | BUF_COMPUTE_UNCHANGED (buf, start, end); |
| 3638 | 3910 | ||
| 3639 | /* If this is a buffer not in the selected window, | 3911 | /* If BUF is visible, consider updating the display if ... */ |
| 3640 | we must do other windows. */ | 3912 | if (buffer_window_count (buf) > 0) |
| 3641 | if (buf != XBUFFER (XWINDOW (selected_window)->buffer)) | 3913 | { |
| 3642 | windows_or_buffers_changed = 1; | 3914 | /* ... it's visible in other window than selected, */ |
| 3643 | /* If multiple windows show this buffer, we must do other windows. */ | 3915 | if (buf != XBUFFER (XWINDOW (selected_window)->contents)) |
| 3644 | else if (buffer_shared > 1) | 3916 | windows_or_buffers_changed = 1; |
| 3645 | windows_or_buffers_changed = 1; | 3917 | /* ... or if we modify an overlay at the end of the buffer |
| 3646 | /* If we modify an overlay at the end of the buffer, we cannot | 3918 | and so we cannot be sure that window end is still valid. */ |
| 3647 | be sure that window end is still valid. */ | 3919 | else if (end >= ZV && start <= ZV) |
| 3648 | else if (end >= ZV && start <= ZV) | 3920 | windows_or_buffers_changed = 1; |
| 3649 | windows_or_buffers_changed = 1; | 3921 | } |
| 3650 | 3922 | ||
| 3651 | ++BUF_OVERLAY_MODIFF (buf); | 3923 | ++BUF_OVERLAY_MODIFF (buf); |
| 3652 | } | 3924 | } |
| 3653 | 3925 | ||
| 3654 | 3926 | /* Remove OVERLAY from LIST. */ | |
| 3927 | |||
| 3655 | static struct Lisp_Overlay * | 3928 | static struct Lisp_Overlay * |
| 3656 | unchain_overlay (struct Lisp_Overlay *list, struct Lisp_Overlay *overlay) | 3929 | unchain_overlay (struct Lisp_Overlay *list, struct Lisp_Overlay *overlay) |
| 3657 | { | 3930 | { |
| 3658 | struct Lisp_Overlay *tmp, *prev; | 3931 | register struct Lisp_Overlay *tail, **prev = &list; |
| 3659 | for (tmp = list, prev = NULL; tmp; prev = tmp, tmp = tmp->next) | 3932 | |
| 3660 | if (tmp == overlay) | 3933 | for (tail = list; tail; prev = &tail->next, tail = *prev) |
| 3934 | if (tail == overlay) | ||
| 3661 | { | 3935 | { |
| 3662 | if (prev) | 3936 | *prev = overlay->next; |
| 3663 | prev->next = tmp->next; | ||
| 3664 | else | ||
| 3665 | list = tmp->next; | ||
| 3666 | overlay->next = NULL; | 3937 | overlay->next = NULL; |
| 3667 | break; | 3938 | break; |
| 3668 | } | 3939 | } |
| 3669 | return list; | 3940 | return list; |
| 3670 | } | 3941 | } |
| 3671 | 3942 | ||
| 3943 | /* Remove OVERLAY from both overlay lists of B. */ | ||
| 3944 | |||
| 3945 | static void | ||
| 3946 | unchain_both (struct buffer *b, Lisp_Object overlay) | ||
| 3947 | { | ||
| 3948 | struct Lisp_Overlay *ov = XOVERLAY (overlay); | ||
| 3949 | |||
| 3950 | set_buffer_overlays_before (b, unchain_overlay (b->overlays_before, ov)); | ||
| 3951 | set_buffer_overlays_after (b, unchain_overlay (b->overlays_after, ov)); | ||
| 3952 | eassert (XOVERLAY (overlay)->next == NULL); | ||
| 3953 | } | ||
| 3954 | |||
| 3672 | DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0, | 3955 | DEFUN ("move-overlay", Fmove_overlay, Smove_overlay, 3, 4, 0, |
| 3673 | doc: /* Set the endpoints of OVERLAY to BEG and END in BUFFER. | 3956 | doc: /* Set the endpoints of OVERLAY to BEG and END in BUFFER. |
| 3674 | If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now. | 3957 | If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now. |
| @@ -3691,12 +3974,10 @@ buffer. */) | |||
| 3691 | if (NILP (Fbuffer_live_p (buffer))) | 3974 | if (NILP (Fbuffer_live_p (buffer))) |
| 3692 | error ("Attempt to move overlay to a dead buffer"); | 3975 | error ("Attempt to move overlay to a dead buffer"); |
| 3693 | 3976 | ||
| 3694 | if (MARKERP (beg) | 3977 | if (MARKERP (beg) && !EQ (Fmarker_buffer (beg), buffer)) |
| 3695 | && ! EQ (Fmarker_buffer (beg), buffer)) | 3978 | signal_error ("Marker points into wrong buffer", beg); |
| 3696 | error ("Marker points into wrong buffer"); | 3979 | if (MARKERP (end) && !EQ (Fmarker_buffer (end), buffer)) |
| 3697 | if (MARKERP (end) | 3980 | signal_error ("Marker points into wrong buffer", end); |
| 3698 | && ! EQ (Fmarker_buffer (end), buffer)) | ||
| 3699 | error ("Marker points into wrong buffer"); | ||
| 3700 | 3981 | ||
| 3701 | CHECK_NUMBER_COERCE_MARKER (beg); | 3982 | CHECK_NUMBER_COERCE_MARKER (beg); |
| 3702 | CHECK_NUMBER_COERCE_MARKER (end); | 3983 | CHECK_NUMBER_COERCE_MARKER (end); |
| @@ -3719,11 +4000,7 @@ buffer. */) | |||
| 3719 | o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); | 4000 | o_beg = OVERLAY_POSITION (OVERLAY_START (overlay)); |
| 3720 | o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); | 4001 | o_end = OVERLAY_POSITION (OVERLAY_END (overlay)); |
| 3721 | 4002 | ||
| 3722 | ob->overlays_before = | 4003 | unchain_both (ob, overlay); |
| 3723 | unchain_overlay (ob->overlays_before, XOVERLAY (overlay)); | ||
| 3724 | ob->overlays_after = | ||
| 3725 | unchain_overlay (ob->overlays_after, XOVERLAY (overlay)); | ||
| 3726 | eassert (XOVERLAY (overlay)->next == NULL); | ||
| 3727 | } | 4004 | } |
| 3728 | 4005 | ||
| 3729 | /* Set the overlay boundaries, which may clip them. */ | 4006 | /* Set the overlay boundaries, which may clip them. */ |
| @@ -3764,12 +4041,12 @@ buffer. */) | |||
| 3764 | if (n_end < b->overlay_center) | 4041 | if (n_end < b->overlay_center) |
| 3765 | { | 4042 | { |
| 3766 | XOVERLAY (overlay)->next = b->overlays_after; | 4043 | XOVERLAY (overlay)->next = b->overlays_after; |
| 3767 | b->overlays_after = XOVERLAY (overlay); | 4044 | set_buffer_overlays_after (b, XOVERLAY (overlay)); |
| 3768 | } | 4045 | } |
| 3769 | else | 4046 | else |
| 3770 | { | 4047 | { |
| 3771 | XOVERLAY (overlay)->next = b->overlays_before; | 4048 | XOVERLAY (overlay)->next = b->overlays_before; |
| 3772 | b->overlays_before = XOVERLAY (overlay); | 4049 | set_buffer_overlays_before (b, XOVERLAY (overlay)); |
| 3773 | } | 4050 | } |
| 3774 | 4051 | ||
| 3775 | /* This puts it in the right list, and in the right order. */ | 4052 | /* This puts it in the right list, and in the right order. */ |
| @@ -3795,17 +4072,8 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0, | |||
| 3795 | b = XBUFFER (buffer); | 4072 | b = XBUFFER (buffer); |
| 3796 | specbind (Qinhibit_quit, Qt); | 4073 | specbind (Qinhibit_quit, Qt); |
| 3797 | 4074 | ||
| 3798 | b->overlays_before | 4075 | unchain_both (b, overlay); |
| 3799 | = unchain_overlay (b->overlays_before, XOVERLAY (overlay)); | 4076 | drop_overlay (b, XOVERLAY (overlay)); |
| 3800 | b->overlays_after | ||
| 3801 | = unchain_overlay (b->overlays_after, XOVERLAY (overlay)); | ||
| 3802 | eassert (XOVERLAY (overlay)->next == NULL); | ||
| 3803 | |||
| 3804 | modify_overlay (b, | ||
| 3805 | marker_position (OVERLAY_START (overlay)), | ||
| 3806 | marker_position (OVERLAY_END (overlay))); | ||
| 3807 | Fset_marker (OVERLAY_START (overlay), Qnil, Qnil); | ||
| 3808 | Fset_marker (OVERLAY_END (overlay), Qnil, Qnil); | ||
| 3809 | 4077 | ||
| 3810 | /* When deleting an overlay with before or after strings, turn off | 4078 | /* When deleting an overlay with before or after strings, turn off |
| 3811 | display optimizations for the affected buffer, on the basis that | 4079 | display optimizations for the affected buffer, on the basis that |
| @@ -3818,6 +4086,26 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0, | |||
| 3818 | 4086 | ||
| 3819 | return unbind_to (count, Qnil); | 4087 | return unbind_to (count, Qnil); |
| 3820 | } | 4088 | } |
| 4089 | |||
| 4090 | DEFUN ("delete-all-overlays", Fdelete_all_overlays, Sdelete_all_overlays, 0, 1, 0, | ||
| 4091 | doc: /* Delete all overlays of BUFFER. | ||
| 4092 | BUFFER omitted or nil means delete all overlays of the current | ||
| 4093 | buffer. */) | ||
| 4094 | (Lisp_Object buffer) | ||
| 4095 | { | ||
| 4096 | register struct buffer *buf; | ||
| 4097 | |||
| 4098 | if (NILP (buffer)) | ||
| 4099 | buf = current_buffer; | ||
| 4100 | else | ||
| 4101 | { | ||
| 4102 | CHECK_BUFFER (buffer); | ||
| 4103 | buf = XBUFFER (buffer); | ||
| 4104 | } | ||
| 4105 | |||
| 4106 | delete_all_overlays (buf); | ||
| 4107 | return Qnil; | ||
| 4108 | } | ||
| 3821 | 4109 | ||
| 3822 | /* Overlay dissection functions. */ | 4110 | /* Overlay dissection functions. */ |
| 3823 | 4111 | ||
| @@ -3871,14 +4159,17 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0, | |||
| 3871 | 4159 | ||
| 3872 | CHECK_NUMBER_COERCE_MARKER (pos); | 4160 | CHECK_NUMBER_COERCE_MARKER (pos); |
| 3873 | 4161 | ||
| 4162 | if (!buffer_has_overlays ()) | ||
| 4163 | return Qnil; | ||
| 4164 | |||
| 3874 | len = 10; | 4165 | len = 10; |
| 3875 | /* We can't use alloca here because overlays_at can call xrealloc. */ | 4166 | /* We can't use alloca here because overlays_at can call xrealloc. */ |
| 3876 | overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); | 4167 | overlay_vec = xmalloc (len * sizeof *overlay_vec); |
| 3877 | 4168 | ||
| 3878 | /* Put all the overlays we want in a vector in overlay_vec. | 4169 | /* Put all the overlays we want in a vector in overlay_vec. |
| 3879 | Store the length in len. */ | 4170 | Store the length in len. */ |
| 3880 | noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, | 4171 | noverlays = overlays_at (XINT (pos), 1, &overlay_vec, &len, |
| 3881 | 0, 0, 0); | 4172 | NULL, NULL, 0); |
| 3882 | 4173 | ||
| 3883 | /* Make a list of them all. */ | 4174 | /* Make a list of them all. */ |
| 3884 | result = Flist (noverlays, overlay_vec); | 4175 | result = Flist (noverlays, overlay_vec); |
| @@ -3903,8 +4194,11 @@ end of the buffer. */) | |||
| 3903 | CHECK_NUMBER_COERCE_MARKER (beg); | 4194 | CHECK_NUMBER_COERCE_MARKER (beg); |
| 3904 | CHECK_NUMBER_COERCE_MARKER (end); | 4195 | CHECK_NUMBER_COERCE_MARKER (end); |
| 3905 | 4196 | ||
| 4197 | if (!buffer_has_overlays ()) | ||
| 4198 | return Qnil; | ||
| 4199 | |||
| 3906 | len = 10; | 4200 | len = 10; |
| 3907 | overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); | 4201 | overlay_vec = xmalloc (len * sizeof *overlay_vec); |
| 3908 | 4202 | ||
| 3909 | /* Put all the overlays we want in a vector in overlay_vec. | 4203 | /* Put all the overlays we want in a vector in overlay_vec. |
| 3910 | Store the length in len. */ | 4204 | Store the length in len. */ |
| @@ -3931,8 +4225,11 @@ the value is (point-max). */) | |||
| 3931 | 4225 | ||
| 3932 | CHECK_NUMBER_COERCE_MARKER (pos); | 4226 | CHECK_NUMBER_COERCE_MARKER (pos); |
| 3933 | 4227 | ||
| 4228 | if (!buffer_has_overlays ()) | ||
| 4229 | return make_number (ZV); | ||
| 4230 | |||
| 3934 | len = 10; | 4231 | len = 10; |
| 3935 | overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); | 4232 | overlay_vec = xmalloc (len * sizeof *overlay_vec); |
| 3936 | 4233 | ||
| 3937 | /* Put all the overlays we want in a vector in overlay_vec. | 4234 | /* Put all the overlays we want in a vector in overlay_vec. |
| 3938 | Store the length in len. | 4235 | Store the length in len. |
| @@ -3970,13 +4267,16 @@ the value is (point-min). */) | |||
| 3970 | 4267 | ||
| 3971 | CHECK_NUMBER_COERCE_MARKER (pos); | 4268 | CHECK_NUMBER_COERCE_MARKER (pos); |
| 3972 | 4269 | ||
| 4270 | if (!buffer_has_overlays ()) | ||
| 4271 | return make_number (BEGV); | ||
| 4272 | |||
| 3973 | /* At beginning of buffer, we know the answer; | 4273 | /* At beginning of buffer, we know the answer; |
| 3974 | avoid bug subtracting 1 below. */ | 4274 | avoid bug subtracting 1 below. */ |
| 3975 | if (XINT (pos) == BEGV) | 4275 | if (XINT (pos) == BEGV) |
| 3976 | return pos; | 4276 | return pos; |
| 3977 | 4277 | ||
| 3978 | len = 10; | 4278 | len = 10; |
| 3979 | overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); | 4279 | overlay_vec = xmalloc (len * sizeof *overlay_vec); |
| 3980 | 4280 | ||
| 3981 | /* Put all the overlays we want in a vector in overlay_vec. | 4281 | /* Put all the overlays we want in a vector in overlay_vec. |
| 3982 | Store the length in len. | 4282 | Store the length in len. |
| @@ -4001,6 +4301,7 @@ However, the overlays you get are the real objects that the buffer uses. */) | |||
| 4001 | { | 4301 | { |
| 4002 | struct Lisp_Overlay *ol; | 4302 | struct Lisp_Overlay *ol; |
| 4003 | Lisp_Object before = Qnil, after = Qnil, tmp; | 4303 | Lisp_Object before = Qnil, after = Qnil, tmp; |
| 4304 | |||
| 4004 | for (ol = current_buffer->overlays_before; ol; ol = ol->next) | 4305 | for (ol = current_buffer->overlays_before; ol; ol = ol->next) |
| 4005 | { | 4306 | { |
| 4006 | XSETMISC (tmp, ol); | 4307 | XSETMISC (tmp, ol); |
| @@ -4011,6 +4312,7 @@ However, the overlays you get are the real objects that the buffer uses. */) | |||
| 4011 | XSETMISC (tmp, ol); | 4312 | XSETMISC (tmp, ol); |
| 4012 | after = Fcons (tmp, after); | 4313 | after = Fcons (tmp, after); |
| 4013 | } | 4314 | } |
| 4315 | |||
| 4014 | return Fcons (Fnreverse (before), Fnreverse (after)); | 4316 | return Fcons (Fnreverse (before), Fnreverse (after)); |
| 4015 | } | 4317 | } |
| 4016 | 4318 | ||
| @@ -4042,7 +4344,7 @@ VALUE will be returned.*/) | |||
| 4042 | (Lisp_Object overlay, Lisp_Object prop, Lisp_Object value) | 4344 | (Lisp_Object overlay, Lisp_Object prop, Lisp_Object value) |
| 4043 | { | 4345 | { |
| 4044 | Lisp_Object tail, buffer; | 4346 | Lisp_Object tail, buffer; |
| 4045 | int changed; | 4347 | bool changed; |
| 4046 | 4348 | ||
| 4047 | CHECK_OVERLAY (overlay); | 4349 | CHECK_OVERLAY (overlay); |
| 4048 | 4350 | ||
| @@ -4059,8 +4361,8 @@ VALUE will be returned.*/) | |||
| 4059 | } | 4361 | } |
| 4060 | /* It wasn't in the list, so add it to the front. */ | 4362 | /* It wasn't in the list, so add it to the front. */ |
| 4061 | changed = !NILP (value); | 4363 | changed = !NILP (value); |
| 4062 | XOVERLAY (overlay)->plist | 4364 | set_overlay_plist |
| 4063 | = Fcons (prop, Fcons (value, XOVERLAY (overlay)->plist)); | 4365 | (overlay, Fcons (prop, Fcons (value, XOVERLAY (overlay)->plist))); |
| 4064 | found: | 4366 | found: |
| 4065 | if (! NILP (buffer)) | 4367 | if (! NILP (buffer)) |
| 4066 | { | 4368 | { |
| @@ -4117,7 +4419,7 @@ add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay) | |||
| 4117 | and the insert-after-hooks of overlay ending at START. | 4419 | and the insert-after-hooks of overlay ending at START. |
| 4118 | 4420 | ||
| 4119 | This is called both before and after the modification. | 4421 | This is called both before and after the modification. |
| 4120 | AFTER is nonzero when we call after the modification. | 4422 | AFTER is true when we call after the modification. |
| 4121 | 4423 | ||
| 4122 | ARG1, ARG2, ARG3 are arguments to pass to the hook functions. | 4424 | ARG1, ARG2, ARG3 are arguments to pass to the hook functions. |
| 4123 | When AFTER is nonzero, they are the start position, | 4425 | When AFTER is nonzero, they are the start position, |
| @@ -4125,13 +4427,13 @@ add_overlay_mod_hooklist (Lisp_Object functionlist, Lisp_Object overlay) | |||
| 4125 | and the length of deleted or replaced old text. */ | 4427 | and the length of deleted or replaced old text. */ |
| 4126 | 4428 | ||
| 4127 | void | 4429 | void |
| 4128 | report_overlay_modification (Lisp_Object start, Lisp_Object end, int after, | 4430 | report_overlay_modification (Lisp_Object start, Lisp_Object end, bool after, |
| 4129 | Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3) | 4431 | Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3) |
| 4130 | { | 4432 | { |
| 4131 | Lisp_Object prop, overlay; | 4433 | Lisp_Object prop, overlay; |
| 4132 | struct Lisp_Overlay *tail; | 4434 | struct Lisp_Overlay *tail; |
| 4133 | /* 1 if this change is an insertion. */ | 4435 | /* True if this change is an insertion. */ |
| 4134 | int insertion = (after ? XFASTINT (arg3) == 0 : EQ (start, end)); | 4436 | bool insertion = (after ? XFASTINT (arg3) == 0 : EQ (start, end)); |
| 4135 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | 4437 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| 4136 | 4438 | ||
| 4137 | overlay = Qnil; | 4439 | overlay = Qnil; |
| @@ -4231,11 +4533,11 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after, | |||
| 4231 | First copy the vector contents, in case some of these hooks | 4533 | First copy the vector contents, in case some of these hooks |
| 4232 | do subsequent modification of the buffer. */ | 4534 | do subsequent modification of the buffer. */ |
| 4233 | ptrdiff_t size = last_overlay_modification_hooks_used; | 4535 | ptrdiff_t size = last_overlay_modification_hooks_used; |
| 4234 | Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); | 4536 | Lisp_Object *copy = alloca (size * sizeof *copy); |
| 4235 | ptrdiff_t i; | 4537 | ptrdiff_t i; |
| 4236 | 4538 | ||
| 4237 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, | 4539 | memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, |
| 4238 | size * sizeof (Lisp_Object)); | 4540 | size * word_size); |
| 4239 | gcpro1.var = copy; | 4541 | gcpro1.var = copy; |
| 4240 | gcpro1.nvars = size; | 4542 | gcpro1.nvars = size; |
| 4241 | 4543 | ||
| @@ -4251,7 +4553,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after, | |||
| 4251 | } | 4553 | } |
| 4252 | 4554 | ||
| 4253 | static void | 4555 | static void |
| 4254 | call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, int after, | 4556 | call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, bool after, |
| 4255 | Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3) | 4557 | Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3) |
| 4256 | { | 4558 | { |
| 4257 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | 4559 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
| @@ -4305,34 +4607,13 @@ evaporate_overlays (ptrdiff_t pos) | |||
| 4305 | for (; CONSP (hit_list); hit_list = XCDR (hit_list)) | 4607 | for (; CONSP (hit_list); hit_list = XCDR (hit_list)) |
| 4306 | Fdelete_overlay (XCAR (hit_list)); | 4608 | Fdelete_overlay (XCAR (hit_list)); |
| 4307 | } | 4609 | } |
| 4308 | |||
| 4309 | /* Somebody has tried to store a value with an unacceptable type | ||
| 4310 | in the slot with offset OFFSET. */ | ||
| 4311 | |||
| 4312 | void | ||
| 4313 | buffer_slot_type_mismatch (Lisp_Object newval, int type) | ||
| 4314 | { | ||
| 4315 | Lisp_Object predicate; | ||
| 4316 | |||
| 4317 | switch (type) | ||
| 4318 | { | ||
| 4319 | case_Lisp_Int: predicate = Qintegerp; break; | ||
| 4320 | case Lisp_String: predicate = Qstringp; break; | ||
| 4321 | case Lisp_Symbol: predicate = Qsymbolp; break; | ||
| 4322 | default: abort (); | ||
| 4323 | } | ||
| 4324 | |||
| 4325 | wrong_type_argument (predicate, newval); | ||
| 4326 | } | ||
| 4327 | 4610 | ||
| 4328 | |||
| 4329 | /*********************************************************************** | 4611 | /*********************************************************************** |
| 4330 | Allocation with mmap | 4612 | Allocation with mmap |
| 4331 | ***********************************************************************/ | 4613 | ***********************************************************************/ |
| 4332 | 4614 | ||
| 4333 | #ifdef USE_MMAP_FOR_BUFFERS | 4615 | #ifdef USE_MMAP_FOR_BUFFERS |
| 4334 | 4616 | ||
| 4335 | #include <sys/types.h> | ||
| 4336 | #include <sys/mman.h> | 4617 | #include <sys/mman.h> |
| 4337 | 4618 | ||
| 4338 | #ifndef MAP_ANON | 4619 | #ifndef MAP_ANON |
| @@ -4347,8 +4628,6 @@ buffer_slot_type_mismatch (Lisp_Object newval, int type) | |||
| 4347 | #define MAP_FAILED ((void *) -1) | 4628 | #define MAP_FAILED ((void *) -1) |
| 4348 | #endif | 4629 | #endif |
| 4349 | 4630 | ||
| 4350 | #include <stdio.h> | ||
| 4351 | |||
| 4352 | #if MAP_ANON == 0 | 4631 | #if MAP_ANON == 0 |
| 4353 | #include <fcntl.h> | 4632 | #include <fcntl.h> |
| 4354 | #endif | 4633 | #endif |
| @@ -4410,7 +4689,7 @@ static int mmap_page_size; | |||
| 4410 | 4689 | ||
| 4411 | /* 1 means mmap has been initialized. */ | 4690 | /* 1 means mmap has been initialized. */ |
| 4412 | 4691 | ||
| 4413 | static int mmap_initialized_p; | 4692 | static bool mmap_initialized_p; |
| 4414 | 4693 | ||
| 4415 | /* Value is X rounded up to the next multiple of N. */ | 4694 | /* Value is X rounded up to the next multiple of N. */ |
| 4416 | 4695 | ||
| @@ -4458,7 +4737,7 @@ mmap_init (void) | |||
| 4458 | if (mmap_fd <= 0) | 4737 | if (mmap_fd <= 0) |
| 4459 | { | 4738 | { |
| 4460 | /* No anonymous mmap -- we need the file descriptor. */ | 4739 | /* No anonymous mmap -- we need the file descriptor. */ |
| 4461 | mmap_fd = open ("/dev/zero", O_RDONLY); | 4740 | mmap_fd = emacs_open ("/dev/zero", O_RDONLY, 0); |
| 4462 | if (mmap_fd == -1) | 4741 | if (mmap_fd == -1) |
| 4463 | fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); | 4742 | fatal ("Cannot open /dev/zero: %s", emacs_strerror (errno)); |
| 4464 | } | 4743 | } |
| @@ -4483,7 +4762,7 @@ static struct mmap_region * | |||
| 4483 | mmap_find (void *start, void *end) | 4762 | mmap_find (void *start, void *end) |
| 4484 | { | 4763 | { |
| 4485 | struct mmap_region *r; | 4764 | struct mmap_region *r; |
| 4486 | char *s = (char *) start, *e = (char *) end; | 4765 | char *s = start, *e = end; |
| 4487 | 4766 | ||
| 4488 | for (r = mmap_regions; r; r = r->next) | 4767 | for (r = mmap_regions; r; r = r->next) |
| 4489 | { | 4768 | { |
| @@ -4506,9 +4785,9 @@ mmap_find (void *start, void *end) | |||
| 4506 | 4785 | ||
| 4507 | 4786 | ||
| 4508 | /* Unmap a region. P is a pointer to the start of the user-araa of | 4787 | /* Unmap a region. P is a pointer to the start of the user-araa of |
| 4509 | the region. Value is non-zero if successful. */ | 4788 | the region. */ |
| 4510 | 4789 | ||
| 4511 | static int | 4790 | static void |
| 4512 | mmap_free_1 (struct mmap_region *r) | 4791 | mmap_free_1 (struct mmap_region *r) |
| 4513 | { | 4792 | { |
| 4514 | if (r->next) | 4793 | if (r->next) |
| @@ -4519,24 +4798,19 @@ mmap_free_1 (struct mmap_region *r) | |||
| 4519 | mmap_regions = r->next; | 4798 | mmap_regions = r->next; |
| 4520 | 4799 | ||
| 4521 | if (munmap (r, r->nbytes_mapped) == -1) | 4800 | if (munmap (r, r->nbytes_mapped) == -1) |
| 4522 | { | 4801 | fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); |
| 4523 | fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); | ||
| 4524 | return 0; | ||
| 4525 | } | ||
| 4526 | |||
| 4527 | return 1; | ||
| 4528 | } | 4802 | } |
| 4529 | 4803 | ||
| 4530 | 4804 | ||
| 4531 | /* Enlarge region R by NPAGES pages. NPAGES < 0 means shrink R. | 4805 | /* Enlarge region R by NPAGES pages. NPAGES < 0 means shrink R. |
| 4532 | Value is non-zero if successful. */ | 4806 | Value is true if successful. */ |
| 4533 | 4807 | ||
| 4534 | static int | 4808 | static bool |
| 4535 | mmap_enlarge (struct mmap_region *r, int npages) | 4809 | mmap_enlarge (struct mmap_region *r, int npages) |
| 4536 | { | 4810 | { |
| 4537 | char *region_end = (char *) r + r->nbytes_mapped; | 4811 | char *region_end = (char *) r + r->nbytes_mapped; |
| 4538 | size_t nbytes; | 4812 | size_t nbytes; |
| 4539 | int success = 0; | 4813 | bool success = 0; |
| 4540 | 4814 | ||
| 4541 | if (npages < 0) | 4815 | if (npages < 0) |
| 4542 | { | 4816 | { |
| @@ -4586,17 +4860,16 @@ mmap_enlarge (struct mmap_region *r, int npages) | |||
| 4586 | } | 4860 | } |
| 4587 | 4861 | ||
| 4588 | 4862 | ||
| 4589 | /* Set or reset variables holding references to mapped regions. If | 4863 | /* Set or reset variables holding references to mapped regions. |
| 4590 | RESTORE_P is zero, set all variables to null. If RESTORE_P is | 4864 | If not RESTORE_P, set all variables to null. If RESTORE_P, set all |
| 4591 | non-zero, set all variables to the start of the user-areas | 4865 | variables to the start of the user-areas of mapped regions. |
| 4592 | of mapped regions. | ||
| 4593 | 4866 | ||
| 4594 | This function is called from Fdump_emacs to ensure that the dumped | 4867 | This function is called from Fdump_emacs to ensure that the dumped |
| 4595 | Emacs doesn't contain references to memory that won't be mapped | 4868 | Emacs doesn't contain references to memory that won't be mapped |
| 4596 | when Emacs starts. */ | 4869 | when Emacs starts. */ |
| 4597 | 4870 | ||
| 4598 | void | 4871 | void |
| 4599 | mmap_set_vars (int restore_p) | 4872 | mmap_set_vars (bool restore_p) |
| 4600 | { | 4873 | { |
| 4601 | struct mmap_region *r; | 4874 | struct mmap_region *r; |
| 4602 | 4875 | ||
| @@ -4648,7 +4921,7 @@ mmap_alloc (void **var, size_t nbytes) | |||
| 4648 | } | 4921 | } |
| 4649 | else | 4922 | else |
| 4650 | { | 4923 | { |
| 4651 | struct mmap_region *r = (struct mmap_region *) p; | 4924 | struct mmap_region *r = p; |
| 4652 | 4925 | ||
| 4653 | r->nbytes_specified = nbytes; | 4926 | r->nbytes_specified = nbytes; |
| 4654 | r->nbytes_mapped = map; | 4927 | r->nbytes_mapped = map; |
| @@ -4773,7 +5046,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes) | |||
| 4773 | { | 5046 | { |
| 4774 | void *p; | 5047 | void *p; |
| 4775 | 5048 | ||
| 4776 | BLOCK_INPUT; | 5049 | block_input (); |
| 4777 | #if defined USE_MMAP_FOR_BUFFERS | 5050 | #if defined USE_MMAP_FOR_BUFFERS |
| 4778 | p = mmap_alloc ((void **) &b->text->beg, nbytes); | 5051 | p = mmap_alloc ((void **) &b->text->beg, nbytes); |
| 4779 | #elif defined REL_ALLOC | 5052 | #elif defined REL_ALLOC |
| @@ -4784,12 +5057,12 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes) | |||
| 4784 | 5057 | ||
| 4785 | if (p == NULL) | 5058 | if (p == NULL) |
| 4786 | { | 5059 | { |
| 4787 | UNBLOCK_INPUT; | 5060 | unblock_input (); |
| 4788 | memory_full (nbytes); | 5061 | memory_full (nbytes); |
| 4789 | } | 5062 | } |
| 4790 | 5063 | ||
| 4791 | b->text->beg = (unsigned char *) p; | 5064 | b->text->beg = p; |
| 4792 | UNBLOCK_INPUT; | 5065 | unblock_input (); |
| 4793 | } | 5066 | } |
| 4794 | 5067 | ||
| 4795 | /* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means | 5068 | /* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means |
| @@ -4801,7 +5074,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta) | |||
| 4801 | void *p; | 5074 | void *p; |
| 4802 | ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 | 5075 | ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 |
| 4803 | + delta); | 5076 | + delta); |
| 4804 | BLOCK_INPUT; | 5077 | block_input (); |
| 4805 | #if defined USE_MMAP_FOR_BUFFERS | 5078 | #if defined USE_MMAP_FOR_BUFFERS |
| 4806 | p = mmap_realloc ((void **) &b->text->beg, nbytes); | 5079 | p = mmap_realloc ((void **) &b->text->beg, nbytes); |
| 4807 | #elif defined REL_ALLOC | 5080 | #elif defined REL_ALLOC |
| @@ -4812,12 +5085,12 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta) | |||
| 4812 | 5085 | ||
| 4813 | if (p == NULL) | 5086 | if (p == NULL) |
| 4814 | { | 5087 | { |
| 4815 | UNBLOCK_INPUT; | 5088 | unblock_input (); |
| 4816 | memory_full (nbytes); | 5089 | memory_full (nbytes); |
| 4817 | } | 5090 | } |
| 4818 | 5091 | ||
| 4819 | BUF_BEG_ADDR (b) = (unsigned char *) p; | 5092 | BUF_BEG_ADDR (b) = p; |
| 4820 | UNBLOCK_INPUT; | 5093 | unblock_input (); |
| 4821 | } | 5094 | } |
| 4822 | 5095 | ||
| 4823 | 5096 | ||
| @@ -4826,7 +5099,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta) | |||
| 4826 | static void | 5099 | static void |
| 4827 | free_buffer_text (struct buffer *b) | 5100 | free_buffer_text (struct buffer *b) |
| 4828 | { | 5101 | { |
| 4829 | BLOCK_INPUT; | 5102 | block_input (); |
| 4830 | 5103 | ||
| 4831 | #if defined USE_MMAP_FOR_BUFFERS | 5104 | #if defined USE_MMAP_FOR_BUFFERS |
| 4832 | mmap_free ((void **) &b->text->beg); | 5105 | mmap_free ((void **) &b->text->beg); |
| @@ -4837,7 +5110,7 @@ free_buffer_text (struct buffer *b) | |||
| 4837 | #endif | 5110 | #endif |
| 4838 | 5111 | ||
| 4839 | BUF_BEG_ADDR (b) = NULL; | 5112 | BUF_BEG_ADDR (b) = NULL; |
| 4840 | UNBLOCK_INPUT; | 5113 | unblock_input (); |
| 4841 | } | 5114 | } |
| 4842 | 5115 | ||
| 4843 | 5116 | ||
| @@ -4864,68 +5137,73 @@ init_buffer_once (void) | |||
| 4864 | /* Prevent GC from getting confused. */ | 5137 | /* Prevent GC from getting confused. */ |
| 4865 | buffer_defaults.text = &buffer_defaults.own_text; | 5138 | buffer_defaults.text = &buffer_defaults.own_text; |
| 4866 | buffer_local_symbols.text = &buffer_local_symbols.own_text; | 5139 | buffer_local_symbols.text = &buffer_local_symbols.own_text; |
| 4867 | BUF_INTERVALS (&buffer_defaults) = 0; | 5140 | /* No one will share the text with these buffers, but let's play it safe. */ |
| 4868 | BUF_INTERVALS (&buffer_local_symbols) = 0; | 5141 | buffer_defaults.indirections = 0; |
| 4869 | XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, 0); | 5142 | buffer_local_symbols.indirections = 0; |
| 4870 | XSETBUFFER (Vbuffer_defaults, &buffer_defaults); | 5143 | /* Likewise no one will display them. */ |
| 4871 | XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, 0); | 5144 | buffer_defaults.window_count = 0; |
| 4872 | XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols); | 5145 | buffer_local_symbols.window_count = 0; |
| 5146 | set_buffer_intervals (&buffer_defaults, NULL); | ||
| 5147 | set_buffer_intervals (&buffer_local_symbols, NULL); | ||
| 5148 | /* This is not strictly necessary, but let's make them initialized. */ | ||
| 5149 | bset_name (&buffer_defaults, build_pure_c_string (" *buffer-defaults*")); | ||
| 5150 | bset_name (&buffer_local_symbols, build_pure_c_string (" *buffer-local-symbols*")); | ||
| 5151 | BUFFER_PVEC_INIT (&buffer_defaults); | ||
| 5152 | BUFFER_PVEC_INIT (&buffer_local_symbols); | ||
| 4873 | 5153 | ||
| 4874 | /* Set up the default values of various buffer slots. */ | 5154 | /* Set up the default values of various buffer slots. */ |
| 4875 | /* Must do these before making the first buffer! */ | 5155 | /* Must do these before making the first buffer! */ |
| 4876 | 5156 | ||
| 4877 | /* real setup is done in bindings.el */ | 5157 | /* real setup is done in bindings.el */ |
| 4878 | BVAR (&buffer_defaults, mode_line_format) = make_pure_c_string ("%-"); | 5158 | bset_mode_line_format (&buffer_defaults, build_pure_c_string ("%-")); |
| 4879 | BVAR (&buffer_defaults, header_line_format) = Qnil; | 5159 | bset_header_line_format (&buffer_defaults, Qnil); |
| 4880 | BVAR (&buffer_defaults, abbrev_mode) = Qnil; | 5160 | bset_abbrev_mode (&buffer_defaults, Qnil); |
| 4881 | BVAR (&buffer_defaults, overwrite_mode) = Qnil; | 5161 | bset_overwrite_mode (&buffer_defaults, Qnil); |
| 4882 | BVAR (&buffer_defaults, case_fold_search) = Qt; | 5162 | bset_case_fold_search (&buffer_defaults, Qt); |
| 4883 | BVAR (&buffer_defaults, auto_fill_function) = Qnil; | 5163 | bset_auto_fill_function (&buffer_defaults, Qnil); |
| 4884 | BVAR (&buffer_defaults, selective_display) = Qnil; | 5164 | bset_selective_display (&buffer_defaults, Qnil); |
| 4885 | #ifndef old | 5165 | bset_selective_display_ellipses (&buffer_defaults, Qt); |
| 4886 | BVAR (&buffer_defaults, selective_display_ellipses) = Qt; | 5166 | bset_abbrev_table (&buffer_defaults, Qnil); |
| 4887 | #endif | 5167 | bset_display_table (&buffer_defaults, Qnil); |
| 4888 | BVAR (&buffer_defaults, abbrev_table) = Qnil; | 5168 | bset_undo_list (&buffer_defaults, Qnil); |
| 4889 | BVAR (&buffer_defaults, display_table) = Qnil; | 5169 | bset_mark_active (&buffer_defaults, Qnil); |
| 4890 | BVAR (&buffer_defaults, undo_list) = Qnil; | 5170 | bset_file_format (&buffer_defaults, Qnil); |
| 4891 | BVAR (&buffer_defaults, mark_active) = Qnil; | 5171 | bset_auto_save_file_format (&buffer_defaults, Qt); |
| 4892 | BVAR (&buffer_defaults, file_format) = Qnil; | 5172 | set_buffer_overlays_before (&buffer_defaults, NULL); |
| 4893 | BVAR (&buffer_defaults, auto_save_file_format) = Qt; | 5173 | set_buffer_overlays_after (&buffer_defaults, NULL); |
| 4894 | buffer_defaults.overlays_before = NULL; | ||
| 4895 | buffer_defaults.overlays_after = NULL; | ||
| 4896 | buffer_defaults.overlay_center = BEG; | 5174 | buffer_defaults.overlay_center = BEG; |
| 4897 | 5175 | ||
| 4898 | XSETFASTINT (BVAR (&buffer_defaults, tab_width), 8); | 5176 | XSETFASTINT (BVAR (&buffer_defaults, tab_width), 8); |
| 4899 | BVAR (&buffer_defaults, truncate_lines) = Qnil; | 5177 | bset_truncate_lines (&buffer_defaults, Qnil); |
| 4900 | BVAR (&buffer_defaults, word_wrap) = Qnil; | 5178 | bset_word_wrap (&buffer_defaults, Qnil); |
| 4901 | BVAR (&buffer_defaults, ctl_arrow) = Qt; | 5179 | bset_ctl_arrow (&buffer_defaults, Qt); |
| 4902 | BVAR (&buffer_defaults, bidi_display_reordering) = Qt; | 5180 | bset_bidi_display_reordering (&buffer_defaults, Qt); |
| 4903 | BVAR (&buffer_defaults, bidi_paragraph_direction) = Qnil; | 5181 | bset_bidi_paragraph_direction (&buffer_defaults, Qnil); |
| 4904 | BVAR (&buffer_defaults, cursor_type) = Qt; | 5182 | bset_cursor_type (&buffer_defaults, Qt); |
| 4905 | BVAR (&buffer_defaults, extra_line_spacing) = Qnil; | 5183 | bset_extra_line_spacing (&buffer_defaults, Qnil); |
| 4906 | BVAR (&buffer_defaults, cursor_in_non_selected_windows) = Qt; | 5184 | bset_cursor_in_non_selected_windows (&buffer_defaults, Qt); |
| 4907 | 5185 | ||
| 4908 | BVAR (&buffer_defaults, enable_multibyte_characters) = Qt; | 5186 | bset_enable_multibyte_characters (&buffer_defaults, Qt); |
| 4909 | BVAR (&buffer_defaults, buffer_file_coding_system) = Qnil; | 5187 | bset_buffer_file_coding_system (&buffer_defaults, Qnil); |
| 4910 | XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70); | 5188 | XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70); |
| 4911 | XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0); | 5189 | XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0); |
| 4912 | BVAR (&buffer_defaults, cache_long_line_scans) = Qnil; | 5190 | bset_cache_long_scans (&buffer_defaults, Qnil); |
| 4913 | BVAR (&buffer_defaults, file_truename) = Qnil; | 5191 | bset_file_truename (&buffer_defaults, Qnil); |
| 4914 | XSETFASTINT (BVAR (&buffer_defaults, display_count), 0); | 5192 | XSETFASTINT (BVAR (&buffer_defaults, display_count), 0); |
| 4915 | XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0); | 5193 | XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0); |
| 4916 | XSETFASTINT (BVAR (&buffer_defaults, right_margin_cols), 0); | 5194 | XSETFASTINT (BVAR (&buffer_defaults, right_margin_cols), 0); |
| 4917 | BVAR (&buffer_defaults, left_fringe_width) = Qnil; | 5195 | bset_left_fringe_width (&buffer_defaults, Qnil); |
| 4918 | BVAR (&buffer_defaults, right_fringe_width) = Qnil; | 5196 | bset_right_fringe_width (&buffer_defaults, Qnil); |
| 4919 | BVAR (&buffer_defaults, fringes_outside_margins) = Qnil; | 5197 | bset_fringes_outside_margins (&buffer_defaults, Qnil); |
| 4920 | BVAR (&buffer_defaults, scroll_bar_width) = Qnil; | 5198 | bset_scroll_bar_width (&buffer_defaults, Qnil); |
| 4921 | BVAR (&buffer_defaults, vertical_scroll_bar_type) = Qt; | 5199 | bset_vertical_scroll_bar_type (&buffer_defaults, Qt); |
| 4922 | BVAR (&buffer_defaults, indicate_empty_lines) = Qnil; | 5200 | bset_indicate_empty_lines (&buffer_defaults, Qnil); |
| 4923 | BVAR (&buffer_defaults, indicate_buffer_boundaries) = Qnil; | 5201 | bset_indicate_buffer_boundaries (&buffer_defaults, Qnil); |
| 4924 | BVAR (&buffer_defaults, fringe_indicator_alist) = Qnil; | 5202 | bset_fringe_indicator_alist (&buffer_defaults, Qnil); |
| 4925 | BVAR (&buffer_defaults, fringe_cursor_alist) = Qnil; | 5203 | bset_fringe_cursor_alist (&buffer_defaults, Qnil); |
| 4926 | BVAR (&buffer_defaults, scroll_up_aggressively) = Qnil; | 5204 | bset_scroll_up_aggressively (&buffer_defaults, Qnil); |
| 4927 | BVAR (&buffer_defaults, scroll_down_aggressively) = Qnil; | 5205 | bset_scroll_down_aggressively (&buffer_defaults, Qnil); |
| 4928 | BVAR (&buffer_defaults, display_time) = Qnil; | 5206 | bset_display_time (&buffer_defaults, Qnil); |
| 4929 | 5207 | ||
| 4930 | /* Assign the local-flags to the slots that have default values. | 5208 | /* Assign the local-flags to the slots that have default values. |
| 4931 | The local flag is a bit that is used in the buffer | 5209 | The local flag is a bit that is used in the buffer |
| @@ -4933,28 +5211,28 @@ init_buffer_once (void) | |||
| 4933 | The local flag bits are in the local_var_flags slot of the buffer. */ | 5211 | The local flag bits are in the local_var_flags slot of the buffer. */ |
| 4934 | 5212 | ||
| 4935 | /* Nothing can work if this isn't true */ | 5213 | /* Nothing can work if this isn't true */ |
| 4936 | { verify (sizeof (EMACS_INT) == sizeof (Lisp_Object)); } | 5214 | { verify (sizeof (EMACS_INT) == word_size); } |
| 4937 | 5215 | ||
| 4938 | /* 0 means not a lisp var, -1 means always local, else mask */ | 5216 | /* 0 means not a lisp var, -1 means always local, else mask */ |
| 4939 | memset (&buffer_local_flags, 0, sizeof buffer_local_flags); | 5217 | memset (&buffer_local_flags, 0, sizeof buffer_local_flags); |
| 4940 | XSETINT (BVAR (&buffer_local_flags, filename), -1); | 5218 | bset_filename (&buffer_local_flags, make_number (-1)); |
| 4941 | XSETINT (BVAR (&buffer_local_flags, directory), -1); | 5219 | bset_directory (&buffer_local_flags, make_number (-1)); |
| 4942 | XSETINT (BVAR (&buffer_local_flags, backed_up), -1); | 5220 | bset_backed_up (&buffer_local_flags, make_number (-1)); |
| 4943 | XSETINT (BVAR (&buffer_local_flags, save_length), -1); | 5221 | bset_save_length (&buffer_local_flags, make_number (-1)); |
| 4944 | XSETINT (BVAR (&buffer_local_flags, auto_save_file_name), -1); | 5222 | bset_auto_save_file_name (&buffer_local_flags, make_number (-1)); |
| 4945 | XSETINT (BVAR (&buffer_local_flags, read_only), -1); | 5223 | bset_read_only (&buffer_local_flags, make_number (-1)); |
| 4946 | XSETINT (BVAR (&buffer_local_flags, major_mode), -1); | 5224 | bset_major_mode (&buffer_local_flags, make_number (-1)); |
| 4947 | XSETINT (BVAR (&buffer_local_flags, mode_name), -1); | 5225 | bset_mode_name (&buffer_local_flags, make_number (-1)); |
| 4948 | XSETINT (BVAR (&buffer_local_flags, undo_list), -1); | 5226 | bset_undo_list (&buffer_local_flags, make_number (-1)); |
| 4949 | XSETINT (BVAR (&buffer_local_flags, mark_active), -1); | 5227 | bset_mark_active (&buffer_local_flags, make_number (-1)); |
| 4950 | XSETINT (BVAR (&buffer_local_flags, point_before_scroll), -1); | 5228 | bset_point_before_scroll (&buffer_local_flags, make_number (-1)); |
| 4951 | XSETINT (BVAR (&buffer_local_flags, file_truename), -1); | 5229 | bset_file_truename (&buffer_local_flags, make_number (-1)); |
| 4952 | XSETINT (BVAR (&buffer_local_flags, invisibility_spec), -1); | 5230 | bset_invisibility_spec (&buffer_local_flags, make_number (-1)); |
| 4953 | XSETINT (BVAR (&buffer_local_flags, file_format), -1); | 5231 | bset_file_format (&buffer_local_flags, make_number (-1)); |
| 4954 | XSETINT (BVAR (&buffer_local_flags, auto_save_file_format), -1); | 5232 | bset_auto_save_file_format (&buffer_local_flags, make_number (-1)); |
| 4955 | XSETINT (BVAR (&buffer_local_flags, display_count), -1); | 5233 | bset_display_count (&buffer_local_flags, make_number (-1)); |
| 4956 | XSETINT (BVAR (&buffer_local_flags, display_time), -1); | 5234 | bset_display_time (&buffer_local_flags, make_number (-1)); |
| 4957 | XSETINT (BVAR (&buffer_local_flags, enable_multibyte_characters), -1); | 5235 | bset_enable_multibyte_characters (&buffer_local_flags, make_number (-1)); |
| 4958 | 5236 | ||
| 4959 | idx = 1; | 5237 | idx = 1; |
| 4960 | XSETFASTINT (BVAR (&buffer_local_flags, mode_line_format), idx); ++idx; | 5238 | XSETFASTINT (BVAR (&buffer_local_flags, mode_line_format), idx); ++idx; |
| @@ -4963,9 +5241,7 @@ init_buffer_once (void) | |||
| 4963 | XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx; | 5241 | XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx; |
| 4964 | XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx; | 5242 | XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx; |
| 4965 | XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx; | 5243 | XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx; |
| 4966 | #ifndef old | ||
| 4967 | XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx; | 5244 | XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx; |
| 4968 | #endif | ||
| 4969 | XSETFASTINT (BVAR (&buffer_local_flags, tab_width), idx); ++idx; | 5245 | XSETFASTINT (BVAR (&buffer_local_flags, tab_width), idx); ++idx; |
| 4970 | XSETFASTINT (BVAR (&buffer_local_flags, truncate_lines), idx); ++idx; | 5246 | XSETFASTINT (BVAR (&buffer_local_flags, truncate_lines), idx); ++idx; |
| 4971 | XSETFASTINT (BVAR (&buffer_local_flags, word_wrap), idx); ++idx; | 5247 | XSETFASTINT (BVAR (&buffer_local_flags, word_wrap), idx); ++idx; |
| @@ -4975,7 +5251,7 @@ init_buffer_once (void) | |||
| 4975 | XSETFASTINT (BVAR (&buffer_local_flags, abbrev_table), idx); ++idx; | 5251 | XSETFASTINT (BVAR (&buffer_local_flags, abbrev_table), idx); ++idx; |
| 4976 | XSETFASTINT (BVAR (&buffer_local_flags, display_table), idx); ++idx; | 5252 | XSETFASTINT (BVAR (&buffer_local_flags, display_table), idx); ++idx; |
| 4977 | XSETFASTINT (BVAR (&buffer_local_flags, syntax_table), idx); ++idx; | 5253 | XSETFASTINT (BVAR (&buffer_local_flags, syntax_table), idx); ++idx; |
| 4978 | XSETFASTINT (BVAR (&buffer_local_flags, cache_long_line_scans), idx); ++idx; | 5254 | XSETFASTINT (BVAR (&buffer_local_flags, cache_long_scans), idx); ++idx; |
| 4979 | XSETFASTINT (BVAR (&buffer_local_flags, category_table), idx); ++idx; | 5255 | XSETFASTINT (BVAR (&buffer_local_flags, category_table), idx); ++idx; |
| 4980 | XSETFASTINT (BVAR (&buffer_local_flags, bidi_display_reordering), idx); ++idx; | 5256 | XSETFASTINT (BVAR (&buffer_local_flags, bidi_display_reordering), idx); ++idx; |
| 4981 | XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_direction), idx); ++idx; | 5257 | XSETFASTINT (BVAR (&buffer_local_flags, bidi_paragraph_direction), idx); ++idx; |
| @@ -5002,17 +5278,17 @@ init_buffer_once (void) | |||
| 5002 | 5278 | ||
| 5003 | /* Need more room? */ | 5279 | /* Need more room? */ |
| 5004 | if (idx >= MAX_PER_BUFFER_VARS) | 5280 | if (idx >= MAX_PER_BUFFER_VARS) |
| 5005 | abort (); | 5281 | emacs_abort (); |
| 5006 | last_per_buffer_idx = idx; | 5282 | last_per_buffer_idx = idx; |
| 5007 | 5283 | ||
| 5008 | Vbuffer_alist = Qnil; | 5284 | Vbuffer_alist = Qnil; |
| 5009 | current_buffer = 0; | 5285 | current_buffer = 0; |
| 5010 | all_buffers = 0; | 5286 | all_buffers = 0; |
| 5011 | 5287 | ||
| 5012 | QSFundamental = make_pure_c_string ("Fundamental"); | 5288 | QSFundamental = build_pure_c_string ("Fundamental"); |
| 5013 | 5289 | ||
| 5014 | Qfundamental_mode = intern_c_string ("fundamental-mode"); | 5290 | Qfundamental_mode = intern_c_string ("fundamental-mode"); |
| 5015 | BVAR (&buffer_defaults, major_mode) = Qfundamental_mode; | 5291 | bset_major_mode (&buffer_defaults, Qfundamental_mode); |
| 5016 | 5292 | ||
| 5017 | Qmode_class = intern_c_string ("mode-class"); | 5293 | Qmode_class = intern_c_string ("mode-class"); |
| 5018 | 5294 | ||
| @@ -5024,10 +5300,10 @@ init_buffer_once (void) | |||
| 5024 | Fput (Qkill_buffer_hook, Qpermanent_local, Qt); | 5300 | Fput (Qkill_buffer_hook, Qpermanent_local, Qt); |
| 5025 | 5301 | ||
| 5026 | /* super-magic invisible buffer */ | 5302 | /* super-magic invisible buffer */ |
| 5027 | Vprin1_to_string_buffer = Fget_buffer_create (make_pure_c_string (" prin1")); | 5303 | Vprin1_to_string_buffer = Fget_buffer_create (build_pure_c_string (" prin1")); |
| 5028 | Vbuffer_alist = Qnil; | 5304 | Vbuffer_alist = Qnil; |
| 5029 | 5305 | ||
| 5030 | Fset_buffer (Fget_buffer_create (make_pure_c_string ("*scratch*"))); | 5306 | Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*"))); |
| 5031 | 5307 | ||
| 5032 | inhibit_modification_hooks = 0; | 5308 | inhibit_modification_hooks = 0; |
| 5033 | } | 5309 | } |
| @@ -5046,7 +5322,7 @@ init_buffer (void) | |||
| 5046 | Map new memory. */ | 5322 | Map new memory. */ |
| 5047 | struct buffer *b; | 5323 | struct buffer *b; |
| 5048 | 5324 | ||
| 5049 | for (b = all_buffers; b; b = b->header.next.buffer) | 5325 | FOR_EACH_BUFFER (b) |
| 5050 | if (b->text->beg == NULL) | 5326 | if (b->text->beg == NULL) |
| 5051 | enlarge_buffer_text (b, 0); | 5327 | enlarge_buffer_text (b, 0); |
| 5052 | } | 5328 | } |
| @@ -5067,20 +5343,21 @@ init_buffer (void) | |||
| 5067 | if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) | 5343 | if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) |
| 5068 | { | 5344 | { |
| 5069 | /* Grow buffer to add directory separator and '\0'. */ | 5345 | /* Grow buffer to add directory separator and '\0'. */ |
| 5070 | pwd = (char *) realloc (pwd, len + 2); | 5346 | pwd = realloc (pwd, len + 2); |
| 5071 | if (!pwd) | 5347 | if (!pwd) |
| 5072 | fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); | 5348 | fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); |
| 5073 | pwd[len] = DIRECTORY_SEP; | 5349 | pwd[len] = DIRECTORY_SEP; |
| 5074 | pwd[len + 1] = '\0'; | 5350 | pwd[len + 1] = '\0'; |
| 5351 | len++; | ||
| 5075 | } | 5352 | } |
| 5076 | 5353 | ||
| 5077 | BVAR (current_buffer, directory) = make_unibyte_string (pwd, strlen (pwd)); | 5354 | bset_directory (current_buffer, make_unibyte_string (pwd, len)); |
| 5078 | if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) | 5355 | if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) |
| 5079 | /* At this moment, we still don't know how to decode the | 5356 | /* At this moment, we still don't know how to decode the |
| 5080 | directory name. So, we keep the bytes in multibyte form so | 5357 | directory name. So, we keep the bytes in multibyte form so |
| 5081 | that ENCODE_FILE correctly gets the original bytes. */ | 5358 | that ENCODE_FILE correctly gets the original bytes. */ |
| 5082 | BVAR (current_buffer, directory) | 5359 | bset_directory |
| 5083 | = string_to_multibyte (BVAR (current_buffer, directory)); | 5360 | (current_buffer, string_to_multibyte (BVAR (current_buffer, directory))); |
| 5084 | 5361 | ||
| 5085 | /* Add /: to the front of the name | 5362 | /* Add /: to the front of the name |
| 5086 | if it would otherwise be treated as magic. */ | 5363 | if it would otherwise be treated as magic. */ |
| @@ -5091,34 +5368,33 @@ init_buffer (void) | |||
| 5091 | However, it is not necessary to turn / into /:/. | 5368 | However, it is not necessary to turn / into /:/. |
| 5092 | So avoid doing that. */ | 5369 | So avoid doing that. */ |
| 5093 | && strcmp ("/", SSDATA (BVAR (current_buffer, directory)))) | 5370 | && strcmp ("/", SSDATA (BVAR (current_buffer, directory)))) |
| 5094 | BVAR (current_buffer, directory) | 5371 | bset_directory |
| 5095 | = concat2 (build_string ("/:"), BVAR (current_buffer, directory)); | 5372 | (current_buffer, |
| 5373 | concat2 (build_string ("/:"), BVAR (current_buffer, directory))); | ||
| 5096 | 5374 | ||
| 5097 | temp = get_minibuffer (0); | 5375 | temp = get_minibuffer (0); |
| 5098 | BVAR (XBUFFER (temp), directory) = BVAR (current_buffer, directory); | 5376 | bset_directory (XBUFFER (temp), BVAR (current_buffer, directory)); |
| 5099 | 5377 | ||
| 5100 | free (pwd); | 5378 | free (pwd); |
| 5101 | } | 5379 | } |
| 5102 | 5380 | ||
| 5103 | /* Similar to defvar_lisp but define a variable whose value is the Lisp | 5381 | /* Similar to defvar_lisp but define a variable whose value is the |
| 5104 | Object stored in the current buffer. address is the address of the slot | 5382 | Lisp_Object stored in the current buffer. LNAME is the Lisp-level |
| 5105 | in the buffer that is current now. */ | 5383 | variable name. VNAME is the name of the buffer slot. PREDICATE |
| 5106 | 5384 | is nil for a general Lisp variable. If PREDICATE is non-nil, then | |
| 5107 | /* TYPE is nil for a general Lisp variable. | 5385 | only Lisp values that satisfies the PREDICATE are allowed (except |
| 5108 | An integer specifies a type; then only Lisp values | 5386 | that nil is allowed too). DOC is a dummy where you write the doc |
| 5109 | with that type code are allowed (except that nil is allowed too). | 5387 | string as a comment. */ |
| 5110 | LNAME is the Lisp-level variable name. | 5388 | |
| 5111 | VNAME is the name of the buffer slot. | 5389 | #define DEFVAR_PER_BUFFER(lname, vname, predicate, doc) \ |
| 5112 | DOC is a dummy where you write the doc string as a comment. */ | 5390 | do { \ |
| 5113 | #define DEFVAR_PER_BUFFER(lname, vname, type, doc) \ | 5391 | static struct Lisp_Buffer_Objfwd bo_fwd; \ |
| 5114 | do { \ | 5392 | defvar_per_buffer (&bo_fwd, lname, vname, predicate); \ |
| 5115 | static struct Lisp_Buffer_Objfwd bo_fwd; \ | ||
| 5116 | defvar_per_buffer (&bo_fwd, lname, vname, type); \ | ||
| 5117 | } while (0) | 5393 | } while (0) |
| 5118 | 5394 | ||
| 5119 | static void | 5395 | static void |
| 5120 | defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring, | 5396 | defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring, |
| 5121 | Lisp_Object *address, Lisp_Object type) | 5397 | Lisp_Object *address, Lisp_Object predicate) |
| 5122 | { | 5398 | { |
| 5123 | struct Lisp_Symbol *sym; | 5399 | struct Lisp_Symbol *sym; |
| 5124 | int offset; | 5400 | int offset; |
| @@ -5128,20 +5404,16 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring, | |||
| 5128 | 5404 | ||
| 5129 | bo_fwd->type = Lisp_Fwd_Buffer_Obj; | 5405 | bo_fwd->type = Lisp_Fwd_Buffer_Obj; |
| 5130 | bo_fwd->offset = offset; | 5406 | bo_fwd->offset = offset; |
| 5131 | bo_fwd->slottype = type; | 5407 | bo_fwd->predicate = predicate; |
| 5132 | sym->declared_special = 1; | 5408 | sym->declared_special = 1; |
| 5133 | sym->redirect = SYMBOL_FORWARDED; | 5409 | sym->redirect = SYMBOL_FORWARDED; |
| 5134 | { | 5410 | SET_SYMBOL_FWD (sym, (union Lisp_Fwd *) bo_fwd); |
| 5135 | /* I tried to do the job without a cast, but it seems impossible. | ||
| 5136 | union Lisp_Fwd *fwd; &(fwd->u_buffer_objfwd) = bo_fwd; */ | ||
| 5137 | SET_SYMBOL_FWD (sym, (union Lisp_Fwd *)bo_fwd); | ||
| 5138 | } | ||
| 5139 | XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym); | 5411 | XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym); |
| 5140 | 5412 | ||
| 5141 | if (PER_BUFFER_IDX (offset) == 0) | 5413 | if (PER_BUFFER_IDX (offset) == 0) |
| 5142 | /* Did a DEFVAR_PER_BUFFER without initializing the corresponding | 5414 | /* Did a DEFVAR_PER_BUFFER without initializing the corresponding |
| 5143 | slot of buffer_local_flags */ | 5415 | slot of buffer_local_flags */ |
| 5144 | abort (); | 5416 | emacs_abort (); |
| 5145 | } | 5417 | } |
| 5146 | 5418 | ||
| 5147 | 5419 | ||
| @@ -5153,8 +5425,6 @@ syms_of_buffer (void) | |||
| 5153 | last_overlay_modification_hooks | 5425 | last_overlay_modification_hooks |
| 5154 | = Fmake_vector (make_number (10), Qnil); | 5426 | = Fmake_vector (make_number (10), Qnil); |
| 5155 | 5427 | ||
| 5156 | staticpro (&Vbuffer_defaults); | ||
| 5157 | staticpro (&Vbuffer_local_symbols); | ||
| 5158 | staticpro (&Qfundamental_mode); | 5428 | staticpro (&Qfundamental_mode); |
| 5159 | staticpro (&Qmode_class); | 5429 | staticpro (&Qmode_class); |
| 5160 | staticpro (&QSFundamental); | 5430 | staticpro (&QSFundamental); |
| @@ -5179,9 +5449,9 @@ syms_of_buffer (void) | |||
| 5179 | DEFSYM (Qkill_buffer_query_functions, "kill-buffer-query-functions"); | 5449 | DEFSYM (Qkill_buffer_query_functions, "kill-buffer-query-functions"); |
| 5180 | 5450 | ||
| 5181 | Fput (Qprotected_field, Qerror_conditions, | 5451 | Fput (Qprotected_field, Qerror_conditions, |
| 5182 | pure_cons (Qprotected_field, pure_cons (Qerror, Qnil))); | 5452 | listn (CONSTYPE_PURE, 2, Qprotected_field, Qerror)); |
| 5183 | Fput (Qprotected_field, Qerror_message, | 5453 | Fput (Qprotected_field, Qerror_message, |
| 5184 | make_pure_c_string ("Attempt to modify a protected field")); | 5454 | build_pure_c_string ("Attempt to modify a protected field")); |
| 5185 | 5455 | ||
| 5186 | DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format", | 5456 | DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format", |
| 5187 | mode_line_format, | 5457 | mode_line_format, |
| @@ -5245,6 +5515,8 @@ This is the same as (default-value 'left-margin). */); | |||
| 5245 | DEFVAR_BUFFER_DEFAULTS ("default-tab-width", | 5515 | DEFVAR_BUFFER_DEFAULTS ("default-tab-width", |
| 5246 | tab_width, | 5516 | tab_width, |
| 5247 | doc: /* Default value of `tab-width' for buffers that do not override it. | 5517 | doc: /* Default value of `tab-width' for buffers that do not override it. |
| 5518 | NOTE: This controls the display width of a TAB character, and not | ||
| 5519 | the size of an indentation step. | ||
| 5248 | This is the same as (default-value 'tab-width). */); | 5520 | This is the same as (default-value 'tab-width). */); |
| 5249 | 5521 | ||
| 5250 | DEFVAR_BUFFER_DEFAULTS ("default-case-fold-search", | 5522 | DEFVAR_BUFFER_DEFAULTS ("default-case-fold-search", |
| @@ -5329,31 +5601,40 @@ the mode line appears at the bottom. */); | |||
| 5329 | DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format), | 5601 | DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format), |
| 5330 | Qnil, | 5602 | Qnil, |
| 5331 | doc: /* Template for displaying mode line for current buffer. | 5603 | doc: /* Template for displaying mode line for current buffer. |
| 5332 | Each buffer has its own value of this variable. | 5604 | |
| 5333 | Value may be nil, a string, a symbol or a list or cons cell. | 5605 | The value may be nil, a string, a symbol or a list. |
| 5606 | |||
| 5334 | A value of nil means don't display a mode line. | 5607 | A value of nil means don't display a mode line. |
| 5335 | For a symbol, its value is used (but it is ignored if t or nil). | 5608 | |
| 5336 | A string appearing directly as the value of a symbol is processed verbatim | 5609 | For any symbol other than t or nil, the symbol's value is processed as |
| 5337 | in that the %-constructs below are not recognized. | 5610 | a mode line construct. As a special exception, if that value is a |
| 5338 | Note that unless the symbol is marked as a `risky-local-variable', all | 5611 | string, the string is processed verbatim, without handling any |
| 5339 | properties in any strings, as well as all :eval and :propertize forms | 5612 | %-constructs (see below). Also, unless the symbol has a non-nil |
| 5340 | in the value of that symbol will be ignored. | 5613 | `risky-local-variable' property, all properties in any strings, as |
| 5341 | For a list of the form `(:eval FORM)', FORM is evaluated and the result | 5614 | well as all :eval and :propertize forms in the value, are ignored. |
| 5342 | is used as a mode line element. Be careful--FORM should not load any files, | 5615 | |
| 5343 | because that can cause an infinite recursion. | 5616 | A list whose car is a string or list is processed by processing each |
| 5344 | For a list of the form `(:propertize ELT PROPS...)', ELT is displayed | 5617 | of the list elements recursively, as separate mode line constructs, |
| 5345 | with the specified properties PROPS applied. | 5618 | and concatenating the results. |
| 5346 | For a list whose car is a symbol, the symbol's value is taken, | 5619 | |
| 5347 | and if that is non-nil, the cadr of the list is processed recursively. | 5620 | A list of the form `(:eval FORM)' is processed by evaluating FORM and |
| 5348 | Otherwise, the caddr of the list (if there is one) is processed. | 5621 | using the result as a mode line construct. Be careful--FORM should |
| 5349 | For a list whose car is a string or list, each element is processed | 5622 | not load any files, because that can cause an infinite recursion. |
| 5350 | recursively and the results are effectively concatenated. | 5623 | |
| 5351 | For a list whose car is an integer, the cdr of the list is processed | 5624 | A list of the form `(:propertize ELT PROPS...)' is processed by |
| 5352 | and padded (if the number is positive) or truncated (if negative) | 5625 | processing ELT as the mode line construct, and adding the text |
| 5353 | to the width specified by that number. | 5626 | properties PROPS to the result. |
| 5627 | |||
| 5628 | A list whose car is a symbol is processed by examining the symbol's | ||
| 5629 | value, and, if that value is non-nil, processing the cadr of the list | ||
| 5630 | recursively; and if that value is nil, processing the caddr of the | ||
| 5631 | list recursively. | ||
| 5632 | |||
| 5633 | A list whose car is an integer is processed by processing the cadr of | ||
| 5634 | the list, and padding (if the number is positive) or truncating (if | ||
| 5635 | negative) to the width specified by that number. | ||
| 5636 | |||
| 5354 | A string is printed verbatim in the mode line except for %-constructs: | 5637 | A string is printed verbatim in the mode line except for %-constructs: |
| 5355 | (%-constructs are allowed when the string is the entire mode-line-format | ||
| 5356 | or when it is found in a cons-cell or a list) | ||
| 5357 | %b -- print buffer name. %f -- print visited file name. | 5638 | %b -- print buffer name. %f -- print visited file name. |
| 5358 | %F -- print frame name. | 5639 | %F -- print frame name. |
| 5359 | %* -- print %, * or hyphen. %+ -- print *, % or hyphen. | 5640 | %* -- print %, * or hyphen. %+ -- print *, % or hyphen. |
| @@ -5384,7 +5665,7 @@ Decimal digits after the % specify field width to which to pad. */); | |||
| 5384 | doc: /* Value of `major-mode' for new buffers. */); | 5665 | doc: /* Value of `major-mode' for new buffers. */); |
| 5385 | 5666 | ||
| 5386 | DEFVAR_PER_BUFFER ("major-mode", &BVAR (current_buffer, major_mode), | 5667 | DEFVAR_PER_BUFFER ("major-mode", &BVAR (current_buffer, major_mode), |
| 5387 | make_number (Lisp_Symbol), | 5668 | Qsymbolp, |
| 5388 | doc: /* Symbol for current buffer's major mode. | 5669 | doc: /* Symbol for current buffer's major mode. |
| 5389 | The default value (normally `fundamental-mode') affects new buffers. | 5670 | The default value (normally `fundamental-mode') affects new buffers. |
| 5390 | A value of nil means to use the current buffer's major mode, provided | 5671 | A value of nil means to use the current buffer's major mode, provided |
| @@ -5415,18 +5696,20 @@ Use the command `abbrev-mode' to change this variable. */); | |||
| 5415 | doc: /* Non-nil if searches and matches should ignore case. */); | 5696 | doc: /* Non-nil if searches and matches should ignore case. */); |
| 5416 | 5697 | ||
| 5417 | DEFVAR_PER_BUFFER ("fill-column", &BVAR (current_buffer, fill_column), | 5698 | DEFVAR_PER_BUFFER ("fill-column", &BVAR (current_buffer, fill_column), |
| 5418 | make_number (LISP_INT_TAG), | 5699 | Qintegerp, |
| 5419 | doc: /* Column beyond which automatic line-wrapping should happen. | 5700 | doc: /* Column beyond which automatic line-wrapping should happen. |
| 5420 | Interactively, you can set the buffer local value using \\[set-fill-column]. */); | 5701 | Interactively, you can set the buffer local value using \\[set-fill-column]. */); |
| 5421 | 5702 | ||
| 5422 | DEFVAR_PER_BUFFER ("left-margin", &BVAR (current_buffer, left_margin), | 5703 | DEFVAR_PER_BUFFER ("left-margin", &BVAR (current_buffer, left_margin), |
| 5423 | make_number (LISP_INT_TAG), | 5704 | Qintegerp, |
| 5424 | doc: /* Column for the default `indent-line-function' to indent to. | 5705 | doc: /* Column for the default `indent-line-function' to indent to. |
| 5425 | Linefeed indents to this column in Fundamental mode. */); | 5706 | Linefeed indents to this column in Fundamental mode. */); |
| 5426 | 5707 | ||
| 5427 | DEFVAR_PER_BUFFER ("tab-width", &BVAR (current_buffer, tab_width), | 5708 | DEFVAR_PER_BUFFER ("tab-width", &BVAR (current_buffer, tab_width), |
| 5428 | make_number (LISP_INT_TAG), | 5709 | Qintegerp, |
| 5429 | doc: /* Distance between tab stops (for display of tab characters), in columns. | 5710 | doc: /* Distance between tab stops (for display of tab characters), in columns. |
| 5711 | NOTE: This controls the display width of a TAB character, and not | ||
| 5712 | the size of an indentation step. | ||
| 5430 | This should be an integer greater than zero. */); | 5713 | This should be an integer greater than zero. */); |
| 5431 | 5714 | ||
| 5432 | DEFVAR_PER_BUFFER ("ctl-arrow", &BVAR (current_buffer, ctl_arrow), Qnil, | 5715 | DEFVAR_PER_BUFFER ("ctl-arrow", &BVAR (current_buffer, ctl_arrow), Qnil, |
| @@ -5501,10 +5784,16 @@ This variable has no effect if long lines are truncated (see | |||
| 5501 | `truncate-lines' and `truncate-partial-width-windows'). If you use | 5784 | `truncate-lines' and `truncate-partial-width-windows'). If you use |
| 5502 | word-wrapping, you might want to reduce the value of | 5785 | word-wrapping, you might want to reduce the value of |
| 5503 | `truncate-partial-width-windows', since wrapping can make text readable | 5786 | `truncate-partial-width-windows', since wrapping can make text readable |
| 5504 | in narrower windows. */); | 5787 | in narrower windows. |
| 5788 | |||
| 5789 | Instead of setting this variable directly, most users should use | ||
| 5790 | Visual Line mode . Visual Line mode, when enabled, sets `word-wrap' | ||
| 5791 | to t, and additionally redefines simple editing commands to act on | ||
| 5792 | visual lines rather than logical lines. See the documentation of | ||
| 5793 | `visual-line-mode'. */); | ||
| 5505 | 5794 | ||
| 5506 | DEFVAR_PER_BUFFER ("default-directory", &BVAR (current_buffer, directory), | 5795 | DEFVAR_PER_BUFFER ("default-directory", &BVAR (current_buffer, directory), |
| 5507 | make_number (Lisp_String), | 5796 | Qstringp, |
| 5508 | doc: /* Name of default directory of current buffer. Should end with slash. | 5797 | doc: /* Name of default directory of current buffer. Should end with slash. |
| 5509 | To interactively change the default directory, use command `cd'. */); | 5798 | To interactively change the default directory, use command `cd'. */); |
| 5510 | 5799 | ||
| @@ -5517,18 +5806,18 @@ NOTE: This variable is not a hook; | |||
| 5517 | its value may not be a list of functions. */); | 5806 | its value may not be a list of functions. */); |
| 5518 | 5807 | ||
| 5519 | DEFVAR_PER_BUFFER ("buffer-file-name", &BVAR (current_buffer, filename), | 5808 | DEFVAR_PER_BUFFER ("buffer-file-name", &BVAR (current_buffer, filename), |
| 5520 | make_number (Lisp_String), | 5809 | Qstringp, |
| 5521 | doc: /* Name of file visited in current buffer, or nil if not visiting a file. */); | 5810 | doc: /* Name of file visited in current buffer, or nil if not visiting a file. */); |
| 5522 | 5811 | ||
| 5523 | DEFVAR_PER_BUFFER ("buffer-file-truename", &BVAR (current_buffer, file_truename), | 5812 | DEFVAR_PER_BUFFER ("buffer-file-truename", &BVAR (current_buffer, file_truename), |
| 5524 | make_number (Lisp_String), | 5813 | Qstringp, |
| 5525 | doc: /* Abbreviated truename of file visited in current buffer, or nil if none. | 5814 | doc: /* Abbreviated truename of file visited in current buffer, or nil if none. |
| 5526 | The truename of a file is calculated by `file-truename' | 5815 | The truename of a file is calculated by `file-truename' |
| 5527 | and then abbreviated with `abbreviate-file-name'. */); | 5816 | and then abbreviated with `abbreviate-file-name'. */); |
| 5528 | 5817 | ||
| 5529 | DEFVAR_PER_BUFFER ("buffer-auto-save-file-name", | 5818 | DEFVAR_PER_BUFFER ("buffer-auto-save-file-name", |
| 5530 | &BVAR (current_buffer, auto_save_file_name), | 5819 | &BVAR (current_buffer, auto_save_file_name), |
| 5531 | make_number (Lisp_String), | 5820 | Qstringp, |
| 5532 | doc: /* Name of file for auto-saving current buffer. | 5821 | doc: /* Name of file for auto-saving current buffer. |
| 5533 | If it is nil, that means don't auto-save this buffer. */); | 5822 | If it is nil, that means don't auto-save this buffer. */); |
| 5534 | 5823 | ||
| @@ -5540,7 +5829,7 @@ If it is nil, that means don't auto-save this buffer. */); | |||
| 5540 | Backing up is done before the first time the file is saved. */); | 5829 | Backing up is done before the first time the file is saved. */); |
| 5541 | 5830 | ||
| 5542 | DEFVAR_PER_BUFFER ("buffer-saved-size", &BVAR (current_buffer, save_length), | 5831 | DEFVAR_PER_BUFFER ("buffer-saved-size", &BVAR (current_buffer, save_length), |
| 5543 | make_number (LISP_INT_TAG), | 5832 | Qintegerp, |
| 5544 | doc: /* Length of current buffer when last read in, saved or auto-saved. | 5833 | doc: /* Length of current buffer when last read in, saved or auto-saved. |
| 5545 | 0 initially. | 5834 | 0 initially. |
| 5546 | -1 means auto-saving turned off until next real save. | 5835 | -1 means auto-saving turned off until next real save. |
| @@ -5558,12 +5847,10 @@ A value of t means that the character ^M makes itself and | |||
| 5558 | all the rest of the line invisible; also, when saving the buffer | 5847 | all the rest of the line invisible; also, when saving the buffer |
| 5559 | in a file, save the ^M as a newline. */); | 5848 | in a file, save the ^M as a newline. */); |
| 5560 | 5849 | ||
| 5561 | #ifndef old | ||
| 5562 | DEFVAR_PER_BUFFER ("selective-display-ellipses", | 5850 | DEFVAR_PER_BUFFER ("selective-display-ellipses", |
| 5563 | &BVAR (current_buffer, selective_display_ellipses), | 5851 | &BVAR (current_buffer, selective_display_ellipses), |
| 5564 | Qnil, | 5852 | Qnil, |
| 5565 | doc: /* Non-nil means display ... on previous line when a line is invisible. */); | 5853 | doc: /* Non-nil means display ... on previous line when a line is invisible. */); |
| 5566 | #endif | ||
| 5567 | 5854 | ||
| 5568 | DEFVAR_PER_BUFFER ("overwrite-mode", &BVAR (current_buffer, overwrite_mode), Qnil, | 5855 | DEFVAR_PER_BUFFER ("overwrite-mode", &BVAR (current_buffer, overwrite_mode), Qnil, |
| 5569 | doc: /* Non-nil if self-insertion should replace existing text. | 5856 | doc: /* Non-nil if self-insertion should replace existing text. |
| @@ -5612,34 +5899,49 @@ In addition, a char-table has six extra slots to control the display of: | |||
| 5612 | See also the functions `display-table-slot' and `set-display-table-slot'. */); | 5899 | See also the functions `display-table-slot' and `set-display-table-slot'. */); |
| 5613 | 5900 | ||
| 5614 | DEFVAR_PER_BUFFER ("left-margin-width", &BVAR (current_buffer, left_margin_cols), | 5901 | DEFVAR_PER_BUFFER ("left-margin-width", &BVAR (current_buffer, left_margin_cols), |
| 5615 | Qnil, | 5902 | Qintegerp, |
| 5616 | doc: /* Width of left marginal area for display of a buffer. | 5903 | doc: /* Width of left marginal area for display of a buffer. |
| 5617 | A value of nil means no marginal area. */); | 5904 | A value of nil means no marginal area. |
| 5905 | |||
| 5906 | Setting this variable does not take effect until a new buffer is displayed | ||
| 5907 | in a window. To make the change take effect, call `set-window-buffer'. */); | ||
| 5618 | 5908 | ||
| 5619 | DEFVAR_PER_BUFFER ("right-margin-width", &BVAR (current_buffer, right_margin_cols), | 5909 | DEFVAR_PER_BUFFER ("right-margin-width", &BVAR (current_buffer, right_margin_cols), |
| 5620 | Qnil, | 5910 | Qintegerp, |
| 5621 | doc: /* Width of right marginal area for display of a buffer. | 5911 | doc: /* Width of right marginal area for display of a buffer. |
| 5622 | A value of nil means no marginal area. */); | 5912 | A value of nil means no marginal area. |
| 5913 | |||
| 5914 | Setting this variable does not take effect until a new buffer is displayed | ||
| 5915 | in a window. To make the change take effect, call `set-window-buffer'. */); | ||
| 5623 | 5916 | ||
| 5624 | DEFVAR_PER_BUFFER ("left-fringe-width", &BVAR (current_buffer, left_fringe_width), | 5917 | DEFVAR_PER_BUFFER ("left-fringe-width", &BVAR (current_buffer, left_fringe_width), |
| 5625 | Qnil, | 5918 | Qintegerp, |
| 5626 | doc: /* Width of this buffer's left fringe (in pixels). | 5919 | doc: /* Width of this buffer's left fringe (in pixels). |
| 5627 | A value of 0 means no left fringe is shown in this buffer's window. | 5920 | A value of 0 means no left fringe is shown in this buffer's window. |
| 5628 | A value of nil means to use the left fringe width from the window's frame. */); | 5921 | A value of nil means to use the left fringe width from the window's frame. |
| 5922 | |||
| 5923 | Setting this variable does not take effect until a new buffer is displayed | ||
| 5924 | in a window. To make the change take effect, call `set-window-buffer'. */); | ||
| 5629 | 5925 | ||
| 5630 | DEFVAR_PER_BUFFER ("right-fringe-width", &BVAR (current_buffer, right_fringe_width), | 5926 | DEFVAR_PER_BUFFER ("right-fringe-width", &BVAR (current_buffer, right_fringe_width), |
| 5631 | Qnil, | 5927 | Qintegerp, |
| 5632 | doc: /* Width of this buffer's right fringe (in pixels). | 5928 | doc: /* Width of this buffer's right fringe (in pixels). |
| 5633 | A value of 0 means no right fringe is shown in this buffer's window. | 5929 | A value of 0 means no right fringe is shown in this buffer's window. |
| 5634 | A value of nil means to use the right fringe width from the window's frame. */); | 5930 | A value of nil means to use the right fringe width from the window's frame. |
| 5931 | |||
| 5932 | Setting this variable does not take effect until a new buffer is displayed | ||
| 5933 | in a window. To make the change take effect, call `set-window-buffer'. */); | ||
| 5635 | 5934 | ||
| 5636 | DEFVAR_PER_BUFFER ("fringes-outside-margins", &BVAR (current_buffer, fringes_outside_margins), | 5935 | DEFVAR_PER_BUFFER ("fringes-outside-margins", &BVAR (current_buffer, fringes_outside_margins), |
| 5637 | Qnil, | 5936 | Qnil, |
| 5638 | doc: /* Non-nil means to display fringes outside display margins. | 5937 | doc: /* Non-nil means to display fringes outside display margins. |
| 5639 | A value of nil means to display fringes between margins and buffer text. */); | 5938 | A value of nil means to display fringes between margins and buffer text. |
| 5939 | |||
| 5940 | Setting this variable does not take effect until a new buffer is displayed | ||
| 5941 | in a window. To make the change take effect, call `set-window-buffer'. */); | ||
| 5640 | 5942 | ||
| 5641 | DEFVAR_PER_BUFFER ("scroll-bar-width", &BVAR (current_buffer, scroll_bar_width), | 5943 | DEFVAR_PER_BUFFER ("scroll-bar-width", &BVAR (current_buffer, scroll_bar_width), |
| 5642 | Qnil, | 5944 | Qintegerp, |
| 5643 | doc: /* Width of this buffer's scroll bars in pixels. | 5945 | doc: /* Width of this buffer's scroll bars in pixels. |
| 5644 | A value of nil means to use the scroll bar width from the window's frame. */); | 5946 | A value of nil means to use the scroll bar width from the window's frame. */); |
| 5645 | 5947 | ||
| @@ -5719,7 +6021,7 @@ BITMAP is the corresponding fringe bitmap shown for the logical | |||
| 5719 | cursor type. */); | 6021 | cursor type. */); |
| 5720 | 6022 | ||
| 5721 | DEFVAR_PER_BUFFER ("scroll-up-aggressively", | 6023 | DEFVAR_PER_BUFFER ("scroll-up-aggressively", |
| 5722 | &BVAR (current_buffer, scroll_up_aggressively), Qnil, | 6024 | &BVAR (current_buffer, scroll_up_aggressively), Qfloatp, |
| 5723 | doc: /* How far to scroll windows upward. | 6025 | doc: /* How far to scroll windows upward. |
| 5724 | If you move point off the bottom, the window scrolls automatically. | 6026 | If you move point off the bottom, the window scrolls automatically. |
| 5725 | This variable controls how far it scrolls. The value nil, the default, | 6027 | This variable controls how far it scrolls. The value nil, the default, |
| @@ -5732,7 +6034,7 @@ window scrolls by a full window height. Meaningful values are | |||
| 5732 | between 0.0 and 1.0, inclusive. */); | 6034 | between 0.0 and 1.0, inclusive. */); |
| 5733 | 6035 | ||
| 5734 | DEFVAR_PER_BUFFER ("scroll-down-aggressively", | 6036 | DEFVAR_PER_BUFFER ("scroll-down-aggressively", |
| 5735 | &BVAR (current_buffer, scroll_down_aggressively), Qnil, | 6037 | &BVAR (current_buffer, scroll_down_aggressively), Qfloatp, |
| 5736 | doc: /* How far to scroll windows downward. | 6038 | doc: /* How far to scroll windows downward. |
| 5737 | If you move point off the top, the window scrolls automatically. | 6039 | If you move point off the top, the window scrolls automatically. |
| 5738 | This variable controls how far it scrolls. The value nil, the default, | 6040 | This variable controls how far it scrolls. The value nil, the default, |
| @@ -5744,10 +6046,6 @@ simple case that you moved off with C-b means scrolling just one line. | |||
| 5744 | window scrolls by a full window height. Meaningful values are | 6046 | window scrolls by a full window height. Meaningful values are |
| 5745 | between 0.0 and 1.0, inclusive. */); | 6047 | between 0.0 and 1.0, inclusive. */); |
| 5746 | 6048 | ||
| 5747 | /*DEFVAR_LISP ("debug-check-symbol", &Vcheck_symbol, | ||
| 5748 | "Don't ask."); | ||
| 5749 | */ | ||
| 5750 | |||
| 5751 | DEFVAR_LISP ("before-change-functions", Vbefore_change_functions, | 6049 | DEFVAR_LISP ("before-change-functions", Vbefore_change_functions, |
| 5752 | doc: /* List of functions to call before each text change. | 6050 | doc: /* List of functions to call before each text change. |
| 5753 | Two arguments are passed to each function: the positions of | 6051 | Two arguments are passed to each function: the positions of |
| @@ -5798,12 +6096,17 @@ An entry (TEXT . POSITION) represents the deletion of the string TEXT | |||
| 5798 | from (abs POSITION). If POSITION is positive, point was at the front | 6096 | from (abs POSITION). If POSITION is positive, point was at the front |
| 5799 | of the text being deleted; if negative, point was at the end. | 6097 | of the text being deleted; if negative, point was at the end. |
| 5800 | 6098 | ||
| 5801 | An entry (t HIGH . LOW) indicates that the buffer previously had | 6099 | An entry (t HIGH LOW USEC PSEC) indicates that the buffer was previously |
| 5802 | \"unmodified\" status. HIGH and LOW are the high and low 16-bit portions | 6100 | unmodified; (HIGH LOW USEC PSEC) is in the same style as (current-time) |
| 5803 | of the visited file's modification time, as of that time. If the | 6101 | and is the visited file's modification time, as of that time. If the |
| 5804 | modification time of the most recent save is different, this entry is | 6102 | modification time of the most recent save is different, this entry is |
| 5805 | obsolete. | 6103 | obsolete. |
| 5806 | 6104 | ||
| 6105 | An entry (t . 0) means means the buffer was previously unmodified but | ||
| 6106 | its time stamp was unknown because it was not associated with a file. | ||
| 6107 | An entry (t . -1) is similar, except that it means the buffer's visited | ||
| 6108 | file did not exist. | ||
| 6109 | |||
| 5807 | An entry (nil PROPERTY VALUE BEG . END) indicates that a text property | 6110 | An entry (nil PROPERTY VALUE BEG . END) indicates that a text property |
| 5808 | was modified between BEG and END. PROPERTY is the property name, | 6111 | was modified between BEG and END. PROPERTY is the property name, |
| 5809 | and VALUE is the old value. | 6112 | and VALUE is the old value. |
| @@ -5813,7 +6116,7 @@ An entry (apply FUN-NAME . ARGS) means undo the change with | |||
| 5813 | 6116 | ||
| 5814 | An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo | 6117 | An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo |
| 5815 | in the active region. BEG and END is the range affected by this entry | 6118 | in the active region. BEG and END is the range affected by this entry |
| 5816 | and DELTA is the number of bytes added or deleted in that range by | 6119 | and DELTA is the number of characters added or deleted in that range by |
| 5817 | this change. | 6120 | this change. |
| 5818 | 6121 | ||
| 5819 | An entry (MARKER . DISTANCE) indicates that the marker MARKER | 6122 | An entry (MARKER . DISTANCE) indicates that the marker MARKER |
| @@ -5831,8 +6134,8 @@ If the value of the variable is t, undo information is not recorded. */); | |||
| 5831 | DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer, mark_active), Qnil, | 6134 | DEFVAR_PER_BUFFER ("mark-active", &BVAR (current_buffer, mark_active), Qnil, |
| 5832 | doc: /* Non-nil means the mark and region are currently active in this buffer. */); | 6135 | doc: /* Non-nil means the mark and region are currently active in this buffer. */); |
| 5833 | 6136 | ||
| 5834 | DEFVAR_PER_BUFFER ("cache-long-line-scans", &BVAR (current_buffer, cache_long_line_scans), Qnil, | 6137 | DEFVAR_PER_BUFFER ("cache-long-scans", &BVAR (current_buffer, cache_long_scans), Qnil, |
| 5835 | doc: /* Non-nil means that Emacs should use caches to handle long lines more quickly. | 6138 | doc: /* Non-nil means that Emacs should use caches in attempt to speedup buffer scans. |
| 5836 | 6139 | ||
| 5837 | Normally, the line-motion functions work by scanning the buffer for | 6140 | Normally, the line-motion functions work by scanning the buffer for |
| 5838 | newlines. Columnar operations (like `move-to-column' and | 6141 | newlines. Columnar operations (like `move-to-column' and |
| @@ -5842,18 +6145,24 @@ buffer's lines are very long (say, more than 500 characters), these | |||
| 5842 | motion functions will take longer to execute. Emacs may also take | 6145 | motion functions will take longer to execute. Emacs may also take |
| 5843 | longer to update the display. | 6146 | longer to update the display. |
| 5844 | 6147 | ||
| 5845 | If `cache-long-line-scans' is non-nil, these motion functions cache the | 6148 | If `cache-long-scans' is non-nil, these motion functions cache the |
| 5846 | results of their scans, and consult the cache to avoid rescanning | 6149 | results of their scans, and consult the cache to avoid rescanning |
| 5847 | regions of the buffer until the text is modified. The caches are most | 6150 | regions of the buffer until the text is modified. The caches are most |
| 5848 | beneficial when they prevent the most searching---that is, when the | 6151 | beneficial when they prevent the most searching---that is, when the |
| 5849 | buffer contains long lines and large regions of characters with the | 6152 | buffer contains long lines and large regions of characters with the |
| 5850 | same, fixed screen width. | 6153 | same, fixed screen width. |
| 5851 | 6154 | ||
| 5852 | When `cache-long-line-scans' is non-nil, processing short lines will | 6155 | When `cache-long-scans' is non-nil, processing short lines will |
| 5853 | become slightly slower (because of the overhead of consulting the | 6156 | become slightly slower (because of the overhead of consulting the |
| 5854 | cache), and the caches will use memory roughly proportional to the | 6157 | cache), and the caches will use memory roughly proportional to the |
| 5855 | number of newlines and characters whose screen width varies. | 6158 | number of newlines and characters whose screen width varies. |
| 5856 | 6159 | ||
| 6160 | Bidirectional editing also requires buffer scans to find paragraph | ||
| 6161 | separators. If you have large paragraphs or no paragraph separators | ||
| 6162 | at all, these scans may be slow. If `cache-long-scans' is non-nil, | ||
| 6163 | results of these scans are cached. This doesn't help too much if | ||
| 6164 | paragraphs are of the reasonable (few thousands of characters) size. | ||
| 6165 | |||
| 5857 | The caches require no explicit maintenance; their accuracy is | 6166 | The caches require no explicit maintenance; their accuracy is |
| 5858 | maintained internally by the Emacs primitives. Enabling or disabling | 6167 | maintained internally by the Emacs primitives. Enabling or disabling |
| 5859 | the cache should not affect the behavior of any of the motion | 6168 | the cache should not affect the behavior of any of the motion |
| @@ -5886,7 +6195,7 @@ then characters with property value PROP are invisible, | |||
| 5886 | and they have an ellipsis as well if ELLIPSIS is non-nil. */); | 6195 | and they have an ellipsis as well if ELLIPSIS is non-nil. */); |
| 5887 | 6196 | ||
| 5888 | DEFVAR_PER_BUFFER ("buffer-display-count", | 6197 | DEFVAR_PER_BUFFER ("buffer-display-count", |
| 5889 | &BVAR (current_buffer, display_count), Qnil, | 6198 | &BVAR (current_buffer, display_count), Qintegerp, |
| 5890 | doc: /* A number incremented each time this buffer is displayed in a window. | 6199 | doc: /* A number incremented each time this buffer is displayed in a window. |
| 5891 | The function `set-window-buffer' increments it. */); | 6200 | The function `set-window-buffer' increments it. */); |
| 5892 | 6201 | ||
| @@ -5930,22 +6239,22 @@ is a member of the list. */); | |||
| 5930 | doc: /* Cursor to use when this buffer is in the selected window. | 6239 | doc: /* Cursor to use when this buffer is in the selected window. |
| 5931 | Values are interpreted as follows: | 6240 | Values are interpreted as follows: |
| 5932 | 6241 | ||
| 5933 | t use the cursor specified for the frame | 6242 | t use the cursor specified for the frame |
| 5934 | nil don't display a cursor | 6243 | nil don't display a cursor |
| 5935 | box display a filled box cursor | 6244 | box display a filled box cursor |
| 5936 | hollow display a hollow box cursor | 6245 | hollow display a hollow box cursor |
| 5937 | bar display a vertical bar cursor with default width | 6246 | bar display a vertical bar cursor with default width |
| 5938 | (bar . WIDTH) display a vertical bar cursor with width WIDTH | 6247 | (bar . WIDTH) display a vertical bar cursor with width WIDTH |
| 5939 | hbar display a horizontal bar cursor with default height | 6248 | hbar display a horizontal bar cursor with default height |
| 5940 | (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT | 6249 | (hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT |
| 5941 | ANYTHING ELSE display a hollow box cursor | 6250 | ANYTHING ELSE display a hollow box cursor |
| 5942 | 6251 | ||
| 5943 | When the buffer is displayed in a non-selected window, the | 6252 | When the buffer is displayed in a non-selected window, the |
| 5944 | cursor's appearance is instead controlled by the variable | 6253 | cursor's appearance is instead controlled by the variable |
| 5945 | `cursor-in-non-selected-windows'. */); | 6254 | `cursor-in-non-selected-windows'. */); |
| 5946 | 6255 | ||
| 5947 | DEFVAR_PER_BUFFER ("line-spacing", | 6256 | DEFVAR_PER_BUFFER ("line-spacing", |
| 5948 | &BVAR (current_buffer, extra_line_spacing), Qnil, | 6257 | &BVAR (current_buffer, extra_line_spacing), Qnumberp, |
| 5949 | doc: /* Additional space to put between lines when displaying a buffer. | 6258 | doc: /* Additional space to put between lines when displaying a buffer. |
| 5950 | The space is measured in pixels, and put below lines on graphic displays, | 6259 | The space is measured in pixels, and put below lines on graphic displays, |
| 5951 | see `display-graphic-p'. | 6260 | see `display-graphic-p'. |
| @@ -5964,7 +6273,9 @@ Use Custom to set this variable and update the display." */); | |||
| 5964 | DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions, | 6273 | DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions, |
| 5965 | doc: /* List of functions called with no args to query before killing a buffer. | 6274 | doc: /* List of functions called with no args to query before killing a buffer. |
| 5966 | The buffer being killed will be current while the functions are running. | 6275 | The buffer being killed will be current while the functions are running. |
| 5967 | If any of them returns nil, the buffer is not killed. */); | 6276 | |
| 6277 | If any of them returns nil, the buffer is not killed. Functions run by | ||
| 6278 | this hook are supposed to not change the current buffer. */); | ||
| 5968 | Vkill_buffer_query_functions = Qnil; | 6279 | Vkill_buffer_query_functions = Qnil; |
| 5969 | 6280 | ||
| 5970 | DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook, | 6281 | DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook, |
| @@ -5989,7 +6300,6 @@ and `bury-buffer-internal'. */); | |||
| 5989 | defsubr (&Smake_indirect_buffer); | 6300 | defsubr (&Smake_indirect_buffer); |
| 5990 | defsubr (&Sgenerate_new_buffer_name); | 6301 | defsubr (&Sgenerate_new_buffer_name); |
| 5991 | defsubr (&Sbuffer_name); | 6302 | defsubr (&Sbuffer_name); |
| 5992 | /*defsubr (&Sbuffer_number);*/ | ||
| 5993 | defsubr (&Sbuffer_file_name); | 6303 | defsubr (&Sbuffer_file_name); |
| 5994 | defsubr (&Sbuffer_base_buffer); | 6304 | defsubr (&Sbuffer_base_buffer); |
| 5995 | defsubr (&Sbuffer_local_value); | 6305 | defsubr (&Sbuffer_local_value); |
| @@ -6015,6 +6325,7 @@ and `bury-buffer-internal'. */); | |||
| 6015 | defsubr (&Soverlayp); | 6325 | defsubr (&Soverlayp); |
| 6016 | defsubr (&Smake_overlay); | 6326 | defsubr (&Smake_overlay); |
| 6017 | defsubr (&Sdelete_overlay); | 6327 | defsubr (&Sdelete_overlay); |
| 6328 | defsubr (&Sdelete_all_overlays); | ||
| 6018 | defsubr (&Smove_overlay); | 6329 | defsubr (&Smove_overlay); |
| 6019 | defsubr (&Soverlay_start); | 6330 | defsubr (&Soverlay_start); |
| 6020 | defsubr (&Soverlay_end); | 6331 | defsubr (&Soverlay_end); |