comparison src/editfns.c @ 377:d883f39b8495 r21-2b4

Import from CVS: tag r21-2b4
author cvs
date Mon, 13 Aug 2007 11:05:42 +0200
parents cc15677e0335
children 8626e4521993
comparison
equal deleted inserted replaced
376:e2295b4d9f2e 377:d883f39b8495
37 #include "events.h" /* for EVENTP */ 37 #include "events.h" /* for EVENTP */
38 #include "extents.h" 38 #include "extents.h"
39 #include "frame.h" 39 #include "frame.h"
40 #include "insdel.h" 40 #include "insdel.h"
41 #include "window.h" 41 #include "window.h"
42 #include "chartab.h"
42 #include "line-number.h" 43 #include "line-number.h"
43 44
44 #include "systime.h" 45 #include "systime.h"
45 #include "sysdep.h" 46 #include "sysdep.h"
46 #include "syspwd.h" 47 #include "syspwd.h"
1620 1621
1621 get_buffer_range_char (b, start, end, &begv, &zv, GB_ALLOW_NIL); 1622 get_buffer_range_char (b, start, end, &begv, &zv, GB_ALLOW_NIL);
1622 return make_string_from_buffer (b, begv, zv - begv); 1623 return make_string_from_buffer (b, begv, zv - begv);
1623 } 1624 }
1624 1625
1626 /* It might make more sense to name this
1627 `buffer-substring-no-extents', but this name is FSFmacs-compatible,
1628 and what the function does is probably good enough for what the
1629 user-code will typically want to use it for. */
1630 DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties, 0, 3, 0, /*
1631 Return the text from BEG to END, as a string, without copying the extents.
1632 */
1633 (start, end, buffer))
1634 {
1635 /* This function can GC */
1636 Bufpos begv, zv;
1637 struct buffer *b = decode_buffer (buffer, 1);
1638
1639 get_buffer_range_char (b, start, end, &begv, &zv, GB_ALLOW_NIL);
1640 return make_string_from_buffer_no_extents (b, begv, zv - begv);
1641 }
1642
1625 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, 1, 3, 0, /* 1643 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, 1, 3, 0, /*
1626 Insert before point a substring of the contents of buffer BUFFER. 1644 Insert before point a substring of the contents of buffer BUFFER.
1627 BUFFER may be a buffer or a buffer name. 1645 BUFFER may be a buffer or a buffer name.
1628 Arguments START and END are character numbers specifying the substring. 1646 Arguments START and END are character numbers specifying the substring.
1629 They default to the beginning and the end of BUFFER. 1647 They default to the beginning and the end of BUFFER.
1781 1799
1782 unbind_to (count, Qnil); 1800 unbind_to (count, Qnil);
1783 return Qnil; 1801 return Qnil;
1784 } 1802 }
1785 1803
1804 /* #### Shouldn't this also accept a BUFFER argument, in the good old
1805 XEmacs tradition? */
1786 DEFUN ("translate-region", Ftranslate_region, 3, 3, 0, /* 1806 DEFUN ("translate-region", Ftranslate_region, 3, 3, 0, /*
1787 From START to END, translate characters according to TABLE. 1807 Translate characters from START to END according to TABLE.
1788 TABLE is a string; the Nth character in it is the mapping 1808
1789 for the character with code N. Returns the number of characters changed. 1809 If TABLE is a string, the Nth character in it is the mapping for the
1810 character with code N.
1811
1812 If TABLE is a vector, its Nth element is the mapping for character
1813 with code N. The values of elements may be characters, strings, or
1814 nil (nil meaning don't replace.)
1815
1816 If TABLE is a char-table, its elements describe the mapping between
1817 characters and their replacements. The char-table should be of type
1818 `char' or `generic'.
1819
1820 Returns the number of substitutions performed.
1790 */ 1821 */
1791 (start, end, table)) 1822 (start, end, table))
1792 { 1823 {
1793 /* This function can GC */ 1824 /* This function can GC */
1794 Bufpos pos, stop; /* Limits of the region. */ 1825 Bufpos pos, stop; /* Limits of the region. */
1795 REGISTER Emchar oc; /* Old character. */ 1826 int cnt = 0; /* Number of changes made. */
1796 REGISTER Emchar nc; /* New character. */
1797 int cnt; /* Number of changes made. */
1798 Charcount size; /* Size of translate table. */
1799 int mc_count; 1827 int mc_count;
1800 struct buffer *buf = current_buffer; 1828 struct buffer *buf = current_buffer;
1829 Emchar oc;
1801 1830
1802 get_buffer_range_char (buf, start, end, &pos, &stop, 0); 1831 get_buffer_range_char (buf, start, end, &pos, &stop, 0);
1803 CHECK_STRING (table);
1804
1805 size = XSTRING_CHAR_LENGTH (table);
1806
1807 cnt = 0;
1808 mc_count = begin_multiple_change (buf, pos, stop); 1832 mc_count = begin_multiple_change (buf, pos, stop);
1809 for (; pos < stop; pos++) 1833 if (STRINGP (table))
1810 { 1834 {
1811 oc = BUF_FETCH_CHAR (buf, pos); 1835 struct Lisp_String *stable = XSTRING (table);
1812 if (oc >= 0 && oc < size) 1836 Charcount size = string_char_length (stable);
1837 #ifdef MULE
1838 /* Under Mule, string_char(n) is O(n), so for large tables or
1839 large regions it makes sense to create an array of Emchars. */
1840 if (size * (stop - pos) > 65536)
1813 { 1841 {
1814 nc = string_char (XSTRING (table), oc); 1842 Emchar *etable = alloca_array (Emchar, size);
1815 if (nc != oc) 1843 convert_bufbyte_string_into_emchar_string
1844 (string_data (stable), string_length (stable), etable);
1845 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++)
1816 { 1846 {
1817 buffer_replace_char (buf, pos, nc, 0, 0); 1847 if (oc < size)
1848 {
1849 Emchar nc = etable[oc];
1850 if (nc != oc)
1851 {
1852 buffer_replace_char (buf, pos, nc, 0, 0);
1853 ++cnt;
1854 }
1855 }
1856 }
1857 }
1858 else
1859 #endif /* MULE */
1860 {
1861 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++)
1862 {
1863 if (oc < size)
1864 {
1865 Emchar nc = string_char (stable, oc);
1866 if (nc != oc)
1867 {
1868 buffer_replace_char (buf, pos, nc, 0, 0);
1869 ++cnt;
1870 }
1871 }
1872 }
1873 }
1874 }
1875 else if (VECTORP (table))
1876 {
1877 Charcount size = XVECTOR_LENGTH (table);
1878 Lisp_Object *vtable = XVECTOR_DATA (table);
1879
1880 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++)
1881 {
1882 if (oc < size)
1883 {
1884 Lisp_Object replacement = vtable[oc];
1885 retry:
1886 if (CHAR_OR_CHAR_INTP (replacement))
1887 {
1888 Emchar nc = XCHAR_OR_CHAR_INT (replacement);
1889 if (nc != oc)
1890 {
1891 buffer_replace_char (buf, pos, nc, 0, 0);
1892 ++cnt;
1893 }
1894 }
1895 else if (STRINGP (replacement))
1896 {
1897 Charcount incr = XSTRING_CHAR_LENGTH (replacement) - 1;
1898 buffer_delete_range (buf, pos, pos + 1, 0);
1899 buffer_insert_lisp_string_1 (buf, pos, replacement, 0);
1900 pos += incr, stop += incr;
1901 ++cnt;
1902 }
1903 else if (!NILP (replacement))
1904 {
1905 replacement = wrong_type_argument (Qchar_or_string_p, replacement);
1906 goto retry;
1907 }
1908 }
1909 }
1910 }
1911 else if (CHAR_TABLEP (table)
1912 && (XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_GENERIC
1913 || XCHAR_TABLE_TYPE (table) == CHAR_TABLE_TYPE_CHAR))
1914 {
1915 struct Lisp_Char_Table *ctable = XCHAR_TABLE (table);
1916
1917 for (; pos < stop && (oc = BUF_FETCH_CHAR (buf, pos), 1); pos++)
1918 {
1919 Lisp_Object replacement = get_char_table (oc, ctable);
1920 retry2:
1921 if (CHAR_OR_CHAR_INTP (replacement))
1922 {
1923 Emchar nc = XCHAR_OR_CHAR_INT (replacement);
1924 if (nc != oc)
1925 {
1926 buffer_replace_char (buf, pos, nc, 0, 0);
1927 ++cnt;
1928 }
1929 }
1930 else if (STRINGP (replacement))
1931 {
1932 Charcount incr = XSTRING_CHAR_LENGTH (replacement) - 1;
1933 buffer_delete_range (buf, pos, pos + 1, 0);
1934 buffer_insert_lisp_string_1 (buf, pos, replacement, 0);
1935 pos += incr, stop += incr;
1818 ++cnt; 1936 ++cnt;
1819 } 1937 }
1938 else if (!NILP (replacement))
1939 {
1940 replacement = wrong_type_argument (Qchar_or_string_p, replacement);
1941 goto retry2;
1942 }
1820 } 1943 }
1821 } 1944 }
1945 else
1946 dead_wrong_type_argument (Qstringp, table);
1822 end_multiple_change (buf, mc_count); 1947 end_multiple_change (buf, mc_count);
1823 1948
1824 return make_int (cnt); 1949 return make_int (cnt);
1825 } 1950 }
1826 1951
2261 DEFSUBR (Fchar_Equal); 2386 DEFSUBR (Fchar_Equal);
2262 DEFSUBR (Fgoto_char); 2387 DEFSUBR (Fgoto_char);
2263 DEFSUBR (Fstring_to_char); 2388 DEFSUBR (Fstring_to_char);
2264 DEFSUBR (Fchar_to_string); 2389 DEFSUBR (Fchar_to_string);
2265 DEFSUBR (Fbuffer_substring); 2390 DEFSUBR (Fbuffer_substring);
2391 DEFSUBR (Fbuffer_substring_no_properties);
2266 2392
2267 DEFSUBR (Fpoint_marker); 2393 DEFSUBR (Fpoint_marker);
2268 DEFSUBR (Fmark_marker); 2394 DEFSUBR (Fmark_marker);
2269 DEFSUBR (Fpoint); 2395 DEFSUBR (Fpoint);
2270 DEFSUBR (Fregion_beginning); 2396 DEFSUBR (Fregion_beginning);