aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa1998-03-03 01:29:16 +0000
committerKenichi Handa1998-03-03 01:29:16 +0000
commitd26650180fcd1ef5507cb569c552db4f69eb9ef0 (patch)
tree900c7e402d7c39485aadf71bf2590ba1d80fa68a /src
parent54e15bb98c80eb9cb09f32f708277ff67d4358c3 (diff)
downloademacs-d26650180fcd1ef5507cb569c552db4f69eb9ef0.tar.gz
emacs-d26650180fcd1ef5507cb569c552db4f69eb9ef0.zip
(DEFAULT_NONASCII_INSERT_OFFSET): Macro definition is
moved to charset.h. (unibyte_char_to_multibyte): Always return a valid character. (Funibyte_char_to_multibyte): New function. (syms_of_charset): Defsubr it. Doc-string of nonascii-insert-offset is modified.
Diffstat (limited to 'src')
-rw-r--r--src/charset.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/charset.c b/src/charset.c
index a49d0cf4b30..6134f040663 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -286,24 +286,24 @@ unify_char (table, c, charset, c1, c2)
286 return MAKE_CHAR (alt_charset, c1, c2); 286 return MAKE_CHAR (alt_charset, c1, c2);
287} 287}
288 288
289#define DEFAULT_NONASCII_INSERT_OFFSET 0x800 289/* Convert the unibyte character C to multibyte based on
290 Vnonascii_translate_table or nonascii_insert_offset. If they can't
291 convert C to a valid multibyte character, convert it based on
292 DEFAULT_NONASCII_INSERT_OFFSET which makes C a Latin-1 character. */
290 293
291/* Convert the unibyte character C to multibyte
292 based on Vnonascii_translate_table or nonascii_insert_offset.
293 Note that copy_text in insdel.c has similar code. */
294
295int
296unibyte_char_to_multibyte (c) 294unibyte_char_to_multibyte (c)
297 int c; 295 int c;
298{ 296{
299 if (c >= 0200 && c < 0400) 297 if (c >= 0240 && c < 0400)
300 { 298 {
299 int c_save = c;
300
301 if (! NILP (Vnonascii_translate_table)) 301 if (! NILP (Vnonascii_translate_table))
302 c = XINT (Faref (Vnonascii_translate_table, make_number (c))); 302 c = XINT (Faref (Vnonascii_translate_table, make_number (c)));
303 else if (nonascii_insert_offset > 0) 303 else if (nonascii_insert_offset > 0)
304 c += nonascii_insert_offset; 304 c += nonascii_insert_offset;
305 else 305 if (c >= 0240 && (c < 0400 || ! VALID_MULTIBYTE_CHAR_P (c)))
306 c += DEFAULT_NONASCII_INSERT_OFFSET; 306 c = c_save + DEFAULT_NONASCII_INSERT_OFFSET;
307 } 307 }
308 return c; 308 return c;
309} 309}
@@ -864,6 +864,26 @@ a valid generic character.")
864 return (CHAR_VALID_P (XFASTINT (object), !NILP (genericp)) ? Qt : Qnil); 864 return (CHAR_VALID_P (XFASTINT (object), !NILP (genericp)) ? Qt : Qnil);
865} 865}
866 866
867DEFUN ("unibyte-char-to-multibyte", Funibyte_char_to_multibyte,
868 Sunibyte_char_to_multibyte, 1, 1, 0,
869 "Convert the unibyte character CH to multibyte character.\n\
870The conversion is done based on nonascii-translate-table (which see)\n\
871 or nonascii-insert-offset (which see).")
872 (ch)
873 Lisp_Object ch;
874{
875 int c;
876
877 CHECK_NUMBER (ch, 0);
878 c = XINT (ch);
879 if (c < 0 || c >= 0400)
880 error ("Invalid unibyte character: %d", c);
881 c = unibyte_char_to_multibyte (c);
882 if (c < 0)
883 error ("Can't convert to multibyte character: %d", XINT (ch));
884 return make_number (c);
885}
886
867DEFUN ("char-bytes", Fchar_bytes, Schar_bytes, 1, 1, 0, 887DEFUN ("char-bytes", Fchar_bytes, Schar_bytes, 1, 1, 0,
868 "Return byte length of multi-byte form of CHAR.") 888 "Return byte length of multi-byte form of CHAR.")
869 (ch) 889 (ch)
@@ -1663,6 +1683,7 @@ syms_of_charset ()
1663 defsubr (&Schar_charset); 1683 defsubr (&Schar_charset);
1664 defsubr (&Siso_charset); 1684 defsubr (&Siso_charset);
1665 defsubr (&Schar_valid_p); 1685 defsubr (&Schar_valid_p);
1686 defsubr (&Sunibyte_char_to_multibyte);
1666 defsubr (&Schar_bytes); 1687 defsubr (&Schar_bytes);
1667 defsubr (&Schar_width); 1688 defsubr (&Schar_width);
1668 defsubr (&Sstring_width); 1689 defsubr (&Sstring_width);
@@ -1708,7 +1729,7 @@ An ID of a unification table is an index of this vector.");
1708 leading_code_private_22 = LEADING_CODE_PRIVATE_22; 1729 leading_code_private_22 = LEADING_CODE_PRIVATE_22;
1709 1730
1710 DEFVAR_INT ("nonascii-insert-offset", &nonascii_insert_offset, 1731 DEFVAR_INT ("nonascii-insert-offset", &nonascii_insert_offset,
1711 "Offset for converting non-ASCII unibyte codes 0200...0377 to multibyte.\n\ 1732 "Offset for converting non-ASCII unibyte codes 0240...0377 to multibyte.\n\
1712This is used for converting unibyte text to multibyte,\n\ 1733This is used for converting unibyte text to multibyte,\n\
1713and for inserting character codes specified by number.\n\n\ 1734and for inserting character codes specified by number.\n\n\
1714Conversion is performed only when multibyte characters are enabled,\n\ 1735Conversion is performed only when multibyte characters are enabled,\n\