diff options
| author | Stefan Monnier | 2000-10-15 21:42:41 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-10-15 21:42:41 +0000 |
| commit | c65adb44b076706b9849a065e2da00eb27388bbb (patch) | |
| tree | 9256170454e8746b8070bcc1f2aac39dc446bd6c | |
| parent | ad64a8881c2fcc37e7c84528b01363798aa90c5f (diff) | |
| download | emacs-c65adb44b076706b9849a065e2da00eb27388bbb.tar.gz emacs-c65adb44b076706b9849a065e2da00eb27388bbb.zip | |
(Fstring_to_syntax): New function extracted from Fmodify_syntax_entry.
(Fmodify_syntax_entry): Use it and document the ! and | fences.
(skip_chars, Fforward_comment): Remove unused variables.
(syms_of_syntax): Add defsubr for string-to-syntax.
| -rw-r--r-- | src/syntax.c | 146 |
1 files changed, 77 insertions, 69 deletions
diff --git a/src/syntax.c b/src/syntax.c index 463e1747b0a..b28500f1127 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -894,86 +894,35 @@ DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0, | |||
| 894 | return Qnil; | 894 | return Qnil; |
| 895 | } | 895 | } |
| 896 | 896 | ||
| 897 | /* This comment supplies the doc string for modify-syntax-entry, | 897 | DEFUN ("string-to-syntax", Fstring_to_syntax, Sstring_to_syntax, 1, 1, 0, |
| 898 | for make-docfile to see. We cannot put this in the real DEFUN | 898 | "Convert a syntax specification STRING into syntax cell form.\n\ |
| 899 | due to limits in the Unix cpp. | 899 | STRING should be a string as it is allowed as argument of\n\ |
| 900 | 900 | `modify-syntax-entry'. Value is the equivalent cons cell\n\ | |
| 901 | DEFUN ("modify-syntax-entry", foo, bar, 2, 3, 0, | 901 | \(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'\n\ |
| 902 | "Set syntax for character CHAR according to string S.\n\ | 902 | text property.") |
| 903 | The syntax is changed only for table TABLE, which defaults to\n\ | 903 | (string) |
| 904 | the current buffer's syntax table.\n\ | 904 | Lisp_Object string; |
| 905 | The first character of S should be one of the following:\n\ | ||
| 906 | Space or - whitespace syntax. w word constituent.\n\ | ||
| 907 | _ symbol constituent. . punctuation.\n\ | ||
| 908 | ( open-parenthesis. ) close-parenthesis.\n\ | ||
| 909 | \" string quote. \\ escape.\n\ | ||
| 910 | $ paired delimiter. ' expression quote or prefix operator.\n\ | ||
| 911 | < comment starter. > comment ender.\n\ | ||
| 912 | / character-quote. @ inherit from `standard-syntax-table'.\n\ | ||
| 913 | \n\ | ||
| 914 | Only single-character comment start and end sequences are represented thus.\n\ | ||
| 915 | Two-character sequences are represented as described below.\n\ | ||
| 916 | The second character of S is the matching parenthesis,\n\ | ||
| 917 | used only if the first character is `(' or `)'.\n\ | ||
| 918 | Any additional characters are flags.\n\ | ||
| 919 | Defined flags are the characters 1, 2, 3, 4, b, p, and n.\n\ | ||
| 920 | 1 means CHAR is the start of a two-char comment start sequence.\n\ | ||
| 921 | 2 means CHAR is the second character of such a sequence.\n\ | ||
| 922 | 3 means CHAR is the start of a two-char comment end sequence.\n\ | ||
| 923 | 4 means CHAR is the second character of such a sequence.\n\ | ||
| 924 | \n\ | ||
| 925 | There can be up to two orthogonal comment sequences. This is to support\n\ | ||
| 926 | language modes such as C++. By default, all comment sequences are of style\n\ | ||
| 927 | a, but you can set the comment sequence style to b (on the second character\n\ | ||
| 928 | of a comment-start, or the first character of a comment-end sequence) using\n\ | ||
| 929 | this flag:\n\ | ||
| 930 | b means CHAR is part of comment sequence b.\n\ | ||
| 931 | n means CHAR is part of a nestable comment sequence.\n\ | ||
| 932 | \n\ | ||
| 933 | p means CHAR is a prefix character for `backward-prefix-chars';\n\ | ||
| 934 | such characters are treated as whitespace when they occur\n\ | ||
| 935 | between expressions.") | ||
| 936 | (char, s, table) | ||
| 937 | */ | ||
| 938 | |||
| 939 | DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3, | ||
| 940 | /* I really don't know why this is interactive | ||
| 941 | help-form should at least be made useful whilst reading the second arg | ||
| 942 | */ | ||
| 943 | "cSet syntax for character: \nsSet syntax for %s to: ", | ||
| 944 | 0 /* See immediately above */) | ||
| 945 | (c, newentry, syntax_table) | ||
| 946 | Lisp_Object c, newentry, syntax_table; | ||
| 947 | { | 905 | { |
| 948 | register unsigned char *p; | 906 | register unsigned char *p; |
| 949 | register enum syntaxcode code; | 907 | register enum syntaxcode code; |
| 950 | int val; | 908 | int val; |
| 951 | Lisp_Object match; | 909 | Lisp_Object match; |
| 952 | 910 | ||
| 953 | CHECK_NUMBER (c, 0); | 911 | CHECK_STRING (string, 0); |
| 954 | CHECK_STRING (newentry, 1); | ||
| 955 | |||
| 956 | if (NILP (syntax_table)) | ||
| 957 | syntax_table = current_buffer->syntax_table; | ||
| 958 | else | ||
| 959 | check_syntax_table (syntax_table); | ||
| 960 | 912 | ||
| 961 | p = XSTRING (newentry)->data; | 913 | p = XSTRING (string)->data; |
| 962 | code = (enum syntaxcode) syntax_spec_code[*p++]; | 914 | code = (enum syntaxcode) syntax_spec_code[*p++]; |
| 963 | if (((int) code & 0377) == 0377) | 915 | if (((int) code & 0377) == 0377) |
| 964 | error ("invalid syntax description letter: %c", p[-1]); | 916 | error ("invalid syntax description letter: %c", p[-1]); |
| 965 | 917 | ||
| 966 | if (code == Sinherit) | 918 | if (code == Sinherit) |
| 967 | { | 919 | return Qnil; |
| 968 | SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), Qnil); | ||
| 969 | return Qnil; | ||
| 970 | } | ||
| 971 | 920 | ||
| 972 | if (*p) | 921 | if (*p) |
| 973 | { | 922 | { |
| 974 | int len; | 923 | int len; |
| 975 | int character = (STRING_CHAR_AND_LENGTH | 924 | int character = (STRING_CHAR_AND_LENGTH |
| 976 | (p, STRING_BYTES (XSTRING (newentry)) - 1, len)); | 925 | (p, STRING_BYTES (XSTRING (string)) - 1, len)); |
| 977 | XSETINT (match, character); | 926 | XSETINT (match, character); |
| 978 | if (XFASTINT (match) == ' ') | 927 | if (XFASTINT (match) == ' ') |
| 979 | match = Qnil; | 928 | match = Qnil; |
| @@ -1016,13 +965,72 @@ DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3, | |||
| 1016 | } | 965 | } |
| 1017 | 966 | ||
| 1018 | if (val < XVECTOR (Vsyntax_code_object)->size && NILP (match)) | 967 | if (val < XVECTOR (Vsyntax_code_object)->size && NILP (match)) |
| 1019 | newentry = XVECTOR (Vsyntax_code_object)->contents[val]; | 968 | return XVECTOR (Vsyntax_code_object)->contents[val]; |
| 1020 | else | 969 | else |
| 1021 | /* Since we can't use a shared object, let's make a new one. */ | 970 | /* Since we can't use a shared object, let's make a new one. */ |
| 1022 | newentry = Fcons (make_number (val), match); | 971 | return Fcons (make_number (val), match); |
| 1023 | 972 | } | |
| 1024 | SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), newentry); | 973 | |
| 974 | /* This comment supplies the doc string for modify-syntax-entry, | ||
| 975 | for make-docfile to see. We cannot put this in the real DEFUN | ||
| 976 | due to limits in the Unix cpp. | ||
| 977 | |||
| 978 | DEFUN ("modify-syntax-entry", foo, bar, 2, 3, 0, | ||
| 979 | "Set syntax for character CHAR according to string S.\n\ | ||
| 980 | The syntax is changed only for table TABLE, which defaults to\n\ | ||
| 981 | the current buffer's syntax table.\n\ | ||
| 982 | The first character of S should be one of the following:\n\ | ||
| 983 | Space or - whitespace syntax. w word constituent.\n\ | ||
| 984 | _ symbol constituent. . punctuation.\n\ | ||
| 985 | ( open-parenthesis. ) close-parenthesis.\n\ | ||
| 986 | \" string quote. \\ escape.\n\ | ||
| 987 | $ paired delimiter. ' expression quote or prefix operator.\n\ | ||
| 988 | < comment starter. > comment ender.\n\ | ||
| 989 | / character-quote. @ inherit from `standard-syntax-table'.\n\ | ||
| 990 | | generic string fence. ! generic comment fence.\n\ | ||
| 991 | \n\ | ||
| 992 | Only single-character comment start and end sequences are represented thus.\n\ | ||
| 993 | Two-character sequences are represented as described below.\n\ | ||
| 994 | The second character of S is the matching parenthesis,\n\ | ||
| 995 | used only if the first character is `(' or `)'.\n\ | ||
| 996 | Any additional characters are flags.\n\ | ||
| 997 | Defined flags are the characters 1, 2, 3, 4, b, p, and n.\n\ | ||
| 998 | 1 means CHAR is the start of a two-char comment start sequence.\n\ | ||
| 999 | 2 means CHAR is the second character of such a sequence.\n\ | ||
| 1000 | 3 means CHAR is the start of a two-char comment end sequence.\n\ | ||
| 1001 | 4 means CHAR is the second character of such a sequence.\n\ | ||
| 1002 | \n\ | ||
| 1003 | There can be up to two orthogonal comment sequences. This is to support\n\ | ||
| 1004 | language modes such as C++. By default, all comment sequences are of style\n\ | ||
| 1005 | a, but you can set the comment sequence style to b (on the second character\n\ | ||
| 1006 | of a comment-start, or the first character of a comment-end sequence) using\n\ | ||
| 1007 | this flag:\n\ | ||
| 1008 | b means CHAR is part of comment sequence b.\n\ | ||
| 1009 | n means CHAR is part of a nestable comment sequence.\n\ | ||
| 1010 | \n\ | ||
| 1011 | p means CHAR is a prefix character for `backward-prefix-chars';\n\ | ||
| 1012 | such characters are treated as whitespace when they occur\n\ | ||
| 1013 | between expressions.") | ||
| 1014 | (char, s, table) | ||
| 1015 | */ | ||
| 1016 | |||
| 1017 | DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3, | ||
| 1018 | /* I really don't know why this is interactive | ||
| 1019 | help-form should at least be made useful whilst reading the second arg | ||
| 1020 | */ | ||
| 1021 | "cSet syntax for character: \nsSet syntax for %s to: ", | ||
| 1022 | 0 /* See immediately above */) | ||
| 1023 | (c, newentry, syntax_table) | ||
| 1024 | Lisp_Object c, newentry, syntax_table; | ||
| 1025 | { | ||
| 1026 | CHECK_NUMBER (c, 0); | ||
| 1027 | |||
| 1028 | if (NILP (syntax_table)) | ||
| 1029 | syntax_table = current_buffer->syntax_table; | ||
| 1030 | else | ||
| 1031 | check_syntax_table (syntax_table); | ||
| 1025 | 1032 | ||
| 1033 | SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), Fstring_to_syntax (newentry)); | ||
| 1026 | return Qnil; | 1034 | return Qnil; |
| 1027 | } | 1035 | } |
| 1028 | 1036 | ||
| @@ -1382,7 +1390,6 @@ skip_chars (forwardp, syntaxp, string, lim) | |||
| 1382 | Lisp_Object string, lim; | 1390 | Lisp_Object string, lim; |
| 1383 | { | 1391 | { |
| 1384 | register unsigned int c; | 1392 | register unsigned int c; |
| 1385 | register int ch; | ||
| 1386 | unsigned char fastmap[0400]; | 1393 | unsigned char fastmap[0400]; |
| 1387 | /* If SYNTAXP is 0, STRING may contain multi-byte form of characters | 1394 | /* If SYNTAXP is 0, STRING may contain multi-byte form of characters |
| 1388 | of which codes don't fit in FASTMAP. In that case, set the | 1395 | of which codes don't fit in FASTMAP. In that case, set the |
| @@ -1897,7 +1904,7 @@ between them, return t; otherwise return nil.") | |||
| 1897 | { | 1904 | { |
| 1898 | while (1) | 1905 | while (1) |
| 1899 | { | 1906 | { |
| 1900 | int quoted, comstart_second; | 1907 | int quoted; |
| 1901 | 1908 | ||
| 1902 | if (from <= stop) | 1909 | if (from <= stop) |
| 1903 | { | 1910 | { |
| @@ -3035,6 +3042,7 @@ relevant only for open/close type."); | |||
| 3035 | defsubr (&Sset_syntax_table); | 3042 | defsubr (&Sset_syntax_table); |
| 3036 | defsubr (&Schar_syntax); | 3043 | defsubr (&Schar_syntax); |
| 3037 | defsubr (&Smatching_paren); | 3044 | defsubr (&Smatching_paren); |
| 3045 | defsubr (&Sstring_to_syntax); | ||
| 3038 | defsubr (&Smodify_syntax_entry); | 3046 | defsubr (&Smodify_syntax_entry); |
| 3039 | defsubr (&Sdescribe_syntax); | 3047 | defsubr (&Sdescribe_syntax); |
| 3040 | 3048 | ||