comparison src/search.c @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents abe6d1db359e
children 1ccc32a20af4
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
930 return make_int (BUF_PT (buf) - start_point); 930 return make_int (BUF_PT (buf) - start_point);
931 } 931 }
932 } 932 }
933 933
934 DEFUN ("skip-chars-forward", Fskip_chars_forward, 1, 3, 0, /* 934 DEFUN ("skip-chars-forward", Fskip_chars_forward, 1, 3, 0, /*
935 Move point forward, stopping before a char not in STRING, or at pos LIM. 935 Move point forward, stopping before a char not in STRING, or at pos LIMIT.
936 STRING is like the inside of a `[...]' in a regular expression 936 STRING is like the inside of a `[...]' in a regular expression
937 except that `]' is never special and `\\' quotes `^', `-' or `\\'. 937 except that `]' is never special and `\\' quotes `^', `-' or `\\'.
938 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter. 938 Thus, with arg "a-zA-Z", this skips letters stopping before first nonletter.
939 With arg "^a-zA-Z", skips nonletters stopping before first letter. 939 With arg "^a-zA-Z", skips nonletters stopping before first letter.
940 Returns the distance traveled, either zero or positive. 940 Returns the distance traveled, either zero or positive.
941 941
942 Optional argument BUFFER defaults to the current buffer. 942 Optional argument BUFFER defaults to the current buffer.
943 */ 943 */
944 (string, lim, buffer)) 944 (string, limit, buffer))
945 { 945 {
946 return skip_chars (decode_buffer (buffer, 0), 1, 0, string, lim); 946 return skip_chars (decode_buffer (buffer, 0), 1, 0, string, limit);
947 } 947 }
948 948
949 DEFUN ("skip-chars-backward", Fskip_chars_backward, 1, 3, 0, /* 949 DEFUN ("skip-chars-backward", Fskip_chars_backward, 1, 3, 0, /*
950 Move point backward, stopping after a char not in STRING, or at pos LIM. 950 Move point backward, stopping after a char not in STRING, or at pos LIMIT.
951 See `skip-chars-forward' for details. 951 See `skip-chars-forward' for details.
952 Returns the distance traveled, either zero or negative. 952 Returns the distance traveled, either zero or negative.
953 953
954 Optional argument BUFFER defaults to the current buffer. 954 Optional argument BUFFER defaults to the current buffer.
955 */ 955 */
956 (string, lim, buffer)) 956 (string, limit, buffer))
957 { 957 {
958 return skip_chars (decode_buffer (buffer, 0), 0, 0, string, lim); 958 return skip_chars (decode_buffer (buffer, 0), 0, 0, string, limit);
959 } 959 }
960 960
961 961
962 DEFUN ("skip-syntax-forward", Fskip_syntax_forward, 1, 3, 0, /* 962 DEFUN ("skip-syntax-forward", Fskip_syntax_forward, 1, 3, 0, /*
963 Move point forward across chars in specified syntax classes. 963 Move point forward across chars in specified syntax classes.
964 SYNTAX is a string of syntax code characters. 964 SYNTAX is a string of syntax code characters.
965 Stop before a char whose syntax is not in SYNTAX, or at position LIM. 965 Stop before a char whose syntax is not in SYNTAX, or at position LIMIT.
966 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX. 966 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
967 This function returns the distance traveled, either zero or positive. 967 This function returns the distance traveled, either zero or positive.
968 968
969 Optional argument BUFFER defaults to the current buffer. 969 Optional argument BUFFER defaults to the current buffer.
970 */ 970 */
971 (syntax, lim, buffer)) 971 (syntax, limit, buffer))
972 { 972 {
973 return skip_chars (decode_buffer (buffer, 0), 1, 1, syntax, lim); 973 return skip_chars (decode_buffer (buffer, 0), 1, 1, syntax, limit);
974 } 974 }
975 975
976 DEFUN ("skip-syntax-backward", Fskip_syntax_backward, 1, 3, 0, /* 976 DEFUN ("skip-syntax-backward", Fskip_syntax_backward, 1, 3, 0, /*
977 Move point backward across chars in specified syntax classes. 977 Move point backward across chars in specified syntax classes.
978 SYNTAX is a string of syntax code characters. 978 SYNTAX is a string of syntax code characters.
979 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIM. 979 Stop on reaching a char whose syntax is not in SYNTAX, or at position LIMIT.
980 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX. 980 If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX.
981 This function returns the distance traveled, either zero or negative. 981 This function returns the distance traveled, either zero or negative.
982 982
983 Optional argument BUFFER defaults to the current buffer. 983 Optional argument BUFFER defaults to the current buffer.
984 */ 984 */
985 (syntax, lim, buffer)) 985 (syntax, limit, buffer))
986 { 986 {
987 return skip_chars (decode_buffer (buffer, 0), 0, 1, syntax, lim); 987 return skip_chars (decode_buffer (buffer, 0), 0, 1, syntax, limit);
988 } 988 }
989 989
990 990
991 /* Subroutines of Lisp buffer search functions. */ 991 /* Subroutines of Lisp buffer search functions. */
992 992
993 static Lisp_Object 993 static Lisp_Object
994 search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object no_error, 994 search_command (Lisp_Object string, Lisp_Object limit, Lisp_Object noerror,
995 Lisp_Object count, Lisp_Object buffer, int direction, 995 Lisp_Object count, Lisp_Object buffer, int direction,
996 int RE, int posix) 996 int RE, int posix)
997 { 997 {
998 /* This function has been Mule-ized, except for the trt table handling. */ 998 /* This function has been Mule-ized, except for the trt table handling. */
999 REGISTER Bufpos np; 999 REGISTER Bufpos np;
1007 n *= XINT (count); 1007 n *= XINT (count);
1008 } 1008 }
1009 1009
1010 buf = decode_buffer (buffer, 0); 1010 buf = decode_buffer (buffer, 0);
1011 CHECK_STRING (string); 1011 CHECK_STRING (string);
1012 if (NILP (bound)) 1012 if (NILP (limit))
1013 lim = n > 0 ? BUF_ZV (buf) : BUF_BEGV (buf); 1013 lim = n > 0 ? BUF_ZV (buf) : BUF_BEGV (buf);
1014 else 1014 else
1015 { 1015 {
1016 CHECK_INT_COERCE_MARKER (bound); 1016 CHECK_INT_COERCE_MARKER (limit);
1017 lim = XINT (bound); 1017 lim = XINT (limit);
1018 if (n > 0 ? lim < BUF_PT (buf) : lim > BUF_PT (buf)) 1018 if (n > 0 ? lim < BUF_PT (buf) : lim > BUF_PT (buf))
1019 error ("Invalid search bound (wrong side of point)"); 1019 error ("Invalid search limit (wrong side of point)");
1020 if (lim > BUF_ZV (buf)) 1020 if (lim > BUF_ZV (buf))
1021 lim = BUF_ZV (buf); 1021 lim = BUF_ZV (buf);
1022 if (lim < BUF_BEGV (buf)) 1022 if (lim < BUF_BEGV (buf))
1023 lim = BUF_BEGV (buf); 1023 lim = BUF_BEGV (buf);
1024 } 1024 }
1031 ? MIRROR_EQV_TABLE_AS_STRING (buf) 1031 ? MIRROR_EQV_TABLE_AS_STRING (buf)
1032 : 0), posix); 1032 : 0), posix);
1033 1033
1034 if (np <= 0) 1034 if (np <= 0)
1035 { 1035 {
1036 if (NILP (no_error)) 1036 if (NILP (noerror))
1037 return signal_failure (string); 1037 return signal_failure (string);
1038 if (!EQ (no_error, Qt)) 1038 if (!EQ (noerror, Qt))
1039 { 1039 {
1040 if (lim < BUF_BEGV (buf) || lim > BUF_ZV (buf)) 1040 if (lim < BUF_BEGV (buf) || lim > BUF_ZV (buf))
1041 abort (); 1041 abort ();
1042 BUF_SET_PT (buf, lim); 1042 BUF_SET_PT (buf, lim);
1043 return Qnil; 1043 return Qnil;
1643 } 1643 }
1644 1644
1645 DEFUN ("search-backward", Fsearch_backward, 1, 5, "sSearch backward: ", /* 1645 DEFUN ("search-backward", Fsearch_backward, 1, 5, "sSearch backward: ", /*
1646 Search backward from point for STRING. 1646 Search backward from point for STRING.
1647 Set point to the beginning of the occurrence found, and return point. 1647 Set point to the beginning of the occurrence found, and return point.
1648 An optional second argument bounds the search; it is a buffer position. 1648
1649 The match found must not extend before that position. 1649 Optional second argument LIMIT bounds the search; it is a buffer
1650 Optional third argument, if t, means if fail just return nil (no error). 1650 position. The match found must not extend before that position.
1651 If not nil and not t, position at limit of search and return nil. 1651 The value nil is equivalent to (point-min).
1652 Optional fourth argument is repeat count--search for successive occurrences. 1652
1653 Optional third argument NOERROR, if t, means just return nil (no
1654 error) if the search fails. If neither nil nor t, set point to LIMIT
1655 and return nil.
1656
1657 Optional fourth argument COUNT is a repeat count--search for
1658 successive occurrences.
1659
1653 Optional fifth argument BUFFER specifies the buffer to search in and 1660 Optional fifth argument BUFFER specifies the buffer to search in and
1654 defaults to the current buffer. 1661 defaults to the current buffer.
1662
1655 See also the functions `match-beginning', `match-end' and `replace-match'. 1663 See also the functions `match-beginning', `match-end' and `replace-match'.
1656 */ 1664 */
1657 (string, bound, no_error, count, buffer)) 1665 (string, limit, noerror, count, buffer))
1658 { 1666 {
1659 return search_command (string, bound, no_error, count, buffer, -1, 0, 0); 1667 return search_command (string, limit, noerror, count, buffer, -1, 0, 0);
1660 } 1668 }
1661 1669
1662 DEFUN ("search-forward", Fsearch_forward, 1, 5, "sSearch: ", /* 1670 DEFUN ("search-forward", Fsearch_forward, 1, 5, "sSearch: ", /*
1663 Search forward from point for STRING. 1671 Search forward from point for STRING.
1664 Set point to the end of the occurrence found, and return point. 1672 Set point to the end of the occurrence found, and return point.
1665 An optional second argument bounds the search; it is a buffer position. 1673
1666 The match found must not extend after that position. nil is equivalent 1674 Optional second argument LIMIT bounds the search; it is a buffer
1667 to (point-max). 1675 position. The match found must not extend after that position. The
1668 Optional third argument, if t, means if fail just return nil (no error). 1676 value nil is equivalent to (point-max).
1669 If not nil and not t, move to limit of search and return nil. 1677
1670 Optional fourth argument is repeat count--search for successive occurrences. 1678 Optional third argument NOERROR, if t, means just return nil (no
1679 error) if the search fails. If neither nil nor t, set point to LIMIT
1680 and return nil.
1681
1682 Optional fourth argument COUNT is a repeat count--search for
1683 successive occurrences.
1684
1671 Optional fifth argument BUFFER specifies the buffer to search in and 1685 Optional fifth argument BUFFER specifies the buffer to search in and
1672 defaults to the current buffer. 1686 defaults to the current buffer.
1687
1673 See also the functions `match-beginning', `match-end' and `replace-match'. 1688 See also the functions `match-beginning', `match-end' and `replace-match'.
1674 */ 1689 */
1675 (string, bound, no_error, count, buffer)) 1690 (string, limit, noerror, count, buffer))
1676 { 1691 {
1677 return search_command (string, bound, no_error, count, buffer, 1, 0, 0); 1692 return search_command (string, limit, noerror, count, buffer, 1, 0, 0);
1678 } 1693 }
1679 1694
1680 DEFUN ("word-search-backward", Fword_search_backward, 1, 5, 1695 DEFUN ("word-search-backward", Fword_search_backward, 1, 5,
1681 "sWord search backward: ", /* 1696 "sWord search backward: ", /*
1682 Search backward from point for STRING, ignoring differences in punctuation. 1697 Search backward from point for STRING, ignoring differences in punctuation.
1683 Set point to the beginning of the occurrence found, and return point. 1698 Set point to the beginning of the occurrence found, and return point.
1684 An optional second argument bounds the search; it is a buffer position. 1699
1685 The match found must not extend before that position. 1700 Optional second argument LIMIT bounds the search; it is a buffer
1686 Optional third argument, if t, means if fail just return nil (no error). 1701 position. The match found must not extend before that position.
1687 If not nil and not t, move to limit of search and return nil. 1702 The value nil is equivalent to (point-min).
1688 Optional fourth argument is repeat count--search for successive occurrences. 1703
1704 Optional third argument NOERROR, if t, means just return nil (no
1705 error) if the search fails. If neither nil nor t, set point to LIMIT
1706 and return nil.
1707
1708 Optional fourth argument COUNT is a repeat count--search for
1709 successive occurrences.
1710
1689 Optional fifth argument BUFFER specifies the buffer to search in and 1711 Optional fifth argument BUFFER specifies the buffer to search in and
1690 defaults to the current buffer. 1712 defaults to the current buffer.
1713
1714 See also the functions `match-beginning', `match-end' and `replace-match'.
1691 */ 1715 */
1692 (string, bound, no_error, count, buffer)) 1716 (string, limit, noerror, count, buffer))
1693 { 1717 {
1694 return search_command (wordify (buffer, string), bound, no_error, count, 1718 return search_command (wordify (buffer, string), limit, noerror, count,
1695 buffer, -1, 1, 0); 1719 buffer, -1, 1, 0);
1696 } 1720 }
1697 1721
1698 DEFUN ("word-search-forward", Fword_search_forward, 1, 5, "sWord search: ", /* 1722 DEFUN ("word-search-forward", Fword_search_forward, 1, 5, "sWord search: ", /*
1699 Search forward from point for STRING, ignoring differences in punctuation. 1723 Search forward from point for STRING, ignoring differences in punctuation.
1700 Set point to the end of the occurrence found, and return point. 1724 Set point to the end of the occurrence found, and return point.
1701 An optional second argument bounds the search; it is a buffer position. 1725
1702 The match found must not extend after that position. 1726 Optional second argument LIMIT bounds the search; it is a buffer
1703 Optional third argument, if t, means if fail just return nil (no error). 1727 position. The match found must not extend after that position. The
1704 If not nil and not t, move to limit of search and return nil. 1728 value nil is equivalent to (point-max).
1705 Optional fourth argument is repeat count--search for successive occurrences. 1729
1730 Optional third argument NOERROR, if t, means just return nil (no
1731 error) if the search fails. If neither nil nor t, set point to LIMIT
1732 and return nil.
1733
1734 Optional fourth argument COUNT is a repeat count--search for
1735 successive occurrences.
1736
1706 Optional fifth argument BUFFER specifies the buffer to search in and 1737 Optional fifth argument BUFFER specifies the buffer to search in and
1707 defaults to the current buffer. 1738 defaults to the current buffer.
1739
1740 See also the functions `match-beginning', `match-end' and `replace-match'.
1708 */ 1741 */
1709 (string, bound, no_error, count, buffer)) 1742 (string, limit, noerror, count, buffer))
1710 { 1743 {
1711 return search_command (wordify (buffer, string), bound, no_error, count, 1744 return search_command (wordify (buffer, string), limit, noerror, count,
1712 buffer, 1, 1, 0); 1745 buffer, 1, 1, 0);
1713 } 1746 }
1714 1747
1715 DEFUN ("re-search-backward", Fre_search_backward, 1, 5, 1748 DEFUN ("re-search-backward", Fre_search_backward, 1, 5,
1716 "sRE search backward: ", /* 1749 "sRE search backward: ", /*
1717 Search backward from point for match for regular expression REGEXP. 1750 Search backward from point for match for regular expression REGEXP.
1718 Set point to the beginning of the match, and return point. 1751 Set point to the beginning of the match, and return point.
1719 The match found is the one starting last in the buffer 1752 The match found is the one starting last in the buffer
1720 and yet ending before the origin of the search. 1753 and yet ending before the origin of the search.
1721 An optional second argument bounds the search; it is a buffer position. 1754
1722 The match found must start at or after that position. 1755 Optional second argument LIMIT bounds the search; it is a buffer
1723 Optional third argument, if t, means if fail just return nil (no error). 1756 position. The match found must not extend before that position.
1724 If not nil and not t, move to limit of search and return nil. 1757 The value nil is equivalent to (point-min).
1725 Optional fourth argument is repeat count--search for successive occurrences. 1758
1759 Optional third argument NOERROR, if t, means just return nil (no
1760 error) if the search fails. If neither nil nor t, set point to LIMIT
1761 and return nil.
1762
1763 Optional fourth argument COUNT is a repeat count--search for
1764 successive occurrences.
1765
1726 Optional fifth argument BUFFER specifies the buffer to search in and 1766 Optional fifth argument BUFFER specifies the buffer to search in and
1727 defaults to the current buffer. 1767 defaults to the current buffer.
1768
1728 See also the functions `match-beginning', `match-end' and `replace-match'. 1769 See also the functions `match-beginning', `match-end' and `replace-match'.
1729 */ 1770 */
1730 (regexp, bound, no_error, count, buffer)) 1771 (regexp, limit, noerror, count, buffer))
1731 { 1772 {
1732 return search_command (regexp, bound, no_error, count, buffer, -1, 1, 0); 1773 return search_command (regexp, limit, noerror, count, buffer, -1, 1, 0);
1733 } 1774 }
1734 1775
1735 DEFUN ("re-search-forward", Fre_search_forward, 1, 5, "sRE search: ", /* 1776 DEFUN ("re-search-forward", Fre_search_forward, 1, 5, "sRE search: ", /*
1736 Search forward from point for regular expression REGEXP. 1777 Search forward from point for regular expression REGEXP.
1737 Set point to the end of the occurrence found, and return point. 1778 Set point to the end of the occurrence found, and return point.
1738 An optional second argument bounds the search; it is a buffer position. 1779
1739 The match found must not extend after that position. 1780 Optional second argument LIMIT bounds the search; it is a buffer
1740 Optional third argument, if t, means if fail just return nil (no error). 1781 position. The match found must not extend after that position. The
1741 If not nil and not t, move to limit of search and return nil. 1782 value nil is equivalent to (point-max).
1742 Optional fourth argument is repeat count--search for successive occurrences. 1783
1784 Optional third argument NOERROR, if t, means just return nil (no
1785 error) if the search fails. If neither nil nor t, set point to LIMIT
1786 and return nil.
1787
1788 Optional fourth argument COUNT is a repeat count--search for
1789 successive occurrences.
1790
1743 Optional fifth argument BUFFER specifies the buffer to search in and 1791 Optional fifth argument BUFFER specifies the buffer to search in and
1744 defaults to the current buffer. 1792 defaults to the current buffer.
1793
1745 See also the functions `match-beginning', `match-end' and `replace-match'. 1794 See also the functions `match-beginning', `match-end' and `replace-match'.
1746 */ 1795 */
1747 (regexp, bound, no_error, count, buffer)) 1796 (regexp, limit, noerror, count, buffer))
1748 { 1797 {
1749 return search_command (regexp, bound, no_error, count, buffer, 1, 1, 0); 1798 return search_command (regexp, limit, noerror, count, buffer, 1, 1, 0);
1750 } 1799 }
1751 1800
1752 DEFUN ("posix-search-backward", Fposix_search_backward, 1, 5, 1801 DEFUN ("posix-search-backward", Fposix_search_backward, 1, 5,
1753 "sPosix search backward: ", /* 1802 "sPosix search backward: ", /*
1754 Search backward from point for match for regular expression REGEXP. 1803 Search backward from point for match for regular expression REGEXP.
1755 Find the longest match in accord with Posix regular expression rules. 1804 Find the longest match in accord with Posix regular expression rules.
1756 Set point to the beginning of the match, and return point. 1805 Set point to the beginning of the match, and return point.
1757 The match found is the one starting last in the buffer 1806 The match found is the one starting last in the buffer
1758 and yet ending before the origin of the search. 1807 and yet ending before the origin of the search.
1759 An optional second argument bounds the search; it is a buffer position. 1808
1760 The match found must start at or after that position. 1809 Optional second argument LIMIT bounds the search; it is a buffer
1761 Optional third argument, if t, means if fail just return nil (no error). 1810 position. The match found must not extend before that position.
1762 If not nil and not t, move to limit of search and return nil. 1811 The value nil is equivalent to (point-min).
1763 Optional fourth argument is repeat count--search for successive occurrences. 1812
1813 Optional third argument NOERROR, if t, means just return nil (no
1814 error) if the search fails. If neither nil nor t, set point to LIMIT
1815 and return nil.
1816
1817 Optional fourth argument COUNT is a repeat count--search for
1818 successive occurrences.
1819
1764 Optional fifth argument BUFFER specifies the buffer to search in and 1820 Optional fifth argument BUFFER specifies the buffer to search in and
1765 defaults to the current buffer. 1821 defaults to the current buffer.
1822
1766 See also the functions `match-beginning', `match-end' and `replace-match'. 1823 See also the functions `match-beginning', `match-end' and `replace-match'.
1767 */ 1824 */
1768 (regexp, bound, no_error, count, buffer)) 1825 (regexp, limit, noerror, count, buffer))
1769 { 1826 {
1770 return search_command (regexp, bound, no_error, count, buffer, -1, 1, 1); 1827 return search_command (regexp, limit, noerror, count, buffer, -1, 1, 1);
1771 } 1828 }
1772 1829
1773 DEFUN ("posix-search-forward", Fposix_search_forward, 1, 5, "sPosix search: ", /* 1830 DEFUN ("posix-search-forward", Fposix_search_forward, 1, 5, "sPosix search: ", /*
1774 Search forward from point for regular expression REGEXP. 1831 Search forward from point for regular expression REGEXP.
1775 Find the longest match in accord with Posix regular expression rules. 1832 Find the longest match in accord with Posix regular expression rules.
1776 Set point to the end of the occurrence found, and return point. 1833 Set point to the end of the occurrence found, and return point.
1777 An optional second argument bounds the search; it is a buffer position. 1834
1778 The match found must not extend after that position. 1835 Optional second argument LIMIT bounds the search; it is a buffer
1779 Optional third argument, if t, means if fail just return nil (no error). 1836 position. The match found must not extend after that position. The
1780 If not nil and not t, move to limit of search and return nil. 1837 value nil is equivalent to (point-max).
1781 Optional fourth argument is repeat count--search for successive occurrences. 1838
1839 Optional third argument NOERROR, if t, means just return nil (no
1840 error) if the search fails. If neither nil nor t, set point to LIMIT
1841 and return nil.
1842
1843 Optional fourth argument COUNT is a repeat count--search for
1844 successive occurrences.
1845
1782 Optional fifth argument BUFFER specifies the buffer to search in and 1846 Optional fifth argument BUFFER specifies the buffer to search in and
1783 defaults to the current buffer. 1847 defaults to the current buffer.
1848
1784 See also the functions `match-beginning', `match-end' and `replace-match'. 1849 See also the functions `match-beginning', `match-end' and `replace-match'.
1785 */ 1850 */
1786 (regexp, bound, no_error, count, buffer)) 1851 (regexp, limit, noerror, count, buffer))
1787 { 1852 {
1788 return search_command (regexp, bound, no_error, count, buffer, 1, 1, 1); 1853 return search_command (regexp, limit, noerror, count, buffer, 1, 1, 1);
1789 } 1854 }
1790 1855
1791 1856
1792 static Lisp_Object 1857 static Lisp_Object
1793 free_created_dynarrs (Lisp_Object cons) 1858 free_created_dynarrs (Lisp_Object cons)
1799 free_cons (XCONS (cons)); 1864 free_cons (XCONS (cons));
1800 return Qnil; 1865 return Qnil;
1801 } 1866 }
1802 1867
1803 DEFUN ("replace-match", Freplace_match, 1, 5, 0, /* 1868 DEFUN ("replace-match", Freplace_match, 1, 5, 0, /*
1804 Replace text matched by last search with NEWTEXT. 1869 Replace text matched by last search with REPLACEMENT.
1805 If second arg FIXEDCASE is non-nil, do not alter case of replacement text. 1870 If second arg FIXEDCASE is non-nil, do not alter case of replacement text.
1806 Otherwise maybe capitalize the whole text, or maybe just word initials, 1871 Otherwise maybe capitalize the whole text, or maybe just word initials,
1807 based on the replaced text. 1872 based on the replaced text.
1808 If the replaced text has only capital letters 1873 If the replaced text has only capital letters
1809 and has at least one multiletter word, convert NEWTEXT to all caps. 1874 and has at least one multiletter word, convert REPLACEMENT to all caps.
1810 If the replaced text has at least one word starting with a capital letter, 1875 If the replaced text has at least one word starting with a capital letter,
1811 then capitalize each word in NEWTEXT. 1876 then capitalize each word in REPLACEMENT.
1812 1877
1813 If third arg LITERAL is non-nil, insert NEWTEXT literally. 1878 If third arg LITERAL is non-nil, insert REPLACEMENT literally.
1814 Otherwise treat `\\' as special: 1879 Otherwise treat `\\' as special:
1815 `\\&' in NEWTEXT means substitute original matched text. 1880 `\\&' in REPLACEMENT means substitute original matched text.
1816 `\\N' means substitute what matched the Nth `\\(...\\)'. 1881 `\\N' means substitute what matched the Nth `\\(...\\)'.
1817 If Nth parens didn't match, substitute nothing. 1882 If Nth parens didn't match, substitute nothing.
1818 `\\\\' means insert one `\\'. 1883 `\\\\' means insert one `\\'.
1819 `\\u' means upcase the next character. 1884 `\\u' means upcase the next character.
1820 `\\l' means downcase the next character. 1885 `\\l' means downcase the next character.
1829 The optional fourth argument STRING can be a string to modify. 1894 The optional fourth argument STRING can be a string to modify.
1830 In that case, this function creates and returns a new string 1895 In that case, this function creates and returns a new string
1831 which is made by replacing the part of STRING that was matched. 1896 which is made by replacing the part of STRING that was matched.
1832 When fourth argument is a string, fifth argument STRBUFFER specifies 1897 When fourth argument is a string, fifth argument STRBUFFER specifies
1833 the buffer to be used for syntax-table and case-table lookup and 1898 the buffer to be used for syntax-table and case-table lookup and
1834 defaults to the current buffer. (When fourth argument is not a string, 1899 defaults to the current buffer. When fourth argument is not a string,
1835 the buffer that the match occurred in has automatically been remembered 1900 the buffer that the match occurred in has automatically been remembered
1836 and you do not need to specify it.) 1901 and you do not need to specify it.
1837 */ 1902 */
1838 (newtext, fixedcase, literal, string, strbuffer)) 1903 (replacement, fixedcase, literal, string, strbuffer))
1839 { 1904 {
1840 /* This function has been Mule-ized. */ 1905 /* This function has been Mule-ized. */
1841 /* This function can GC */ 1906 /* This function can GC */
1842 enum { nochange, all_caps, cap_initial } case_action; 1907 enum { nochange, all_caps, cap_initial } case_action;
1843 Bufpos pos, last; 1908 Bufpos pos, last;
1853 Lisp_Object buffer; 1918 Lisp_Object buffer;
1854 int_dynarr *ul_action_dynarr = 0; 1919 int_dynarr *ul_action_dynarr = 0;
1855 int_dynarr *ul_pos_dynarr = 0; 1920 int_dynarr *ul_pos_dynarr = 0;
1856 int speccount; 1921 int speccount;
1857 1922
1858 CHECK_STRING (newtext); 1923 CHECK_STRING (replacement);
1859 1924
1860 if (! NILP (string)) 1925 if (! NILP (string))
1861 { 1926 {
1862 CHECK_STRING (string); 1927 CHECK_STRING (string);
1863 if (!EQ (last_thing_searched, Qt)) 1928 if (!EQ (last_thing_searched, Qt))
1977 2042
1978 speccount = specpdl_depth (); 2043 speccount = specpdl_depth ();
1979 before = Fsubstring (string, Qzero, make_int (search_regs.start[0])); 2044 before = Fsubstring (string, Qzero, make_int (search_regs.start[0]));
1980 after = Fsubstring (string, make_int (search_regs.end[0]), Qnil); 2045 after = Fsubstring (string, make_int (search_regs.end[0]), Qnil);
1981 2046
1982 /* Do case substitution into NEWTEXT if desired. */ 2047 /* Do case substitution into REPLACEMENT if desired. */
1983 if (NILP (literal)) 2048 if (NILP (literal))
1984 { 2049 {
1985 Charcount stlen = XSTRING_CHAR_LENGTH (newtext); 2050 Charcount stlen = XSTRING_CHAR_LENGTH (replacement);
1986 Charcount strpos; 2051 Charcount strpos;
1987 /* XEmacs change: rewrote this loop somewhat to make it 2052 /* XEmacs change: rewrote this loop somewhat to make it
1988 cleaner. Also added \U, \E, etc. */ 2053 cleaner. Also added \U, \E, etc. */
1989 Charcount literal_start = 0; 2054 Charcount literal_start = 0;
1990 /* We build up the substituted string in ACCUM. */ 2055 /* We build up the substituted string in ACCUM. */
2007 /* If SUBSTART is set, we need to also insert the 2072 /* If SUBSTART is set, we need to also insert the
2008 text from SUBSTART to SUBEND in the original string. */ 2073 text from SUBSTART to SUBEND in the original string. */
2009 Charcount substart = -1; 2074 Charcount substart = -1;
2010 Charcount subend = -1; 2075 Charcount subend = -1;
2011 2076
2012 c = string_char (XSTRING (newtext), strpos); 2077 c = string_char (XSTRING (replacement), strpos);
2013 if (c == '\\' && strpos < stlen - 1) 2078 if (c == '\\' && strpos < stlen - 1)
2014 { 2079 {
2015 c = string_char (XSTRING (newtext), ++strpos); 2080 c = string_char (XSTRING (replacement), ++strpos);
2016 if (c == '&') 2081 if (c == '&')
2017 { 2082 {
2018 literal_end = strpos - 1; 2083 literal_end = strpos - 1;
2019 substart = search_regs.start[0]; 2084 substart = search_regs.start[0];
2020 subend = search_regs.end[0]; 2085 subend = search_regs.end[0];
2059 if (literal_end >= 0) 2124 if (literal_end >= 0)
2060 { 2125 {
2061 Lisp_Object literal_text = Qnil; 2126 Lisp_Object literal_text = Qnil;
2062 Lisp_Object substring = Qnil; 2127 Lisp_Object substring = Qnil;
2063 if (literal_end != literal_start) 2128 if (literal_end != literal_start)
2064 literal_text = Fsubstring (newtext, 2129 literal_text = Fsubstring (replacement,
2065 make_int (literal_start), 2130 make_int (literal_start),
2066 make_int (literal_end)); 2131 make_int (literal_end));
2067 if (substart >= 0 && subend != substart) 2132 if (substart >= 0 && subend != substart)
2068 substring = Fsubstring (string, 2133 substring = Fsubstring (string,
2069 make_int (substart), 2134 make_int (substart),
2074 } 2139 }
2075 } 2140 }
2076 2141
2077 if (strpos != literal_start) 2142 if (strpos != literal_start)
2078 /* some literal text at end to be inserted */ 2143 /* some literal text at end to be inserted */
2079 newtext = concat2 (accum, Fsubstring (newtext, 2144 replacement = concat2 (accum, Fsubstring (replacement,
2080 make_int (literal_start), 2145 make_int (literal_start),
2081 make_int (strpos))); 2146 make_int (strpos)));
2082 else 2147 else
2083 newtext = accum; 2148 replacement = accum;
2084 } 2149 }
2150
2151 /* replacement can be nil. */
2152 if (NILP (replacement))
2153 replacement = build_string ("");
2085 2154
2086 if (case_action == all_caps) 2155 if (case_action == all_caps)
2087 newtext = Fupcase (newtext, buffer); 2156 replacement = Fupcase (replacement, buffer);
2088 else if (case_action == cap_initial) 2157 else if (case_action == cap_initial)
2089 newtext = Fupcase_initials (newtext, buffer); 2158 replacement = Fupcase_initials (replacement, buffer);
2090 2159
2091 /* Now finally, we need to process the \U's, \E's, etc. */ 2160 /* Now finally, we need to process the \U's, \E's, etc. */
2092 if (ul_pos_dynarr) 2161 if (ul_pos_dynarr)
2093 { 2162 {
2094 int i = 0; 2163 int i = 0;
2095 int cur_action = 'E'; 2164 int cur_action = 'E';
2096 Charcount stlen = XSTRING_CHAR_LENGTH (newtext); 2165 Charcount stlen = XSTRING_CHAR_LENGTH (replacement);
2097 Charcount strpos; 2166 Charcount strpos;
2098 2167
2099 for (strpos = 0; strpos < stlen; strpos++) 2168 for (strpos = 0; strpos < stlen; strpos++)
2100 { 2169 {
2101 Emchar curchar = string_char (XSTRING (newtext), strpos); 2170 Emchar curchar = string_char (XSTRING (replacement), strpos);
2102 Emchar newchar = -1; 2171 Emchar newchar = -1;
2103 if (i < Dynarr_length (ul_pos_dynarr) && 2172 if (i < Dynarr_length (ul_pos_dynarr) &&
2104 strpos == Dynarr_at (ul_pos_dynarr, i)) 2173 strpos == Dynarr_at (ul_pos_dynarr, i))
2105 { 2174 {
2106 int new_action = Dynarr_at (ul_action_dynarr, i); 2175 int new_action = Dynarr_at (ul_action_dynarr, i);
2120 newchar = DOWNCASE (buf, curchar); 2189 newchar = DOWNCASE (buf, curchar);
2121 else 2190 else
2122 newchar = curchar; 2191 newchar = curchar;
2123 } 2192 }
2124 if (newchar != curchar) 2193 if (newchar != curchar)
2125 set_string_char (XSTRING (newtext), strpos, newchar); 2194 set_string_char (XSTRING (replacement), strpos, newchar);
2126 } 2195 }
2127 } 2196 }
2128 2197
2129 /* frees the Dynarrs if necessary. */ 2198 /* frees the Dynarrs if necessary. */
2130 unbind_to (speccount, Qnil); 2199 unbind_to (speccount, Qnil);
2131 return concat3 (before, newtext, after); 2200 return concat3 (before, replacement, after);
2132 } 2201 }
2133 2202
2134 mc_count = begin_multiple_change (buf, search_regs.start[0], 2203 mc_count = begin_multiple_change (buf, search_regs.start[0],
2135 search_regs.end[0]); 2204 search_regs.end[0]);
2136 2205
2142 delete the original text. This means that markers at the 2211 delete the original text. This means that markers at the
2143 beginning or end of the original will float to the corresponding 2212 beginning or end of the original will float to the corresponding
2144 position in the replacement. */ 2213 position in the replacement. */
2145 BUF_SET_PT (buf, search_regs.start[0]); 2214 BUF_SET_PT (buf, search_regs.start[0]);
2146 if (!NILP (literal)) 2215 if (!NILP (literal))
2147 Finsert (1, &newtext); 2216 Finsert (1, &replacement);
2148 else 2217 else
2149 { 2218 {
2150 Charcount stlen = XSTRING_CHAR_LENGTH (newtext); 2219 Charcount stlen = XSTRING_CHAR_LENGTH (replacement);
2151 Charcount strpos; 2220 Charcount strpos;
2152 struct gcpro gcpro1; 2221 struct gcpro gcpro1;
2153 GCPRO1 (newtext); 2222 GCPRO1 (replacement);
2154 for (strpos = 0; strpos < stlen; strpos++) 2223 for (strpos = 0; strpos < stlen; strpos++)
2155 { 2224 {
2156 Charcount offset = BUF_PT (buf) - search_regs.start[0]; 2225 Charcount offset = BUF_PT (buf) - search_regs.start[0];
2157 2226
2158 c = string_char (XSTRING (newtext), strpos); 2227 c = string_char (XSTRING (replacement), strpos);
2159 if (c == '\\' && strpos < stlen - 1) 2228 if (c == '\\' && strpos < stlen - 1)
2160 { 2229 {
2161 c = string_char (XSTRING (newtext), ++strpos); 2230 c = string_char (XSTRING (replacement), ++strpos);
2162 if (c == '&') 2231 if (c == '&')
2163 Finsert_buffer_substring 2232 Finsert_buffer_substring
2164 (buffer, 2233 (buffer,
2165 make_int (search_regs.start[0] + offset), 2234 make_int (search_regs.start[0] + offset),
2166 make_int (search_regs.end[0] + offset)); 2235 make_int (search_regs.end[0] + offset));
2496 /* Quote a string to inactivate reg-expr chars */ 2565 /* Quote a string to inactivate reg-expr chars */
2497 2566
2498 DEFUN ("regexp-quote", Fregexp_quote, 1, 1, 0, /* 2567 DEFUN ("regexp-quote", Fregexp_quote, 1, 1, 0, /*
2499 Return a regexp string which matches exactly STRING and nothing else. 2568 Return a regexp string which matches exactly STRING and nothing else.
2500 */ 2569 */
2501 (str)) 2570 (string))
2502 { 2571 {
2503 REGISTER Bufbyte *in, *out, *end; 2572 REGISTER Bufbyte *in, *out, *end;
2504 REGISTER Bufbyte *temp; 2573 REGISTER Bufbyte *temp;
2505 2574
2506 CHECK_STRING (str); 2575 CHECK_STRING (string);
2507 2576
2508 temp = (Bufbyte *) alloca (XSTRING_LENGTH (str) * 2); 2577 temp = (Bufbyte *) alloca (XSTRING_LENGTH (string) * 2);
2509 2578
2510 /* Now copy the data into the new string, inserting escapes. */ 2579 /* Now copy the data into the new string, inserting escapes. */
2511 2580
2512 in = XSTRING_DATA (str); 2581 in = XSTRING_DATA (string);
2513 end = in + XSTRING_LENGTH (str); 2582 end = in + XSTRING_LENGTH (string);
2514 out = temp; 2583 out = temp;
2515 2584
2516 while (in < end) 2585 while (in < end)
2517 { 2586 {
2518 Emchar c = charptr_emchar (in); 2587 Emchar c = charptr_emchar (in);