diff options
| author | Karl Heuer | 1994-06-12 19:58:00 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-06-12 19:58:00 +0000 |
| commit | 03240d11038e8c52fe56a07685b6191009dd2b10 (patch) | |
| tree | f163c557f17a9633f882ec7f4363e9c71dbcb553 /src | |
| parent | a2570ea9dff54e834b85b989aa31c4ca28c28de6 (diff) | |
| download | emacs-03240d11038e8c52fe56a07685b6191009dd2b10.tar.gz emacs-03240d11038e8c52fe56a07685b6191009dd2b10.zip | |
(transpose_markers): Allow for gap at start of region.
(Ftranspose_regions): Don't precompute pointers into buffer text.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 86 |
1 files changed, 38 insertions, 48 deletions
diff --git a/src/editfns.c b/src/editfns.c index 8b0158c322b..8a7becbcc33 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -1626,11 +1626,7 @@ Case is ignored if `case-fold-search' is non-nil in the current buffer.") | |||
| 1626 | appropriate amount to some, subtracting from some, and leaving the | 1626 | appropriate amount to some, subtracting from some, and leaving the |
| 1627 | rest untouched. Most of this is copied from adjust_markers in insdel.c. | 1627 | rest untouched. Most of this is copied from adjust_markers in insdel.c. |
| 1628 | 1628 | ||
| 1629 | It's caller's job to see that (start1 <= end1 <= start2 <= end2), | 1629 | It's the caller's job to see that (start1 <= end1 <= start2 <= end2). */ |
| 1630 | and that the buffer gap will not conflict with the markers. This | ||
| 1631 | last requirement is odd and maybe should be taken out, but it works | ||
| 1632 | for now because Ftranspose_regions does in fact guarantee that, in | ||
| 1633 | addition to providing universal health-care coverage. */ | ||
| 1634 | 1630 | ||
| 1635 | void | 1631 | void |
| 1636 | transpose_markers (start1, end1, start2, end2) | 1632 | transpose_markers (start1, end1, start2, end2) |
| @@ -1638,10 +1634,8 @@ transpose_markers (start1, end1, start2, end2) | |||
| 1638 | { | 1634 | { |
| 1639 | register int amt1, amt2, diff, mpos; | 1635 | register int amt1, amt2, diff, mpos; |
| 1640 | register Lisp_Object marker; | 1636 | register Lisp_Object marker; |
| 1641 | register struct Lisp_Marker *m; | ||
| 1642 | 1637 | ||
| 1643 | /* Update point as if it were a marker. | 1638 | /* Update point as if it were a marker. */ |
| 1644 | Do this before adjusting the start/end values for the gap. */ | ||
| 1645 | if (PT < start1) | 1639 | if (PT < start1) |
| 1646 | ; | 1640 | ; |
| 1647 | else if (PT < end1) | 1641 | else if (PT < end1) |
| @@ -1651,25 +1645,13 @@ transpose_markers (start1, end1, start2, end2) | |||
| 1651 | else if (PT < end2) | 1645 | else if (PT < end2) |
| 1652 | TEMP_SET_PT (PT - (start2 - start1)); | 1646 | TEMP_SET_PT (PT - (start2 - start1)); |
| 1653 | 1647 | ||
| 1654 | /* Internally, marker positions take the gap into account, so if the | 1648 | /* We used to adjust the endpoints here to account for the gap, but that |
| 1655 | * gap is before one or both of the regions, the region's limits | 1649 | isn't good enough. Even if we assume the caller has tried to move the |
| 1656 | * must be adjusted to compensate. The caller guaranteed that the | 1650 | gap out of our way, it might still be at start1 exactly, for example; |
| 1657 | * gap is not inside any of the regions, however, so this is fairly | 1651 | and that places it `inside' the interval, for our purposes. The amount |
| 1658 | * simple. | 1652 | of adjustment is nontrivial if there's a `denormalized' marker whose |
| 1659 | */ | 1653 | position is between GPT and GPT + GAP_SIZE, so it's simpler to leave |
| 1660 | if (GPT < start1) | 1654 | the dirty work to Fmarker_position, below. */ |
| 1661 | { | ||
| 1662 | register int gs = GAP_SIZE; | ||
| 1663 | start1 += gs; end1 += gs; | ||
| 1664 | start2 += gs; end2 += gs; | ||
| 1665 | } | ||
| 1666 | else if (GPT < start2) | ||
| 1667 | { | ||
| 1668 | /* If the regions are of equal size, the gap could, in theory, | ||
| 1669 | * be somewhere between them. */ | ||
| 1670 | register int gs = GAP_SIZE; | ||
| 1671 | start2 += gs; end2 += gs; | ||
| 1672 | } | ||
| 1673 | 1655 | ||
| 1674 | /* The difference between the region's lengths */ | 1656 | /* The difference between the region's lengths */ |
| 1675 | diff = (end2 - start2) - (end1 - start1); | 1657 | diff = (end2 - start2) - (end1 - start1); |
| @@ -1680,25 +1662,21 @@ transpose_markers (start1, end1, start2, end2) | |||
| 1680 | amt1 = (end2 - start2) + (start2 - end1); | 1662 | amt1 = (end2 - start2) + (start2 - end1); |
| 1681 | amt2 = (end1 - start1) + (start2 - end1); | 1663 | amt2 = (end1 - start1) + (start2 - end1); |
| 1682 | 1664 | ||
| 1683 | marker = current_buffer->markers; | 1665 | for (marker = current_buffer->markers; !NILP (marker); |
| 1684 | 1666 | marker = XMARKER (marker)->chain) | |
| 1685 | while (!NILP (marker)) | ||
| 1686 | { | 1667 | { |
| 1687 | m = XMARKER (marker); | 1668 | mpos = Fmarker_position (marker); |
| 1688 | mpos = m->bufpos; | 1669 | if (mpos >= start1 && mpos < end2) |
| 1689 | if (mpos >= start1 && mpos < end1) /* in region 1 */ | 1670 | { |
| 1690 | { | 1671 | if (mpos < end1) |
| 1691 | m->bufpos += amt1; | 1672 | mpos += amt1; |
| 1692 | } | 1673 | else if (mpos < start2) |
| 1693 | else if (mpos >= start2 && mpos < end2) /* in region 2 */ | 1674 | mpos += diff; |
| 1694 | { | 1675 | else |
| 1695 | m->bufpos -= amt2; | 1676 | mpos -= amt2; |
| 1696 | } | 1677 | if (mpos > GPT) mpos += GAP_SIZE; |
| 1697 | else if (mpos >= end1 && mpos < start2) /* between the regions */ | 1678 | XMARKER (marker)->bufpos = mpos; |
| 1698 | { | 1679 | } |
| 1699 | m->bufpos += diff; | ||
| 1700 | } | ||
| 1701 | marker = m->chain; | ||
| 1702 | } | 1680 | } |
| 1703 | } | 1681 | } |
| 1704 | 1682 | ||
| @@ -1782,9 +1760,6 @@ Transposing beyond buffer boundaries is an error.") | |||
| 1782 | else | 1760 | else |
| 1783 | move_gap (end2); | 1761 | move_gap (end2); |
| 1784 | } | 1762 | } |
| 1785 | |||
| 1786 | start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); | ||
| 1787 | start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); | ||
| 1788 | 1763 | ||
| 1789 | /* Hmmm... how about checking to see if the gap is large | 1764 | /* Hmmm... how about checking to see if the gap is large |
| 1790 | enough to use as the temporary storage? That would avoid an | 1765 | enough to use as the temporary storage? That would avoid an |
| @@ -1813,6 +1788,13 @@ Transposing beyond buffer boundaries is an error.") | |||
| 1813 | temp = (unsigned char *) xmalloc (len2); | 1788 | temp = (unsigned char *) xmalloc (len2); |
| 1814 | else | 1789 | else |
| 1815 | temp = (unsigned char *) alloca (len2); | 1790 | temp = (unsigned char *) alloca (len2); |
| 1791 | |||
| 1792 | /* Don't precompute these addresses. We have to compute them | ||
| 1793 | at the last minute, because the relocating allocator might | ||
| 1794 | have moved the buffer around during the xmalloc. */ | ||
| 1795 | start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); | ||
| 1796 | start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); | ||
| 1797 | |||
| 1816 | bcopy (start2_addr, temp, len2); | 1798 | bcopy (start2_addr, temp, len2); |
| 1817 | bcopy (start1_addr, start1_addr + len2, len1); | 1799 | bcopy (start1_addr, start1_addr + len2, len1); |
| 1818 | bcopy (temp, start1_addr, len2); | 1800 | bcopy (temp, start1_addr, len2); |
| @@ -1826,6 +1808,8 @@ Transposing beyond buffer boundaries is an error.") | |||
| 1826 | temp = (unsigned char *) xmalloc (len1); | 1808 | temp = (unsigned char *) xmalloc (len1); |
| 1827 | else | 1809 | else |
| 1828 | temp = (unsigned char *) alloca (len1); | 1810 | temp = (unsigned char *) alloca (len1); |
| 1811 | start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); | ||
| 1812 | start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); | ||
| 1829 | bcopy (start1_addr, temp, len1); | 1813 | bcopy (start1_addr, temp, len1); |
| 1830 | bcopy (start2_addr, start1_addr, len2); | 1814 | bcopy (start2_addr, start1_addr, len2); |
| 1831 | bcopy (temp, start1_addr + len2, len1); | 1815 | bcopy (temp, start1_addr + len2, len1); |
| @@ -1860,6 +1844,8 @@ Transposing beyond buffer boundaries is an error.") | |||
| 1860 | temp = (unsigned char *) xmalloc (len1); | 1844 | temp = (unsigned char *) xmalloc (len1); |
| 1861 | else | 1845 | else |
| 1862 | temp = (unsigned char *) alloca (len1); | 1846 | temp = (unsigned char *) alloca (len1); |
| 1847 | start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); | ||
| 1848 | start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); | ||
| 1863 | bcopy (start1_addr, temp, len1); | 1849 | bcopy (start1_addr, temp, len1); |
| 1864 | bcopy (start2_addr, start1_addr, len2); | 1850 | bcopy (start2_addr, start1_addr, len2); |
| 1865 | bcopy (temp, start2_addr, len1); | 1851 | bcopy (temp, start2_addr, len1); |
| @@ -1891,6 +1877,8 @@ Transposing beyond buffer boundaries is an error.") | |||
| 1891 | temp = (unsigned char *) xmalloc (len2); | 1877 | temp = (unsigned char *) xmalloc (len2); |
| 1892 | else | 1878 | else |
| 1893 | temp = (unsigned char *) alloca (len2); | 1879 | temp = (unsigned char *) alloca (len2); |
| 1880 | start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); | ||
| 1881 | start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); | ||
| 1894 | bcopy (start2_addr, temp, len2); | 1882 | bcopy (start2_addr, temp, len2); |
| 1895 | bcopy (start1_addr, start1_addr + len_mid + len2, len1); | 1883 | bcopy (start1_addr, start1_addr + len_mid + len2, len1); |
| 1896 | safe_bcopy (start1_addr + len1, start1_addr + len2, len_mid); | 1884 | safe_bcopy (start1_addr + len1, start1_addr + len2, len_mid); |
| @@ -1925,6 +1913,8 @@ Transposing beyond buffer boundaries is an error.") | |||
| 1925 | temp = (unsigned char *) xmalloc (len1); | 1913 | temp = (unsigned char *) xmalloc (len1); |
| 1926 | else | 1914 | else |
| 1927 | temp = (unsigned char *) alloca (len1); | 1915 | temp = (unsigned char *) alloca (len1); |
| 1916 | start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1); | ||
| 1917 | start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2); | ||
| 1928 | bcopy (start1_addr, temp, len1); | 1918 | bcopy (start1_addr, temp, len1); |
| 1929 | bcopy (start2_addr, start1_addr, len2); | 1919 | bcopy (start2_addr, start1_addr, len2); |
| 1930 | bcopy (start1_addr + len1, start1_addr + len2, len_mid); | 1920 | bcopy (start1_addr + len1, start1_addr + len2, len_mid); |