/* 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.
#include <sys/param.h>
#include <errno.h>
#include <stdio.h>
+#include <setjmp.h>
#ifndef USE_CRT_DLL
extern int errno;
\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;
{
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);
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)));
}
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)));
}
}
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. */)
swapfield (own_text, struct buffer_text);
eassert (current_buffer->text == ¤t_buffer->own_text);
eassert (other_buffer->text == &other_buffer->own_text);
+#ifdef REL_ALLOC
+ r_alloc_reset_variable ((POINTER_TYPE **) ¤t_buffer->own_text.beg,
+ (POINTER_TYPE **) &other_buffer->own_text.beg);
+ r_alloc_reset_variable ((POINTER_TYPE **) &other_buffer->own_text.beg,
+ (POINTER_TYPE **) ¤t_buffer->own_text.beg);
+#endif /* REL_ALLOC */
+
swapfield (pt, EMACS_INT);
swapfield (pt_byte, EMACS_INT);
swapfield (begv, EMACS_INT);
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! */
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*")));
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';
}
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", ¤t_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", ¤t_buffer->mode_name,
Qnil,
DEFVAR_PER_BUFFER ("buffer-saved-size", ¤t_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", ¤t_buffer->selective_display,
Qnil,
DEFVAR_PER_BUFFER ("line-spacing",
¤t_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. */);