Example #1
0
/* Get the nearest known position we know the line number of
   (i.e. BUF_BEGV, and cached positions).  The return position will be
   either closer than BEG, or BEG.  The line of this known position
   will be stored in LINE.

   *LINE should be initialized to the line number of BEG (normally,
   BEG will be BUF_BEGV, and *LINE will be XFIXNUM (LINE_NUMBER_BEGV).
   This will initialize the cache, if necessary.  */
static void
get_nearest_line_number (struct buffer *b, Charbpos *beg, Charbpos pos,
			 EMACS_INT *line)
{
  EMACS_INT i;
  Lisp_Object *ring = XVECTOR_DATA (LINE_NUMBER_RING (b));
  Charcount length = pos - *beg;

  if (length < 0)
    length = -length;

  /* Find the ring entry closest to POS, if it is closer than BEG. */
  for (i = 0; i < LINE_NUMBER_RING_SIZE && CONSP (ring[i]); i++)
    {
      Charbpos newpos = marker_position (XCAR (ring[i]));
      Charcount howfar = newpos - pos;
      if (howfar < 0)
	howfar = -howfar;
      if (howfar < length)
	{
	  length = howfar;
	  *beg = newpos;
	  *line = XFIXNUM (XCDR (ring[i]));
	}
    }
}
Example #2
0
/* Invalidate the line number cache positions that lie after POS. */
static void
invalidate_line_number_cache (struct buffer *b, Charbpos pos)
{
  EMACS_INT i, j;
  Lisp_Object *ring = XVECTOR_DATA (LINE_NUMBER_RING (b));

  for (i = 0; i < LINE_NUMBER_RING_SIZE; i++)
    {
      if (!CONSP (ring[i]))
	break;
      /* As the marker stays behind the insertions, this check might
         as well be `>'.  However, Finsert_before_markers can advance
         the marker anyway, which bites in shell buffers.

	 #### This forces recreation of the cached marker (and
	 recalculation of newlines) every time a newline is inserted
	 at point, which is way losing.  Isn't there a way to make a
	 marker impervious to Finsert_before_markers()??  Maybe I
	 should convert the code to use extents.  */
      if (marker_position (XCAR (ring[i])) >= pos)
	{
	  /* Get the marker out of the way.  */
	  Fset_marker (XCAR (ring[i]), Qnil, Qnil);
	  /* ...and shift the ring elements, up to the first nil.  */
	  for (j = i; !NILP (ring[j]) && j < LINE_NUMBER_RING_SIZE - 1; j++)
	    ring[j] = ring[j + 1];
	  ring[j] = Qnil;
	  /* Must recheck position i. */
	  i--;
	}
    }
}
Example #3
0
static Lisp_Object restore_audio_port(Lisp_Object closure)
{
	Lisp_Object *contents = XVECTOR_DATA(closure);
	saved_device_state[1] = XINT(contents[0]);
	saved_device_state[3] = XINT(contents[1]);
	saved_device_state[5] = XINT(contents[2]);
	ALsetparams(AL_DEFAULT_DEVICE, saved_device_state, 6);
	return Qnil;
}
Example #4
0
/* Add a (POS . LINE) pair to the ring, and rotate it. */
static void
add_position_to_cache (struct buffer *b, Charbpos pos, EMACS_INT line)
{
  Lisp_Object *ring = XVECTOR_DATA (LINE_NUMBER_RING (b));
  int i = LINE_NUMBER_RING_SIZE - 1;

  /* Set the last marker in the ring to point nowhere. */
  if (CONSP (ring[i]))
    Fset_marker (XCAR (ring[i]), Qnil, Qnil);

  /* Rotate the ring... */
  for (; i > 0; i--)
    ring[i] = ring[i - 1];

  /* ...and update it. */
  ring[0] = Fcons (Fset_marker (Fmake_marker (), make_fixnum (pos),
				wrap_buffer (b)),
		   make_fixnum (line));
}