return orig_end + added;
}
-DEFUN ("upcase-region", Fupcase_region, Supcase_region, 2, 3,
- "(list (region-beginning) (region-end) (region-noncontiguous-p))",
- doc: /* Convert the region to upper case. In programs, wants two arguments.
-These arguments specify the starting and ending character numbers of
-the region to operate on. When used as a command, the text between
-point and the mark is operated on.
-See also `capitalize-region'. */)
- (Lisp_Object beg, Lisp_Object end, Lisp_Object region_noncontiguous_p)
-{
- Lisp_Object bounds = Qnil;
+/* Casify a possibly noncontiguous region according to FLAG. BEG and
+ END specify the bounds, except that if REGION_NONCONTIGUOUS_P is
+ non-nil, the region's bounds are specified by (funcall
+ region-extract-function 'bounds) instead. */
+static Lisp_Object
+casify_pnc_region (enum case_action flag, Lisp_Object beg, Lisp_Object end,
+ Lisp_Object region_noncontiguous_p)
+{
if (!NILP (region_noncontiguous_p))
{
- bounds = call1 (Fsymbol_value (Qregion_extract_function),
- intern ("bounds"));
-
- while (CONSP (bounds))
+ Lisp_Object bounds = call1 (Vregion_extract_function, Qbounds);
+ FOR_EACH_TAIL (bounds)
{
- casify_region (CASE_UP, XCAR (XCAR (bounds)), XCDR (XCAR (bounds)));
- bounds = XCDR (bounds);
+ CHECK_CONS (XCAR (bounds));
+ casify_region (flag, XCAR (XCAR (bounds)), XCDR (XCAR (bounds)));
}
+ CHECK_LIST_END (bounds, bounds);
}
else
- casify_region (CASE_UP, beg, end);
+ casify_region (flag, beg, end);
return Qnil;
}
+DEFUN ("upcase-region", Fupcase_region, Supcase_region, 2, 3,
+ "(list (region-beginning) (region-end) (region-noncontiguous-p))",
+ doc: /* Convert the region to upper case. In programs, wants two arguments.
+These arguments specify the starting and ending character numbers of
+the region to operate on. When used as a command, the text between
+point and the mark is operated on.
+See also `capitalize-region'. */)
+ (Lisp_Object beg, Lisp_Object end, Lisp_Object region_noncontiguous_p)
+{
+ return casify_pnc_region (CASE_UP, beg, end, region_noncontiguous_p);
+}
+
DEFUN ("downcase-region", Fdowncase_region, Sdowncase_region, 2, 3,
"(list (region-beginning) (region-end) (region-noncontiguous-p))",
doc: /* Convert the region to lower case. In programs, wants two arguments.
point and the mark is operated on. */)
(Lisp_Object beg, Lisp_Object end, Lisp_Object region_noncontiguous_p)
{
- Lisp_Object bounds = Qnil;
-
- if (!NILP (region_noncontiguous_p))
- {
- bounds = call1 (Fsymbol_value (Qregion_extract_function),
- intern ("bounds"));
-
- while (CONSP (bounds))
- {
- casify_region (CASE_DOWN, XCAR (XCAR (bounds)), XCDR (XCAR (bounds)));
- bounds = XCDR (bounds);
- }
- }
- else
- casify_region (CASE_DOWN, beg, end);
-
- return Qnil;
+ return casify_pnc_region (CASE_DOWN, beg, end, region_noncontiguous_p);
}
DEFUN ("capitalize-region", Fcapitalize_region, Scapitalize_region, 2, 3,
character positions to operate on. */)
(Lisp_Object beg, Lisp_Object end, Lisp_Object region_noncontiguous_p)
{
- Lisp_Object bounds = Qnil;
-
- if (!NILP (region_noncontiguous_p))
- {
- bounds = call1 (Fsymbol_value (Qregion_extract_function),
- intern ("bounds"));
-
- while (CONSP (bounds))
- {
- casify_region (CASE_CAPITALIZE, XCAR (XCAR (bounds)), XCDR (XCAR (bounds)));
- bounds = XCDR (bounds);
- }
- }
- else
- casify_region (CASE_CAPITALIZE, beg, end);
-
- return Qnil;
+ return casify_pnc_region (CASE_CAPITALIZE, beg, end, region_noncontiguous_p);
}
/* Like Fcapitalize_region but change only the initials. */
DEFUN ("upcase-initials-region", Fupcase_initials_region,
- Supcase_initials_region, 2, 2, "r",
+ Supcase_initials_region, 2, 3,
+ "(list (region-beginning) (region-end) (region-noncontiguous-p))",
doc: /* Upcase the initial of each word in the region.
This means that each word's first character is converted to either
title case or upper case, and the rest are left unchanged.
In programs, give two arguments, the starting and ending
character positions to operate on. */)
- (Lisp_Object beg, Lisp_Object end)
+ (Lisp_Object beg, Lisp_Object end, Lisp_Object region_noncontiguous_p)
{
- casify_region (CASE_CAPITALIZE_UP, beg, end);
- return Qnil;
+ return casify_pnc_region (CASE_CAPITALIZE_UP, beg, end,
+ region_noncontiguous_p);
}
\f
static Lisp_Object
void
syms_of_casefiddle (void)
{
+ DEFSYM (Qbounds, "bounds");
DEFSYM (Qidentity, "identity");
DEFSYM (Qtitlecase, "titlecase");
DEFSYM (Qspecial_uppercase, "special-uppercase");
DEFSYM (Qspecial_lowercase, "special-lowercase");
DEFSYM (Qspecial_titlecase, "special-titlecase");
+ DEFVAR_LISP ("region-extract-function", Vregion_extract_function,
+ doc: /* Function to get the region's content.
+Called with one argument METHOD which can be:
+- nil: return the content as a string (list of strings for
+ non-contiguous regions).
+- `delete-only': delete the region; the return value is undefined.
+- `bounds': return the boundaries of the region as a list of one
+ or more cons cells of the form (START . END).
+- anything else: delete the region and return its content
+ as a string (or list of strings for non-contiguous regions),
+ after filtering it with `filter-buffer-substring', which
+ is called, for each contiguous sub-region, with METHOD as its
+ 3rd argument. */);
+ Vregion_extract_function = Qnil; /* simple.el sets this. */
+
defsubr (&Supcase);
defsubr (&Sdowncase);
defsubr (&Scapitalize);