category.h 4.5 KB
Newer Older
Karl Heuer's avatar
Karl Heuer committed
1
/* Declarations having to do with Emacs category tables.
Kenichi Handa's avatar
Kenichi Handa committed
2
   Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3
     2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Kenichi Handa's avatar
Kenichi Handa committed
4 5
     National Institute of Advanced Industrial Science and Technology (AIST)
     Registration Number H14PRO021
Kenichi Handa's avatar
Kenichi Handa committed
6
   Copyright (C) 2003
7 8
     National Institute of Advanced Industrial Science and Technology (AIST)
     Registration Number H13PRO009
Karl Heuer's avatar
Karl Heuer committed
9 10 11

This file is part of GNU Emacs.

12
GNU Emacs is free software: you can redistribute it and/or modify
Karl Heuer's avatar
Karl Heuer committed
13
it under the terms of the GNU General Public License as published by
14 15
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
Karl Heuer's avatar
Karl Heuer committed
16 17 18 19 20 21 22

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
23
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
Karl Heuer's avatar
Karl Heuer committed
24

25 26
#ifndef EMACS_CATEGORY_H
#define EMACS_CATEGORY_H
Karl Heuer's avatar
Karl Heuer committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

/* We introduce here three types of object: category, category set,
   and category table.

   A category is like syntax but differs in the following points:

   o A category is represented by a mnemonic character of the range
   ` '(32)..`~'(126) (printable ASCII characters).

   o A category is not exclusive, i.e. a character has multiple
   categories (category set).  Of course, there's a case that a
   category set is empty, i.e. the character has no category.

   o In addition to the predefined categories, a user can define new
   categories.  Total number of categories is limited to 95.

   A category set is a set of categories represented by Lisp
44
   bool-vector of length 128 (only elements of 31th through 126th
Karl Heuer's avatar
Karl Heuer committed
45 46 47 48
   are used).

   A category table is like syntax-table, represented by a Lisp
   char-table.  The contents are category sets or nil.  It has two
49
   extra slots, for a vector of doc string of each category and a
Karl Heuer's avatar
Karl Heuer committed
50 51 52 53 54 55 56 57
   version number.

   The first extra slot is a vector of doc strings of categories, the
   length is 95.  The Nth element corresponding to the category N+32.

   The second extra slot is a version number of the category table.
   But, for the moment, we are not using this slot.  */

58 59
#include "lisp.h"

60 61
INLINE_HEADER_BEGIN

62
#define CATEGORYP(x) RANGED_INTEGERP (0x20, x, 0x7E)
Karl Heuer's avatar
Karl Heuer committed
63

64 65
#define CHECK_CATEGORY(x) \
  CHECK_TYPE (CATEGORYP (x), Qcategoryp, x)
Karl Heuer's avatar
Karl Heuer committed
66 67

#define CATEGORY_SET_P(x) \
68
  (BOOL_VECTOR_P (x) && bool_vector_size (x) == 128)
Karl Heuer's avatar
Karl Heuer committed
69 70 71 72

/* Return a new empty category set.  */
#define MAKE_CATEGORY_SET (Fmake_bool_vector (make_number (128), Qnil))

73 74
#define CHECK_CATEGORY_SET(x) \
  CHECK_TYPE (CATEGORY_SET_P (x), Qcategorysetp, x)
Karl Heuer's avatar
Karl Heuer committed
75

76 77 78
/* Return the category set of character C in the current category table.  */
#define CATEGORY_SET(c) char_category_set (c)

79
/* Return true if CATEGORY_SET contains CATEGORY.
80 81 82 83 84 85
   Faster than '!NILP (Faref (category_set, make_number (category)))'.  */
INLINE bool
CATEGORY_MEMBER (EMACS_INT category, Lisp_Object category_set)
{
  return bool_vector_bitref (category_set, category);
}
Karl Heuer's avatar
Karl Heuer committed
86

87
/* Return true if category set of CH contains CATEGORY.  */
Paul Eggert's avatar
Paul Eggert committed
88
INLINE bool
89 90 91 92 93
CHAR_HAS_CATEGORY (int ch, int category)
{
  Lisp_Object category_set = CATEGORY_SET (ch);
  return CATEGORY_MEMBER (category, category_set);
}
Karl Heuer's avatar
Karl Heuer committed
94 95 96

/* The standard category table is stored where it will automatically
   be used in all new buffers.  */
Tom Tromey's avatar
Tom Tromey committed
97
#define Vstandard_category_table BVAR (&buffer_defaults, category_table)
Karl Heuer's avatar
Karl Heuer committed
98 99

/* Return the doc string of CATEGORY in category table TABLE.  */
100 101 102 103 104 105
#define CATEGORY_DOCSTRING(table, category)				\
  AREF (Fchar_table_extra_slot (table, make_number (0)), ((category) - ' '))

/* Set the doc string of CATEGORY to VALUE in category table TABLE.  */
#define SET_CATEGORY_DOCSTRING(table, category, value)			\
  ASET (Fchar_table_extra_slot (table, make_number (0)), ((category) - ' '), value)
Karl Heuer's avatar
Karl Heuer committed
106 107 108 109

/* Return the version number of category table TABLE.  Not used for
   the moment.  */
#define CATEGORY_TABLE_VERSION (table) \
110
  Fchar_table_extra_slot (table, make_number (1))
Karl Heuer's avatar
Karl Heuer committed
111

112 113
/* Return true if there is a word boundary between two
   word-constituent characters C1 and C2 if they appear in this order.
Kenichi Handa's avatar
Kenichi Handa committed
114 115
   There is no word boundary between two word-constituent ASCII and
   Latin-1 characters.  */
Karl Heuer's avatar
Karl Heuer committed
116 117 118
#define WORD_BOUNDARY_P(c1, c2)					\
  (!(SINGLE_BYTE_CHAR_P (c1) && SINGLE_BYTE_CHAR_P (c2))	\
   && word_boundary_p (c1, c2))
119

120
extern bool word_boundary_p (int, int);
121 122

INLINE_HEADER_END
123 124

#endif /* EMACS_CATEGORY_H */