comparison src/buffer.c @ 373:6240c7796c7a r21-2b2

Import from CVS: tag r21-2b2
author cvs
date Mon, 13 Aug 2007 11:04:06 +0200
parents cc15677e0335
children 8626e4521993
comparison
equal deleted inserted replaced
372:49e1ed2d7ed8 373:6240c7796c7a
230 #define MARKED_SLOT(x) ((markobj) (buf->x)); 230 #define MARKED_SLOT(x) ((markobj) (buf->x));
231 #include "bufslots.h" 231 #include "bufslots.h"
232 #undef MARKED_SLOT 232 #undef MARKED_SLOT
233 233
234 ((markobj) (buf->extent_info)); 234 ((markobj) (buf->extent_info));
235 if (buf->text)
236 ((markobj) (buf->text->line_number_cache));
235 237
236 /* Don't mark normally through the children slot. 238 /* Don't mark normally through the children slot.
237 (Actually, in this case, it doesn't matter.) */ 239 (Actually, in this case, it doesn't matter.) */
238 if (! EQ (buf->indirect_children, Qnull_pointer)) 240 if (! EQ (buf->indirect_children, Qnull_pointer))
239 mark_conses_in_list (buf->indirect_children); 241 mark_conses_in_list (buf->indirect_children);
612 b = allocate_buffer (); 614 b = allocate_buffer ();
613 615
614 b->text = &b->own_text; 616 b->text = &b->own_text;
615 b->base_buffer = 0; 617 b->base_buffer = 0;
616 b->indirect_children = Qnil; 618 b->indirect_children = Qnil;
617 init_buffer_text (b, 0); 619 init_buffer_text (b);
618 620
619 return finish_init_buffer (b, name); 621 return finish_init_buffer (b, name);
620 } 622 }
621 623
622 #if 0 /* #### implement this! Need various changes in insdel.c */
623 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, 2, 2, 624 DEFUN ("make-indirect-buffer", Fmake_indirect_buffer, 2, 2,
624 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ", /* 625 "bMake indirect buffer (to buffer): \nBName of indirect buffer: ", /*
625 Create and return an indirect buffer for buffer BASE, named NAME. 626 Create and return an indirect buffer for buffer BASE, named NAME.
626 BASE should be an existing buffer (or buffer name). 627 BASE should be an existing buffer (or buffer name).
627 NAME should be a string which is not the name of an existing buffer. 628 NAME should be a string which is not the name of an existing buffer.
629 is made the base buffer for the newly created buffer. (Thus, there will 630 is made the base buffer for the newly created buffer. (Thus, there will
630 never be indirect buffers whose base buffers are themselves indirect.) 631 never be indirect buffers whose base buffers are themselves indirect.)
631 */ 632 */
632 (base_buffer, name)) 633 (base_buffer, name))
633 { 634 {
634 Lisp_Object buf; 635 /* This function can GC */
635 REGISTER struct buffer *b; 636
637 /* #### The above interactive specification is totally bogus,
638 because it offers an existing buffer as default answer to the
639 second question. However, the second argument may not BE an
640 existing buffer! */
641 struct buffer *b;
642
643 base_buffer = get_buffer (base_buffer, 1);
636 644
637 #ifdef I18N3 645 #ifdef I18N3
638 /* #### Doc string should indicate that the buffer name will get 646 /* #### Doc string should indicate that the buffer name will get
639 translated. */ 647 translated. */
640 #endif 648 #endif
641 649 CHECK_STRING (name);
642 name = LISP_GETTEXT (name); 650 name = LISP_GETTEXT (name);
643 buf = Fget_buffer (name); 651 if (!NILP (Fget_buffer (name)))
644 if (!NILP (buf)) 652 signal_simple_error ("Buffer name already in use", name);
645 error ("Buffer name `%s' is in use", XSTRING_DATA (name));
646
647 base_buffer = Fget_buffer (base_buffer);
648 if (NILP (base_buffer))
649 error ("No such buffer: `%s'", XSTRING_DATA (XBUFFER (base_buffer)->name));
650
651 if (XSTRING_LENGTH (name) == 0) 653 if (XSTRING_LENGTH (name) == 0)
652 error ("Empty string for buffer name is not allowed"); 654 error ("Empty string for buffer name is not allowed");
653 655
654 b = allocate_buffer (); 656 b = allocate_buffer ();
655 657
656 if (XBUFFER (base_buffer)->base_buffer) 658 b->base_buffer = BUFFER_BASE_BUFFER (XBUFFER (base_buffer));
657 b->base_buffer = XBUFFER (base_buffer)->base_buffer;
658 else
659 b->base_buffer = XBUFFER (base_buffer);
660 659
661 /* Use the base buffer's text object. */ 660 /* Use the base buffer's text object. */
662 b->text = b->base_buffer->text; 661 b->text = b->base_buffer->text;
663 b->indirect_children = Qnil; 662 b->indirect_children = Qnil;
664 XSETBUFFER (buf, b);
665 b->base_buffer->indirect_children = 663 b->base_buffer->indirect_children =
666 Fcons (buf, b->base_buffer->indirect_children); 664 Fcons (make_buffer (b), b->base_buffer->indirect_children);
667 init_buffer_text (b, 1); 665 init_buffer_text (b);
668 666
669 return finish_init_buffer (b, name); 667 return finish_init_buffer (b, name);
670 } 668 }
671 #endif /* 0 */
672 669
673 670
674 671
675 static void 672 static void
676 reset_buffer_local_variables (struct buffer *b, int first_time) 673 reset_buffer_local_variables (struct buffer *b, int first_time)
812 struct buffer *buf = decode_buffer (buffer, 0); 809 struct buffer *buf = decode_buffer (buffer, 0);
813 810
814 return Fcopy_sequence (buf->indirect_children); 811 return Fcopy_sequence (buf->indirect_children);
815 } 812 }
816 813
817 /* Map MAPFUN over all buffers that share the same text as BUF
818 (this includes BUF). Pass two arguments to MAPFUN: a buffer,
819 and CLOSURE. If any invocation of MAPFUN returns non-zero,
820 halt immediately and return that value. Otherwise, continue
821 the mapping to the end and return 0. */
822
823 int
824 map_over_sharing_buffers (struct buffer *buf,
825 int (*mapfun) (struct buffer *buf, void *closure),
826 void *closure)
827 {
828 int result;
829 Lisp_Object tail;
830
831 if (buf->base_buffer)
832 {
833 buf = buf->base_buffer;
834 assert (!buf->base_buffer);
835 }
836
837 result = (mapfun) (buf, closure);
838 if (result)
839 return result;
840
841 LIST_LOOP (tail, buf->indirect_children)
842 {
843 Lisp_Object buffer = XCAR (tail);
844 result = (mapfun) (XBUFFER (buffer), closure);
845 if (result)
846 return result;
847 }
848
849 return 0;
850 }
851
852 DEFUN ("buffer-local-variables", Fbuffer_local_variables, 0, 1, 0, /* 814 DEFUN ("buffer-local-variables", Fbuffer_local_variables, 0, 1, 0, /*
853 Return an alist of variables that are buffer-local in BUFFER. 815 Return an alist of variables that are buffer-local in BUFFER.
854 Most elements look like (SYMBOL . VALUE), describing one variable. 816 Most elements look like (SYMBOL . VALUE), describing one variable.
855 For a symbol that is locally unbound, just the symbol appears in the value. 817 For a symbol that is locally unbound, just the symbol appears in the value.
856 Note that storing new VALUEs in these elements doesn't change the variables. 818 Note that storing new VALUEs in these elements doesn't change the variables.
1285 Lisp_Object rest; 1247 Lisp_Object rest;
1286 1248
1287 GCPRO1 (buf); 1249 GCPRO1 (buf);
1288 1250
1289 LIST_LOOP (rest, b->indirect_children) 1251 LIST_LOOP (rest, b->indirect_children)
1290 Fkill_buffer (XCAR (rest)); 1252 {
1253 Fkill_buffer (XCAR (rest));
1254 /* Keep indirect_children updated in case a
1255 query-function/hook throws. */
1256 b->indirect_children = XCDR (rest);
1257 }
1291 1258
1292 UNGCPRO; 1259 UNGCPRO;
1293 } 1260 }
1294 1261
1295 /* Make this buffer not be current. 1262 /* Make this buffer not be current.
1370 uninit_buffer_markers (b); 1337 uninit_buffer_markers (b);
1371 1338
1372 kill_buffer_local_variables (b); 1339 kill_buffer_local_variables (b);
1373 1340
1374 b->name = Qnil; 1341 b->name = Qnil;
1375 uninit_buffer_text (b, !!b->base_buffer); 1342 uninit_buffer_text (b);
1376 b->undo_list = Qnil; 1343 b->undo_list = Qnil;
1377 uninit_buffer_extents (b); 1344 uninit_buffer_extents (b);
1378 if (b->base_buffer) 1345 if (b->base_buffer)
1379 { 1346 {
1380 #ifdef ERROR_CHECK_BUFPOS 1347 #ifdef ERROR_CHECK_BUFPOS
1867 DEFSUBR (Fbuffer_list); 1834 DEFSUBR (Fbuffer_list);
1868 DEFSUBR (Fdecode_buffer); 1835 DEFSUBR (Fdecode_buffer);
1869 DEFSUBR (Fget_buffer); 1836 DEFSUBR (Fget_buffer);
1870 DEFSUBR (Fget_file_buffer); 1837 DEFSUBR (Fget_file_buffer);
1871 DEFSUBR (Fget_buffer_create); 1838 DEFSUBR (Fget_buffer_create);
1872 #if 0
1873 DEFSUBR (Fmake_indirect_buffer); 1839 DEFSUBR (Fmake_indirect_buffer);
1874 #endif
1875 1840
1876 DEFSUBR (Fgenerate_new_buffer_name); 1841 DEFSUBR (Fgenerate_new_buffer_name);
1877 DEFSUBR (Fbuffer_name); 1842 DEFSUBR (Fbuffer_name);
1878 DEFSUBR (Fbuffer_file_name); 1843 DEFSUBR (Fbuffer_file_name);
1879 DEFSUBR (Fbuffer_base_buffer); 1844 DEFSUBR (Fbuffer_base_buffer);