home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / src / buffer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-13  |  10.7 KB  |  317 lines

  1. /* Header file for the buffer manipulation primitives.
  2.    Copyright (C) 1985-1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef _EMACS_BUFFER_H_
  21. #define _EMACS_BUFFER_H_
  22.  
  23. #ifdef lint
  24. #include "undo.h"
  25. #endif /* lint */
  26.  
  27.  
  28. #define SET_PT(arg) (set_point ((arg)))
  29. #define SET_BUF_PT(buf, value) (set_buffer_point ((buf),(value)))
  30.  
  31. /* Character position of beginning of buffer.  */ 
  32. #define BEG (1)
  33.  
  34. /* Character position of beginning of accessible range of buffer.  */ 
  35. #define BEGV (current_buffer->text.begv)
  36.  
  37. /* Character position of point in buffer.  */ 
  38. #define PT (current_buffer->text.pt)
  39.  
  40. /* Character position of gap in buffer.  */ 
  41. #define GPT (current_buffer->text.gpt)
  42.  
  43. /* Character position of end of accessible range of buffer.  */ 
  44. #define ZV (current_buffer->text.zv)
  45.  
  46. /* Character position of end of buffer.  */ 
  47. #define Z (current_buffer->text.z)
  48.  
  49. /* Modification count.  */
  50. #define MODIFF (current_buffer->text.modiff)
  51.  
  52. /* Face changed.  */
  53. #define FACECHANGE (current_buffer->text.face_change)
  54.  
  55. /* Address of beginning of buffer.  */ 
  56. #define BEG_ADDR (current_buffer->text.beg)
  57.  
  58. /* Address of beginning of accessible range of buffer.  */ 
  59. #define BEGV_ADDR (CHAR_ADDRESS (current_buffer->text.begv))
  60.  
  61. /* Address of point in buffer.  */ 
  62. #define PT_ADDR (CHAR_ADDRESS (current_buffer->text.pt))
  63.  
  64. /* Address of beginning of gap in buffer.  */ 
  65. #define GPT_ADDR (current_buffer->text.beg + current_buffer->text.gpt - 1)
  66.  
  67. /* Address of end of gap in buffer.  */
  68. #define GAP_END_ADDR (current_buffer->text.beg + current_buffer->text.gpt + current_buffer->text.gap_size - 1)
  69.  
  70. /* Address of end of accessible range of buffer.  */ 
  71. #define ZV_ADDR (&CHAR_AT_POSITION (current_buffer->text.zv))
  72.  
  73. /* Size of gap.  */
  74. #define GAP_SIZE (current_buffer->text.gap_size)
  75.  
  76.  
  77. #define POINT_MARKER_P(marker) \
  78.    (XMARKER (marker)->buffer != 0 && \
  79.     EQ ((marker), XMARKER (marker)->buffer->point_marker))
  80.  
  81.  
  82. /* Now similar macros for a specified buffer.
  83.    Note that many of these evaluate the buffer argument more than once.  */
  84.  
  85. /* Character position of beginning of buffer.  */ 
  86. #define BUF_BEG(buf) (1)
  87.  
  88. /* Character position of beginning of accessible range of buffer.  */ 
  89. #define BUF_BEGV(buf) ((buf)->text.begv)
  90.  
  91. /* Character position of point in buffer.  */ 
  92. #define BUF_PT(buf) ((buf)->text.pt)
  93.  
  94. /* Character position of gap in buffer.  */ 
  95. #define BUF_GPT(buf) ((buf)->text.gpt)
  96.  
  97. /* Character position of end of accessible range of buffer.  */ 
  98. #define BUF_ZV(buf) ((buf)->text.zv)
  99.  
  100. /* Character position of end of buffer.  */ 
  101. #define BUF_Z(buf) ((buf)->text.z)
  102.  
  103. /* Modification count.  */
  104. #define BUF_MODIFF(buf) ((buf)->text.modiff)
  105.  
  106. /* Face changed.  */
  107. #define BUF_FACECHANGE(buf) ((buf)->text.face_change)
  108.  
  109. /* Address of beginning of buffer.  */
  110. #define BUF_BEG_ADDR(buf) ((buf)->text.beg)
  111.  
  112. /* Macro for setting the value of BUF_ZV (BUF) to VALUE,
  113.    by varying the end of the accessible region.  */
  114. #define SET_BUF_ZV(buf, value) ((buf)->text.zv = (value))
  115.  
  116. /* Size of gap.  */
  117. #define BUF_GAP_SIZE(buf) ((buf)->text.gap_size)
  118.  
  119.  
  120. /* Macros from translating between position, pointer, and char. */
  121.  
  122.  
  123. /* Generate the position in buffer, taking the gap into account. */
  124. #define BUF_TRUE_POS(buf, pos) ((pos) >= BUF_GPT ((buf)) ? \
  125.                 ((pos) + BUF_GAP_SIZE ((buf))) : (pos))
  126.  
  127. /* Address of character at position POS in buffer BUF. */
  128. #define BUF_CHAR_ADDRESS(buf, pos) ((buf)->text.beg \
  129.                     + (BUF_TRUE_POS ((buf), (pos))) - 1)
  130.  
  131. /* The character at position POS in BUF. */
  132. #define BUF_CHAR_AT(buf, pos) (*BUF_CHAR_ADDRESS ((buf), (pos)))
  133.  
  134. /* Address of character at position POS in current buffer. */
  135. #define CHAR_ADDRESS(pos) (BUF_CHAR_ADDRESS ((current_buffer), (pos)))
  136.  
  137. /* Character at position n in current buffer.  No range checking */
  138. #define CHAR_AT(n) (*CHAR_ADDRESS ((n)))
  139.  
  140. /* Convert the address of a char in the buffer into a character position.  */
  141. #define PTR_CHAR_POS(ptr) \
  142. ((ptr) - (current_buffer)->text.beg - (ptr - (current_buffer)->text.beg < (unsigned) GPT ? 0 : GAP_SIZE))
  143.  
  144. struct buffer_text
  145.   {
  146.     unsigned char *beg;        /* Actual address of buffer contents. */    
  147.     int begv;            /* Index of beginning of accessible range. */
  148.     int pt;            /* Position of point in buffer. */
  149.     int gpt;            /* Index of gap in buffer. */
  150.     int zv;            /* Index of end of accessible range. */
  151.     int z;            /* Index of end of buffer. */
  152.     int gap_size;        /* Size of buffer's gap */
  153.     int modiff;            /* This counts buffer-modification events
  154.                    for this buffer.  It is incremented for
  155.                    each such event, and never otherwise
  156.                    changed.  */
  157.     int face_change;        /* This is set when a change in how the text
  158.                    should be displayed (e.g., font, color)
  159.                    is made. */
  160.   };
  161.  
  162. struct buffer
  163.   {
  164.     /* Everything before the `name' slot must be of a non-Lisp_Object type,
  165.        and every slot after `name' must be a Lisp_Object.
  166.  
  167.        Check out mark_buffer (alloc.c) to see why.
  168.      */
  169.  
  170.     /* This structure holds the coordinates of the buffer contents.  */
  171.     struct buffer_text text;
  172.  
  173.     /* Next buffer, in chain of all buffers including killed buffers.
  174.        This chain is used only for garbage collection, in order to
  175.        collect killed buffers properly.  */
  176.     struct buffer *next;
  177.  
  178.     /* Flags saying which DEFVAR_PER_BUFFER variables
  179.        are local to this buffer.  */
  180.     int local_var_flags;
  181.  
  182.     /* Value of text.modiff when buffer last saved */
  183.     int save_modified;
  184.  
  185.     /* Set to the modtime of the visited file when read or written.
  186.        -1 means visited file was nonexistent.
  187.        0 means visited file modtime unknown; in no case complain
  188.        about any mismatch on next save attempt.  */
  189.     int modtime;
  190.  
  191.     /* the value of text.modiff at the last auto-save. */
  192.     int auto_save_modified;
  193.  
  194.     /* Position in buffer at which display started
  195.        the last time this buffer was displayed */
  196.     int last_window_start;
  197.  
  198.     struct stack_of_extents *cached_stack;
  199.  
  200.     /* These next two are exceptions -- both slots are be handled 
  201.        "specially" by gc_sweep, and their contents are not lisp-accessible 
  202.        as a local variable, but they are Lisp_Objects. */
  203.  
  204.     /* The markers that refer to this buffer.  This
  205.        is actually a single marker -- successive elements in its marker
  206.        `chain' are the other markers referring to this buffer */
  207.     Lisp_Object markers;
  208.  
  209.     /* Active regions in this buffer. */
  210.     Lisp_Object extents;
  211.  
  212.     /* Everything from here down must be a Lisp_Object */
  213.  
  214.     /* the name of this buffer */
  215.     Lisp_Object name;
  216. #undef MARKED_SLOT
  217. #define MARKED_SLOT(x) Lisp_Object x
  218. #include "bufslots.h"
  219. #undef MARKED_SLOT
  220. };
  221.  
  222. #ifdef emacs
  223.  
  224. extern struct buffer *current_buffer;
  225. extern struct buffer *all_buffers;
  226.  
  227. /* This structure holds the default values of the buffer-local variables
  228.    defined with DefBufferLispVar, that have special slots in each buffer.
  229.    The default value occupies the same slot in this structure
  230.    as an individual buffer's value occupies in that buffer.
  231.    Setting the default value also goes through the alist of buffers
  232.    and stores into each buffer that does not say it has a local value.  */
  233.  
  234. extern struct buffer buffer_defaults;
  235.  
  236. /* This structure marks which slots in a buffer have corresponding
  237.    default values in buffer_defaults.
  238.    Each such slot has a nonzero value in this structure.
  239.    The value has only one nonzero bit.
  240.  
  241.    When a buffer has its own local value for a slot,
  242.    the bit for that slot (found in the same slot in this structure)
  243.    is turned on in the buffer's local_var_flags slot.
  244.  
  245.    If a slot in this structure is zero, then even though there may
  246.    be a DefBufferLispVar for the slot, there is no default valuefeor it;
  247.    and the corresponding slot in buffer_defaults is not used.  */
  248.  
  249. extern struct buffer buffer_local_flags;
  250.  
  251. /* For each buffer slot, this points to the Lisp symbol name
  252.    for that slot in the current buffer.  It is 0 for slots
  253.    that don't have such names.  */
  254.  
  255. extern struct buffer buffer_local_symbols;
  256.  
  257. /* Point in the current buffer. */
  258. #define point (current_buffer->text.pt)
  259.  
  260. /*  Return the maximum index in the buffer it is safe to scan forwards
  261.     past N to.  This is used to prevent buffer scans from running into
  262.     the gap (see search.c) */
  263. #define BUFFER_CEILING_OF(n) (((n) < GPT && GPT < ZV ? GPT : ZV) - 1)
  264.  
  265. /*  Return the minium index in the buffer it is safe to scan backwards
  266.     past N to. */
  267. #define BUFFER_FLOOR_OF(n) (BEGV <= GPT && GPT <= (n) ? GPT : BEGV)
  268.  
  269. extern void reset_buffer ();
  270.  
  271. /* Functions to call before and after each text change. */
  272. extern Lisp_Object Vbefore_change_function;
  273. extern Lisp_Object Vafter_change_function;
  274. extern Lisp_Object Vfirst_change_function;
  275.  
  276. /* Fields.
  277.  
  278. A field is like a marker but it defines a region rather than a
  279. point.  Like a marker, a field is asocated with a buffer.
  280. The field mechanism uses the marker mechanism in the
  281. sense that its start and end points are maintained as markers
  282. updated in the usual way as the buffer changes.
  283.  
  284. A field can be protected or unprotected.  If it is protected,
  285. no modifications can be made that affect the field in its buffer,
  286. when protected field checking is enabled.
  287.  
  288. Each field also contains an alist, in which you can store
  289. whatever you like.  */
  290.  
  291. /* Slots in a field:  */
  292.  
  293. #define FIELD_BUFFER(f) (XVECTOR(f)->contents[1])
  294. #define FIELD_START_MARKER(f) (XVECTOR(f)->contents[2])
  295. #define FIELD_END_MARKER(f) (XVECTOR(f)->contents[3])
  296. #define FIELD_PROTECTED_FLAG(f) (XVECTOR(f)->contents[4])
  297. #define FIELD_ALIST(f) (XVECTOR(f)->contents[5])
  298.  
  299. /* Allocation of buffer data. */
  300. #ifdef REL_ALLOC
  301. #define BUFFER_ALLOC(data,size) ((unsigned char *) r_alloc (&data, (size)))
  302. #define BUFFER_REALLOC(data,size) ((unsigned char *) r_re_alloc (&data, (size)))
  303. #define BUFFER_FREE(data) (r_alloc_free (&data))
  304. #else
  305. #define BUFFER_ALLOC(data,size) (data = (unsigned char *) xmalloc ((size)))
  306. #define BUFFER_REALLOC(data,size) ((unsigned char *) xrealloc ((data), (size)))
  307. #define BUFFER_FREE(data) (free ((data)))
  308. #endif
  309.  
  310. extern Lisp_Object Vbuffer_alist;
  311. #define internal_set_buffer(b) set_buffer_internal((b)) /*Compatibility*/
  312. extern void set_buffer_internal (struct buffer *b);
  313.  
  314. #endif /* emacs */
  315.  
  316. #endif /* _EMACS_BUFFER_H_ */
  317.