summaryrefslogtreecommitdiff
path: root/src/casefiddle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/casefiddle.c')
-rw-r--r--src/casefiddle.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/casefiddle.c b/src/casefiddle.c
index 7e445703901..b252f07ae13 100644
--- a/src/casefiddle.c
+++ b/src/casefiddle.c
@@ -92,6 +92,12 @@ prepare_casing_context (struct casing_context *ctx,
SETUP_BUFFER_SYNTAX_TABLE (); /* For syntax_prefix_flag_p. */
}
+static bool
+case_ch_is_word (enum syntaxcode syntax)
+{
+ return syntax == Sword || (case_symbols_as_words && syntax == Ssymbol);
+}
+
struct casing_str_buf
{
unsigned char data[max (6, MAX_MULTIBYTE_LENGTH)];
@@ -115,7 +121,7 @@ case_character_impl (struct casing_str_buf *buf,
/* Update inword state */
bool was_inword = ctx->inword;
- ctx->inword = SYNTAX (ch) == Sword &&
+ ctx->inword = case_ch_is_word (SYNTAX (ch)) &&
(!ctx->inbuffer || was_inword || !syntax_prefix_flag_p (ch));
/* Normalize flag so its one of CASE_UP, CASE_DOWN or CASE_CAPITALIZE. */
@@ -222,7 +228,7 @@ case_character (struct casing_str_buf *buf, struct casing_context *ctx,
has a word syntax (i.e. current character is end of word), use final
sigma. */
if (was_inword && ch == GREEK_CAPITAL_LETTER_SIGMA && changed
- && (!next || SYNTAX (STRING_CHAR (next)) != Sword))
+ && (!next || !case_ch_is_word (SYNTAX (STRING_CHAR (next)))))
{
buf->len_bytes = CHAR_STRING (GREEK_SMALL_LETTER_FINAL_SIGMA, buf->data);
buf->len_chars = 1;
@@ -283,8 +289,8 @@ do_casify_multibyte_string (struct casing_context *ctx, Lisp_Object obj)
ptrdiff_t size = SCHARS (obj), n;
USE_SAFE_ALLOCA;
- if (INT_MULTIPLY_WRAPV (size, MAX_MULTIBYTE_LENGTH, &n)
- || INT_ADD_WRAPV (n, sizeof (struct casing_str_buf), &n))
+ if (ckd_mul (&n, size, MAX_MULTIBYTE_LENGTH)
+ || ckd_add (&n, n, sizeof (struct casing_str_buf)))
n = PTRDIFF_MAX;
unsigned char *dst = SAFE_ALLOCA (n);
unsigned char *dst_end = dst + n;
@@ -720,6 +726,21 @@ Called with one argument METHOD which can be:
3rd argument. */);
Vregion_extract_function = Qnil; /* simple.el sets this. */
+ DEFVAR_BOOL ("case-symbols-as-words", case_symbols_as_words,
+ doc: /* If non-nil, case functions treat symbol syntax as part of words.
+
+Functions such as `upcase-initials' and `replace-match' check or modify
+the case pattern of sequences of characters. Normally, these operate on
+sequences of characters whose syntax is word constituent. If this
+variable is non-nil, then they operate on sequences of characters whose
+syntax is either word constituent or symbol constituent.
+
+This is useful for programming languages and styles where only the first
+letter of a symbol's name is ever capitalized.*/);
+ case_symbols_as_words = 0;
+ DEFSYM (Qcase_symbols_as_words, "case-symbols-as-words");
+ Fmake_variable_buffer_local (Qcase_symbols_as_words);
+
defsubr (&Supcase);
defsubr (&Sdowncase);
defsubr (&Scapitalize);