Function: find-composition-internal

find-composition-internal is a function defined in composite.c.

Signature

(find-composition-internal POS LIMIT STRING DETAIL-P)

Documentation

Internal use only.

Return information about composition at or nearest to position POS. See find-composition for more details.

Source Code

// Defined in /usr/src/emacs/src/composite.c
{
  Lisp_Object prop, tail, gstring;
  ptrdiff_t start, end, from, to;
  int id;

  EMACS_INT fixed_pos = fix_position (pos);
  if (!NILP (limit))
    to = clip_to_bounds (PTRDIFF_MIN, fix_position (limit), ZV);
  else
    to = -1;

  if (!NILP (string))
    {
      CHECK_STRING (string);
      if (! (0 <= fixed_pos && fixed_pos <= SCHARS (string)))
	args_out_of_range (string, pos);
    }
  else
    {
      if (! (BEGV <= fixed_pos && fixed_pos <= ZV))
	args_out_of_range (Fcurrent_buffer (), pos);
    }
  from = fixed_pos;

  if (!find_composition (from, to, &start, &end, &prop, string))
    {
      if (((NILP (string)
	    && !NILP (BVAR (current_buffer, enable_multibyte_characters)))
	   || (!NILP (string) && STRING_MULTIBYTE (string)))
	  && ! inhibit_auto_composition ()
	  && find_automatic_composition (from, to, (ptrdiff_t) -1,
					 &start, &end, &gstring, string))
	return list3 (make_fixnum (start), make_fixnum (end), gstring);
      return Qnil;
    }
  if (! (start <= fixed_pos && fixed_pos < end))
    {
      ptrdiff_t s, e;

      if (find_automatic_composition (from, to, (ptrdiff_t) -1,
				      &s, &e, &gstring, string)
	  && (e <= fixed_pos ? e > end : s < start))
	return list3 (make_fixnum (s), make_fixnum (e), gstring);
    }
  if (!composition_valid_p (start, end, prop))
    return list3 (make_fixnum (start), make_fixnum (end), Qnil);
  if (NILP (detail_p))
    return list3 (make_fixnum (start), make_fixnum (end), Qt);

  if (composition_registered_p (prop))
    id = COMPOSITION_ID (prop);
  else
    {
      ptrdiff_t start_byte = (NILP (string)
			      ? CHAR_TO_BYTE (start)
			      : string_char_to_byte (string, start));
      id = get_composition_id (start, start_byte, end - start, prop, string);
    }

  if (id >= 0)
    {
      Lisp_Object components, relative_p, mod_func;
      enum composition_method method = composition_method (prop);
      int width = composition_table[id]->width;

      components = Fcopy_sequence (COMPOSITION_COMPONENTS (prop));
      relative_p = (method == COMPOSITION_WITH_RULE_ALTCHARS
		    ? Qnil : Qt);
      mod_func = COMPOSITION_MODIFICATION_FUNC (prop);
      tail = list4 (components, relative_p, mod_func, make_fixnum (width));
    }
  else
    tail = Qnil;

  return Fcons (make_fixnum (start), Fcons (make_fixnum (end), tail));
}