aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorKenichi Handa2012-07-17 07:25:00 +0900
committerKenichi Handa2012-07-17 07:25:00 +0900
commit69c41c4070c86baac11a627e9c3d366420aeb7cc (patch)
treee07fda92570b5e4f264c9a7869b57960940008f0 /src/buffer.c
parent8c536f15bf95916d56bb50495d22b7da7e09fff9 (diff)
parent758e556a7ab8f61c007e34310ba399a9aaf15362 (diff)
downloademacs-69c41c4070c86baac11a627e9c3d366420aeb7cc.tar.gz
emacs-69c41c4070c86baac11a627e9c3d366420aeb7cc.zip
merge trunk
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c286
1 files changed, 150 insertions, 136 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 386d9a78153..b8c81a10d54 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -33,8 +33,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33#include "intervals.h" 33#include "intervals.h"
34#include "window.h" 34#include "window.h"
35#include "commands.h" 35#include "commands.h"
36#include "buffer.h"
37#include "character.h" 36#include "character.h"
37#include "buffer.h"
38#include "region-cache.h" 38#include "region-cache.h"
39#include "indent.h" 39#include "indent.h"
40#include "blockinput.h" 40#include "blockinput.h"
@@ -107,8 +107,6 @@ static char buffer_permanent_local_flags[MAX_PER_BUFFER_VARS];
107 107
108int last_per_buffer_idx; 108int last_per_buffer_idx;
109 109
110static Lisp_Object Fset_buffer_major_mode (Lisp_Object);
111static Lisp_Object Fdelete_overlay (Lisp_Object);
112static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay, 110static void call_overlay_mod_hooks (Lisp_Object list, Lisp_Object overlay,
113 int after, Lisp_Object arg1, 111 int after, Lisp_Object arg1,
114 Lisp_Object arg2, Lisp_Object arg3); 112 Lisp_Object arg2, Lisp_Object arg3);
@@ -460,16 +458,9 @@ copy_overlays (struct buffer *b, struct Lisp_Overlay *list)
460static void 458static void
461clone_per_buffer_values (struct buffer *from, struct buffer *to) 459clone_per_buffer_values (struct buffer *from, struct buffer *to)
462{ 460{
463 Lisp_Object to_buffer;
464 int offset; 461 int offset;
465 462
466 XSETBUFFER (to_buffer, to); 463 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 { 464 {
474 Lisp_Object obj; 465 Lisp_Object obj;
475 466
@@ -481,9 +472,9 @@ clone_per_buffer_values (struct buffer *from, struct buffer *to)
481 if (MARKERP (obj) && XMARKER (obj)->buffer == from) 472 if (MARKERP (obj) && XMARKER (obj)->buffer == from)
482 { 473 {
483 struct Lisp_Marker *m = XMARKER (obj); 474 struct Lisp_Marker *m = XMARKER (obj);
484 obj = Fmake_marker (); 475
476 obj = build_marker (to, m->charpos, m->bytepos);
485 XMARKER (obj)->insertion_type = m->insertion_type; 477 XMARKER (obj)->insertion_type = m->insertion_type;
486 set_marker_both (obj, to_buffer, m->charpos, m->bytepos);
487 } 478 }
488 479
489 PER_BUFFER_VALUE (to, offset) = obj; 480 PER_BUFFER_VALUE (to, offset) = obj;
@@ -621,32 +612,24 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
621 eassert (NILP (BVAR (b->base_buffer, begv_marker))); 612 eassert (NILP (BVAR (b->base_buffer, begv_marker)));
622 eassert (NILP (BVAR (b->base_buffer, zv_marker))); 613 eassert (NILP (BVAR (b->base_buffer, zv_marker)));
623 614
624 BVAR (b->base_buffer, pt_marker) = Fmake_marker (); 615 BVAR (b->base_buffer, pt_marker)
625 set_marker_both (BVAR (b->base_buffer, pt_marker), base_buffer, 616 = build_marker (b->base_buffer, b->base_buffer->pt, b->base_buffer->pt_byte);
626 b->base_buffer->pt,
627 b->base_buffer->pt_byte);
628 617
629 BVAR (b->base_buffer, begv_marker) = Fmake_marker (); 618 BVAR (b->base_buffer, begv_marker)
630 set_marker_both (BVAR (b->base_buffer, begv_marker), base_buffer, 619 = build_marker (b->base_buffer, b->base_buffer->begv, b->base_buffer->begv_byte);
631 b->base_buffer->begv, 620
632 b->base_buffer->begv_byte); 621 BVAR (b->base_buffer, zv_marker)
622 = build_marker (b->base_buffer, b->base_buffer->zv, b->base_buffer->zv_byte);
633 623
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; 624 XMARKER (BVAR (b->base_buffer, zv_marker))->insertion_type = 1;
639 } 625 }
640 626
641 if (NILP (clone)) 627 if (NILP (clone))
642 { 628 {
643 /* Give the indirect buffer markers for its narrowing. */ 629 /* Give the indirect buffer markers for its narrowing. */
644 BVAR (b, pt_marker) = Fmake_marker (); 630 BVAR (b, pt_marker) = build_marker (b, b->pt, b->pt_byte);
645 set_marker_both (BVAR (b, pt_marker), buf, b->pt, b->pt_byte); 631 BVAR (b, begv_marker) = build_marker (b, b->begv, b->begv_byte);
646 BVAR (b, begv_marker) = Fmake_marker (); 632 BVAR (b, zv_marker) = 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; 633 XMARKER (BVAR (b, zv_marker))->insertion_type = 1;
651 } 634 }
652 else 635 else
@@ -673,27 +656,40 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
673 return buf; 656 return buf;
674} 657}
675 658
659/* Mark OV as no longer associated with B. */
660
661static void
662drop_overlay (struct buffer *b, struct Lisp_Overlay *ov)
663{
664 eassert (b == XBUFFER (Fmarker_buffer (ov->start)));
665 modify_overlay (b, marker_position (ov->start), marker_position (ov->end));
666 Fset_marker (ov->start, Qnil, Qnil);
667 Fset_marker (ov->end, Qnil, Qnil);
668
669}
670
671/* Delete all overlays of B and reset it's overlay lists. */
672
676void 673void
677delete_all_overlays (struct buffer *b) 674delete_all_overlays (struct buffer *b)
678{ 675{
679 Lisp_Object overlay; 676 struct Lisp_Overlay *ov, *next;
680 677
681 /* `reset_buffer' blindly sets the list of overlays to NULL, so we 678 for (ov = b->overlays_before; ov; ov = next)
682 have to empty the list, otherwise we end up with overlays that
683 think they belong to this buffer while the buffer doesn't know about
684 them any more. */
685 while (b->overlays_before)
686 { 679 {
687 XSETMISC (overlay, b->overlays_before); 680 drop_overlay (b, ov);
688 Fdelete_overlay (overlay); 681 next = ov->next;
682 ov->next = NULL;
689 } 683 }
690 while (b->overlays_after) 684
685 for (ov = b->overlays_after; ov; ov = next)
691 { 686 {
692 XSETMISC (overlay, b->overlays_after); 687 drop_overlay (b, ov);
693 Fdelete_overlay (overlay); 688 next = ov->next;
689 ov->next = NULL;
694 } 690 }
695 eassert (b->overlays_before == NULL); 691
696 eassert (b->overlays_after == NULL); 692 b->overlays_before = b->overlays_after = NULL;
697} 693}
698 694
699/* Reinitialize everything about a buffer except its name and contents 695/* Reinitialize everything about a buffer except its name and contents
@@ -709,7 +705,7 @@ reset_buffer (register struct buffer *b)
709 BVAR (b, filename) = Qnil; 705 BVAR (b, filename) = Qnil;
710 BVAR (b, file_truename) = Qnil; 706 BVAR (b, file_truename) = Qnil;
711 BVAR (b, directory) = (current_buffer) ? BVAR (current_buffer, directory) : Qnil; 707 BVAR (b, directory) = (current_buffer) ? BVAR (current_buffer, directory) : Qnil;
712 b->modtime = 0; 708 b->modtime = make_emacs_time (0, UNKNOWN_MODTIME_NSECS);
713 b->modtime_size = -1; 709 b->modtime_size = -1;
714 XSETFASTINT (BVAR (b, save_length), 0); 710 XSETFASTINT (BVAR (b, save_length), 0);
715 b->last_window_start = 1; 711 b->last_window_start = 1;
@@ -820,14 +816,8 @@ reset_buffer_local_variables (register struct buffer *b, int permanent_too)
820 if (permanent_too || buffer_permanent_local_flags[i] == 0) 816 if (permanent_too || buffer_permanent_local_flags[i] == 0)
821 SET_PER_BUFFER_VALUE_P (b, i, 0); 817 SET_PER_BUFFER_VALUE_P (b, i, 0);
822 818
823 /* For each slot that has a default value, 819 /* For each slot that has a default value, copy that into the slot. */
824 copy that into the slot. */ 820 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 { 821 {
832 int idx = PER_BUFFER_IDX (offset); 822 int idx = PER_BUFFER_IDX (offset);
833 if ((idx > 0 823 if ((idx > 0
@@ -848,10 +838,14 @@ If there is no live buffer named NAME, then return NAME.
848Otherwise modify name by appending `<NUMBER>', incrementing NUMBER 838Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
849\(starting at 2) until an unused name is found, and then return that name. 839\(starting at 2) until an unused name is found, and then return that name.
850Optional second argument IGNORE specifies a name that is okay to use (if 840Optional second argument IGNORE specifies a name that is okay to use (if
851it is in the sequence to be tried) even if a buffer with that name exists. */) 841it is in the sequence to be tried) even if a buffer with that name exists.
842
843If NAME begins with a space (i.e., a buffer that is not normally
844visible to users), then if buffer NAME already exists a random number
845is first appended to NAME, to speed up finding a non-existent buffer. */)
852 (register Lisp_Object name, Lisp_Object ignore) 846 (register Lisp_Object name, Lisp_Object ignore)
853{ 847{
854 register Lisp_Object gentemp, tem; 848 register Lisp_Object gentemp, tem, tem2;
855 ptrdiff_t count; 849 ptrdiff_t count;
856 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"]; 850 char number[INT_BUFSIZE_BOUND (ptrdiff_t) + sizeof "<>"];
857 851
@@ -864,11 +858,24 @@ it is in the sequence to be tried) even if a buffer with that name exists. */)
864 if (NILP (tem)) 858 if (NILP (tem))
865 return name; 859 return name;
866 860
861 if (!strncmp (SSDATA (name), " ", 1)) /* see bug#1229 */
862 {
863 /* Note fileio.c:make_temp_name does random differently. */
864 tem2 = concat2 (name, make_formatted_string
865 (number, "-%"pI"d",
866 XFASTINT (Frandom (make_number (999999)))));
867 tem = Fget_buffer (tem2);
868 if (NILP (tem))
869 return tem2;
870 }
871 else
872 tem2 = name;
873
867 count = 1; 874 count = 1;
868 while (1) 875 while (1)
869 { 876 {
870 sprintf (number, "<%"pD"d>", ++count); 877 gentemp = concat2 (tem2, make_formatted_string
871 gentemp = concat2 (name, build_string (number)); 878 (number, "<%"pD"d>", ++count));
872 tem = Fstring_equal (gentemp, ignore); 879 tem = Fstring_equal (gentemp, ignore);
873 if (!NILP (tem)) 880 if (!NILP (tem))
874 return gentemp; 881 return gentemp;
@@ -1063,12 +1070,7 @@ No argument or nil as argument means use current buffer as BUFFER. */)
1063 { 1070 {
1064 int offset, idx; 1071 int offset, idx;
1065 1072
1066 /* buffer-local Lisp variables start at `undo_list', 1073 for_each_per_buffer_object_at (offset)
1067 tho only the ones from `name' on are GC'd normally. */
1068 for (offset = PER_BUFFER_VAR_OFFSET (FIRST_FIELD_PER_BUFFER);
1069 offset <= PER_BUFFER_VAR_OFFSET (LAST_FIELD_PER_BUFFER);
1070 /* sizeof EMACS_INT == sizeof Lisp_Object */
1071 offset += (sizeof (EMACS_INT)))
1072 { 1074 {
1073 idx = PER_BUFFER_IDX (offset); 1075 idx = PER_BUFFER_IDX (offset);
1074 if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) 1076 if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
@@ -1434,24 +1436,26 @@ No argument or nil as argument means do this for the current buffer. */)
1434 DEFVAR_LISP ("kill-buffer-hook", ..., "\ 1436 DEFVAR_LISP ("kill-buffer-hook", ..., "\
1435Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\ 1437Hook to be run (by `run-hooks', which see) when a buffer is killed.\n\
1436The buffer being killed will be current while the hook is running.\n\ 1438The buffer being killed will be current while the hook is running.\n\
1437See `kill-buffer'." 1439
1438 */ 1440Functions run by this hook are supposed to not change the current
1441buffer. See `kill-buffer'."
1442*/
1439DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ", 1443DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 0, 1, "bKill buffer: ",
1440 doc: /* Kill buffer BUFFER-OR-NAME. 1444 doc: /* Kill the buffer specified by BUFFER-OR-NAME.
1441The argument may be a buffer or the name of an existing buffer. 1445The argument may be a buffer or the name of an existing buffer.
1442Argument nil or omitted means kill the current buffer. Return t if the 1446Argument nil or omitted means kill the current buffer. Return t if the
1443buffer is actually killed, nil otherwise. 1447buffer is actually killed, nil otherwise.
1444 1448
1445This function calls `replace-buffer-in-windows' for cleaning up all 1449The functions in `kill-buffer-query-functions' are called with the
1446windows currently displaying the buffer to be killed. The functions in 1450buffer to be killed as the current buffer. If any of them returns nil,
1447`kill-buffer-query-functions' are called with the buffer to be killed as 1451the buffer is not killed. The hook `kill-buffer-hook' is run before the
1448the current buffer. If any of them returns nil, the buffer is not 1452buffer is actually killed. The buffer being killed will be current
1449killed. The hook `kill-buffer-hook' is run before the buffer is 1453while the hook is running. Functions called by any of these hooks are
1450actually killed. The buffer being killed will be current while the hook 1454supposed to not change the current buffer.
1451is running.
1452 1455
1453Any processes that have this buffer as the `process-buffer' are killed 1456Any processes that have this buffer as the `process-buffer' are killed
1454with SIGHUP. */) 1457with SIGHUP. This function calls `replace-buffer-in-windows' for
1458cleaning up all windows currently displaying the buffer to be killed. */)
1455 (Lisp_Object buffer_or_name) 1459 (Lisp_Object buffer_or_name)
1456{ 1460{
1457 Lisp_Object buffer; 1461 Lisp_Object buffer;
@@ -1505,6 +1509,10 @@ with SIGHUP. */)
1505 unbind_to (count, Qnil); 1509 unbind_to (count, Qnil);
1506 } 1510 }
1507 1511
1512 /* If the hooks have killed the buffer, exit now. */
1513 if (NILP (BVAR (b, name)))
1514 return Qt;
1515
1508 /* We have no more questions to ask. Verify that it is valid 1516 /* We have no more questions to ask. Verify that it is valid
1509 to kill the buffer. This must be done after the questions 1517 to kill the buffer. This must be done after the questions
1510 since anything can happen within do_yes_or_no_p. */ 1518 since anything can happen within do_yes_or_no_p. */
@@ -1513,9 +1521,6 @@ with SIGHUP. */)
1513 if (EQ (buffer, XWINDOW (minibuf_window)->buffer)) 1521 if (EQ (buffer, XWINDOW (minibuf_window)->buffer))
1514 return Qnil; 1522 return Qnil;
1515 1523
1516 if (NILP (BVAR (b, name)))
1517 return Qnil;
1518
1519 /* When we kill a base buffer, kill all its indirect buffers. 1524 /* When we kill a base buffer, kill all its indirect buffers.
1520 We do it at this stage so nothing terrible happens if they 1525 We do it at this stage so nothing terrible happens if they
1521 ask questions or their hooks get errors. */ 1526 ask questions or their hooks get errors. */
@@ -1536,6 +1541,10 @@ with SIGHUP. */)
1536 } 1541 }
1537 1542
1538 UNGCPRO; 1543 UNGCPRO;
1544
1545 /* Exit if we now have killed the base buffer (Bug#11665). */
1546 if (NILP (BVAR (b, name)))
1547 return Qt;
1539 } 1548 }
1540 1549
1541 /* Run replace_buffer_in_windows before making another buffer current 1550 /* Run replace_buffer_in_windows before making another buffer current
@@ -1544,9 +1553,12 @@ with SIGHUP. */)
1544 buffer. (Bug#10114) */ 1553 buffer. (Bug#10114) */
1545 replace_buffer_in_windows (buffer); 1554 replace_buffer_in_windows (buffer);
1546 1555
1547 /* Make this buffer not be current. 1556 /* Exit if replacing the buffer in windows has killed our buffer. */
1548 In the process, notice if this is the sole visible buffer 1557 if (NILP (BVAR (b, name)))
1549 and give up if so. */ 1558 return Qt;
1559
1560 /* Make this buffer not be current. Exit if it is the sole visible
1561 buffer. */
1550 if (b == current_buffer) 1562 if (b == current_buffer)
1551 { 1563 {
1552 tem = Fother_buffer (buffer, Qnil, Qnil); 1564 tem = Fother_buffer (buffer, Qnil, Qnil);
@@ -1555,15 +1567,12 @@ with SIGHUP. */)
1555 return Qnil; 1567 return Qnil;
1556 } 1568 }
1557 1569
1558 /* Notice if the buffer to kill is the sole visible buffer 1570 /* If the buffer now current is shown in the minibuffer and our buffer
1559 when we're currently in the mini-buffer, and give up if so. */ 1571 is the sole other buffer give up. */
1560 XSETBUFFER (tem, current_buffer); 1572 XSETBUFFER (tem, current_buffer);
1561 if (EQ (tem, XWINDOW (minibuf_window)->buffer)) 1573 if (EQ (tem, XWINDOW (minibuf_window)->buffer)
1562 { 1574 && EQ (buffer, Fother_buffer (buffer, Qnil, Qnil)))
1563 tem = Fother_buffer (buffer, Qnil, Qnil); 1575 return Qnil;
1564 if (EQ (buffer, tem))
1565 return Qnil;
1566 }
1567 1576
1568 /* Now there is no question: we can kill the buffer. */ 1577 /* Now there is no question: we can kill the buffer. */
1569 1578
@@ -1576,11 +1585,10 @@ with SIGHUP. */)
1576 kill_buffer_processes (buffer); 1585 kill_buffer_processes (buffer);
1577 UNGCPRO; 1586 UNGCPRO;
1578 1587
1579 /* Killing buffer processes may run sentinels which may 1588 /* Killing buffer processes may run sentinels which may have killed
1580 have called kill-buffer. */ 1589 our buffer. */
1581
1582 if (NILP (BVAR (b, name))) 1590 if (NILP (BVAR (b, name)))
1583 return Qnil; 1591 return Qt;
1584 1592
1585 /* These may run Lisp code and into infinite loops (if someone 1593 /* These may run Lisp code and into infinite loops (if someone
1586 insisted on circular lists) so allow quitting here. */ 1594 insisted on circular lists) so allow quitting here. */
@@ -1592,8 +1600,7 @@ with SIGHUP. */)
1592 Vinhibit_quit = Qt; 1600 Vinhibit_quit = Qt;
1593 /* Remove the buffer from the list of all buffers. */ 1601 /* Remove the buffer from the list of all buffers. */
1594 Vbuffer_alist = Fdelq (Frassq (buffer, Vbuffer_alist), Vbuffer_alist); 1602 Vbuffer_alist = Fdelq (Frassq (buffer, Vbuffer_alist), Vbuffer_alist);
1595 /* If replace_buffer_in_windows didn't do its job correctly fix that 1603 /* If replace_buffer_in_windows didn't do its job fix that now. */
1596 now. */
1597 replace_buffer_in_windows_safely (buffer); 1604 replace_buffer_in_windows_safely (buffer);
1598 Vinhibit_quit = tem; 1605 Vinhibit_quit = tem;
1599 1606
@@ -1611,6 +1618,10 @@ with SIGHUP. */)
1611 internal_delete_file (BVAR (b, auto_save_file_name)); 1618 internal_delete_file (BVAR (b, auto_save_file_name));
1612 } 1619 }
1613 1620
1621 /* Deleting an auto-save file could have killed our buffer. */
1622 if (NILP (BVAR (b, name)))
1623 return Qt;
1624
1614 if (b->base_buffer) 1625 if (b->base_buffer)
1615 { 1626 {
1616 /* Unchain all markers that belong to this indirect buffer. 1627 /* Unchain all markers that belong to this indirect buffer.
@@ -2785,11 +2796,11 @@ mouse_face_overlay_overlaps (Lisp_Object overlay)
2785 Lisp_Object *v, tem; 2796 Lisp_Object *v, tem;
2786 2797
2787 size = 10; 2798 size = 10;
2788 v = (Lisp_Object *) alloca (size * sizeof *v); 2799 v = alloca (size * sizeof *v);
2789 n = overlays_in (start, end, 0, &v, &size, NULL, NULL); 2800 n = overlays_in (start, end, 0, &v, &size, NULL, NULL);
2790 if (n > size) 2801 if (n > size)
2791 { 2802 {
2792 v = (Lisp_Object *) alloca (n * sizeof *v); 2803 v = alloca (n * sizeof *v);
2793 overlays_in (start, end, 0, &v, &n, NULL, NULL); 2804 overlays_in (start, end, 0, &v, &n, NULL, NULL);
2794 } 2805 }
2795 2806
@@ -2877,8 +2888,7 @@ ptrdiff_t
2877sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w) 2888sort_overlays (Lisp_Object *overlay_vec, ptrdiff_t noverlays, struct window *w)
2878{ 2889{
2879 ptrdiff_t i, j; 2890 ptrdiff_t i, j;
2880 struct sortvec *sortvec; 2891 struct sortvec *sortvec = alloca (noverlays * sizeof *sortvec);
2881 sortvec = (struct sortvec *) alloca (noverlays * sizeof (struct sortvec));
2882 2892
2883 /* Put the valid and relevant overlays into sortvec. */ 2893 /* Put the valid and relevant overlays into sortvec. */
2884 2894
@@ -3663,18 +3673,17 @@ modify_overlay (struct buffer *buf, ptrdiff_t start, ptrdiff_t end)
3663 ++BUF_OVERLAY_MODIFF (buf); 3673 ++BUF_OVERLAY_MODIFF (buf);
3664} 3674}
3665 3675
3666 3676/* Remove OVERLAY from LIST. */
3677
3667static struct Lisp_Overlay * 3678static struct Lisp_Overlay *
3668unchain_overlay (struct Lisp_Overlay *list, struct Lisp_Overlay *overlay) 3679unchain_overlay (struct Lisp_Overlay *list, struct Lisp_Overlay *overlay)
3669{ 3680{
3670 struct Lisp_Overlay *tmp, *prev; 3681 register struct Lisp_Overlay *tail, **prev = &list;
3671 for (tmp = list, prev = NULL; tmp; prev = tmp, tmp = tmp->next) 3682
3672 if (tmp == overlay) 3683 for (tail = list; tail; prev = &tail->next, tail = *prev)
3684 if (tail == overlay)
3673 { 3685 {
3674 if (prev) 3686 *prev = overlay->next;
3675 prev->next = tmp->next;
3676 else
3677 list = tmp->next;
3678 overlay->next = NULL; 3687 overlay->next = NULL;
3679 break; 3688 break;
3680 } 3689 }
@@ -3813,11 +3822,7 @@ DEFUN ("delete-overlay", Fdelete_overlay, Sdelete_overlay, 1, 1, 0,
3813 = unchain_overlay (b->overlays_after, XOVERLAY (overlay)); 3822 = unchain_overlay (b->overlays_after, XOVERLAY (overlay));
3814 eassert (XOVERLAY (overlay)->next == NULL); 3823 eassert (XOVERLAY (overlay)->next == NULL);
3815 3824
3816 modify_overlay (b, 3825 drop_overlay (b, XOVERLAY (overlay));
3817 marker_position (OVERLAY_START (overlay)),
3818 marker_position (OVERLAY_END (overlay)));
3819 Fset_marker (OVERLAY_START (overlay), Qnil, Qnil);
3820 Fset_marker (OVERLAY_END (overlay), Qnil, Qnil);
3821 3826
3822 /* When deleting an overlay with before or after strings, turn off 3827 /* When deleting an overlay with before or after strings, turn off
3823 display optimizations for the affected buffer, on the basis that 3828 display optimizations for the affected buffer, on the basis that
@@ -3885,7 +3890,7 @@ DEFUN ("overlays-at", Foverlays_at, Soverlays_at, 1, 1, 0,
3885 3890
3886 len = 10; 3891 len = 10;
3887 /* We can't use alloca here because overlays_at can call xrealloc. */ 3892 /* We can't use alloca here because overlays_at can call xrealloc. */
3888 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 3893 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3889 3894
3890 /* Put all the overlays we want in a vector in overlay_vec. 3895 /* Put all the overlays we want in a vector in overlay_vec.
3891 Store the length in len. */ 3896 Store the length in len. */
@@ -3916,7 +3921,7 @@ end of the buffer. */)
3916 CHECK_NUMBER_COERCE_MARKER (end); 3921 CHECK_NUMBER_COERCE_MARKER (end);
3917 3922
3918 len = 10; 3923 len = 10;
3919 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 3924 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3920 3925
3921 /* Put all the overlays we want in a vector in overlay_vec. 3926 /* Put all the overlays we want in a vector in overlay_vec.
3922 Store the length in len. */ 3927 Store the length in len. */
@@ -3944,7 +3949,7 @@ the value is (point-max). */)
3944 CHECK_NUMBER_COERCE_MARKER (pos); 3949 CHECK_NUMBER_COERCE_MARKER (pos);
3945 3950
3946 len = 10; 3951 len = 10;
3947 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 3952 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3948 3953
3949 /* Put all the overlays we want in a vector in overlay_vec. 3954 /* Put all the overlays we want in a vector in overlay_vec.
3950 Store the length in len. 3955 Store the length in len.
@@ -3988,7 +3993,7 @@ the value is (point-min). */)
3988 return pos; 3993 return pos;
3989 3994
3990 len = 10; 3995 len = 10;
3991 overlay_vec = (Lisp_Object *) xmalloc (len * sizeof (Lisp_Object)); 3996 overlay_vec = xmalloc (len * sizeof *overlay_vec);
3992 3997
3993 /* Put all the overlays we want in a vector in overlay_vec. 3998 /* Put all the overlays we want in a vector in overlay_vec.
3994 Store the length in len. 3999 Store the length in len.
@@ -4243,7 +4248,7 @@ report_overlay_modification (Lisp_Object start, Lisp_Object end, int after,
4243 First copy the vector contents, in case some of these hooks 4248 First copy the vector contents, in case some of these hooks
4244 do subsequent modification of the buffer. */ 4249 do subsequent modification of the buffer. */
4245 ptrdiff_t size = last_overlay_modification_hooks_used; 4250 ptrdiff_t size = last_overlay_modification_hooks_used;
4246 Lisp_Object *copy = (Lisp_Object *) alloca (size * sizeof (Lisp_Object)); 4251 Lisp_Object *copy = alloca (size * sizeof *copy);
4247 ptrdiff_t i; 4252 ptrdiff_t i;
4248 4253
4249 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents, 4254 memcpy (copy, XVECTOR (last_overlay_modification_hooks)->contents,
@@ -4862,6 +4867,12 @@ void
4862init_buffer_once (void) 4867init_buffer_once (void)
4863{ 4868{
4864 int idx; 4869 int idx;
4870 /* If you add, remove, or reorder Lisp_Objects in a struct buffer, make
4871 sure that this is still correct. Otherwise, mark_vectorlike may not
4872 trace all Lisp_Objects in buffer_defaults and buffer_local_symbols. */
4873 const int pvecsize
4874 = (offsetof (struct buffer, own_text) - sizeof (struct vectorlike_header))
4875 / sizeof (Lisp_Object);
4865 4876
4866 memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags); 4877 memset (buffer_permanent_local_flags, 0, sizeof buffer_permanent_local_flags);
4867 4878
@@ -4878,25 +4889,23 @@ init_buffer_once (void)
4878 buffer_local_symbols.text = &buffer_local_symbols.own_text; 4889 buffer_local_symbols.text = &buffer_local_symbols.own_text;
4879 BUF_INTERVALS (&buffer_defaults) = 0; 4890 BUF_INTERVALS (&buffer_defaults) = 0;
4880 BUF_INTERVALS (&buffer_local_symbols) = 0; 4891 BUF_INTERVALS (&buffer_local_symbols) = 0;
4881 XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, 0); 4892 XSETPVECTYPESIZE (&buffer_defaults, PVEC_BUFFER, pvecsize);
4882 XSETBUFFER (Vbuffer_defaults, &buffer_defaults); 4893 XSETBUFFER (Vbuffer_defaults, &buffer_defaults);
4883 XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, 0); 4894 XSETPVECTYPESIZE (&buffer_local_symbols, PVEC_BUFFER, pvecsize);
4884 XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols); 4895 XSETBUFFER (Vbuffer_local_symbols, &buffer_local_symbols);
4885 4896
4886 /* Set up the default values of various buffer slots. */ 4897 /* Set up the default values of various buffer slots. */
4887 /* Must do these before making the first buffer! */ 4898 /* Must do these before making the first buffer! */
4888 4899
4889 /* real setup is done in bindings.el */ 4900 /* real setup is done in bindings.el */
4890 BVAR (&buffer_defaults, mode_line_format) = make_pure_c_string ("%-"); 4901 BVAR (&buffer_defaults, mode_line_format) = build_pure_c_string ("%-");
4891 BVAR (&buffer_defaults, header_line_format) = Qnil; 4902 BVAR (&buffer_defaults, header_line_format) = Qnil;
4892 BVAR (&buffer_defaults, abbrev_mode) = Qnil; 4903 BVAR (&buffer_defaults, abbrev_mode) = Qnil;
4893 BVAR (&buffer_defaults, overwrite_mode) = Qnil; 4904 BVAR (&buffer_defaults, overwrite_mode) = Qnil;
4894 BVAR (&buffer_defaults, case_fold_search) = Qt; 4905 BVAR (&buffer_defaults, case_fold_search) = Qt;
4895 BVAR (&buffer_defaults, auto_fill_function) = Qnil; 4906 BVAR (&buffer_defaults, auto_fill_function) = Qnil;
4896 BVAR (&buffer_defaults, selective_display) = Qnil; 4907 BVAR (&buffer_defaults, selective_display) = Qnil;
4897#ifndef old
4898 BVAR (&buffer_defaults, selective_display_ellipses) = Qt; 4908 BVAR (&buffer_defaults, selective_display_ellipses) = Qt;
4899#endif
4900 BVAR (&buffer_defaults, abbrev_table) = Qnil; 4909 BVAR (&buffer_defaults, abbrev_table) = Qnil;
4901 BVAR (&buffer_defaults, display_table) = Qnil; 4910 BVAR (&buffer_defaults, display_table) = Qnil;
4902 BVAR (&buffer_defaults, undo_list) = Qnil; 4911 BVAR (&buffer_defaults, undo_list) = Qnil;
@@ -4975,9 +4984,7 @@ init_buffer_once (void)
4975 XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx; 4984 XSETFASTINT (BVAR (&buffer_local_flags, case_fold_search), idx); ++idx;
4976 XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx; 4985 XSETFASTINT (BVAR (&buffer_local_flags, auto_fill_function), idx); ++idx;
4977 XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx; 4986 XSETFASTINT (BVAR (&buffer_local_flags, selective_display), idx); ++idx;
4978#ifndef old
4979 XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx; 4987 XSETFASTINT (BVAR (&buffer_local_flags, selective_display_ellipses), idx); ++idx;
4980#endif
4981 XSETFASTINT (BVAR (&buffer_local_flags, tab_width), idx); ++idx; 4988 XSETFASTINT (BVAR (&buffer_local_flags, tab_width), idx); ++idx;
4982 XSETFASTINT (BVAR (&buffer_local_flags, truncate_lines), idx); ++idx; 4989 XSETFASTINT (BVAR (&buffer_local_flags, truncate_lines), idx); ++idx;
4983 XSETFASTINT (BVAR (&buffer_local_flags, word_wrap), idx); ++idx; 4990 XSETFASTINT (BVAR (&buffer_local_flags, word_wrap), idx); ++idx;
@@ -5021,7 +5028,7 @@ init_buffer_once (void)
5021 current_buffer = 0; 5028 current_buffer = 0;
5022 all_buffers = 0; 5029 all_buffers = 0;
5023 5030
5024 QSFundamental = make_pure_c_string ("Fundamental"); 5031 QSFundamental = build_pure_c_string ("Fundamental");
5025 5032
5026 Qfundamental_mode = intern_c_string ("fundamental-mode"); 5033 Qfundamental_mode = intern_c_string ("fundamental-mode");
5027 BVAR (&buffer_defaults, major_mode) = Qfundamental_mode; 5034 BVAR (&buffer_defaults, major_mode) = Qfundamental_mode;
@@ -5036,10 +5043,10 @@ init_buffer_once (void)
5036 Fput (Qkill_buffer_hook, Qpermanent_local, Qt); 5043 Fput (Qkill_buffer_hook, Qpermanent_local, Qt);
5037 5044
5038 /* super-magic invisible buffer */ 5045 /* super-magic invisible buffer */
5039 Vprin1_to_string_buffer = Fget_buffer_create (make_pure_c_string (" prin1")); 5046 Vprin1_to_string_buffer = Fget_buffer_create (build_pure_c_string (" prin1"));
5040 Vbuffer_alist = Qnil; 5047 Vbuffer_alist = Qnil;
5041 5048
5042 Fset_buffer (Fget_buffer_create (make_pure_c_string ("*scratch*"))); 5049 Fset_buffer (Fget_buffer_create (build_pure_c_string ("*scratch*")));
5043 5050
5044 inhibit_modification_hooks = 0; 5051 inhibit_modification_hooks = 0;
5045} 5052}
@@ -5079,14 +5086,15 @@ init_buffer (void)
5079 if (!(IS_DIRECTORY_SEP (pwd[len - 1]))) 5086 if (!(IS_DIRECTORY_SEP (pwd[len - 1])))
5080 { 5087 {
5081 /* Grow buffer to add directory separator and '\0'. */ 5088 /* Grow buffer to add directory separator and '\0'. */
5082 pwd = (char *) realloc (pwd, len + 2); 5089 pwd = realloc (pwd, len + 2);
5083 if (!pwd) 5090 if (!pwd)
5084 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno)); 5091 fatal ("`get_current_dir_name' failed: %s\n", strerror (errno));
5085 pwd[len] = DIRECTORY_SEP; 5092 pwd[len] = DIRECTORY_SEP;
5086 pwd[len + 1] = '\0'; 5093 pwd[len + 1] = '\0';
5094 len++;
5087 } 5095 }
5088 5096
5089 BVAR (current_buffer, directory) = make_unibyte_string (pwd, strlen (pwd)); 5097 BVAR (current_buffer, directory) = make_unibyte_string (pwd, len);
5090 if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters))) 5098 if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))
5091 /* At this moment, we still don't know how to decode the 5099 /* At this moment, we still don't know how to decode the
5092 directory name. So, we keep the bytes in multibyte form so 5100 directory name. So, we keep the bytes in multibyte form so
@@ -5193,7 +5201,7 @@ syms_of_buffer (void)
5193 Fput (Qprotected_field, Qerror_conditions, 5201 Fput (Qprotected_field, Qerror_conditions,
5194 pure_cons (Qprotected_field, pure_cons (Qerror, Qnil))); 5202 pure_cons (Qprotected_field, pure_cons (Qerror, Qnil)));
5195 Fput (Qprotected_field, Qerror_message, 5203 Fput (Qprotected_field, Qerror_message,
5196 make_pure_c_string ("Attempt to modify a protected field")); 5204 build_pure_c_string ("Attempt to modify a protected field"));
5197 5205
5198 DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format", 5206 DEFVAR_BUFFER_DEFAULTS ("default-mode-line-format",
5199 mode_line_format, 5207 mode_line_format,
@@ -5522,7 +5530,13 @@ This variable has no effect if long lines are truncated (see
5522`truncate-lines' and `truncate-partial-width-windows'). If you use 5530`truncate-lines' and `truncate-partial-width-windows'). If you use
5523word-wrapping, you might want to reduce the value of 5531word-wrapping, you might want to reduce the value of
5524`truncate-partial-width-windows', since wrapping can make text readable 5532`truncate-partial-width-windows', since wrapping can make text readable
5525in narrower windows. */); 5533in narrower windows.
5534
5535Instead of setting this variable directly, most users should use
5536Visual Line mode . Visual Line mode, when enabled, sets `word-wrap'
5537to t, and additionally redefines simple editing commands to act on
5538visual lines rather than logical lines. See the documentation of
5539`visual-line-mode'. */);
5526 5540
5527 DEFVAR_PER_BUFFER ("default-directory", &BVAR (current_buffer, directory), 5541 DEFVAR_PER_BUFFER ("default-directory", &BVAR (current_buffer, directory),
5528 make_number (Lisp_String), 5542 make_number (Lisp_String),
@@ -5579,12 +5593,10 @@ A value of t means that the character ^M makes itself and
5579all the rest of the line invisible; also, when saving the buffer 5593all the rest of the line invisible; also, when saving the buffer
5580in a file, save the ^M as a newline. */); 5594in a file, save the ^M as a newline. */);
5581 5595
5582#ifndef old
5583 DEFVAR_PER_BUFFER ("selective-display-ellipses", 5596 DEFVAR_PER_BUFFER ("selective-display-ellipses",
5584 &BVAR (current_buffer, selective_display_ellipses), 5597 &BVAR (current_buffer, selective_display_ellipses),
5585 Qnil, 5598 Qnil,
5586 doc: /* Non-nil means display ... on previous line when a line is invisible. */); 5599 doc: /* Non-nil means display ... on previous line when a line is invisible. */);
5587#endif
5588 5600
5589 DEFVAR_PER_BUFFER ("overwrite-mode", &BVAR (current_buffer, overwrite_mode), Qnil, 5601 DEFVAR_PER_BUFFER ("overwrite-mode", &BVAR (current_buffer, overwrite_mode), Qnil,
5590 doc: /* Non-nil if self-insertion should replace existing text. 5602 doc: /* Non-nil if self-insertion should replace existing text.
@@ -5819,9 +5831,9 @@ An entry (TEXT . POSITION) represents the deletion of the string TEXT
5819from (abs POSITION). If POSITION is positive, point was at the front 5831from (abs POSITION). If POSITION is positive, point was at the front
5820of the text being deleted; if negative, point was at the end. 5832of the text being deleted; if negative, point was at the end.
5821 5833
5822An entry (t HIGH . LOW) indicates that the buffer previously had 5834An entry (t HIGH LOW USEC PSEC) indicates that the buffer was previously
5823\"unmodified\" status. HIGH and LOW are the high and low 16-bit portions 5835unmodified; (HIGH LOW USEC PSEC) is in the same style as (current-time)
5824of the visited file's modification time, as of that time. If the 5836and is the visited file's modification time, as of that time. If the
5825modification time of the most recent save is different, this entry is 5837modification time of the most recent save is different, this entry is
5826obsolete. 5838obsolete.
5827 5839
@@ -5985,7 +5997,9 @@ Use Custom to set this variable and update the display." */);
5985 DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions, 5997 DEFVAR_LISP ("kill-buffer-query-functions", Vkill_buffer_query_functions,
5986 doc: /* List of functions called with no args to query before killing a buffer. 5998 doc: /* List of functions called with no args to query before killing a buffer.
5987The buffer being killed will be current while the functions are running. 5999The buffer being killed will be current while the functions are running.
5988If any of them returns nil, the buffer is not killed. */); 6000
6001If any of them returns nil, the buffer is not killed. Functions run by
6002this hook are supposed to not change the current buffer. */);
5989 Vkill_buffer_query_functions = Qnil; 6003 Vkill_buffer_query_functions = Qnil;
5990 6004
5991 DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook, 6005 DEFVAR_LISP ("change-major-mode-hook", Vchange_major_mode_hook,