]> code.delx.au - gnu-emacs/blobdiff - src/buffer.c
(mac_dialog_modal_filter) [MAC_OSX]: New function.
[gnu-emacs] / src / buffer.c
index 3502afc9bf01d716f942f9a9948ac69579b5bfe2..cf5cdb38a2238521b6b57d29e7fea102167501fe 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",
@@ -1305,15 +1331,16 @@ See `kill-buffer'."
  */
 DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 1, 1, "bKill buffer: ",
        doc: /* Kill the buffer BUFFER.
-The argument may be a buffer or may be the name of a buffer.
-An argument of nil means kill the current buffer.
+The argument may be a buffer or the name of a buffer.
+With a nil argument, kill the current buffer.
+
+Value is t if the buffer is actually killed, nil otherwise.
 
-Value is t if the buffer is actually killed, nil if user says no.
+The functions in `kill-buffer-query-functions' are called with BUFFER as
+the current buffer.  If any of them returns nil, the buffer is not killed.
 
-The value of `kill-buffer-hook' (which may be local to that buffer),
-if not void, is a list of functions to be called, with no arguments,
-before the buffer is actually killed.  The buffer to be killed is current
-when the hook functions are called.
+The hook `kill-buffer-hook' is run before the buffer is actually killed.
+The buffer being killed will be current while the hook is running.
 
 Any processes that have this buffer as the `process-buffer' are killed
 with SIGHUP.  */)
@@ -1684,9 +1711,18 @@ the window-buffer correspondences.  */)
   char *err;
 
   if (EQ (buffer, Fwindow_buffer (selected_window)))
-    /* Basically a NOP.  Avoid signalling an error if the selected window
-       is dedicated, or a minibuffer, ...  */
-    return Fset_buffer (buffer);
+    {
+      /* 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);
+      return Fset_buffer (buffer);
+    }
 
   err = no_switch_window (selected_window);
   if (err) error (err);
@@ -2115,10 +2151,11 @@ current buffer is cleared.  */)
 {
   struct Lisp_Marker *tail, *markers;
   struct buffer *other;
-  int undo_enabled_p = !EQ (current_buffer->undo_list, Qt);
   int begv, zv;
   int narrowed = (BEG != BEGV || Z != ZV);
   int modified_p = !NILP (Fbuffer_modified_p (Qnil));
+  Lisp_Object old_undo = current_buffer->undo_list;
+  struct gcpro gcpro1;
 
   if (current_buffer->base_buffer)
     error ("Cannot do `set-buffer-multibyte' on an indirect buffer");
@@ -2127,10 +2164,11 @@ current buffer is cleared.  */)
   if (NILP (flag) == NILP (current_buffer->enable_multibyte_characters))
     return flag;
 
-  /* It would be better to update the list,
-     but this is good enough for now.  */
-  if (undo_enabled_p)
-    current_buffer->undo_list = Qt;
+  GCPRO1 (old_undo);
+
+  /* Don't record these buffer changes.  We will put a special undo entry
+     instead.  */
+  current_buffer->undo_list = Qt;
 
   /* If the cached position is for this buffer, clear it out.  */
   clear_charpos_cache (current_buffer);
@@ -2330,8 +2368,17 @@ current buffer is cleared.  */)
       set_intervals_multibyte (1);
     }
 
-  if (undo_enabled_p)
-    current_buffer->undo_list = Qnil;
+  if (!EQ (old_undo, Qt))
+    {
+      /* Represent all the above changes by a special undo entry.  */
+      extern Lisp_Object Qapply;
+      current_buffer->undo_list = Fcons (list3 (Qapply,
+                                               intern ("set-buffer-multibyte"),
+                                               NILP (flag) ? Qt : Qnil),
+                                        old_undo);
+    }
+
+  UNGCPRO;
 
   /* Changing the multibyteness of a buffer means that all windows
      showing that buffer must be updated thoroughly.  */
@@ -5309,8 +5356,8 @@ This is the same as (default-value 'fill-column).  */);
 This is the same as (default-value 'left-margin).  */);
 
   DEFVAR_LISP_NOPRO ("default-tab-width",
-             &buffer_defaults.tab_width,
-    doc: /* Default value of `tab-width' for buffers that do not override it.
+                    &buffer_defaults.tab_width,
+                    doc: /* Default value of `tab-width' for buffers that do not override it.
 This is the same as (default-value 'tab-width).  */);
 
   DEFVAR_LISP_NOPRO ("default-case-fold-search",
@@ -5385,13 +5432,13 @@ This is the same as (default-value 'fringe-cursor-alist').  */);
                     &buffer_defaults.scroll_up_aggressively,
                     doc: /* Default value of `scroll-up-aggressively'.
 This value applies in buffers that don't have their own local values.
-This variable is an alias for (default-value 'scroll-up-aggressively).  */);
+This is the same as (default-value 'scroll-up-aggressively).  */);
 
   DEFVAR_LISP_NOPRO ("default-scroll-down-aggressively",
                     &buffer_defaults.scroll_down_aggressively,
                     doc: /* Default value of `scroll-down-aggressively'.
 This value applies in buffers that don't have their own local values.
-This variable is an alias for (default-value 'scroll-down-aggressively).  */);
+This is the same as (default-value 'scroll-down-aggressively).  */);
 
   DEFVAR_PER_BUFFER ("header-line-format",
                     &current_buffer->header_line_format,
@@ -5445,7 +5492,7 @@ A string is printed verbatim in the mode line except for %-constructs:
         or print Bottom or All.
   %n -- print Narrow if appropriate.
   %t -- visited file is text or binary (if OS supports this distinction).
-  %z -- print mnemonics of buffer, terminal, and keyboard coding systems.
+  %z -- print mnemonics of keyboard, terminal, and buffer coding systems.
   %Z -- like %z, but including the end-of-line format.
   %e -- print error message about full memory.
   %[ -- print one [ for each recursive editing level.  %] similar.
@@ -5454,8 +5501,8 @@ 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, provided it is not
-marked as "special".
+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
@@ -5485,7 +5532,7 @@ 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),
-                    doc: /* *Column for the default indent-line-function to indent to.
+                    doc: /* *Column for the default `indent-line-function' to indent to.
 Linefeed indents to this column in Fundamental mode.  */);
 
   DEFVAR_PER_BUFFER ("tab-width", &current_buffer->tab_width,
@@ -5632,9 +5679,9 @@ primitives `aref' and `aset' can be used to access elements of a char-table.
 Each of the char-table elements control how to display the corresponding
 text character: the element at index C in the table says how to display
 the character whose code is C.  Each element should be a vector of
-characters or nil.  nil means display the character in the default fashion;
-otherwise, the characters from the vector are delivered to the screen
-instead of the original character.
+characters or nil.  The value nil means display the character in the
+default fashion; otherwise, the characters from the vector are delivered
+to the screen instead of the original character.
 
 For example, (aset buffer-display-table ?X ?Y) will cause Emacs to display
 a capital Y instead of each X character.
@@ -5765,7 +5812,7 @@ cursor type.  */);
                     &current_buffer->scroll_up_aggressively, Qnil,
                     doc: /* How far to scroll windows upward.
 If you move point off the bottom, the window scrolls automatically.
-This variable controls how far it scrolls.  nil, the default,
+This variable controls how far it scrolls.  The value nil, the default,
 means scroll to center point.  A fraction means scroll to put point
 that fraction of the window's height from the bottom of the window.
 When the value is 0.0, point goes at the bottom line, which in the simple
@@ -5778,7 +5825,7 @@ between 0.0 and 1.0, inclusive.  */);
                     &current_buffer->scroll_down_aggressively, Qnil,
                     doc: /* How far to scroll windows downward.
 If you move point off the top, the window scrolls automatically.
-This variable controls how far it scrolls.  nil, the default,
+This variable controls how far it scrolls.  The value nil, the default,
 means scroll to center point.  A fraction means scroll to put point
 that fraction of the window's height from the top of the window.
 When the value is 0.0, point goes at the top line, which in the simple
@@ -5872,8 +5919,8 @@ An entry of the form POSITION indicates that point was at the buffer
 location given by the integer.  Undoing an entry of this form places
 point at POSITION.
 
-nil marks undo boundaries.  The undo command treats the changes
-between two undo boundaries as a single step to be undone.
+Entries with value `nil' mark undo boundaries.  The undo command treats
+the changes between two undo boundaries as a single step to be undone.
 
 If the value of the variable is t, undo information is not recorded.  */);
 
@@ -5969,7 +6016,7 @@ is a member of the list.  */);
   Vinhibit_read_only = Qnil;
 
   DEFVAR_PER_BUFFER ("cursor-type", &current_buffer->cursor_type, Qnil,
-     doc: /* Cursor to use when this buffer is in the selected window.
+                    doc: /* Cursor to use when this buffer is in the selected window.
 Values are interpreted as follows:
 
   t              use the cursor specified for the frame
@@ -5990,15 +6037,17 @@ this variable has no effect; the cursor appears as a hollow box.  */);
                     doc: /* Additional space to put between lines when displaying a buffer.
 The space is measured in pixels, and put below lines on window systems.
 If value is a floating point number, it specifies the spacing relative
-to the default frame line height.  nil means add no extra space.  */);
+to the default frame line height.  A value of nil means add no extra space.  */);
 
   DEFVAR_PER_BUFFER ("cursor-in-non-selected-windows",
                     &current_buffer->cursor_in_non_selected_windows, Qnil,
-    doc: /* *Cursor type to display in non-selected windows.
-t means to use hollow box cursor.  See `cursor-type' for other values.  */);
+                    doc: /* *Cursor type to display in non-selected windows.
+The value t means to use hollow box cursor.  See `cursor-type' for other values.  */);
 
   DEFVAR_LISP ("kill-buffer-query-functions", &Vkill_buffer_query_functions,
-              doc: /* List of functions called with no args to query before killing a buffer.  */);
+              doc: /* List of functions called with no args to query before killing a buffer.
+The buffer being killed will be current while the functions are running.
+If any of them returns nil, the buffer is not killed.  */);
   Vkill_buffer_query_functions = Qnil;
 
   DEFVAR_LISP ("change-major-mode-hook", &Vchange_major_mode_hook,
@@ -6024,6 +6073,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);