(starttls-negotiate): Avoid the cl.el decf function.
[bpt/emacs.git] / src / intervals.c
index fa40253..5e08e13 100644 (file)
@@ -1,13 +1,13 @@
 /* Code for doing intervals.
    Copyright (C) 1993, 1994, 1995, 1997, 1998, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+                 2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,9 +15,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 /* NOTES:
@@ -41,6 +39,7 @@ Boston, MA 02110-1301, USA.  */
 
 
 #include <config.h>
+#include <setjmp.h>
 #include "lisp.h"
 #include "intervals.h"
 #include "buffer.h"
@@ -53,9 +52,9 @@ Boston, MA 02110-1301, USA.  */
 
 #define TMEM(sym, set) (CONSP (set) ? ! NILP (Fmemq (sym, set)) : ! NILP (set))
 
-Lisp_Object merge_properties_sticky ();
-static INTERVAL reproduce_tree P_ ((INTERVAL, INTERVAL));
-static INTERVAL reproduce_tree_obj P_ ((INTERVAL, Lisp_Object));
+Lisp_Object merge_properties_sticky (Lisp_Object pleft, Lisp_Object pright);
+static INTERVAL reproduce_tree (INTERVAL, INTERVAL);
+static INTERVAL reproduce_tree_obj (INTERVAL, Lisp_Object);
 \f
 /* Utility functions for intervals.  */
 
@@ -63,8 +62,7 @@ static INTERVAL reproduce_tree_obj P_ ((INTERVAL, Lisp_Object));
 /* Create the root interval of some object, a buffer or string.  */
 
 INTERVAL
-create_root_interval (parent)
-     Lisp_Object parent;
+create_root_interval (Lisp_Object parent)
 {
   INTERVAL new;
 
@@ -96,8 +94,7 @@ create_root_interval (parent)
 /* Make the interval TARGET have exactly the properties of SOURCE */
 
 void
-copy_properties (source, target)
-     register INTERVAL source, target;
+copy_properties (register INTERVAL source, register INTERVAL target)
 {
   if (DEFAULT_INTERVAL_P (source) && DEFAULT_INTERVAL_P (target))
     return;
@@ -111,8 +108,7 @@ copy_properties (source, target)
    is added to TARGET if TARGET has no such property as yet.  */
 
 static void
-merge_properties (source, target)
-     register INTERVAL source, target;
+merge_properties (register INTERVAL source, register INTERVAL target)
 {
   register Lisp_Object o, sym, val;
 
@@ -150,8 +146,7 @@ merge_properties (source, target)
    0 otherwise.  */
 
 int
-intervals_equal (i0, i1)
-     INTERVAL i0, i1;
+intervals_equal (INTERVAL i0, INTERVAL i1)
 {
   register Lisp_Object i0_cdr, i0_sym;
   register Lisp_Object i1_cdr, i1_val;
@@ -207,10 +202,7 @@ intervals_equal (i0, i1)
    Pass FUNCTION two args: an interval, and ARG.  */
 
 void
-traverse_intervals_noorder (tree, function, arg)
-     INTERVAL tree;
-     void (* function) P_ ((INTERVAL, Lisp_Object));
-     Lisp_Object arg;
+traverse_intervals_noorder (INTERVAL tree, void (*function) (INTERVAL, Lisp_Object), Lisp_Object arg)
 {
   /* Minimize stack usage.  */
   while (!NULL_INTERVAL_P (tree))
@@ -230,11 +222,8 @@ traverse_intervals_noorder (tree, function, arg)
    Pass FUNCTION two args: an interval, and ARG.  */
 
 void
-traverse_intervals (tree, position, function, arg)
-     INTERVAL tree;
-     int position;
-     void (* function) P_ ((INTERVAL, Lisp_Object));
-     Lisp_Object arg;
+traverse_intervals (INTERVAL tree, EMACS_INT position,
+                   void (*function) (INTERVAL, Lisp_Object), Lisp_Object arg)
 {
   while (!NULL_INTERVAL_P (tree))
     {
@@ -324,12 +313,11 @@ root_interval (interval)
 */
 
 static INLINE INTERVAL
-rotate_right (interval)
-     INTERVAL interval;
+rotate_right (INTERVAL interval)
 {
   INTERVAL i;
   INTERVAL B = interval->left;
-  int old_total = interval->total_length;
+  EMACS_INT old_total = interval->total_length;
 
   /* Deal with any Parent of A;  make it point to B.  */
   if (! ROOT_INTERVAL_P (interval))
@@ -372,12 +360,11 @@ rotate_right (interval)
 */
 
 static INLINE INTERVAL
-rotate_left (interval)
-     INTERVAL interval;
+rotate_left (INTERVAL interval)
 {
   INTERVAL i;
   INTERVAL B = interval->right;
-  int old_total = interval->total_length;
+  EMACS_INT old_total = interval->total_length;
 
   /* Deal with any parent of A;  make it point to B.  */
   if (! ROOT_INTERVAL_P (interval))
@@ -414,10 +401,9 @@ rotate_left (interval)
    themselves are already balanced.  */
 
 static INTERVAL
-balance_an_interval (i)
-     INTERVAL i;
+balance_an_interval (INTERVAL i)
 {
-  register int old_diff, new_diff;
+  register EMACS_INT old_diff, new_diff;
 
   while (1)
     {
@@ -452,8 +438,7 @@ balance_an_interval (i)
    Lisp Object.  */
 
 static INLINE INTERVAL
-balance_possible_root_interval (interval)
-     register INTERVAL interval;
+balance_possible_root_interval (register INTERVAL interval)
 {
   Lisp_Object parent;
   int have_parent = 0;
@@ -483,8 +468,7 @@ balance_possible_root_interval (interval)
    (the amount of text).  */
 
 static INTERVAL
-balance_intervals_internal (tree)
-     register INTERVAL tree;
+balance_intervals_internal (register INTERVAL tree)
 {
   /* Balance within each side.  */
   if (tree->left)
@@ -497,8 +481,7 @@ balance_intervals_internal (tree)
 /* Advertised interface to balance intervals.  */
 
 INTERVAL
-balance_intervals (tree)
-     INTERVAL tree;
+balance_intervals (INTERVAL tree)
 {
   if (tree == NULL_INTERVAL)
     return NULL_INTERVAL;
@@ -520,13 +503,11 @@ balance_intervals (tree)
    it is still a root after this operation.  */
 
 INTERVAL
-split_interval_right (interval, offset)
-     INTERVAL interval;
-     int offset;
+split_interval_right (INTERVAL interval, EMACS_INT offset)
 {
   INTERVAL new = make_interval ();
-  int position = interval->position;
-  int new_length = LENGTH (interval) - offset;
+  EMACS_INT position = interval->position;
+  EMACS_INT new_length = LENGTH (interval) - offset;
 
   new->position = position + offset;
   SET_INTERVAL_PARENT (new, interval);
@@ -567,12 +548,10 @@ split_interval_right (interval, offset)
    it is still a root after this operation.  */
 
 INTERVAL
-split_interval_left (interval, offset)
-     INTERVAL interval;
-     int offset;
+split_interval_left (INTERVAL interval, EMACS_INT offset)
 {
   INTERVAL new = make_interval ();
-  int new_length = offset;
+  EMACS_INT new_length = offset;
 
   new->position = interval->position;
   interval->position = interval->position + offset;
@@ -609,8 +588,7 @@ split_interval_left (interval, offset)
    of another interval!  */
 
 int
-interval_start_pos (source)
-     INTERVAL source;
+interval_start_pos (INTERVAL source)
 {
   Lisp_Object parent;
 
@@ -636,13 +614,11 @@ interval_start_pos (source)
    will update this cache based on the result of find_interval.  */
 
 INTERVAL
-find_interval (tree, position)
-     register INTERVAL tree;
-     register int position;
+find_interval (register INTERVAL tree, register EMACS_INT position)
 {
   /* The distance from the left edge of the subtree at TREE
                     to POSITION.  */
-  register int relative_position;
+  register EMACS_INT relative_position;
 
   if (NULL_INTERVAL_P (tree))
     return NULL_INTERVAL;
@@ -692,11 +668,10 @@ find_interval (tree, position)
    find_interval).  */
 
 INTERVAL
-next_interval (interval)
-     register INTERVAL interval;
+next_interval (register INTERVAL interval)
 {
   register INTERVAL i = interval;
-  register int next_position;
+  register EMACS_INT next_position;
 
   if (NULL_INTERVAL_P (i))
     return NULL_INTERVAL;
@@ -732,8 +707,7 @@ next_interval (interval)
    find_interval).  */
 
 INTERVAL
-previous_interval (interval)
-     register INTERVAL interval;
+previous_interval (register INTERVAL interval)
 {
   register INTERVAL i;
 
@@ -772,9 +746,7 @@ previous_interval (interval)
    To speed up the process, we assume that the ->position of
    I and all its parents is already uptodate.  */
 INTERVAL
-update_interval (i, pos)
-     register INTERVAL i;
-     int pos;
+update_interval (register INTERVAL i, EMACS_INT pos)
 {
   if (NULL_INTERVAL_P (i))
     return NULL_INTERVAL;
@@ -893,15 +865,14 @@ adjust_intervals_for_insertion (tree, position, length)
    this text, and make it have the merged properties of both ends.  */
 
 static INTERVAL
-adjust_intervals_for_insertion (tree, position, length)
-     INTERVAL tree;
-     int position, length;
+adjust_intervals_for_insertion (INTERVAL tree,
+                               EMACS_INT position, EMACS_INT length)
 {
   register INTERVAL i;
   register INTERVAL temp;
   int eobp = 0;
   Lisp_Object parent;
-  int offset;
+  EMACS_INT offset;
 
   if (TOTAL_LENGTH (tree) == 0)        /* Paranoia */
     abort ();
@@ -1120,8 +1091,7 @@ FR     8  9  A  B
 */
 
 Lisp_Object
-merge_properties_sticky (pleft, pright)
-     Lisp_Object pleft, pright;
+merge_properties_sticky (Lisp_Object pleft, Lisp_Object pright)
 {
   register Lisp_Object props, front, rear;
   Lisp_Object lfront, lrear, rfront, rrear;
@@ -1257,11 +1227,10 @@ merge_properties_sticky (pleft, pright)
    storing the resulting subtree into its parent.  */
 
 static INTERVAL
-delete_node (i)
-     register INTERVAL i;
+delete_node (register INTERVAL i)
 {
   register INTERVAL migrate, this;
-  register int migrate_amt;
+  register EMACS_INT migrate_amt;
 
   if (NULL_INTERVAL_P (i->left))
     return i->right;
@@ -1291,11 +1260,10 @@ delete_node (i)
    for the length of I.  */
 
 void
-delete_interval (i)
-     register INTERVAL i;
+delete_interval (register INTERVAL i)
 {
   register INTERVAL parent;
-  int amt = LENGTH (i);
+  EMACS_INT amt = LENGTH (i);
 
   if (amt > 0)                 /* Only used on zero-length intervals now.  */
     abort ();
@@ -1345,12 +1313,11 @@ delete_interval (i)
    Do this by recursing down TREE to the interval in question, and
    deleting the appropriate amount of text.  */
 
-static int
-interval_deletion_adjustment (tree, from, amount)
-     register INTERVAL tree;
-     register int from, amount;
+static EMACS_INT
+interval_deletion_adjustment (register INTERVAL tree, register EMACS_INT from,
+                             register EMACS_INT amount)
 {
-  register int relative_position = from;
+  register EMACS_INT relative_position = from;
 
   if (NULL_INTERVAL_P (tree))
     return 0;
@@ -1358,9 +1325,9 @@ interval_deletion_adjustment (tree, from, amount)
   /* Left branch */
   if (relative_position < LEFT_TOTAL_LENGTH (tree))
     {
-      int subtract = interval_deletion_adjustment (tree->left,
-                                                  relative_position,
-                                                  amount);
+      EMACS_INT subtract = interval_deletion_adjustment (tree->left,
+                                                         relative_position,
+                                                         amount);
       tree->total_length -= subtract;
       CHECK_TOTAL_LENGTH (tree);
       return subtract;
@@ -1369,7 +1336,7 @@ interval_deletion_adjustment (tree, from, amount)
   else if (relative_position >= (TOTAL_LENGTH (tree)
                                 - RIGHT_TOTAL_LENGTH (tree)))
     {
-      int subtract;
+      EMACS_INT subtract;
 
       relative_position -= (tree->total_length
                            - RIGHT_TOTAL_LENGTH (tree));
@@ -1384,9 +1351,9 @@ interval_deletion_adjustment (tree, from, amount)
   else
     {
       /* How much can we delete from this interval?  */
-      int my_amount = ((tree->total_length
-                       - RIGHT_TOTAL_LENGTH (tree))
-                      - relative_position);
+      EMACS_INT my_amount = ((tree->total_length
+                              - RIGHT_TOTAL_LENGTH (tree))
+                             - relative_position);
 
       if (amount > my_amount)
        amount = my_amount;
@@ -1408,14 +1375,13 @@ interval_deletion_adjustment (tree, from, amount)
    buffer position, i.e. origin 1).  */
 
 static void
-adjust_intervals_for_deletion (buffer, start, length)
-     struct buffer *buffer;
-     int start, length;
+adjust_intervals_for_deletion (struct buffer *buffer,
+                              EMACS_INT start, EMACS_INT length)
 {
-  register int left_to_delete = length;
+  register EMACS_INT left_to_delete = length;
   register INTERVAL tree = BUF_INTERVALS (buffer);
   Lisp_Object parent;
-  int offset;
+  EMACS_INT offset;
 
   GET_INTERVAL_OBJECT (parent, tree);
   offset = (BUFFERP (parent) ? BUF_BEG (XBUFFER (parent)) : 0);
@@ -1461,9 +1427,7 @@ adjust_intervals_for_deletion (buffer, start, length)
    of LENGTH.  */
 
 INLINE void
-offset_intervals (buffer, start, length)
-     struct buffer *buffer;
-     int start, length;
+offset_intervals (struct buffer *buffer, EMACS_INT start, EMACS_INT length)
 {
   if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) || length == 0)
     return;
@@ -1484,10 +1448,9 @@ offset_intervals (buffer, start, length)
    interval.  */
 
 INTERVAL
-merge_interval_right (i)
-     register INTERVAL i;
+merge_interval_right (register INTERVAL i)
 {
-  register int absorb = LENGTH (i);
+  register EMACS_INT absorb = LENGTH (i);
   register INTERVAL successor;
 
   /* Zero out this interval.  */
@@ -1541,10 +1504,9 @@ merge_interval_right (i)
    The caller must verify that this is not the first (leftmost) interval.  */
 
 INTERVAL
-merge_interval_left (i)
-     register INTERVAL i;
+merge_interval_left (register INTERVAL i)
 {
-  register int absorb = LENGTH (i);
+  register EMACS_INT absorb = LENGTH (i);
   register INTERVAL predecessor;
 
   /* Zero out this interval.  */
@@ -1596,12 +1558,11 @@ merge_interval_left (i)
    the pointers of the copy.  */
 
 static INTERVAL
-reproduce_tree (source, parent)
-     INTERVAL source, parent;
+reproduce_tree (INTERVAL source, INTERVAL parent)
 {
   register INTERVAL t = make_interval ();
 
-  bcopy (source, t, INTERVAL_SIZE);
+  memcpy (t, source, INTERVAL_SIZE);
   copy_properties (source, t);
   SET_INTERVAL_PARENT (t, parent);
   if (! NULL_LEFT_CHILD (source))
@@ -1613,13 +1574,11 @@ reproduce_tree (source, parent)
 }
 
 static INTERVAL
-reproduce_tree_obj (source, parent)
-     INTERVAL source;
-     Lisp_Object parent;
+reproduce_tree_obj (INTERVAL source, Lisp_Object parent)
 {
   register INTERVAL t = make_interval ();
 
-  bcopy (source, t, INTERVAL_SIZE);
+  memcpy (t, source, INTERVAL_SIZE);
   copy_properties (source, t);
   SET_INTERVAL_OBJECT (t, parent);
   if (! NULL_LEFT_CHILD (source))
@@ -1643,7 +1602,7 @@ reproduce_tree_obj (source, parent)
 static INTERVAL
 make_new_interval (intervals, start, length)
      INTERVAL intervals;
-     int start, length;
+     EMACS_INT start, length;
 {
   INTERVAL slot;
 
@@ -1715,15 +1674,13 @@ make_new_interval (intervals, start, length)
    text...  */
 
 void
-graft_intervals_into_buffer (source, position, length, buffer, inherit)
-     INTERVAL source;
-     int position, length;
-     struct buffer *buffer;
-     int inherit;
+graft_intervals_into_buffer (INTERVAL source, EMACS_INT position,
+                            EMACS_INT length, struct buffer *buffer,
+                            int inherit)
 {
   register INTERVAL under, over, this, prev;
   register INTERVAL tree;
-  int over_used;
+  EMACS_INT over_used;
 
   tree = BUF_INTERVALS (buffer);
 
@@ -1877,18 +1834,13 @@ graft_intervals_into_buffer (source, position, length, buffer, inherit)
    and for PROP appearing on the default-text-properties list.  */
 
 Lisp_Object
-textget (plist, prop)
-     Lisp_Object plist;
-     register Lisp_Object prop;
+textget (Lisp_Object plist, register Lisp_Object prop)
 {
   return lookup_char_property (plist, prop, 1);
 }
 
 Lisp_Object
-lookup_char_property (plist, prop, textprop)
-     Lisp_Object plist;
-     register Lisp_Object prop;
-     int textprop;
+lookup_char_property (Lisp_Object plist, register Lisp_Object prop, int textprop)
 {
   register Lisp_Object tail, fallback = Qnil;
 
@@ -1926,9 +1878,7 @@ lookup_char_property (plist, prop, textprop)
 /* Set point "temporarily", without checking any text properties.  */
 
 INLINE void
-temp_set_point (buffer, charpos)
-     struct buffer *buffer;
-     int charpos;
+temp_set_point (struct buffer *buffer, EMACS_INT charpos)
 {
   temp_set_point_both (buffer, charpos,
                       buf_charpos_to_bytepos (buffer, charpos));
@@ -1938,9 +1888,8 @@ temp_set_point (buffer, charpos)
    byte position BYTEPOS.  */
 
 INLINE void
-temp_set_point_both (buffer, charpos, bytepos)
-     int charpos, bytepos;
-     struct buffer *buffer;
+temp_set_point_both (struct buffer *buffer,
+                    EMACS_INT charpos, EMACS_INT bytepos)
 {
   /* In a single-byte buffer, the two positions must be equal.  */
   if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer)
@@ -1961,11 +1910,9 @@ temp_set_point_both (buffer, charpos, bytepos)
    before an intangible character, move to an ok place.  */
 
 void
-set_point (buffer, charpos)
-     register struct buffer *buffer;
-     register int charpos;
+set_point (EMACS_INT charpos)
 {
-  set_point_both (buffer, charpos, buf_charpos_to_bytepos (buffer, charpos));
+  set_point_both (charpos, buf_charpos_to_bytepos (current_buffer, charpos));
 }
 
 /* If there's an invisible character at position POS + TEST_OFFS in the
@@ -1979,9 +1926,9 @@ set_point (buffer, charpos)
    Note that `stickiness' is determined by overlay marker insertion types,
    if the invisible property comes from an overlay.  */
 
-static int
-adjust_for_invis_intang (pos, test_offs, adj, test_intang)
-     int pos, test_offs, adj, test_intang;
+static EMACS_INT
+adjust_for_invis_intang (EMACS_INT pos, EMACS_INT test_offs, EMACS_INT adj,
+                        int test_intang)
 {
   Lisp_Object invis_propval, invis_overlay;
   Lisp_Object test_pos;
@@ -2019,72 +1966,66 @@ adjust_for_invis_intang (pos, test_offs, adj, test_intang)
    before an intangible character, move to an ok place.  */
 
 void
-set_point_both (buffer, charpos, bytepos)
-     register struct buffer *buffer;
-     register int charpos, bytepos;
+set_point_both (EMACS_INT charpos, EMACS_INT bytepos)
 {
   register INTERVAL to, from, toprev, fromprev;
-  int buffer_point;
-  int old_position = BUF_PT (buffer);
+  EMACS_INT buffer_point;
+  EMACS_INT old_position = PT;
   /* This ensures that we move forward past intangible text when the
      initial position is the same as the destination, in the rare
      instances where this is important, e.g. in line-move-finish
      (simple.el).  */
   int backwards = (charpos < old_position ? 1 : 0);
   int have_overlays;
-  int original_position;
+  EMACS_INT original_position;
 
-  buffer->point_before_scroll = Qnil;
+  current_buffer->point_before_scroll = Qnil;
 
-  if (charpos == BUF_PT (buffer))
+  if (charpos == PT)
     return;
 
   /* In a single-byte buffer, the two positions must be equal.  */
-  if (BUF_ZV (buffer) == BUF_ZV_BYTE (buffer)
-      && charpos != bytepos)
-    abort ();
+  eassert (ZV != ZV_BYTE || charpos == bytepos);
 
   /* Check this now, before checking if the buffer has any intervals.
      That way, we can catch conditions which break this sanity check
      whether or not there are intervals in the buffer.  */
-  if (charpos > BUF_ZV (buffer) || charpos < BUF_BEGV (buffer))
-    abort ();
+  eassert (charpos <= ZV && charpos >= BEGV);
 
-  have_overlays = (buffer->overlays_before || buffer->overlays_after);
+  have_overlays = (current_buffer->overlays_before
+                  || current_buffer->overlays_after);
 
   /* If we have no text properties and overlays,
      then we can do it quickly.  */
-  if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) && ! have_overlays)
+  if (NULL_INTERVAL_P (BUF_INTERVALS (current_buffer)) && ! have_overlays)
     {
-      temp_set_point_both (buffer, charpos, bytepos);
+      temp_set_point_both (current_buffer, charpos, bytepos);
       return;
     }
 
   /* Set TO to the interval containing the char after CHARPOS,
      and TOPREV to the interval containing the char before CHARPOS.
      Either one may be null.  They may be equal.  */
-  to = find_interval (BUF_INTERVALS (buffer), charpos);
-  if (charpos == BUF_BEGV (buffer))
+  to = find_interval (BUF_INTERVALS (current_buffer), charpos);
+  if (charpos == BEGV)
     toprev = 0;
   else if (to && to->position == charpos)
     toprev = previous_interval (to);
   else
     toprev = to;
 
-  buffer_point = (BUF_PT (buffer) == BUF_ZV (buffer)
-                 ? BUF_ZV (buffer) - 1
-                 : BUF_PT (buffer));
+  buffer_point = (PT == ZV ? ZV - 1 : PT);
 
   /* Set FROM to the interval containing the char after PT,
      and FROMPREV to the interval containing the char before PT.
      Either one may be null.  They may be equal.  */
   /* We could cache this and save time.  */
-  from = find_interval (BUF_INTERVALS (buffer), buffer_point);
-  if (buffer_point == BUF_BEGV (buffer))
+  from = find_interval (BUF_INTERVALS (current_buffer), buffer_point);
+  if (buffer_point == BEGV)
     fromprev = 0;
-  else if (from && from->position == BUF_PT (buffer))
+  else if (from && from->position == PT)
     fromprev = previous_interval (from);
-  else if (buffer_point != BUF_PT (buffer))
+  else if (buffer_point != PT)
     fromprev = from, from = 0;
   else
     fromprev = from;
@@ -2093,7 +2034,7 @@ set_point_both (buffer, charpos, bytepos)
   if (to == from && toprev == fromprev && INTERVAL_VISIBLE_P (to)
       && ! have_overlays)
     {
-      temp_set_point_both (buffer, charpos, bytepos);
+      temp_set_point_both (current_buffer, charpos, bytepos);
       return;
     }
 
@@ -2130,7 +2071,7 @@ set_point_both (buffer, charpos, bytepos)
 
          if (! NILP (intangible_propval))
            {
-             while (XINT (pos) > BUF_BEGV (buffer)
+             while (XINT (pos) > BEGV
                     && EQ (Fget_char_property (make_number (XINT (pos) - 1),
                                                Qintangible, Qnil),
                            intangible_propval))
@@ -2163,7 +2104,7 @@ set_point_both (buffer, charpos, bytepos)
 
          if (! NILP (intangible_propval))
            {
-             while (XINT (pos) < BUF_ZV (buffer)
+             while (XINT (pos) < ZV
                     && EQ (Fget_char_property (pos, Qintangible, Qnil),
                            intangible_propval))
                pos = Fnext_char_property_change (pos, Qnil);
@@ -2177,7 +2118,7 @@ set_point_both (buffer, charpos, bytepos)
            }
        }
 
-      bytepos = buf_charpos_to_bytepos (buffer, charpos);
+      bytepos = buf_charpos_to_bytepos (current_buffer, charpos);
     }
 
   if (charpos != original_position)
@@ -2185,8 +2126,8 @@ set_point_both (buffer, charpos, bytepos)
       /* Set TO to the interval containing the char after CHARPOS,
         and TOPREV to the interval containing the char before CHARPOS.
         Either one may be null.  They may be equal.  */
-      to = find_interval (BUF_INTERVALS (buffer), charpos);
-      if (charpos == BUF_BEGV (buffer))
+      to = find_interval (BUF_INTERVALS (current_buffer), charpos);
+      if (charpos == BEGV)
        toprev = 0;
       else if (to && to->position == charpos)
        toprev = previous_interval (to);
@@ -2198,7 +2139,7 @@ set_point_both (buffer, charpos, bytepos)
      and TOPREV is the interval before the stopping point.
      One or the other may be null.  */
 
-  temp_set_point_both (buffer, charpos, bytepos);
+  temp_set_point_both (current_buffer, charpos, bytepos);
 
   /* We run point-left and point-entered hooks here, if the
      two intervals are not equivalent.  These hooks take
@@ -2249,8 +2190,7 @@ set_point_both (buffer, charpos, bytepos)
    segment that reaches all the way to point.  */
 
 void
-move_if_not_intangible (position)
-     int position;
+move_if_not_intangible (EMACS_INT position)
 {
   Lisp_Object pos;
   Lisp_Object intangible_propval;
@@ -2313,11 +2253,8 @@ move_if_not_intangible (position)
    nil means the current buffer. */
 
 int
-get_property_and_range (pos, prop, val, start, end, object)
-     int pos;
-     Lisp_Object prop, *val;
-     EMACS_INT *start, *end;
-     Lisp_Object object;
+get_property_and_range (EMACS_INT pos, Lisp_Object prop, Lisp_Object *val,
+                       EMACS_INT *start, EMACS_INT *end, Lisp_Object object)
 {
   INTERVAL i, prev, next;
 
@@ -2360,13 +2297,11 @@ get_property_and_range (pos, prop, val, start, end, object)
    POSITION must be in the accessible part of BUFFER.  */
 
 Lisp_Object
-get_local_map (position, buffer, type)
-     register int position;
-     register struct buffer *buffer;
-     Lisp_Object type;
+get_local_map (register EMACS_INT position, register struct buffer *buffer,
+              Lisp_Object type)
 {
   Lisp_Object prop, lispy_position, lispy_buffer;
-  int old_begv, old_zv, old_begv_byte, old_zv_byte;
+  EMACS_INT old_begv, old_zv, old_begv_byte, old_zv_byte;
 
   /* Perhaps we should just change `position' to the limit.  */
   if (position > BUF_ZV (buffer) || position < BUF_BEGV (buffer))
@@ -2416,12 +2351,10 @@ get_local_map (position, buffer, type)
    The new interval tree has no parent and has a starting-position of 0.  */
 
 INTERVAL
-copy_intervals (tree, start, length)
-     INTERVAL tree;
-     int start, length;
+copy_intervals (INTERVAL tree, EMACS_INT start, EMACS_INT length)
 {
   register INTERVAL i, new, t;
-  register int got, prevlen;
+  register EMACS_INT got, prevlen;
 
   if (NULL_INTERVAL_P (tree) || length <= 0)
     return NULL_INTERVAL;
@@ -2459,10 +2392,8 @@ copy_intervals (tree, start, length)
 /* Give STRING the properties of BUFFER from POSITION to LENGTH.  */
 
 INLINE void
-copy_intervals_to_string (string, buffer, position, length)
-     Lisp_Object string;
-     struct buffer *buffer;
-     int position, length;
+copy_intervals_to_string (Lisp_Object string, struct buffer *buffer,
+                         EMACS_INT position, EMACS_INT length)
 {
   INTERVAL interval_copy = copy_intervals (BUF_INTERVALS (buffer),
                                           position, length);
@@ -2477,12 +2408,11 @@ copy_intervals_to_string (string, buffer, position, length)
    Assume they have identical characters.  */
 
 int
-compare_string_intervals (s1, s2)
-     Lisp_Object s1, s2;
+compare_string_intervals (Lisp_Object s1, Lisp_Object s2)
 {
   INTERVAL i1, i2;
-  int pos = 0;
-  int end = SCHARS (s1);
+  EMACS_INT pos = 0;
+  EMACS_INT end = SCHARS (s1);
 
   i1 = find_interval (STRING_INTERVALS (s1), 0);
   i2 = find_interval (STRING_INTERVALS (s2), 0);
@@ -2490,9 +2420,9 @@ compare_string_intervals (s1, s2)
   while (pos < end)
     {
       /* Determine how far we can go before we reach the end of I1 or I2.  */
-      int len1 = (i1 != 0 ? INTERVAL_LAST_POS (i1) : end) - pos;
-      int len2 = (i2 != 0 ? INTERVAL_LAST_POS (i2) : end) - pos;
-      int distance = min (len1, len2);
+      EMACS_INT len1 = (i1 != 0 ? INTERVAL_LAST_POS (i1) : end) - pos;
+      EMACS_INT len2 = (i2 != 0 ? INTERVAL_LAST_POS (i2) : end) - pos;
+      EMACS_INT distance = min (len1, len2);
 
       /* If we ever find a mismatch between the strings,
         they differ.  */
@@ -2516,10 +2446,9 @@ compare_string_intervals (s1, s2)
    START_BYTE ... END_BYTE in bytes.  */
 
 static void
-set_intervals_multibyte_1 (i, multi_flag, start, start_byte, end, end_byte)
-     INTERVAL i;
-     int multi_flag;
-     int start, start_byte, end, end_byte;
+set_intervals_multibyte_1 (INTERVAL i, int multi_flag,
+                          EMACS_INT start, EMACS_INT start_byte,
+                          EMACS_INT end, EMACS_INT end_byte)
 {
   /* Fix the length of this interval.  */
   if (multi_flag)
@@ -2537,11 +2466,11 @@ set_intervals_multibyte_1 (i, multi_flag, start, start_byte, end, end_byte)
   /* Recursively fix the length of the subintervals.  */
   if (i->left)
     {
-      int left_end, left_end_byte;
+      EMACS_INT left_end, left_end_byte;
 
       if (multi_flag)
        {
-         int temp;
+         EMACS_INT temp;
          left_end_byte = start_byte + LEFT_TOTAL_LENGTH (i);
          left_end = BYTE_TO_CHAR (left_end_byte);
 
@@ -2570,11 +2499,11 @@ set_intervals_multibyte_1 (i, multi_flag, start, start_byte, end, end_byte)
     }
   if (i->right)
     {
-      int right_start_byte, right_start;
+      EMACS_INT right_start_byte, right_start;
 
       if (multi_flag)
        {
-         int temp;
+         EMACS_INT temp;
 
          right_start_byte = end_byte - RIGHT_TOTAL_LENGTH (i);
          right_start = BYTE_TO_CHAR (right_start_byte);
@@ -2629,8 +2558,7 @@ set_intervals_multibyte_1 (i, multi_flag, start, start_byte, end, end_byte)
    or to fit them as non-multibyte (if MULTI_FLAG is 0).  */
 
 void
-set_intervals_multibyte (multi_flag)
-     int multi_flag;
+set_intervals_multibyte (int multi_flag)
 {
   if (BUF_INTERVALS (current_buffer))
     set_intervals_multibyte_1 (BUF_INTERVALS (current_buffer), multi_flag,