comparison src/buffer.c @ 17022:907fb167f7de

Include charset.h. (Fget_buffer_create): Allocate an extra byte for a buffer, and make it always 0 for anchoring. (reset_buffer): Handle a new member `enable_multibyte_characters' in the struct buffer. (fix_overlay_before): New function. (init_buffer_once): Handle new members in the struct buffer. (syms_of_buffer): Declare new buffer local variables `enable-multibyte-characters' and `direction-reserved'.
author Karl Heuer <kwzh@gnu.org>
date Thu, 20 Feb 1997 06:44:32 +0000
parents 299b0e0f0a93
children fdad8ea24563
comparison
equal deleted inserted replaced
17021:35f01092d865 17022:907fb167f7de
33 #include "lisp.h" 33 #include "lisp.h"
34 #include "intervals.h" 34 #include "intervals.h"
35 #include "window.h" 35 #include "window.h"
36 #include "commands.h" 36 #include "commands.h"
37 #include "buffer.h" 37 #include "buffer.h"
38 #include "charset.h"
38 #include "region-cache.h" 39 #include "region-cache.h"
39 #include "indent.h" 40 #include "indent.h"
40 #include "blockinput.h" 41 #include "blockinput.h"
41 42
42 struct buffer *current_buffer; /* the current buffer */ 43 struct buffer *current_buffer; /* the current buffer */
300 b->text = &b->own_text; 301 b->text = &b->own_text;
301 b->base_buffer = 0; 302 b->base_buffer = 0;
302 303
303 BUF_GAP_SIZE (b) = 20; 304 BUF_GAP_SIZE (b) = 20;
304 BLOCK_INPUT; 305 BLOCK_INPUT;
305 BUFFER_ALLOC (BUF_BEG_ADDR (b), BUF_GAP_SIZE (b)); 306 /* We allocate extra 1-byte at the tail and keep it always '\0' for
307 anchoring a search. */
308 BUFFER_ALLOC (BUF_BEG_ADDR (b), (BUF_GAP_SIZE (b) + 1));
306 UNBLOCK_INPUT; 309 UNBLOCK_INPUT;
307 if (! BUF_BEG_ADDR (b)) 310 if (! BUF_BEG_ADDR (b))
308 buffer_memory_full (); 311 buffer_memory_full ();
309 312
310 BUF_PT (b) = 1; 313 BUF_PT (b) = 1;
314 BUF_Z (b) = 1; 317 BUF_Z (b) = 1;
315 BUF_MODIFF (b) = 1; 318 BUF_MODIFF (b) = 1;
316 BUF_OVERLAY_MODIFF (b) = 1; 319 BUF_OVERLAY_MODIFF (b) = 1;
317 BUF_SAVE_MODIFF (b) = 1; 320 BUF_SAVE_MODIFF (b) = 1;
318 BUF_INTERVALS (b) = 0; 321 BUF_INTERVALS (b) = 0;
322 *(BUF_GPT_ADDR (b)) = *(BUF_Z_ADDR (b)) = 0; /* Put an anchor '\0'. */
319 323
320 b->newline_cache = 0; 324 b->newline_cache = 0;
321 b->width_run_cache = 0; 325 b->width_run_cache = 0;
322 b->width_table = Qnil; 326 b->width_table = Qnil;
323 327
470 b->overlays_after = Qnil; 474 b->overlays_after = Qnil;
471 XSETFASTINT (b->overlay_center, 1); 475 XSETFASTINT (b->overlay_center, 1);
472 b->mark_active = Qnil; 476 b->mark_active = Qnil;
473 b->point_before_scroll = Qnil; 477 b->point_before_scroll = Qnil;
474 b->file_format = Qnil; 478 b->file_format = Qnil;
479 b->enable_multibyte_characters = Qt;
475 b->last_selected_window = Qnil; 480 b->last_selected_window = Qnil;
476 b->extra2 = Qnil; 481 b->extra2 = Qnil;
477 b->extra3 = Qnil; 482 b->extra3 = Qnil;
478 } 483 }
479 484
2511 2516
2512 *pafter = current_buffer->overlays_after; 2517 *pafter = current_buffer->overlays_after;
2513 current_buffer->overlays_after = after_list; 2518 current_buffer->overlays_after = after_list;
2514 recenter_overlay_lists (current_buffer, 2519 recenter_overlay_lists (current_buffer,
2515 XINT (current_buffer->overlay_center)); 2520 XINT (current_buffer->overlay_center));
2521 }
2522
2523 /* We have two types of overlay: the one whose ending marker is
2524 after-insertion-marker (this is the usual case) and the one whose
2525 ending marker is before-insertion-marker. When `overlays_before'
2526 contains overlays of the latter type and the former type in this
2527 order and both overlays end at inserting position, inserting a text
2528 increases only the ending marker of the latter type, which results
2529 in incorrect ordering of `overlays_before'.
2530
2531 This function fixes ordering of overlays in the slot
2532 `overlays_before' of the buffer *BP. Before the insertion, `point'
2533 was at PREV, and now is at POS. */
2534
2535 fix_overlays_before (bp, prev, pos)
2536 struct buffer *bp;
2537 int prev, pos;
2538 {
2539 Lisp_Object *tailp = &bp->overlays_before;
2540 Lisp_Object *right_place;
2541 int end;
2542
2543 /* After the insertion, the several overlays may be in incorrect
2544 order. The possibility is that, in the list `overlays_before',
2545 an overlay which ends at POS appears after an overlay which ends
2546 at PREV. Since POS is greater than PREV, we must fix the
2547 ordering of these overlays, by moving overlays ends at POS before
2548 the overlays ends at PREV. */
2549
2550 /* At first, find a place where disordered overlays should be linked
2551 in. It is where an overlay which end before POS exists. (i.e. an
2552 overlay whose ending marker is after-insertion-marker if disorder
2553 exists). */
2554 while (!NILP (*tailp)
2555 && ((end = OVERLAY_POSITION (OVERLAY_END (XCONS (*tailp)->car)))
2556 >= pos))
2557 tailp = &XCONS (*tailp)->cdr;
2558
2559 /* If we don't find such an overlay,
2560 or the found one ends before PREV,
2561 or the found one is the last one in the list,
2562 we don't have to fix anything. */
2563 if (NILP (*tailp)
2564 || end < prev
2565 || NILP (XCONS (*tailp)->cdr))
2566 return;
2567
2568 right_place = tailp;
2569 tailp = &XCONS (*tailp)->cdr;
2570
2571 /* Now, end position of overlays in the list *TAILP should be before
2572 or equal to PREV. In the loop, an overlay which ends at POS is
2573 moved ahead to the place pointed by RIGHT_PLACE. If we found an
2574 overlay which ends before PREV, the remaining overlays are in
2575 correct order. */
2576 while (!NILP (*tailp))
2577 {
2578 end = OVERLAY_POSITION (OVERLAY_END (XCONS (*tailp)->car));
2579
2580 if (end == pos)
2581 { /* This overlay is disordered. */
2582 Lisp_Object found = *tailp;
2583
2584 /* Unlink the found overlay. */
2585 *tailp = XCONS (found)->cdr;
2586 /* Move an overlay at RIGHT_PLACE to the next of the found one. */
2587 XCONS (found)->cdr = *right_place;
2588 /* Link it into the right place. */
2589 *right_place = found;
2590 }
2591 else if (end == prev)
2592 tailp = &XCONS (*tailp)->cdr;
2593 else /* No more disordered overlay. */
2594 break;
2595 }
2516 } 2596 }
2517 2597
2518 DEFUN ("overlayp", Foverlayp, Soverlayp, 1, 1, 0, 2598 DEFUN ("overlayp", Foverlayp, Soverlayp, 1, 1, 0,
2519 "Return t if OBJECT is an overlay.") 2599 "Return t if OBJECT is an overlay.")
2520 (object) 2600 (object)
3430 XSETFASTINT (buffer_defaults.overlay_center, BEG); 3510 XSETFASTINT (buffer_defaults.overlay_center, BEG);
3431 3511
3432 XSETFASTINT (buffer_defaults.tab_width, 8); 3512 XSETFASTINT (buffer_defaults.tab_width, 8);
3433 buffer_defaults.truncate_lines = Qnil; 3513 buffer_defaults.truncate_lines = Qnil;
3434 buffer_defaults.ctl_arrow = Qt; 3514 buffer_defaults.ctl_arrow = Qt;
3515 buffer_defaults.direction_reversed = Qnil;
3435 3516
3436 #ifdef DOS_NT 3517 #ifdef DOS_NT
3437 buffer_defaults.buffer_file_type = Qnil; /* TEXT */ 3518 buffer_defaults.buffer_file_type = Qnil; /* TEXT */
3438 #endif 3519 #endif
3439 XSETFASTINT (buffer_defaults.fill_column, 70); 3520 XSETFASTINT (buffer_defaults.fill_column, 70);
3463 XSETINT (buffer_local_flags.mark_active, -1); 3544 XSETINT (buffer_local_flags.mark_active, -1);
3464 XSETINT (buffer_local_flags.point_before_scroll, -1); 3545 XSETINT (buffer_local_flags.point_before_scroll, -1);
3465 XSETINT (buffer_local_flags.file_truename, -1); 3546 XSETINT (buffer_local_flags.file_truename, -1);
3466 XSETINT (buffer_local_flags.invisibility_spec, -1); 3547 XSETINT (buffer_local_flags.invisibility_spec, -1);
3467 XSETINT (buffer_local_flags.file_format, -1); 3548 XSETINT (buffer_local_flags.file_format, -1);
3549 XSETINT (buffer_local_flags.enable_multibyte_characters, -1);
3468 3550
3469 XSETFASTINT (buffer_local_flags.mode_line_format, 1); 3551 XSETFASTINT (buffer_local_flags.mode_line_format, 1);
3470 XSETFASTINT (buffer_local_flags.abbrev_mode, 2); 3552 XSETFASTINT (buffer_local_flags.abbrev_mode, 2);
3471 XSETFASTINT (buffer_local_flags.overwrite_mode, 4); 3553 XSETFASTINT (buffer_local_flags.overwrite_mode, 4);
3472 XSETFASTINT (buffer_local_flags.case_fold_search, 8); 3554 XSETFASTINT (buffer_local_flags.case_fold_search, 8);
3487 /* Make this one a permanent local. */ 3569 /* Make this one a permanent local. */
3488 buffer_permanent_local_flags |= 0x4000; 3570 buffer_permanent_local_flags |= 0x4000;
3489 #endif 3571 #endif
3490 XSETFASTINT (buffer_local_flags.syntax_table, 0x8000); 3572 XSETFASTINT (buffer_local_flags.syntax_table, 0x8000);
3491 XSETFASTINT (buffer_local_flags.cache_long_line_scans, 0x10000); 3573 XSETFASTINT (buffer_local_flags.cache_long_line_scans, 0x10000);
3574 XSETFASTINT (buffer_local_flags.category_table, 0x20000);
3575 XSETFASTINT (buffer_local_flags.direction_reversed, 0x40000);
3492 3576
3493 Vbuffer_alist = Qnil; 3577 Vbuffer_alist = Qnil;
3494 current_buffer = 0; 3578 current_buffer = 0;
3495 all_buffers = 0; 3579 all_buffers = 0;
3496 3580
3627 DEFVAR_LISP_NOPRO ("default-ctl-arrow", 3711 DEFVAR_LISP_NOPRO ("default-ctl-arrow",
3628 &buffer_defaults.ctl_arrow, 3712 &buffer_defaults.ctl_arrow,
3629 "Default value of `ctl-arrow' for buffers that do not override it.\n\ 3713 "Default value of `ctl-arrow' for buffers that do not override it.\n\
3630 This is the same as (default-value 'ctl-arrow)."); 3714 This is the same as (default-value 'ctl-arrow).");
3631 3715
3716 DEFVAR_LISP_NOPRO ("default-direction-reversed",
3717 &buffer_defaults.direction_reversed,
3718 "Default value of `direction_reversed' for buffers that do not override it.\n\
3719 This is the same as (default-value 'direction-reversed).");
3720
3632 DEFVAR_LISP_NOPRO ("default-truncate-lines", 3721 DEFVAR_LISP_NOPRO ("default-truncate-lines",
3633 &buffer_defaults.truncate_lines, 3722 &buffer_defaults.truncate_lines,
3634 "Default value of `truncate-lines' for buffers that do not override it.\n\ 3723 "Default value of `truncate-lines' for buffers that do not override it.\n\
3635 This is the same as (default-value 'truncate-lines)."); 3724 This is the same as (default-value 'truncate-lines).");
3636 3725
3743 "*Non-nil means display control chars with uparrow.\n\ 3832 "*Non-nil means display control chars with uparrow.\n\
3744 Nil means use backslash and octal digits.\n\ 3833 Nil means use backslash and octal digits.\n\
3745 Automatically becomes buffer-local when set in any fashion.\n\ 3834 Automatically becomes buffer-local when set in any fashion.\n\
3746 This variable does not apply to characters whose display is specified\n\ 3835 This variable does not apply to characters whose display is specified\n\
3747 in the current display table (if there is one)."); 3836 in the current display table (if there is one).");
3837
3838 DEFVAR_PER_BUFFER ("enable-multibyte-characters",
3839 &current_buffer->enable_multibyte_characters, Qnil,
3840 "Non-nil means the buffer contents are regarded as multi-byte form\n\
3841 of characters, not a binary code. This affects the display, file I/O,\n\
3842 and behaviors of various editing commands.");
3843
3844 DEFVAR_PER_BUFFER ("direction-reversed", &current_buffer->direction_reversed,
3845 Qnil,
3846 "*Non-nil means lines in the buffer are displayed right to left.");
3748 3847
3749 DEFVAR_PER_BUFFER ("truncate-lines", &current_buffer->truncate_lines, Qnil, 3848 DEFVAR_PER_BUFFER ("truncate-lines", &current_buffer->truncate_lines, Qnil,
3750 "*Non-nil means do not display continuation lines;\n\ 3849 "*Non-nil means do not display continuation lines;\n\
3751 give each line of text one screen line.\n\ 3850 give each line of text one screen line.\n\
3752 Automatically becomes buffer-local when set in any fashion.\n\ 3851 Automatically becomes buffer-local when set in any fashion.\n\