(unchain_marker): Allow differing buffers
[bpt/emacs.git] / src / buffer.c
index 8ab052b..c7caf2a 100644 (file)
@@ -1,5 +1,5 @@
 /* Buffer manipulation primitives for GNU Emacs.
-   Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994
+   Copyright (C) 1985, 1986, 1987, 1988, 1989, 1993, 1994, 1995
        Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -266,7 +266,7 @@ The value is never nil.")
   BUFFER_ALLOC (BUF_BEG_ADDR (b), BUF_GAP_SIZE (b));
   UNBLOCK_INPUT;
   if (! BUF_BEG_ADDR (b))
-    memory_full ();
+    buffer_memory_full ();
 
   BUF_PT (b) = 1;
   BUF_GPT (b) = 1;
@@ -410,6 +410,7 @@ reset_buffer (b)
      register struct buffer *b;
 {
   b->filename = Qnil;
+  b->file_truename = Qnil;
   b->directory = (current_buffer) ? current_buffer->directory : Qnil;
   b->modtime = 0;
   XSETFASTINT (b->save_length, 0);
@@ -423,6 +424,7 @@ reset_buffer (b)
   b->overlays_after = Qnil;
   XSETFASTINT (b->overlay_center, 1);
   b->mark_active = Qnil;
+  b->point_before_scroll = Qnil;
 }
 
 /* Reset buffer B's local variables info.
@@ -449,6 +451,8 @@ reset_buffer_local_variables (b)
   b->case_canon_table = Vascii_canon_table;
   b->case_eqv_table = Vascii_eqv_table;
   b->buffer_file_type = Qnil;
+  b->invisibility_spec = Qt;
+
 #if 0
   b->sort_table = XSTRING (Vascii_sort_table);
   b->folding_sort_table = XSTRING (Vascii_folding_sort_table);
@@ -585,11 +589,6 @@ No argument or nil as argument means use current buffer as BUFFER.")
   result = Qnil;
 
   {
-    /* Reference each variable in the alist in our current buffer.
-       If inquiring about the current buffer, this gets the current values,
-       so store them into the alist so the alist is up to date.
-       If inquiring about some other buffer, this swaps out any values
-       for that buffer, making the alist up to date automatically.  */
     register Lisp_Object tail;
     for (tail = buf->local_var_alist; CONSP (tail); tail = XCONS (tail)->cdr)
       {
@@ -597,9 +596,14 @@ No argument or nil as argument means use current buffer as BUFFER.")
 
        elt = XCONS (tail)->car;
 
-       if (buf == current_buffer)
-         val = find_symbol_value (XCONS (elt)->car);
-       else
+       /* Reference each variable in the alist in buf.
+          If inquiring about the current buffer, this gets the current values,
+          so store them into the alist so the alist is up to date.
+          If inquiring about some other buffer, this swaps out any values
+          for that buffer, making the alist up to date automatically.  */
+       val = find_symbol_value (XCONS (elt)->car);
+       /* Use the current buffer value only if buf is the current buffer.  */
+       if (buf != current_buffer)
          val = XCONS (elt)->cdr;
 
        /* If symbol is unbound, put just the symbol in the list.  */
@@ -1144,7 +1148,14 @@ window even if BUFFER is already visible in the selected window.")
   if (NILP (bufname))
     buf = Fother_buffer (Fcurrent_buffer (), Qnil);
   else
-    buf = Fget_buffer_create (bufname);
+    {
+      buf = Fget_buffer (bufname);
+      if (NILP (buf))
+       {
+         buf = Fget_buffer_create (bufname);
+         Fset_buffer_major_mode (buf);
+       }
+    }
   Fset_buffer (buf);
   record_buffer (buf);
   Fselect_window (Fdisplay_buffer (buf, other));
@@ -1407,135 +1418,6 @@ validate_region (b, e)
     args_out_of_range (*b, *e);
 }
 \f
-static Lisp_Object
-list_buffers_1 (files)
-     Lisp_Object files;
-{
-  register Lisp_Object tail, tem, buf;
-  Lisp_Object col1, col2, col3, minspace;
-  register struct buffer *old = current_buffer, *b;
-  Lisp_Object desired_point;
-  Lisp_Object other_file_symbol;
-
-  desired_point = Qnil;
-  other_file_symbol = intern ("list-buffers-directory");
-
-  XSETFASTINT (col1, 17);
-  XSETFASTINT (col2, 28);
-  XSETFASTINT (col3, 40);
-  XSETFASTINT (minspace, 1);
-
-  Fset_buffer (Vstandard_output);
-  Fbuffer_disable_undo (Vstandard_output);
-  current_buffer->read_only = Qnil;
-
-  write_string ("\
- MR Buffer           Size Mode          File\n\
- -- ------           ---- ----          ----\n", -1);
-
-  for (tail = Vbuffer_alist; !NILP (tail); tail = Fcdr (tail))
-    {
-      buf = Fcdr (Fcar (tail));
-      b = XBUFFER (buf);
-      /* Don't mention the minibuffers. */
-      if (XSTRING (b->name)->data[0] == ' ')
-       continue;
-      /* Optionally don't mention buffers that lack files. */
-      if (!NILP (files) && NILP (b->filename))
-       continue;
-      /* Identify the current buffer. */
-      if (b == old)
-       XSETFASTINT (desired_point, PT);
-      write_string (b == old ? "." : " ", -1);
-      /* Identify modified buffers */
-      write_string (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b) ? "*" : " ", -1);
-      /* The current buffer is special-cased to be marked read-only.
-        It is actually made read-only by the call to
-        Buffer-menu-mode, below. */
-      write_string ((b != current_buffer && NILP (b->read_only))
-                   ? "  " : "% ", -1);
-      Fprinc (b->name, Qnil);
-      tem = Findent_to (col1, make_number (2));
-      {
-       char sizebuf[9];
-       int i;
-       char *p;
-
-       sprintf (sizebuf, "%8d", BUF_Z (b) - BUF_BEG (b));
-       /* Here's how many extra columns the buffer name used.  */
-       i = XFASTINT (tem) - XFASTINT (col1);
-       /* Skip that many spaces in the size, if it has that many,
-          to keep the size values right-aligned if possible.  */
-       p = sizebuf;
-       while (i > 0)
-         {
-           if (*p == ' ')
-             p++;
-           i--;
-         }
-
-       write_string (p, -1);
-      }
-      Findent_to (col2, minspace);
-      Fprinc (b->mode_name, Qnil);
-      Findent_to (col3, minspace);
-
-      if (!NILP (b->filename))
-       Fprinc (b->filename, Qnil);
-      else
-       {
-         /* No visited file; check local value of list-buffers-directory.  */
-         Lisp_Object tem;
-         set_buffer_internal (b);
-         tem = Fboundp (other_file_symbol);
-         if (!NILP (tem))
-           {
-             tem = Fsymbol_value (other_file_symbol);
-             Fset_buffer (Vstandard_output);
-             if (STRINGP (tem))
-               Fprinc (tem, Qnil);
-           }
-         else
-           Fset_buffer (Vstandard_output);
-       }
-      write_string ("\n", -1);
-    }
-
-  tail = intern ("Buffer-menu-mode");
-  if ((tem = Ffboundp (tail), !NILP (tem)))
-    call0 (tail);
-  set_buffer_internal (old);
-  return desired_point;
-}
-
-DEFUN ("list-buffers", Flist_buffers, Slist_buffers, 0, 1, "P",
-  "Display a list of names of existing buffers.\n\
-The list is displayed in a buffer named `*Buffer List*'.\n\
-Note that buffers with names starting with spaces are omitted.\n\
-Non-null optional arg FILES-ONLY means mention only file buffers.\n\
-\n\
-The M column contains a * for buffers that are modified.\n\
-The R column contains a % for buffers that are read-only.")
-  (files)
-     Lisp_Object files;
-{
-  Lisp_Object desired_point;
-
-  desired_point
-    = internal_with_output_to_temp_buffer ("*Buffer List*",
-                                          list_buffers_1, files);
-
-  if (NUMBERP (desired_point))
-    {
-      int count = specpdl_ptr - specpdl;
-      record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
-      Fset_buffer (build_string ("*Buffer List*"));
-      SET_PT (XINT (desired_point));
-      return unbind_to (count, Qnil);
-    }
-  return Qnil;
-}
-
 DEFUN ("kill-all-local-variables", Fkill_all_local_variables, Skill_all_local_variables,
   0, 0, 0,
   "Switch to Fundamental mode by killing current buffer's local variables.\n\
@@ -2822,6 +2704,7 @@ init_buffer_once ()
   XSETFASTINT (buffer_defaults.fill_column, 70);
   XSETFASTINT (buffer_defaults.left_margin, 0);
   buffer_defaults.cache_long_line_scans = Qnil;
+  buffer_defaults.file_truename = Qnil;
 
   /* Assign the local-flags to the slots that have default values.
      The local flag is a bit that is used in the buffer
@@ -2843,6 +2726,9 @@ init_buffer_once ()
   XSETINT (buffer_local_flags.mode_name, -1);
   XSETINT (buffer_local_flags.undo_list, -1);
   XSETINT (buffer_local_flags.mark_active, -1);
+  XSETINT (buffer_local_flags.point_before_scroll, -1);
+  XSETINT (buffer_local_flags.file_truename, -1);
+  XSETINT (buffer_local_flags.invisibility_spec, -1);
 
   XSETFASTINT (buffer_local_flags.mode_line_format, 1);
   XSETFASTINT (buffer_local_flags.abbrev_mode, 2);
@@ -3114,7 +3000,7 @@ and this buffer is not full-frame width.");
     "Non-nil if the visited file is a binary file.\n\
 This variable is meaningful on MS-DOG and Windows NT.\n\
 On those systems, it is automatically local in every buffer.\n\
-On other systems, this variable is normally always nil.")
+On other systems, this variable is normally always nil.");
 #endif
 
   DEFVAR_PER_BUFFER ("default-directory", &current_buffer->directory,
@@ -3135,6 +3021,12 @@ It may not be a list of functions.");
     "Name of file visited in current buffer, or nil if not visiting a file.\n\
 Each buffer has its own value of this variable.");
 
+  DEFVAR_PER_BUFFER ("buffer-file-truename", &current_buffer->file_truename,
+                    make_number (Lisp_String),
+    "Truename of file visited in current buffer, or nil if not visiting a file.\n\
+The truename of a file is calculated by `file-truename'.\n\
+Each buffer has its own value of this variable.");
+
   DEFVAR_PER_BUFFER ("buffer-auto-save-file-name",
                     &current_buffer->auto_save_file_name,
                     make_number (Lisp_String),
@@ -3176,7 +3068,9 @@ Automatically becomes buffer-local when set in any fashion.");
 
   DEFVAR_PER_BUFFER ("overwrite-mode", &current_buffer->overwrite_mode, Qnil,
     "Non-nil if self-insertion should replace existing text.\n\
-If non-nil and not `overwrite-mode-binary', self-insertion still\n\
+The value should be one of `overwrite-mode-textual',\n\
+`overwrite-mode-binary', or nil.\n\
+If it is `overwrite-mode-textual', self-insertion still\n\
 inserts at the end of a line, and inserts when point is before a tab,\n\
 until the tab is filled in.\n\
 If `overwrite-mode-binary', self-insertion replaces newlines and tabs too.\n\
@@ -3297,15 +3191,15 @@ An entry (TEXT . POSITION) represents the deletion of the string TEXT\n\
 from (abs POSITION).  If POSITION is positive, point was at the front\n\
 of the text being deleted; if negative, point was at the end.\n\
 \n\
-An entry (t HIGHWORD LOWWORD) indicates that the buffer had been\n\
-previously unmodified.  HIGHWORD and LOWWORD are the high and low\n\
-16-bit words of the buffer's modification count at the time.  If the\n\
-modification count of the most recent save is different, this entry is\n\
+An entry (t HIGH . LOW) indicates that the buffer previously had\n\
+\"unmodified\" status.  HIGH and LOW are the high and low 16-bit portions\n\
+of the visited file's modification time, as of that time.  If the\n\
+modification time of the most recent save is different, this entry is\n\
 obsolete.\n\
 \n\
-An entry (nil PROP VAL BEG . END) indicates that a text property\n\
-was modified between BEG and END.  PROP is the property name,\n\
-and VAL is the old value.\n\
+An entry (nil PROPERTY VALUE BEG . END) indicates that a text property\n\
+was modified between BEG and END.  PROPERTY is the property name,\n\
+and VALUE is the old value.\n\
 \n\
 An entry of the form POSITION indicates that point was at the buffer\n\
 location given by the integer.  Undoing an entry of this form places\n\
@@ -3352,6 +3246,20 @@ maintained internally by the Emacs primitives.  Enabling or disabling\n\
 the cache should not affect the behavior of any of the motion\n\
 functions; it should only affect their performance.");
 
+  DEFVAR_PER_BUFFER ("point-before-scroll", &current_buffer->point_before_scroll, Qnil,
+  "Value of point before the last series of scroll operations, or nil.");
+
+  DEFVAR_PER_BUFFER ("buffer-invisibility-spec",
+                    &current_buffer->invisibility_spec, Qnil,
+  "Invisibility spec of this buffer.\n\
+The default is t, which means that text is invisible\n\
+if it has a non-nil `invisible' property.\n\
+If the value is a list, a text character is invisible if its `invisible'\n\
+property is an element in that list.\n\
+If an element is a cons cell of the for (PROP . ELLIPSIS),\n\
+then characters with property value PROP is invisible,\n\
+and they have an ellipsis as well if ELLIPSIS is non-nil.");
+
   DEFVAR_LISP ("transient-mark-mode", &Vtransient_mark_mode,
     "*Non-nil means deactivate the mark when the buffer contents change.");
   Vtransient_mark_mode = Qnil;
@@ -3395,7 +3303,6 @@ is a member of the list.");
   defsubr (&Sset_buffer);
   defsubr (&Sbarf_if_buffer_read_only);
   defsubr (&Sbury_buffer);
-  defsubr (&Slist_buffers);
   defsubr (&Skill_all_local_variables);
 
   defsubr (&Soverlayp);
@@ -3419,7 +3326,6 @@ keys_of_buffer ()
 {
   initial_define_key (control_x_map, 'b', "switch-to-buffer");
   initial_define_key (control_x_map, 'k', "kill-buffer");
-  initial_define_key (control_x_map, Ctl ('B'), "list-buffers");
 
   /* This must not be in syms_of_buffer, because Qdisabled is not
      initialized when that function gets called.  */