Function: find-charset-region

find-charset-region is a function defined in charset.c.

Signature

(find-charset-region BEG END &optional TABLE)

Documentation

Return a list of charsets in the region between BEG and END.

BEG and END are buffer positions. Optional arg TABLE if non-nil is a translation table to look up.

If the current buffer is unibyte, the returned list may contain only ascii, eight-bit-control, and eight-bit-graphic.

View in manual

Probably introduced at or before Emacs version 20.1.

Source Code

// Defined in /usr/src/emacs/src/charset.c
{
  Lisp_Object charsets;
  ptrdiff_t from, from_byte, to, stop, stop_byte;
  int i;
  Lisp_Object val;
  bool multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters));

  validate_region (&beg, &end);
  from = XFIXNAT (beg);
  stop = to = XFIXNAT (end);

  if (from < GPT && GPT < to)
    {
      stop = GPT;
      stop_byte = GPT_BYTE;
    }
  else
    stop_byte = CHAR_TO_BYTE (stop);

  from_byte = CHAR_TO_BYTE (from);

  charsets = make_nil_vector (charset_table_used);
  while (1)
    {
      find_charsets_in_text (BYTE_POS_ADDR (from_byte), stop - from,
			     stop_byte - from_byte, charsets, table,
			     multibyte);
      if (stop < to)
	{
	  from = stop, from_byte = stop_byte;
	  stop = to, stop_byte = CHAR_TO_BYTE (stop);
	}
      else
	break;
    }

  val = Qnil;
  for (i = charset_table_used - 1; i >= 0; i--)
    if (!NILP (AREF (charsets, i)))
      val = Fcons (CHARSET_NAME (charset_table + i), val);
  return val;
}