* alloc.c: Do not define struct catchtag.
[bpt/emacs.git] / src / buffer.c
index 50db471..2fc7a8b 100644 (file)
@@ -1,7 +1,7 @@
 /* Buffer manipulation primitives for GNU Emacs.
    Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994,
                  1995, 1997, 1998, 1999, 2000, 2001, 2002,
-                 2003, 2004, 2005, 2006, 2007, 2008
+                 2003, 2004, 2005, 2006, 2007, 2008, 2009
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -26,6 +26,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <sys/param.h>
 #include <errno.h>
 #include <stdio.h>
+#include <setjmp.h>
 
 #ifndef USE_CRT_DLL
 extern int errno;
@@ -877,7 +878,8 @@ it is in the sequence to be tried) even if a buffer with that name exists.  */)
 \f
 DEFUN ("buffer-name", Fbuffer_name, Sbuffer_name, 0, 1, 0,
        doc: /* Return the name of BUFFER, as a string.
-With no argument or nil as argument, return the name of the current buffer.  */)
+BUFFER defaults to the current buffer.
+Return nil if BUFFER has been killed.  */)
      (buffer)
      register Lisp_Object buffer;
 {
@@ -1800,9 +1802,11 @@ messing with the window-buffer correspondences.  */)
        record_buffer (buffer_or_name);
       return Fset_buffer (buffer_or_name);
     }
-
-  if (EQ (minibuf_window, selected_window)
-      || !NILP (Fwindow_dedicated_p (selected_window)))
+  else if (EQ (minibuf_window, selected_window)
+          /* If `dedicated' is neither nil nor t, it means it's
+             dedicatedness can be overridden by an explicit request
+             such as a call to switch-to-buffer.  */
+          || EQ (Fwindow_dedicated_p (selected_window), Qt))
     /* We can't use the selected window so let `pop-to-buffer' try some
        other window. */
     return call3 (intern ("pop-to-buffer"), buffer_or_name, Qnil, norecord);
@@ -1919,12 +1923,14 @@ set_buffer_internal_1 (b)
 
   for (tail = b->local_var_alist; CONSP (tail); tail = XCDR (tail))
     {
-      valcontents = SYMBOL_VALUE (XCAR (XCAR (tail)));
-      if ((BUFFER_LOCAL_VALUEP (valcontents))
+      if (CONSP (XCAR (tail))
+         && SYMBOLP (XCAR (XCAR (tail)))
+         && (valcontents = SYMBOL_VALUE (XCAR (XCAR (tail))),
+             (BUFFER_LOCAL_VALUEP (valcontents)))
          && (tem = XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
              (BOOLFWDP (tem) || INTFWDP (tem) || OBJFWDP (tem))))
-       /* Just reference the variable
-            to cause it to become set for this buffer.  */
+       /* Just reference the variable to cause it to become set for
+          this buffer.  */
        Fsymbol_value (XCAR (XCAR (tail)));
     }
 
@@ -1933,12 +1939,14 @@ set_buffer_internal_1 (b)
   if (old_buf)
     for (tail = old_buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
       {
-       valcontents = SYMBOL_VALUE (XCAR (XCAR (tail)));
-       if ((BUFFER_LOCAL_VALUEP (valcontents))
+       if (CONSP (tail)
+           && SYMBOLP (XCAR (XCAR (tail)))
+           && (valcontents = SYMBOL_VALUE (XCAR (XCAR (tail))),
+               (BUFFER_LOCAL_VALUEP (valcontents)))
            && (tem = XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
                (BOOLFWDP (tem) || INTFWDP (tem) || OBJFWDP (tem))))
-         /* Just reference the variable
-               to cause it to become set for this buffer.  */
+         /* Just reference the variable to cause it to become set for
+            this buffer.  */
          Fsymbol_value (XCAR (XCAR (tail)));
       }
 }
@@ -2182,6 +2190,10 @@ advance_to_char_boundary (byte_pos)
   return byte_pos;
 }
 
+#ifdef REL_ALLOC
+extern void r_alloc_reset_variable P_ ((POINTER_TYPE *, POINTER_TYPE *));
+#endif /* REL_ALLOC */
+
 DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
        1, 1, 0,
        doc: /* Swap the text between current buffer and BUFFER.  */)
@@ -2223,6 +2235,13 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
   swapfield (own_text, struct buffer_text);
   eassert (current_buffer->text == &current_buffer->own_text);
   eassert (other_buffer->text == &other_buffer->own_text);
+#ifdef REL_ALLOC
+  r_alloc_reset_variable ((POINTER_TYPE **) &current_buffer->own_text.beg,
+                         (POINTER_TYPE **) &other_buffer->own_text.beg);
+  r_alloc_reset_variable ((POINTER_TYPE **) &other_buffer->own_text.beg,
+                         (POINTER_TYPE **) &current_buffer->own_text.beg);
+#endif /* REL_ALLOC */
+
   swapfield (pt, EMACS_INT);
   swapfield (pt_byte, EMACS_INT);
   swapfield (begv, EMACS_INT);
@@ -2640,18 +2659,19 @@ static void
 swap_out_buffer_local_variables (b)
      struct buffer *b;
 {
-  Lisp_Object oalist, alist, sym, tem, buffer;
+  Lisp_Object oalist, alist, sym, buffer;
 
   XSETBUFFER (buffer, b);
   oalist = b->local_var_alist;
 
   for (alist = oalist; CONSP (alist); alist = XCDR (alist))
     {
-      sym = XCAR (XCAR (alist));
-
-      /* Need not do anything if some other buffer's binding is now encached.  */
-      tem = XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym))->buffer;
-      if (EQ (tem, buffer))
+      if (CONSP (XCAR (alist))
+         && (sym = XCAR (XCAR (alist)), SYMBOLP (sym))
+         /* Need not do anything if some other buffer's binding is
+            now encached.  */
+         && EQ (XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (sym))->buffer,
+                buffer))
        {
          /* Symbol is set up for this buffer's old local value:
             swap it out!  */
@@ -5298,9 +5318,8 @@ init_buffer_once ()
 
   Qucs_set_table_for_input = intern ("ucs-set-table-for-input");
 
-  Vprin1_to_string_buffer = Fget_buffer_create (build_string (" prin1"));
-
   /* super-magic invisible buffer */
+  Vprin1_to_string_buffer = Fget_buffer_create (build_string (" prin1"));
   Vbuffer_alist = Qnil;
 
   Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
@@ -5343,7 +5362,9 @@ init_buffer ()
   if (!(IS_DIRECTORY_SEP (pwd[len - 1])))
     {
       /* Grow buffer to add directory separator and '\0'.  */
-      pwd = (char *) xrealloc (pwd, len + 2);
+      pwd = (char *) realloc (pwd, len + 2);
+      if (!pwd)
+       fatal ("`get_current_dir_name' failed: %s\n", strerror (errno));
       pwd[len] = DIRECTORY_SEP;
       pwd[len + 1] = '\0';
     }
@@ -5684,19 +5705,20 @@ A string is printed verbatim in the mode line except for %-constructs:
 Decimal digits after the % specify field width to which to pad.  */);
 
   DEFVAR_LISP_NOPRO ("default-major-mode", &buffer_defaults.major_mode,
-                    doc: /* *Major mode for new buffers.  Defaults to `fundamental-mode'.
-A value of nil means use current buffer's major mode,
-provided it is not marked as "special".
-
-When a mode is used by default, `find-file' switches to it
-before it reads the contents into the buffer and before
-it finishes setting up the buffer.  Thus, the mode and
-its hooks should not expect certain variables such as
-`buffer-read-only' and `buffer-file-coding-system' to be set up.  */);
+                    doc: /* *Value of `major-mode' for new buffers.  */);
 
   DEFVAR_PER_BUFFER ("major-mode", &current_buffer->major_mode,
                     make_number (Lisp_Symbol),
-                    doc: /* Symbol for current buffer's major mode.  */);
+                    doc: /* Symbol for current buffer's major mode.
+The default value (normally `fundamental-mode') affects new buffers.
+A value of nil means to use the current buffer's major mode, provided
+it is not marked as "special".
+
+When a mode is used by default, `find-file' switches to it before it
+reads the contents into the buffer and before it finishes setting up
+the buffer.  Thus, the mode and its hooks should not expect certain
+variables such as `buffer-read-only' and `buffer-file-coding-system'
+to be set up.  */);
 
   DEFVAR_PER_BUFFER ("mode-name", &current_buffer->mode_name,
                      Qnil,
@@ -5839,7 +5861,12 @@ Backing up is done before the first time the file is saved.  */);
   DEFVAR_PER_BUFFER ("buffer-saved-size", &current_buffer->save_length,
                     make_number (Lisp_Int),
                     doc: /* Length of current buffer when last read in, saved or auto-saved.
-0 initially.  */);
+0 initially.
+-1 means auto-saving turned off until next real save.
+
+If you set this to -2, that means don't turn off auto-saving in this buffer
+if its text size shrinks.   If you use `buffer-swap-text' on a buffer,
+you probably should set this to -2 in that buffer.  */);
 
   DEFVAR_PER_BUFFER ("selective-display", &current_buffer->selective_display,
                     Qnil,
@@ -6231,7 +6258,8 @@ cursor's appearance is instead controlled by the variable
   DEFVAR_PER_BUFFER ("line-spacing",
                     &current_buffer->extra_line_spacing, Qnil,
                     doc: /* Additional space to put between lines when displaying a buffer.
-The space is measured in pixels, and put below lines on window systems.
+The space is measured in pixels, and put below lines on graphic displays,
+see `display-graphic-p'.
 If value is a floating point number, it specifies the spacing relative
 to the default frame line height.  A value of nil means add no extra space.  */);