* doc/lispref/syntax.texi (Syntax Table Internals): Document it.
* src/syntax.c (Fsyntax_class_to_char): New function (bug#37452).
the corresponding raw syntax descriptor.
@end defun
+@defun syntax-class-to-char syntax
+Given a raw syntax descriptor @var{syntax} (an integer), this function
+returns the corresponding syntax descriptor (a character).
+@end defun
+
@defun syntax-after pos
This function returns the raw syntax descriptor for the character in
the buffer after position @var{pos}, taking account of syntax
\f
* Lisp Changes in Emacs 28.1
++++
+** New function 'syntax-class-to-char'.
+This does the almost the opposite of 'string-to-syntax' -- it returns
+the syntax descriptor (a character) given a raw syntax descriptor.
+
+++
** New function 'buffer-local-boundp'.
This predicate says whether a symbol is bound in a specific buffer.
return make_fixnum (syntax_code_spec[SYNTAX (char_int)]);
}
+DEFUN ("syntax-class-to-char", Fsyntax_class_to_char,
+ Ssyntax_class_to_char, 1, 1, 0,
+ doc: /* Return the syntax char of CLASS, described by an integer.
+For example, if SYNTAX is word constituent (the integer 2), the
+character `w' (119) is returned. */)
+ (Lisp_Object syntax)
+{
+ int syn;
+ CHECK_FIXNUM (syntax);
+ syn = XFIXNUM (syntax);
+
+ if (syn < 0 || syn >= sizeof syntax_code_spec)
+ args_out_of_range (make_fixnum (sizeof syntax_code_spec - 1),
+ syntax);
+ return make_fixnum (syntax_code_spec[syn]);
+}
+
DEFUN ("matching-paren", Fmatching_paren, Smatching_paren, 1, 1, 0,
doc: /* Return the matching parenthesis of CHARACTER, or nil if none. */)
(Lisp_Object character)
defsubr (&Scopy_syntax_table);
defsubr (&Sset_syntax_table);
defsubr (&Schar_syntax);
+ defsubr (&Ssyntax_class_to_char);
defsubr (&Smatching_paren);
defsubr (&Sstring_to_syntax);
defsubr (&Smodify_syntax_entry);
(require 'ert)
(require 'ert-x)
+(require 'cl-lib)
(ert-deftest parse-partial-sexp-continue-over-comment-marker ()
"Continue a parse that stopped in the middle of a comment marker."
(should (equal (parse-partial-sexp aftC pointX nil nil pps-aftC)
ppsX)))))
+(ert-deftest syntax-class-character-test ()
+ (cl-loop for char across " .w_()'\"$\\/<>@!|"
+ for i from 0
+ do (should (= char (syntax-class-to-char i)))
+ when (string-to-syntax (string char))
+ do (should (= char (syntax-class-to-char
+ (car (string-to-syntax (string char)))))))
+ (should-error (syntax-class-to-char -1))
+ (should-error (syntax-class-to-char 200)))
+
(ert-deftest parse-partial-sexp-paren-comments ()
"Test syntax parsing with paren comment markers.
Specifically, where the first character of the comment marker is