Function: insert-char

insert-char is an interactive function defined in editfns.c.

Signature

(insert-char CHARACTER &optional COUNT INHERIT)

Documentation

Insert COUNT copies of CHARACTER.

Interactively, prompt for CHARACTER using read-char-by-name. You can specify CHARACTER in one of these ways:

 - As its Unicode character name, e.g. "LATIN SMALL LETTER A".
   Completion is available; if you type a substring of the name
   preceded by an asterisk *, Emacs shows all names which include
   that substring, not necessarily at the beginning of the name.

 - As a hexadecimal code point, e.g. 263A. Note that code points in
   Emacs are equivalent to Unicode up to 10FFFF (which is the limit of
   the Unicode code space).

 - As a code point with a radix specified with #, e.g. #o21430
   (octal), #x2318 (hex), or #10r8984 (decimal).

If called interactively, COUNT is given by the prefix argument. If omitted or nil, it defaults to 1.

Inserting the character(s) relocates point and before-insertion markers in the same ways as the function insert.

The optional third argument INHERIT, if non-nil, says to inherit text properties from adjoining text, if those properties are sticky. If called interactively, INHERIT is t.

View in manual

Probably introduced at or before Emacs version 18.

Key Bindings

Source Code

// Defined in /usr/src/emacs/src/editfns.c
{
  int i, stringlen;
  register ptrdiff_t n;
  int c, len;
  unsigned char str[MAX_MULTIBYTE_LENGTH];
  char string[4000];

  CHECK_CHARACTER (character);
  if (NILP (count))
    XSETFASTINT (count, 1);
  else
    CHECK_FIXNUM (count);
  c = XFIXNAT (character);

  if (!NILP (BVAR (current_buffer, enable_multibyte_characters)))
    len = CHAR_STRING (c, str);
  else
    str[0] = c, len = 1;
  if (XFIXNUM (count) <= 0)
    return Qnil;
  if (BUF_BYTES_MAX / len < XFIXNUM (count))
    buffer_overflow ();
  n = XFIXNUM (count) * len;
  stringlen = min (n, sizeof string - sizeof string % len);
  for (i = 0; i < stringlen; i++)
    string[i] = str[i % len];
  while (n > stringlen)
    {
      maybe_quit ();
      if (!NILP (inherit))
	insert_and_inherit (string, stringlen);
      else
	insert (string, stringlen);
      n -= stringlen;
    }
  if (!NILP (inherit))
    insert_and_inherit (string, n);
  else
    insert (string, n);
  return Qnil;
}