/* 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.
int buffer_count;
DEFUN ("get-buffer-create", Fget_buffer_create, Sget_buffer_create, 1, 1, 0,
- doc: /* Return the buffer named NAME, or create such a buffer and return it.
-A new buffer is created if there is no live buffer named NAME.
-If NAME starts with a space, the new buffer does not keep undo information.
-If NAME is a buffer instead of a string, then it is the value returned.
-The value is never nil. */)
- (name)
- register Lisp_Object name;
+ doc: /* Return the buffer specified by BUFFER-OR-NAME, creating a new one if needed.
+If BUFFER-OR-NAME is a string and a live buffer with that name exists,
+return that buffer. If no such buffer exists, create a new buffer with
+that name and return it. If BUFFER-OR-NAME starts with a space, the new
+buffer does not keep undo information.
+
+If BUFFER-OR-NAME is a buffer instead of a string, return it as given,
+even if it is dead. The return value is never nil. */)
+ (buffer_or_name)
+ register Lisp_Object buffer_or_name;
{
- register Lisp_Object buf;
+ register Lisp_Object buffer, name;
register struct buffer *b;
- buf = Fget_buffer (name);
- if (!NILP (buf))
- return buf;
+ buffer = Fget_buffer (buffer_or_name);
+ if (!NILP (buffer))
+ return buffer;
- if (SCHARS (name) == 0)
+ if (SCHARS (buffer_or_name) == 0)
error ("Empty string for buffer name is not allowed");
b = allocate_buffer ();
b->begv_marker = Qnil;
b->zv_marker = Qnil;
- name = Fcopy_sequence (name);
+ name = Fcopy_sequence (buffer_or_name);
STRING_SET_INTERVALS (name, NULL_INTERVAL);
b->name = name;
b->name = name;
/* Put this in the alist of all live buffers. */
- XSETBUFFER (buf, b);
- Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buf), Qnil));
+ XSETBUFFER (buffer, b);
+ Vbuffer_alist = nconc2 (Vbuffer_alist, Fcons (Fcons (name, buffer), Qnil));
/* An error in calling the function here (should someone redefine it)
can lead to infinite regress until you run out of stack. rms
says that's not worth protecting against. */
if (!NILP (Ffboundp (Qucs_set_table_for_input)))
- /* buf is on buffer-alist, so no gcpro. */
- call1 (Qucs_set_table_for_input, buf);
+ /* buffer is on buffer-alist, so no gcpro. */
+ call1 (Qucs_set_table_for_input, buffer);
- return buf;
+ return buffer;
}
DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2,
"(list (read-buffer-to-switch \"Switch to buffer: \"))",
- doc: /* Make BUFFER-OR-NAME current and display it in the selected window.
-BUFFER-OR-NAME may be a buffer, a string, or nil. If BUFFER-OR-NAME is
-nil, then this function chooses a buffer using `other-buffer'. If
-BUFFER-OR-NAME is a string and does not identify an existing buffer,
-then this function creates a buffer with that name.
+ doc: /* Make BUFFER-OR-NAME current and display it in selected window.
+BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
+nil. Return the buffer switched to.
+
+If BUFFER-OR-NAME is a string and does not identify an existing
+buffer, create a new buffer with that name. Interactively, if
+`confirm-nonexistent-file-or-buffer' is non-nil, request
+confirmation before creating a new buffer. If BUFFER-OR-NAME is
+nil, switch to buffer returned by `other-buffer'.
-Optional second arg NORECORD non-nil means do not put this buffer at the
-front of the list of recently selected ones. This function returns the
-buffer it switched to as a Lisp object.
+Optional second arg NORECORD non-nil means do not put this buffer
+at the front of the list of recently selected ones. This
+function returns the buffer it switched to as a Lisp object.
-If the selected window is the minibuffer window or dedicated to its
-buffer, use `pop-to-buffer' for displaying the buffer.
+If the selected window is the minibuffer window or dedicated to
+its buffer, use `pop-to-buffer' for displaying the buffer.
WARNING: This is NOT the way to work on another buffer temporarily
-within a Lisp program! Use `set-buffer' instead. That avoids messing
-with the window-buffer correspondences. */)
+within a Lisp program! Use `set-buffer' instead. That avoids
+messing with the window-buffer correspondences. */)
(buffer_or_name, norecord)
Lisp_Object buffer_or_name, norecord;
{
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);
The argument may be a buffer name or an actual buffer object. If
BUFFER-OR-NAME is nil or omitted, bury the current buffer and remove it
-from the selected window if it is displayed there. */)
+from the selected window if it is displayed there. If the selected
+window is dedicated to its buffer, delete that window if there are other
+windows on the same frame. If the selected window is the only window on
+its frame, iconify that frame. */)
(buffer_or_name)
register Lisp_Object buffer_or_name;
{
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. */)
CHECK_BUFFER (buffer);
other_buffer = XBUFFER (buffer);
+ if (NILP (other_buffer->name))
+ error ("Cannot swap a dead buffer's text");
+
/* Actually, it probably works just fine.
* if (other_buffer == current_buffer)
* error ("Cannot swap a buffer's text with itself"); */
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);
swapfield (overlay_center, EMACS_INT);
swapfield (undo_list, Lisp_Object);
swapfield (mark, Lisp_Object);
- if (MARKERP (current_buffer->mark) && XMARKER (current_buffer->mark)->buffer)
- XMARKER (current_buffer->mark)->buffer = current_buffer;
- if (MARKERP (other_buffer->mark) && XMARKER (other_buffer->mark)->buffer)
- XMARKER (other_buffer->mark)->buffer = other_buffer;
swapfield (enable_multibyte_characters, Lisp_Object);
/* FIXME: Not sure what we should do with these *_marker fields.
Hopefully they're just nil anyway. */
current_buffer->text->overlay_modiff++; other_buffer->text->overlay_modiff++;
current_buffer->text->beg_unchanged = current_buffer->text->gpt;
current_buffer->text->end_unchanged = current_buffer->text->gpt;
- other_buffer->text->beg_unchanged = current_buffer->text->gpt;
- other_buffer->text->end_unchanged = current_buffer->text->gpt;
+ other_buffer->text->beg_unchanged = other_buffer->text->gpt;
+ other_buffer->text->end_unchanged = other_buffer->text->gpt;
{
struct Lisp_Marker *m;
for (m = BUF_MARKERS (current_buffer); m; m = m->next)
if (m->buffer == other_buffer)
m->buffer = current_buffer;
+ else
+ /* Since there's no indirect buffer in sight, markers on
+ BUF_MARKERS(buf) should either be for `buf' or dead. */
+ eassert (!m->buffer);
for (m = BUF_MARKERS (other_buffer); m; m = m->next)
if (m->buffer == current_buffer)
m->buffer = other_buffer;
+ else
+ /* Since there's no indirect buffer in sight, markers on
+ BUF_MARKERS(buf) should either be for `buf' or dead. */
+ eassert (!m->buffer);
}
{ /* Some of the C code expects that w->buffer == w->pointm->buffer.
So since we just swapped the markers between the two buffers, we need
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';
}
(hbar . HEIGHT) display a horizontal bar cursor with height HEIGHT
ANYTHING ELSE display a hollow box cursor
-When the buffer is displayed in a nonselected window,
-this variable has no effect; the cursor appears as a hollow box. */);
+When the buffer is displayed in a non-selected window, the
+cursor's appearance is instead controlled by the variable
+`cursor-in-non-selected-windows'. */);
DEFVAR_PER_BUFFER ("line-spacing",
¤t_buffer->extra_line_spacing, Qnil,