Simplify EMACS_TIME-related code.
[bpt/emacs.git] / src / buffer.h
index 1129840..bedb789 100644 (file)
@@ -1,7 +1,7 @@
 /* Header file for the buffer manipulation primitives.
 
-Copyright (C) 1985-1986, 1993-1995, 1997-2012
-                 Free Software Foundation, Inc.
+Copyright (C) 1985-1986, 1993-1995, 1997-2013 Free Software Foundation,
+Inc.
 
 This file is part of GNU Emacs.
 
@@ -18,8 +18,8 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include <sys/types.h> /* for off_t, time_t */
-#include "systime.h" /* for EMACS_TIME */
+#include <sys/types.h>
+#include <time.h>
 
 INLINE_HEADER_BEGIN
 #ifndef BUFFER_INLINE
@@ -82,9 +82,6 @@ INLINE_HEADER_BEGIN
 /* Size of gap.  */
 #define GAP_SIZE (current_buffer->text->gap_size)
 
-/* Is the current buffer narrowed?  */
-#define NARROWED       ((BEGV != BEG) || (ZV != Z))
-
 /* Modification count.  */
 #define MODIFF (current_buffer->text->modiff)
 
@@ -173,10 +170,6 @@ INLINE_HEADER_BEGIN
 /* Size of gap.  */
 #define BUF_GAP_SIZE(buf) ((buf)->text->gap_size)
 
-/* Is this buffer narrowed?  */
-#define BUF_NARROWED(buf) ((BUF_BEGV (buf) != BUF_BEG (buf)) \
-                          || (BUF_ZV (buf) != BUF_Z (buf)))
-
 /* Modification count.  */
 #define BUF_MODIFF(buf) ((buf)->text->modiff)
 
@@ -193,6 +186,9 @@ INLINE_HEADER_BEGIN
 /* FIXME: should we move this into ->text->auto_save_modiff?  */
 #define BUF_AUTOSAVE_MODIFF(buf) ((buf)->auto_save_modified)
 
+/* Compaction count.  */
+#define BUF_COMPACT(buf) ((buf)->text->compact)
+
 /* Marker chain of buffer.  */
 #define BUF_MARKERS(buf) ((buf)->text->markers)
 
@@ -291,24 +287,24 @@ extern void enlarge_buffer_text (struct buffer *, ptrdiff_t);
 /* Access a Lisp position value in POS,
    and store the charpos in CHARPOS and the bytepos in BYTEPOS.  */
 
-#define DECODE_POSITION(charpos, bytepos, pos)                 \
-do                                                             \
-  {                                                            \
-    Lisp_Object __pos = (pos);                                 \
-    if (NUMBERP (__pos))                                       \
-                                                                     \
-       charpos = __pos;                                        \
-       bytepos = buf_charpos_to_bytepos (current_buffer, __pos);  \
-                                                                     \
-    else if (MARKERP (__pos))                                  \
-                                                                     \
-       charpos = marker_position (__pos);                      \
-       bytepos = marker_byte_position (__pos);                 \
-                                                                     \
-    else                                                       \
-      wrong_type_argument (Qinteger_or_marker_p, __pos);       \
-  }                                                            \
-while (0)
+#define DECODE_POSITION(charpos, bytepos, pos)                         \
+  do                                                                   \
+    {                                                                  \
+      Lisp_Object __pos = (pos);                                       \
+      if (NUMBERP (__pos))                                             \
+       {                                                               \
+         charpos = __pos;                                              \
+         bytepos = buf_charpos_to_bytepos (current_buffer, __pos);     \
+       }                                                               \
+      else if (MARKERP (__pos))                                                \
+       {                                                               \
+         charpos = marker_position (__pos);                            \
+         bytepos = marker_byte_position (__pos);                       \
+       }                                                               \
+      else                                                             \
+       wrong_type_argument (Qinteger_or_marker_p, __pos);              \
+    }                                                                  \
+  while (0)
 
 /* Maximum number of bytes in a buffer.
    A buffer cannot contain more bytes than a 1-origin fixnum can represent,
@@ -317,6 +313,16 @@ while (0)
 #define BUF_BYTES_MAX \
   (ptrdiff_t) min (MOST_POSITIVE_FIXNUM - 1, min (SIZE_MAX, PTRDIFF_MAX))
 
+/* Maximum gap size after compact_buffer, in bytes.  Also
+   used in make_gap_larger to get some extra reserved space.  */
+
+#define GAP_BYTES_DFL 2000
+
+/* Minimum gap size after compact_buffer, in bytes.  Also
+   used in make_gap_smaller to avoid too small gap size.  */
+
+#define GAP_BYTES_MIN 20
+
 /* Return the address of byte position N in current buffer.  */
 
 #define BYTE_POS_ADDR(n) \
@@ -626,9 +632,9 @@ struct buffer
   /* List of symbols naming the file format used for auto-save file.  */
   Lisp_Object INTERNAL_FIELD (auto_save_file_format);
 
-  /* True if the newline position cache and width run cache are
-     enabled.  See search.c and indent.c.  */
-  Lisp_Object INTERNAL_FIELD (cache_long_line_scans);
+  /* True if the newline position cache, width run cache and BIDI paragraph
+     cache are enabled.  See search.c, indent.c and bidi.c for details.  */
+  Lisp_Object INTERNAL_FIELD (cache_long_scans);
 
   /* If the width run cache is enabled, this table contains the
      character widths width_run_cache (see above) assumes.  When we
@@ -770,11 +776,15 @@ struct buffer
      In an ordinary buffer, it is 0.  */
   struct buffer *base_buffer;
 
-  /* In an indirect buffer, this is -1. In an ordinary buffer,
+  /* In an indirect buffer, this is -1.  In an ordinary buffer,
      it's the number of indirect buffers that share our text;
      zero means that we're the only owner of this text.  */
   int indirections;
 
+  /* Number of windows showing this buffer.  Always -1 for
+     an indirect buffer since it counts as its base buffer.  */
+  int window_count;
+
   /* A non-zero value in slot IDX means that per-buffer variable
      with index IDX has a local value in this buffer.  The index IDX
      for a buffer-local variable is stored in that variable's slot
@@ -784,13 +794,13 @@ struct buffer
   char local_flags[MAX_PER_BUFFER_VARS];
 
   /* Set to the modtime of the visited file when read or written.
-     EMACS_NSECS (modtime) == NONEXISTENT_MODTIME_NSECS means
-     visited file was nonexistent.  EMACS_NSECS (modtime) ==
+     modtime.tv_nsec == NONEXISTENT_MODTIME_NSECS means
+     visited file was nonexistent.  modtime.tv_nsec ==
      UNKNOWN_MODTIME_NSECS means visited file modtime unknown;
      in no case complain about any mismatch on next save attempt.  */
 #define NONEXISTENT_MODTIME_NSECS (-1)
 #define UNKNOWN_MODTIME_NSECS (-2)
-  EMACS_TIME modtime;
+  struct timespec modtime;
 
   /* Size of the file when modtime was set.  This is used to detect the
      case where the file grew while we were reading it, so the modtime
@@ -829,9 +839,12 @@ struct buffer
      the character's width; if it maps a character to zero, we don't
      know what its width is.  This allows compute_motion to process
      such regions very quickly, using algebra instead of inspecting
-     each character.   See also width_table, below.  */
+     each character.   See also width_table, below.
+
+     The latter cache is used to speedup bidi_find_paragraph_start.  */
   struct region_cache *newline_cache;
   struct region_cache *width_run_cache;
+  struct region_cache *bidi_paragraph_cache;
 
   /* Non-zero means don't use redisplay optimizations for
      displaying this buffer.  */
@@ -992,15 +1005,15 @@ bset_width_table (struct buffer *b, Lisp_Object val)
 #define BUFFER_CHECK_INDIRECTION(b)                    \
   do {                                                 \
     if (BUFFER_LIVE_P (b))                             \
-    {                                                  \
-      if (b->base_buffer)                              \
-       {                                               \
-         eassert (b->indirections == -1);              \
-         eassert (b->base_buffer->indirections > 0);   \
-       }                                               \
-      else                                             \
-       eassert (b->indirections >= 0);                 \
-    }                                                  \
+      {                                                        \
+       if (b->base_buffer)                             \
+         {                                             \
+           eassert (b->indirections == -1);            \
+           eassert (b->base_buffer->indirections > 0); \
+         }                                             \
+       else                                            \
+         eassert (b->indirections >= 0);               \
+      }                                                        \
   } while (0)
 
 /* Chain of all buffers, including killed ones.  */
@@ -1061,9 +1074,10 @@ extern void set_buffer_internal_1 (struct buffer *);
 extern void set_buffer_temp (struct buffer *);
 extern Lisp_Object buffer_local_value_1 (Lisp_Object, Lisp_Object);
 extern void record_buffer (Lisp_Object);
-extern _Noreturn void buffer_slot_type_mismatch (Lisp_Object, int);
 extern void fix_overlays_before (struct buffer *, ptrdiff_t, ptrdiff_t);
 extern void mmap_set_vars (bool);
+extern void restore_buffer (Lisp_Object);
+extern void set_buffer_if_live (Lisp_Object);
 
 /* Set the current buffer to B.
 
@@ -1109,9 +1123,17 @@ record_unwind_current_buffer (void)
       }                                                                        \
   } while (0)
 
+extern Lisp_Object Vbuffer_alist;
 extern Lisp_Object Qbefore_change_functions;
 extern Lisp_Object Qafter_change_functions;
 extern Lisp_Object Qfirst_change_hook;
+extern Lisp_Object Qpriority, Qbefore_string, Qafter_string;
+
+/* FOR_EACH_LIVE_BUFFER (LIST_VAR, BUF_VAR) followed by a statement is
+   a `for' loop which iterates over the buffers from Vbuffer_alist.  */
+
+#define FOR_EACH_LIVE_BUFFER(list_var, buf_var)                        \
+  FOR_EACH_ALIST_VALUE (Vbuffer_alist, list_var, buf_var)
 
 /* Get text properties of B.  */
 
@@ -1173,7 +1195,18 @@ BUF_FETCH_MULTIBYTE_CHAR (struct buffer *buf, ptrdiff_t pos)
        + pos + BUF_BEG_ADDR (buf) - BEG_BYTE);
   return STRING_CHAR (p);
 }
-\f
+
+/* Return number of windows showing B.  */
+
+BUFFER_INLINE int
+buffer_window_count (struct buffer *b)
+{
+  if (b->base_buffer)
+    b = b->base_buffer;
+  eassert (b->window_count >= 0);
+  return b->window_count;
+}
+
 /* Overlays */
 
 /* Return the marker that stands for where OV starts in the buffer.  */