(Foverlay_buffer): Doc fix.
[bpt/emacs.git] / src / buffer.c
index 7560e69..3394e1d 100644 (file)
@@ -1,6 +1,6 @@
 /* Buffer manipulation primitives for GNU Emacs.
-   Copyright (C) 1985,86,87,88,89,93,94,95,97,98, 1999, 2000, 2001, 02, 03, 2004
-       Free Software Foundation, Inc.
+   Copyright (C) 1985, 86, 87, 88, 89, 93, 94, 95, 97, 98, 99, 
+     2000, 01, 02, 03, 04, 2005 Free Software Foundation, Inc. 
 
 This file is part of GNU Emacs.
 
@@ -487,7 +487,7 @@ static void
 clone_per_buffer_values (from, to)
      struct buffer *from, *to;
 {
-  Lisp_Object to_buffer;
+  Lisp_Object to_buffer, tem;
   int offset;
 
   XSETBUFFER (to_buffer, to);
@@ -514,6 +514,14 @@ clone_per_buffer_values (from, to)
 
   to->overlays_before = copy_overlays (to, from->overlays_before);
   to->overlays_after = copy_overlays (to, from->overlays_after);
+
+  /* Copy the alist of local variables,
+     and all the alist elements too.  */
+  to->local_var_alist
+    = Fcopy_sequence (from->local_var_alist);
+  for (tem = to->local_var_alist; CONSP (tem);
+       tem = XCDR (tem))
+    XSETCAR (tem, Fcons (XCAR (XCAR (tem)), XCDR (XCAR (tem))));
 }
 
 
@@ -686,6 +694,7 @@ reset_buffer (b)
   b->mark_active = Qnil;
   b->point_before_scroll = Qnil;
   b->file_format = Qnil;
+  b->auto_save_file_format = Qt;
   b->last_selected_window = Qnil;
   XSETINT (b->display_count, 0);
   b->display_time = Qnil;
@@ -1069,7 +1078,7 @@ A non-nil FLAG means mark the buffer modified.  */)
 
 DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p,
        Srestore_buffer_modified_p, 1, 1, 0,
-       doc: /* Like `set-buffer-modified-p', with a differences concerning redisplay.
+       doc: /* Like `set-buffer-modified-p', with a difference concerning redisplay.
 It is not ensured that mode lines will be updated to show the modified
 state of the current buffer.  Use with care.  */)
      (flag)
@@ -1242,29 +1251,6 @@ If BUFFER is omitted or nil, some interesting buffer is returned.  */)
   return buf;
 }
 \f
-DEFUN ("buffer-disable-undo", Fbuffer_disable_undo, Sbuffer_disable_undo,
-       0, 1, "",
-       doc: /* Make BUFFER stop keeping undo information.
-No argument or nil as argument means do this for the current buffer.  */)
-     (buffer)
-     register Lisp_Object buffer;
-{
-  Lisp_Object real_buffer;
-
-  if (NILP (buffer))
-    XSETBUFFER (real_buffer, current_buffer);
-  else
-    {
-      real_buffer = Fget_buffer (buffer);
-      if (NILP (real_buffer))
-       nsberror (buffer);
-    }
-
-  XBUFFER (real_buffer)->undo_list = Qt;
-
-  return Qnil;
-}
-
 DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo,
        0, 1, "",
        doc: /* Start keeping undo information for buffer BUFFER.
@@ -1656,9 +1642,15 @@ switch_to_buffer_1 (buffer, norecord)
 
 DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ",
        doc: /* Select buffer BUFFER in the current window.
-BUFFER may be a buffer or a buffer name.
+If BUFFER does not identify an existing buffer,
+then this function creates a buffer with that name.
+
+When called from Lisp, BUFFER may be a buffer, a string \(a buffer name),
+or nil.  If BUFFER is nil, then this function chooses a buffer
+using `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.
 
 WARNING: This is NOT the way to work on another buffer temporarily
 within a Lisp program!  Use `set-buffer' instead.  That avoids messing with
@@ -1681,11 +1673,15 @@ the window-buffer correspondences.  */)
 
 DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 3, 0,
        doc: /* Select buffer BUFFER in some window, preferably a different one.
-If BUFFER is nil, then some other buffer is chosen.
+BUFFER may be a buffer, a string \(a buffer name), or nil.
+If BUFFER is a string which is not the name of an existing buffer,
+then this function creates a buffer with that name.
+If BUFFER is nil, then it chooses some other buffer.
 If `pop-up-windows' is non-nil, windows can be split to do this.
 If optional second arg OTHER-WINDOW is non-nil, insist on finding another
 window even if BUFFER is already visible in the selected window,
 and ignore `same-window-regexps' and `same-window-buffer-names'.
+This function returns the buffer it switched to.
 This uses the function `display-buffer' as a subroutine; see the documentation
 of `display-buffer' for additional customization information.
 
@@ -1956,6 +1952,7 @@ DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "",
        doc: /* Put BUFFER at the end of the list of all buffers.
 There it is the least likely candidate for `other-buffer' to return;
 thus, the least likely buffer for \\[switch-to-buffer] to select by default.
+You can specify a buffer name as BUFFER, or an actual buffer object.
 If BUFFER is nil or omitted, bury the current buffer.
 Also, if BUFFER is nil or omitted, remove the current buffer from the
 selected window if it is displayed there.  */)
@@ -3833,7 +3830,8 @@ DEFUN ("overlay-end", Foverlay_end, Soverlay_end, 1, 1, 0,
 }
 
 DEFUN ("overlay-buffer", Foverlay_buffer, Soverlay_buffer, 1, 1, 0,
-       doc: /* Return the buffer OVERLAY belongs to.  */)
+       doc: /* Return the buffer OVERLAY belongs to.
+Return nil if OVERLAY has been deleted.  */)
      (overlay)
        Lisp_Object overlay;
 {
@@ -4944,6 +4942,7 @@ init_buffer_once ()
   buffer_defaults.undo_list = Qnil;
   buffer_defaults.mark_active = Qnil;
   buffer_defaults.file_format = Qnil;
+  buffer_defaults.auto_save_file_format = Qt;
   buffer_defaults.overlays_before = NULL;
   buffer_defaults.overlays_after = NULL;
   buffer_defaults.overlay_center = BEG;
@@ -5002,6 +5001,7 @@ init_buffer_once ()
   XSETINT (buffer_local_flags.file_truename, -1);
   XSETINT (buffer_local_flags.invisibility_spec, -1);
   XSETINT (buffer_local_flags.file_format, -1);
+  XSETINT (buffer_local_flags.auto_save_file_format, -1);
   XSETINT (buffer_local_flags.display_count, -1);
   XSETINT (buffer_local_flags.display_time, -1);
   XSETINT (buffer_local_flags.enable_multibyte_characters, -1);
@@ -5141,7 +5141,13 @@ init_buffer ()
     }
 #endif /* not VMS */
 
-  current_buffer->directory = build_string (buf);
+  current_buffer->directory = make_unibyte_string (buf, strlen (buf));
+  if (! NILP (buffer_defaults.enable_multibyte_characters))
+    /* At this momemnt, we still don't know how to decode the
+       direcotry name.  So, we keep the bytes in multibyte form so
+       that ENCODE_FILE correctly gets the original bytes.  */
+    current_buffer->directory
+      = string_to_multibyte (current_buffer->directory);
 
   /* Add /: to the front of the name
      if it would otherwise be treated as magic.  */
@@ -5409,7 +5415,14 @@ 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'.
-nil here means use current buffer's major mode.  */);
+nil here 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.  */);
 
   DEFVAR_PER_BUFFER ("major-mode", &current_buffer->major_mode,
                     make_number (Lisp_Symbol),
@@ -5429,7 +5442,7 @@ nil here means use current buffer's major mode.  */);
   DEFVAR_PER_BUFFER ("fill-column", &current_buffer->fill_column,
                     make_number (Lisp_Int),
                     doc: /* *Column beyond which automatic line-wrapping should happen.
-Interactively, you can set this using \\[set-fill-column].  */);
+Interactively, you can set the buffer local value using \\[set-fill-column].  */);
 
   DEFVAR_PER_BUFFER ("left-margin", &current_buffer->left_margin,
                     make_number (Lisp_Int),
@@ -5637,9 +5650,12 @@ A value of nil means to use the scroll bar width from the window's frame.  */);
   DEFVAR_PER_BUFFER ("vertical-scroll-bar", &current_buffer->vertical_scroll_bar_type,
                     Qnil,
                     doc: /* *Position of this buffer's vertical scroll bar.
-A value of left or right means to place the vertical scroll bar at that side
-of the window; a value of nil means that this window has no vertical scroll bar.
-A value of t means to use the vertical scroll bar type from the window's frame.  */);
+The value takes effect whenever you tell a window to display this buffer;
+for instance, with `set-window-buffer' or when `display-buffer' displays it.
+
+A value of `left' or `right' means put the vertical scroll bar at that side
+of the window; a value of nil means don't show any vertical scroll bars.
+A value of t (the default) means do whatever the window's frame specifies.  */);
 
   DEFVAR_PER_BUFFER ("indicate-empty-lines",
                     &current_buffer->indicate_empty_lines, Qnil,
@@ -5654,16 +5670,23 @@ If non-nil, the first and last line of the buffer are marked in the fringe
 of a window on window-systems with angle bitmaps, or if the window can be
 scrolled, the top and bottom line of the window are marked with up and down
 arrow bitmaps.
-If value is `left' or `right', both angle and arrow bitmaps are displayed in
-the left or right fringe, resp.  Any other non-nil value causes the
-bitmap on the top line to be displayed in the left fringe, and the
-bitmap on the bottom line in the right fringe.
-If value is a cons (ANGLES . ARROWS), the car specifies the position
-of the angle bitmaps, and the cdr specifies the position of the arrow
-bitmaps.  For example, (t . right) places the top angle bitmap in left
-fringe, the bottom angle bitmap in right fringe, and both arrow
+
+If value is a symbol `left' or `right', both angle and arrow bitmaps
+are displayed in the left or right fringe, resp.  Any other value
+that doesn't look like an alist means displat the angle bitmaps in
+the left fringe but no arrows.
+
+You can exercise more precise control by using an alist as the
+value.  Each alist element (INDICATOR . POSITION) specifies
+where to show one of the indicators.  INDICATOR is one of `top',
+`bottom', `up', `down', or t, which specifies the default position,
+and POSITION is one of `left', `right', or nil, meaning do not show
+this indicator.
+
+For example, ((top . left) (t . right)) places the top angle bitmap in
+left fringe, the bottom angle bitmap in right fringe, and both arrow
 bitmaps in right fringe.  To show just the angle bitmaps in the left
-fringe, but no arrow bitmaps, use (left . nil).  */);
+fringe, but no arrow bitmaps, use ((top .  left) (bottom . left)).  */);
 
   DEFVAR_PER_BUFFER ("scroll-up-aggressively",
                     &current_buffer->scroll_up_aggressively, Qnil,
@@ -5761,6 +5784,14 @@ An entry (nil PROPERTY VALUE BEG . END) indicates that a text property
 was modified between BEG and END.  PROPERTY is the property name,
 and VALUE is the old value.
 
+An entry (apply FUN-NAME . ARGS) means undo the change with
+\(apply FUN-NAME ARGS).
+
+An entry (apply DELTA BEG END FUN-NAME . ARGS) supports selective undo
+in the active region.  BEG and END is the range affected by this entry
+and DELTA is the number of bytes added or deleted in that range by
+this change.
+
 An entry (MARKER . DISTANCE) indicates that the marker MARKER
 was adjusted in position by the offset DISTANCE (an integer).
 
@@ -5780,21 +5811,21 @@ If the value of the variable is t, undo information is not recorded.  */);
                     doc: /* Non-nil means that Emacs should use caches to handle long lines more quickly.
 
 Normally, the line-motion functions work by scanning the buffer for
-newlines.  Columnar operations (like move-to-column and
-compute-motion) also work by scanning the buffer, summing character
+newlines.  Columnar operations (like `move-to-column' and
+`compute-motion') also work by scanning the buffer, summing character
 widths as they go.  This works well for ordinary text, but if the
 buffer's lines are very long (say, more than 500 characters), these
 motion functions will take longer to execute.  Emacs may also take
 longer to update the display.
 
-If cache-long-line-scans is non-nil, these motion functions cache the
+If `cache-long-line-scans' is non-nil, these motion functions cache the
 results of their scans, and consult the cache to avoid rescanning
 regions of the buffer until the text is modified.  The caches are most
 beneficial when they prevent the most searching---that is, when the
 buffer contains long lines and large regions of characters with the
 same, fixed screen width.
 
-When cache-long-line-scans is non-nil, processing short lines will
+When `cache-long-line-scans' is non-nil, processing short lines will
 become slightly slower (because of the overhead of consulting the
 cache), and the caches will use memory roughly proportional to the
 number of newlines and characters whose screen width varies.
@@ -5812,6 +5843,13 @@ functions; it should only affect their performance.  */);
 Formats are defined by `format-alist'.  This variable is
 set when a file is visited.  */);
 
+  DEFVAR_PER_BUFFER ("buffer-auto-save-file-format",
+                    &current_buffer->auto_save_file_format, Qnil,
+                    doc: /* *Format in which to write auto-save files.
+Should be a list of symbols naming formats that are defined in `format-alist'.
+If it is t, which is the default, auto-save files are written in the
+same format as a regular save would use.  */);
+
   DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
                     &current_buffer->invisibility_spec, Qnil,
                     doc: /* Invisibility spec of this buffer.
@@ -5839,7 +5877,14 @@ If the buffer has never been shown in a window, the value is nil.  */);
               doc: /* *Non-nil means deactivate the mark when the buffer contents change.
 Non-nil also enables highlighting of the region whenever the mark is active.
 The variable `highlight-nonselected-windows' controls whether to highlight
-all windows or just the selected window.  */);
+all windows or just the selected window.
+
+If the value is `lambda', that enables Transient Mark mode temporarily
+until the next buffer modification.  If a command sets the value to `only',
+that enables Transient Mark mode for the following command only.
+During that following command, the value of `transient-mark-mode'
+is `identity'.  If it is still `identity' at the end of that command,
+it changes to nil.  */);
   Vtransient_mark_mode = Qnil;
 
   DEFVAR_LISP ("inhibit-read-only", &Vinhibit_read_only,
@@ -5860,8 +5905,8 @@ Values are interpreted as follows:
   hollow        display a hollow box cursor
   bar           display a vertical bar cursor with default width
   (bar . WIDTH)         display a vertical bar cursor with width WIDTH
-  hbar          display a horisontal bar cursor with default width
-  (hbar . WIDTH) display a horisontal bar cursor with width WIDTH
+  hbar          display a horizontal bar cursor with default width
+  (hbar . WIDTH) display a horizontal bar cursor with width WIDTH
   ANYTHING ELSE         display a hollow box cursor.
 
 When the buffer is displayed in a nonselected window,
@@ -5896,7 +5941,6 @@ to the default frame line height.  */);
   defsubr (&Sbuffer_modified_tick);
   defsubr (&Srename_buffer);
   defsubr (&Sother_buffer);
-  defsubr (&Sbuffer_disable_undo);
   defsubr (&Sbuffer_enable_undo);
   defsubr (&Skill_buffer);
   defsubr (&Sset_buffer_major_mode);