comparison src/buffer.h @ 183:e121b013d1f0 r20-3b18

Import from CVS: tag r20-3b18
author cvs
date Mon, 13 Aug 2007 09:54:23 +0200
parents bfd6434d15b3
children 3d6bfa290dbd
comparison
equal deleted inserted replaced
182:f07455f06202 183:e121b013d1f0
219 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer) 219 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer)
220 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer) 220 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer)
221 221
222 #define BUFFER_LIVE_P(b) (!NILP ((b)->name)) 222 #define BUFFER_LIVE_P(b) (!NILP ((b)->name))
223 extern Lisp_Object Qbuffer_live_p; 223 extern Lisp_Object Qbuffer_live_p;
224 #define CHECK_LIVE_BUFFER(x) \ 224 #define CHECK_LIVE_BUFFER(x) \
225 do { CHECK_BUFFER (x); \ 225 do { CHECK_BUFFER (x); \
226 if (!BUFFER_LIVE_P (XBUFFER (x))) \ 226 if (!BUFFER_LIVE_P (XBUFFER (x))) \
227 dead_wrong_type_argument (Qbuffer_live_p, (x)); \ 227 dead_wrong_type_argument (Qbuffer_live_p, (x)); \
228 } while (0) 228 } while (0)
229 #define CONCHECK_LIVE_BUFFER(x) \ 229 #define CONCHECK_LIVE_BUFFER(x) \
230 do { CONCHECK_BUFFER (x); \ 230 do { CONCHECK_BUFFER (x); \
231 if (!BUFFER_LIVE_P (XBUFFER (x))) \ 231 if (!BUFFER_LIVE_P (XBUFFER (x))) \
232 x = wrong_type_argument (Qbuffer_live_p, (x)); \ 232 x = wrong_type_argument (Qbuffer_live_p, (x)); \
233 } while (0) 233 } while (0)
234 234
235 #define BUFFER_OR_STRING_P(x) (BUFFERP (x) || STRINGP (x)) 235 #define BUFFER_OR_STRING_P(x) (BUFFERP (x) || STRINGP (x))
236 236
237 extern Lisp_Object Qbuffer_or_string_p; 237 extern Lisp_Object Qbuffer_or_string_p;
238 #define CHECK_BUFFER_OR_STRING(x) \ 238 #define CHECK_BUFFER_OR_STRING(x) \
239 do { if (!BUFFER_OR_STRING_P (x)) \ 239 do { if (!BUFFER_OR_STRING_P (x)) \
240 dead_wrong_type_argument (Qbuffer_or_string_p, (x)); \ 240 dead_wrong_type_argument (Qbuffer_or_string_p, (x)); \
241 } while (0) 241 } while (0)
242 #define CONCHECK_BUFFER_OR_STRING(x) \ 242 #define CONCHECK_BUFFER_OR_STRING(x) \
243 do { if (!BUFFER_OR_STRING_P (x)) \ 243 do { if (!BUFFER_OR_STRING_P (x)) \
244 x = wrong_type_argument (Qbuffer_or_string_p, (x)); \ 244 x = wrong_type_argument (Qbuffer_or_string_p, (x)); \
245 } while (0) 245 } while (0)
246 246
247 #define CHECK_LIVE_BUFFER_OR_STRING(x) \ 247 #define CHECK_LIVE_BUFFER_OR_STRING(x) \
248 do { CHECK_BUFFER_OR_STRING (x); \ 248 do { CHECK_BUFFER_OR_STRING (x); \
249 if (BUFFERP (x)) \ 249 if (BUFFERP (x)) \
250 CHECK_LIVE_BUFFER (x); \ 250 CHECK_LIVE_BUFFER (x); \
251 } while (0) 251 } while (0)
252 #define CONCHECK_LIVE_BUFFER_OR_STRING(x) \ 252 #define CONCHECK_LIVE_BUFFER_OR_STRING(x) \
253 do { CONCHECK_BUFFER_OR_STRING (x); \ 253 do { CONCHECK_BUFFER_OR_STRING (x); \
254 if (BUFFERP (x)) \ 254 if (BUFFERP (x)) \
255 CONCHECK_LIVE_BUFFER (x); \ 255 CONCHECK_LIVE_BUFFER (x); \
256 } while (0) 256 } while (0)
257 257
258 258
259 259
260 /* NOTE: In all the following macros, we follow these rules concerning 260 /* NOTE: In all the following macros, we follow these rules concerning
523 523
524 INLINE Emchar charptr_emchar (CONST Bufbyte *ptr); 524 INLINE Emchar charptr_emchar (CONST Bufbyte *ptr);
525 INLINE Emchar 525 INLINE Emchar
526 charptr_emchar (CONST Bufbyte *ptr) 526 charptr_emchar (CONST Bufbyte *ptr)
527 { 527 {
528 if (BYTE_ASCII_P (*ptr)) 528 return BYTE_ASCII_P (*ptr) ?
529 return simple_charptr_emchar (ptr); 529 simple_charptr_emchar (ptr) :
530 else 530 non_ascii_charptr_emchar (ptr);
531 return non_ascii_charptr_emchar (ptr);
532 } 531 }
533 532
534 INLINE Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x); 533 INLINE Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x);
535 INLINE Bytecount 534 INLINE Bytecount
536 set_charptr_emchar (Bufbyte *ptr, Emchar x) 535 set_charptr_emchar (Bufbyte *ptr, Emchar x)
537 { 536 {
538 if (!CHAR_MULTIBYTE_P (x)) 537 return !CHAR_MULTIBYTE_P (x) ?
539 return simple_set_charptr_emchar (ptr, x); 538 simple_set_charptr_emchar (ptr, x) :
540 else 539 non_ascii_set_charptr_emchar (ptr, x);
541 return non_ascii_set_charptr_emchar (ptr, x);
542 } 540 }
543 541
544 INLINE Bytecount charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2); 542 INLINE Bytecount charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
545 INLINE Bytecount 543 INLINE Bytecount
546 charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2) 544 charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2)
547 { 545 {
548 if (BYTE_ASCII_P (*ptr)) 546 return BYTE_ASCII_P (*ptr) ?
549 return simple_charptr_copy_char (ptr, ptr2); 547 simple_charptr_copy_char (ptr, ptr2) :
550 else 548 non_ascii_charptr_copy_char (ptr, ptr2);
551 return non_ascii_charptr_copy_char (ptr, ptr2);
552 } 549 }
553 550
554 #else /* not MULE */ 551 #else /* not MULE */
555 552
556 # define charptr_emchar(ptr) simple_charptr_emchar (ptr) 553 # define charptr_emchar(ptr) simple_charptr_emchar (ptr)
573 570
574 INLINE int valid_char_p (Emchar ch); 571 INLINE int valid_char_p (Emchar ch);
575 INLINE int 572 INLINE int
576 valid_char_p (Emchar ch) 573 valid_char_p (Emchar ch)
577 { 574 {
578 if (ch >= 0 && ch < 0400) 575 return (ch >= 0 && ch <= 255) || non_ascii_valid_char_p (ch);
579 return 1;
580 else
581 return non_ascii_valid_char_p (ch);
582 } 576 }
583 577
584 #else /* not MULE */ 578 #else /* not MULE */
585 579
586 #define valid_char_p(ch) ((unsigned int) (ch) < 0400) 580 #define valid_char_p(ch) ((unsigned int) (ch) <= 255)
587 581
588 #endif /* not MULE */ 582 #endif /* not MULE */
589 583
590 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x))) 584 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x)))
591 585
605 599
606 #define XCHAR_OR_CHAR_INT(obj) XREALINT (obj) 600 #define XCHAR_OR_CHAR_INT(obj) XREALINT (obj)
607 601
608 #endif 602 #endif
609 603
610 #define CHECK_CHAR_COERCE_INT(x) \ 604 #define CHECK_CHAR_COERCE_INT(x) do { \
611 do { if (CHARP (x)) \ 605 if (CHARP (x)) \
612 ; \ 606 ; \
613 else if (CHAR_INTP (x)) \ 607 else if (CHAR_INTP (x)) \
614 x = make_char (XINT (x)); \ 608 x = make_char (XINT (x)); \
615 else \ 609 else \
616 x = wrong_type_argument (Qcharacterp, x); } while (0) 610 x = wrong_type_argument (Qcharacterp, x); \
611 } while (0)
617 612
618 #ifdef MULE 613 #ifdef MULE
619 # define MAX_EMCHAR_LEN 4 614 # define MAX_EMCHAR_LEN 4
620 #else 615 #else
621 # define MAX_EMCHAR_LEN 1 616 # define MAX_EMCHAR_LEN 1
660 INLINE Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr); 655 INLINE Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr);
661 INLINE Bytind 656 INLINE Bytind
662 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr) 657 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr)
663 { 658 {
664 return ((ptr) - (buf)->text->beg + 1 659 return ((ptr) - (buf)->text->beg + 1
665 - ((ptr - (buf)->text->beg + 1) > (buf)->text->gpt 660 - ((ptr - (buf)->text->beg + 1) > (buf)->text->gpt
666 ? (buf)->text->gap_size : 0)); 661 ? (buf)->text->gap_size : 0));
667 } 662 }
668 663
669 #define BUF_PTR_BYTE_POS(buf, ptr) \ 664 #define BUF_PTR_BYTE_POS(buf, ptr) \
670 bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr)) 665 bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr))
671 666
701 696
702 INLINE int valid_memind_p (struct buffer *buf, Memind x); 697 INLINE int valid_memind_p (struct buffer *buf, Memind x);
703 INLINE int 698 INLINE int
704 valid_memind_p (struct buffer *buf, Memind x) 699 valid_memind_p (struct buffer *buf, Memind x)
705 { 700 {
706 if (x >= 1 && x <= (Memind) (buf)->text->gpt) 701 return ((x >= 1 && x <= (Memind) (buf)->text->gpt) ||
707 return 1; 702 (x > (Memind) ((buf)->text->gpt + (buf)->text->gap_size) &&
708 if (x > (Memind) ((buf)->text->gpt + (buf)->text->gap_size) 703 x <= (Memind) ((buf)->text->z + (buf)->text->gap_size)));
709 && x <= (Memind) ((buf)->text->z + (buf)->text->gap_size))
710 return 1;
711 return 0;
712 } 704 }
713 705
714 INLINE Memind bytind_to_memind (struct buffer *buf, Bytind x); 706 INLINE Memind bytind_to_memind (struct buffer *buf, Bytind x);
715 INLINE Memind 707 INLINE Memind
716 bytind_to_memind (struct buffer *buf, Bytind x) 708 bytind_to_memind (struct buffer *buf, Bytind x)
717 { 709 {
718 if (x > (buf)->text->gpt) 710 return (Memind) ((x > (buf)->text->gpt) ? (x + (buf)->text->gap_size) : x);
719 return (Memind) (x + (buf)->text->gap_size);
720 else
721 return (Memind) (x);
722 } 711 }
723 712
724 #ifdef ERROR_CHECK_BUFPOS 713 #ifdef ERROR_CHECK_BUFPOS
725 714
726 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x); 715 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x);
727 INLINE Bytind 716 INLINE Bytind
728 memind_to_bytind (struct buffer *buf, Memind x) 717 memind_to_bytind (struct buffer *buf, Memind x)
729 { 718 {
730 assert (valid_memind_p (buf, x)); 719 assert (valid_memind_p (buf, x));
731 if (x > (Memind) (buf)->text->gpt) 720 return (Bytind) ((x > (Memind) (buf)->text->gpt) ?
732 return (Bytind) (x - (buf)->text->gap_size); 721 x - (buf)->text->gap_size :
733 else 722 x);
734 return (Bytind) (x);
735 } 723 }
736 724
737 #else 725 #else
738 726
739 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x); 727 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x);
740 INLINE Bytind 728 INLINE Bytind
741 memind_to_bytind (struct buffer *buf, Memind x) 729 memind_to_bytind (struct buffer *buf, Memind x)
742 { 730 {
743 if (x > (Memind) (buf)->text->gpt) 731 return (Bytind) ((x > (Memind) (buf)->text->gpt) ?
744 return (Bytind) (x - (buf)->text->gap_size); 732 x - (buf)->text->gap_size :
745 else 733 x);
746 return (Bytind) (x);
747 } 734 }
748 735
749 #endif 736 #endif
750 737
751 #define memind_to_bufpos(buf, x) \ 738 #define memind_to_bufpos(buf, x) \
1095 1082
1096 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ 1083 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
1097 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str) 1084 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str)
1098 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ 1085 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
1099 BI_BUF_CHARPTR_COPY_CHAR (buf, bufpos_to_bytind (buf, pos), str) 1086 BI_BUF_CHARPTR_COPY_CHAR (buf, bufpos_to_bytind (buf, pos), str)
1100
1101
1102 1087
1103 1088
1104 1089
1105 1090
1106 /************************************************************************/ 1091 /************************************************************************/
1503 #if 0 /* FSFmacs */ 1488 #if 0 /* FSFmacs */
1504 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly 1489 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly
1505 does too much stuff, such as moving out of invisible extents. */ 1490 does too much stuff, such as moving out of invisible extents. */
1506 #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer)) 1491 #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer))
1507 #define SET_BUF_PT(buf, value) ((buf)->pt = (value)) 1492 #define SET_BUF_PT(buf, value) ((buf)->pt = (value))
1508 #endif 1493 #endif /* FSFmacs */
1509 1494
1510 /*----------------------------------------------------------------------*/ 1495 /*----------------------------------------------------------------------*/
1511 /* Miscellaneous buffer values */ 1496 /* Miscellaneous buffer values */
1512 /*----------------------------------------------------------------------*/ 1497 /*----------------------------------------------------------------------*/
1513 1498
1514 /* Number of characters in buffer */ 1499 /* Number of characters in buffer */
1515 #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf)) 1500 #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf))
1516 1501
1517 /* Is this buffer narrowed? */ 1502 /* Is this buffer narrowed? */
1518 #define BUF_NARROWED(buf) ((BI_BUF_BEGV (buf) != BI_BUF_BEG (buf)) \ 1503 #define BUF_NARROWED(buf) \
1519 || (BI_BUF_ZV (buf) != BI_BUF_Z (buf))) 1504 ((BI_BUF_BEGV (buf) != BI_BUF_BEG (buf)) || \
1505 (BI_BUF_ZV (buf) != BI_BUF_Z (buf)))
1520 1506
1521 /* Modification count. */ 1507 /* Modification count. */
1522 #define BUF_MODIFF(buf) ((buf)->text->modiff) 1508 #define BUF_MODIFF(buf) ((buf)->text->modiff)
1523 1509
1524 /* Saved modification count. */ 1510 /* Saved modification count. */
1781 ((Emchar) (MIRROR_TRT_TABLE_AS_STRING (table)[ch])) 1767 ((Emchar) (MIRROR_TRT_TABLE_AS_STRING (table)[ch]))
1782 # define SET_MIRROR_TRT_TABLE_CHAR_1(table, ch1, ch2) \ 1768 # define SET_MIRROR_TRT_TABLE_CHAR_1(table, ch1, ch2) \
1783 (MIRROR_TRT_TABLE_AS_STRING (table)[ch1] = (Bufbyte) (ch2)) 1769 (MIRROR_TRT_TABLE_AS_STRING (table)[ch1] = (Bufbyte) (ch2))
1784 #endif 1770 #endif
1785 1771
1786 # define IN_TRT_TABLE_DOMAIN(c) (((unsigned EMACS_INT) (c)) < 0400) 1772 # define IN_TRT_TABLE_DOMAIN(c) (((unsigned EMACS_INT) (c)) <= 255)
1787 1773
1788 #ifdef MULE 1774 #ifdef MULE
1789 #define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \ 1775 #define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \
1790 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_downcase_table) 1776 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_downcase_table)
1791 #define MIRROR_UPCASE_TABLE_AS_STRING(buf) \ 1777 #define MIRROR_UPCASE_TABLE_AS_STRING(buf) \
1807 1793
1808 INLINE Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c); 1794 INLINE Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c);
1809 INLINE Emchar 1795 INLINE Emchar
1810 TRT_TABLE_OF (Lisp_Object trt, Emchar c) 1796 TRT_TABLE_OF (Lisp_Object trt, Emchar c)
1811 { 1797 {
1812 if (IN_TRT_TABLE_DOMAIN (c)) 1798 return IN_TRT_TABLE_DOMAIN (c) ? TRT_TABLE_CHAR_1 (trt, c) : c;
1813 return TRT_TABLE_CHAR_1 (trt, c);
1814 else
1815 return c;
1816 } 1799 }
1817 1800
1818 /* Macros used below. */ 1801 /* Macros used below. */
1819 #define DOWNCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->downcase_table, c) 1802 #define DOWNCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->downcase_table, c)
1820 #define UPCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->upcase_table, c) 1803 #define UPCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->upcase_table, c)
1823 1806
1824 INLINE int UPPERCASEP (struct buffer *buf, Emchar ch); 1807 INLINE int UPPERCASEP (struct buffer *buf, Emchar ch);
1825 INLINE int 1808 INLINE int
1826 UPPERCASEP (struct buffer *buf, Emchar ch) 1809 UPPERCASEP (struct buffer *buf, Emchar ch)
1827 { 1810 {
1828 return (DOWNCASE_TABLE_OF (buf, ch) != ch); 1811 return DOWNCASE_TABLE_OF (buf, ch) != ch;
1829 } 1812 }
1830 1813
1831 /* 1 if CH is lower case. */ 1814 /* 1 if CH is lower case. */
1832 1815
1833 INLINE int LOWERCASEP (struct buffer *buf, Emchar ch); 1816 INLINE int LOWERCASEP (struct buffer *buf, Emchar ch);
1834 INLINE int 1817 INLINE int
1835 LOWERCASEP (struct buffer *buf, Emchar ch) 1818 LOWERCASEP (struct buffer *buf, Emchar ch)
1836 { 1819 {
1837 return (UPCASE_TABLE_OF (buf, ch) != ch && 1820 return (UPCASE_TABLE_OF (buf, ch) != ch &&
1838 DOWNCASE_TABLE_OF (buf, ch) == ch); 1821 DOWNCASE_TABLE_OF (buf, ch) == ch);
1839 } 1822 }
1840 1823
1841 /* 1 if CH is neither upper nor lower case. */ 1824 /* 1 if CH is neither upper nor lower case. */
1842 1825
1843 INLINE int NOCASEP (struct buffer *buf, Emchar ch); 1826 INLINE int NOCASEP (struct buffer *buf, Emchar ch);
1844 INLINE int 1827 INLINE int
1845 NOCASEP (struct buffer *buf, Emchar ch) 1828 NOCASEP (struct buffer *buf, Emchar ch)
1846 { 1829 {
1847 return (UPCASE_TABLE_OF (buf, ch) == ch); 1830 return UPCASE_TABLE_OF (buf, ch) == ch;
1848 } 1831 }
1849 1832
1850 /* Upcase a character, or make no change if that cannot be done. */ 1833 /* Upcase a character, or make no change if that cannot be done. */
1851 1834
1852 INLINE Emchar UPCASE (struct buffer *buf, Emchar ch); 1835 INLINE Emchar UPCASE (struct buffer *buf, Emchar ch);
1853 INLINE Emchar 1836 INLINE Emchar
1854 UPCASE (struct buffer *buf, Emchar ch) 1837 UPCASE (struct buffer *buf, Emchar ch)
1855 { 1838 {
1856 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? 1839 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch;
1857 UPCASE_TABLE_OF (buf, ch) : ch;
1858 } 1840 }
1859 1841
1860 /* Upcase a character known to be not upper case. */ 1842 /* Upcase a character known to be not upper case. */
1861 1843
1862 #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch) 1844 #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch)