#include "lisp.h"
#include "buffer.h"
#include "keyboard.h"
+#include "charset.h"
Lisp_Object Vdoc_file_name;
if (p != end)
{
end = index (p, '\n');
- sym = oblookup (Vobarray, p + 2, end - p - 2);
+ sym = oblookup (Vobarray, p + 2,
+ multibyte_chars_in_text (p + 2, end - p - 2),
+ end - p - 2);
if (SYMBOLP (sym))
{
/* Attach a docstring to a variable? */
int length;
Lisp_Object name;
struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
+ int multibyte;
+ int nchars;
if (NILP (string))
return Qnil;
name = Qnil;
GCPRO4 (string, tem, keymap, name);
+ multibyte = STRING_MULTIBYTE (string);
+ nchars = 0;
+
/* KEYMAP is either nil (which means search all the active keymaps)
or a specified local map (which means search just that and the
global map). If non-nil, it might come from Voverriding_local_map,
if (NILP (keymap))
keymap = Voverriding_local_map;
- bsize = XSTRING (string)->size;
+ bsize = XSTRING (string)->size_byte;
bufp = buf = (unsigned char *) xmalloc (bsize);
strp = (unsigned char *) XSTRING (string)->data;
- while (strp < (unsigned char *) XSTRING (string)->data + XSTRING (string)->size)
+ while (strp < XSTRING (string)->data + XSTRING (string)->size_byte)
{
if (strp[0] == '\\' && strp[1] == '=')
{
/* \= quotes the next character;
thus, to put in \[ without its special meaning, use \=\[. */
changed = 1;
- *bufp++ = strp[2];
- strp += 3;
+ strp += 2;
+ if (multibyte)
+ {
+ int len;
+ int maxlen = XSTRING (string)->data + XSTRING (string)->size_byte - strp;
+
+ STRING_CHAR_AND_LENGTH (strp, maxlen, len);
+ if (len == 1)
+ *bufp = *strp;
+ else
+ bcopy (strp, bufp, len);
+ strp += len;
+ bufp += len;
+ nchars++;
+ }
+ else
+ *bufp++ = *strp++, nchars++;
}
else if (strp[0] == '\\' && strp[1] == '[')
{
Lisp_Object firstkey;
+ int length_byte;
changed = 1;
strp += 2; /* skip \[ */
start = strp;
while ((strp - (unsigned char *) XSTRING (string)->data
- < XSTRING (string)->size)
+ < XSTRING (string)->size_byte)
&& *strp != ']')
strp++;
- length = strp - start;
+ length_byte = strp - start;
+
strp++; /* skip ] */
/* Save STRP in IDX. */
idx = strp - (unsigned char *) XSTRING (string)->data;
- tem = Fintern (make_string (start, length), Qnil);
+ tem = Fintern (make_string (start, length_byte), Qnil);
tem = Fwhere_is_internal (tem, keymap, Qt, Qnil);
/* Disregard menu bar bindings; it is positively annoying to
buf = new;
bcopy ("M-x ", bufp, 4);
bufp += 4;
+ nchars += 4;
+ if (multibyte)
+ length = multibyte_chars_in_text (start, length_byte);
+ else
+ length = length_byte;
goto subst;
}
else
else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<'))
{
struct buffer *oldbuf;
+ int length_byte;
changed = 1;
strp += 2; /* skip \{ or \< */
< XSTRING (string)->size)
&& *strp != '}' && *strp != '>')
strp++;
- length = strp - start;
+
+ length_byte = strp - start;
strp++; /* skip } or > */
/* Save STRP in IDX. */
/* Get the value of the keymap in TEM, or nil if undefined.
Do this while still in the user's current buffer
in case it is a local variable. */
- name = Fintern (make_string (start, length), Qnil);
+ name = Fintern (make_string (start, length_byte), Qnil);
tem = Fboundp (name);
if (! NILP (tem))
{
{
name = Fsymbol_name (name);
insert_string ("\nUses keymap \"");
- insert_from_string (name, 0, XSTRING (name)->size, 1);
+ insert_from_string (name, 0, 0,
+ XSTRING (name)->size,
+ XSTRING (name)->size_byte, 1);
insert_string ("\", which is not currently defined.\n");
if (start[-1] == '<') keymap = Qnil;
}
subst_string:
start = XSTRING (tem)->data;
length = XSTRING (tem)->size;
+ length_byte = XSTRING (tem)->size_byte;
subst:
- new = (unsigned char *) xrealloc (buf, bsize += length);
+ new = (unsigned char *) xrealloc (buf, bsize += length_byte);
bufp += new - buf;
buf = new;
- bcopy (start, bufp, length);
- bufp += length;
+ bcopy (start, bufp, length_byte);
+ bufp += length_byte;
+ nchars += length;
/* Check STRING again in case gc relocated it. */
strp = (unsigned char *) XSTRING (string)->data + idx;
}
- else /* just copy other chars */
- *bufp++ = *strp++;
+ else if (! multibyte) /* just copy other chars */
+ *bufp++ = *strp++, nchars++;
+ else
+ {
+ int len;
+ int maxlen = XSTRING (string)->data + XSTRING (string)->size_byte - strp;
+
+ STRING_CHAR_AND_LENGTH (strp, maxlen, len);
+ if (len == 1)
+ *bufp = *strp;
+ else
+ bcopy (strp, bufp, len);
+ strp += len;
+ bufp += len;
+ nchars++;
+ }
}
if (changed) /* don't bother if nothing substituted */
- tem = make_string (buf, bufp - buf);
+ tem = make_multibyte_string (buf, nchars, bufp - buf);
else
tem = string;
xfree (buf);