* etc/NEWS: In terminal-oriented subshells, the EMACS environment
[bpt/emacs.git] / src / buffer.c
index f6c4585..51f93c9 100644 (file)
@@ -374,6 +374,7 @@ The value is never nil.  */)
   BUF_ZV_BYTE (b) = BEG_BYTE;
   BUF_Z_BYTE (b) = BEG_BYTE;
   BUF_MODIFF (b) = 1;
+  BUF_CHARS_MODIFF (b) = 1;
   BUF_OVERLAY_MODIFF (b) = 1;
   BUF_SAVE_MODIFF (b) = 1;
   BUF_INTERVALS (b) = 0;
@@ -1148,6 +1149,31 @@ No argument or nil as argument means use current buffer as BUFFER.  */)
 
   return make_number (BUF_MODIFF (buf));
 }
+
+DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick,
+       Sbuffer_chars_modified_tick, 0, 1, 0,
+       doc: /* Return BUFFER's character-change tick counter.
+Each buffer has a character-change tick counter, which is set to the
+value of the buffer's tick counter \(see `buffer-modified-tick'), each
+time text in that buffer is inserted or deleted.  By comparing the
+values returned by two individual calls of `buffer-chars-modified-tick',
+you can tell whether a character change occurred in that buffer in
+between these calls.  No argument or nil as argument means use current
+buffer as BUFFER.  */)
+     (buffer)
+     register Lisp_Object buffer;
+{
+  register struct buffer *buf;
+  if (NILP (buffer))
+    buf = current_buffer;
+  else
+    {
+      CHECK_BUFFER (buffer);
+      buf = XBUFFER (buffer);
+    }
+
+  return make_number (BUF_CHARS_MODIFF (buf));
+}
 \f
 DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 2,
        "sRename buffer (to new name): \nP",
@@ -1685,10 +1711,15 @@ the window-buffer correspondences.  */)
 
   if (EQ (buffer, Fwindow_buffer (selected_window)))
     {
-      if (NILP (norecord)  && !EQ (buffer, XCDR (XCAR (Vbuffer_alist))))
+      /* Basically a NOP.  Avoid signalling an error in the case where
+        the selected window is dedicated, or a minibuffer.  */
+
+      /* But do put this buffer at the front of the buffer list,
+        unless that has been inhibited.  Note that even if
+        BUFFER is at the front of the main buffer-list already,
+        we still want to move it to the front of the frame's buffer list.  */
+      if (NILP (norecord))
        record_buffer (buffer);
-      /* Basically a NOP.  Avoid signalling an error if the selected window
-        is dedicated, or a minibuffer, ...  */
       return Fset_buffer (buffer);
     }
 
@@ -2340,11 +2371,10 @@ current buffer is cleared.  */)
     {
       /* Represent all the above changes by a special undo entry.  */
       extern Lisp_Object Qapply;
-      Lisp_Object args[3];
-      args[0] = Qapply;
-      args[1] = intern ("set-buffer-multibyte");
-      args[2] = NILP (flag) ? Qt : Qnil;
-      current_buffer->undo_list = Fcons (Flist (3, args), old_undo);
+      current_buffer->undo_list = Fcons (list3 (Qapply,
+                                               intern ("set-buffer-multibyte"),
+                                               NILP (flag) ? Qt : Qnil),
+                                        old_undo);
     }
 
   UNGCPRO;
@@ -6040,6 +6070,7 @@ The function `kill-all-local-variables' runs this before doing anything else.  *
   defsubr (&Sbuffer_modified_p);
   defsubr (&Sset_buffer_modified_p);
   defsubr (&Sbuffer_modified_tick);
+  defsubr (&Sbuffer_chars_modified_tick);
   defsubr (&Srename_buffer);
   defsubr (&Sother_buffer);
   defsubr (&Sbuffer_enable_undo);