aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorRichard M. Stallman1998-02-08 21:10:31 +0000
committerRichard M. Stallman1998-02-08 21:10:31 +0000
commitb05525fa0df8a7a71a1b66c1e22860194bd6421c (patch)
tree17e7eeb88e3091eefcb79d5f54dd83ecbb302f8b /src/buffer.c
parent53f76081244f064f1df4b83ef9e2df30efa29b18 (diff)
downloademacs-b05525fa0df8a7a71a1b66c1e22860194bd6421c.tar.gz
emacs-b05525fa0df8a7a71a1b66c1e22860194bd6421c.zip
(advance_to_char_boundary): New function.
(Fset_buffer_multibyte): Advance all byte-positions to char boundaries. Clear undo list.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/buffer.c b/src/buffer.c
index a623fd5eba3..4f0cc9a1eff 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1672,6 +1672,30 @@ validate_region (b, e)
1672 args_out_of_range (*b, *e); 1672 args_out_of_range (*b, *e);
1673} 1673}
1674 1674
1675/* Advance BYTE_POS up to a character boundary
1676 and return the adjusted position. */
1677
1678static int
1679advance_to_char_boundary (byte_pos)
1680 int byte_pos;
1681{
1682 int pos = byte_pos;
1683
1684 while (1)
1685 {
1686 int c = FETCH_BYTE (pos);
1687 if (SINGLE_BYTE_CHAR_P (c))
1688 break;
1689 if (c == LEADING_CODE_COMPOSITION)
1690 break;
1691 if (BYTES_BY_CHAR_HEAD (c) > 1)
1692 break;
1693 pos++;
1694 }
1695
1696 return pos;
1697}
1698
1675DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte, Sset_buffer_multibyte, 1699DEFUN ("set-buffer-multibyte", Fset_buffer_multibyte, Sset_buffer_multibyte,
1676 1, 1, 0, 1700 1, 1, 0,
1677 "Set the multibyte flag of the current buffer to FLAG.\n\ 1701 "Set the multibyte flag of the current buffer to FLAG.\n\
@@ -1684,6 +1708,11 @@ but the contents viewed as characters do change.")
1684{ 1708{
1685 Lisp_Object tail, markers; 1709 Lisp_Object tail, markers;
1686 1710
1711 /* It would be better to update the list,
1712 but this is good enough for now. */
1713 if (! EQ (current_buffer->undo_list, Qt))
1714 current_buffer->undo_list = Qnil;
1715
1687 /* If the cached position is for this buffer, clear it out. */ 1716 /* If the cached position is for this buffer, clear it out. */
1688 clear_charpos_cache (current_buffer); 1717 clear_charpos_cache (current_buffer);
1689 1718
@@ -1714,27 +1743,43 @@ but the contents viewed as characters do change.")
1714 set_intervals_multibyte needs it too. */ 1743 set_intervals_multibyte needs it too. */
1715 current_buffer->enable_multibyte_characters = Qt; 1744 current_buffer->enable_multibyte_characters = Qt;
1716 1745
1746 GPT_BYTE = advance_to_char_boundary (GPT_BYTE);
1717 GPT = chars_in_text (BEG_ADDR, GPT_BYTE - BEG_BYTE) + BEG; 1747 GPT = chars_in_text (BEG_ADDR, GPT_BYTE - BEG_BYTE) + BEG;
1748
1718 Z = chars_in_text (GPT_ADDR, Z_BYTE - GPT_BYTE) + GPT; 1749 Z = chars_in_text (GPT_ADDR, Z_BYTE - GPT_BYTE) + GPT;
1750
1751 BEGV_BYTE = advance_to_char_boundary (BEGV_BYTE);
1719 if (BEGV_BYTE > GPT_BYTE) 1752 if (BEGV_BYTE > GPT_BYTE)
1720 BEGV = chars_in_text (GPT_ADDR, BEGV_BYTE - GPT_BYTE) + GPT; 1753 BEGV = chars_in_text (GPT_ADDR, BEGV_BYTE - GPT_BYTE) + GPT;
1721 else 1754 else
1722 BEGV = chars_in_text (BEG_ADDR, BEGV_BYTE - BEG_BYTE) + BEG; 1755 BEGV = chars_in_text (BEG_ADDR, BEGV_BYTE - BEG_BYTE) + BEG;
1756
1757 ZV_BYTE = advance_to_char_boundary (ZV_BYTE);
1723 if (ZV_BYTE > GPT_BYTE) 1758 if (ZV_BYTE > GPT_BYTE)
1724 ZV = chars_in_text (GPT_ADDR, ZV_BYTE - GPT_BYTE) + GPT; 1759 ZV = chars_in_text (GPT_ADDR, ZV_BYTE - GPT_BYTE) + GPT;
1725 else 1760 else
1726 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG; 1761 ZV = chars_in_text (BEG_ADDR, ZV_BYTE - BEG_BYTE) + BEG;
1727 if (PT_BYTE > GPT_BYTE) 1762
1728 current_buffer->pt = chars_in_text (GPT_ADDR, PT_BYTE - GPT_BYTE) + GPT; 1763 {
1729 else 1764 int pt_byte = advance_to_char_boundary (PT_BYTE);
1730 current_buffer->pt = chars_in_text (BEG_ADDR, PT_BYTE - BEG_BYTE) + BEG; 1765 int pt;
1766
1767 if (pt_byte > GPT_BYTE)
1768 pt = chars_in_text (GPT_ADDR, pt_byte - GPT_BYTE) + GPT;
1769 else
1770 pt = chars_in_text (BEG_ADDR, pt_byte - BEG_BYTE) + BEG;
1771 TEMP_SET_PT_BOTH (pt, pt_byte);
1772 }
1731 1773
1732 tail = markers = BUF_MARKERS (current_buffer); 1774 tail = markers = BUF_MARKERS (current_buffer);
1733 BUF_MARKERS (current_buffer) = Qnil; 1775 BUF_MARKERS (current_buffer) = Qnil;
1734 1776
1735 while (XSYMBOL (tail) != XSYMBOL (Qnil)) 1777 while (XSYMBOL (tail) != XSYMBOL (Qnil))
1736 { 1778 {
1779 XMARKER (tail)->bytepos
1780 = advance_to_char_boundary (XMARKER (tail)->bytepos);
1737 XMARKER (tail)->charpos = BYTE_TO_CHAR (XMARKER (tail)->bytepos); 1781 XMARKER (tail)->charpos = BYTE_TO_CHAR (XMARKER (tail)->bytepos);
1782
1738 tail = XMARKER (tail)->chain; 1783 tail = XMARKER (tail)->chain;
1739 } 1784 }
1740 BUF_MARKERS (current_buffer) = markers; 1785 BUF_MARKERS (current_buffer) = markers;