7246c817a2c93d695636958154276a16836abba7
[sxemacs] / info / lispref / annotations.texi
1 @c -*-texinfo-*-
2 @c This is part of the SXEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 @c Copyright (C) 1995 Ben Wing.
5 @c Copyright (C) 2005 Sebastian Freundt <hroptatyr@sxemacs.org>
6 @c See the file lispref.texi for copying conditions.
7 @setfilename ../../info/annotations.info
8
9 @node Annotations, Display, Glyphs, top
10 @chapter Annotations
11 @cindex annotation
12
13 An @dfn{annotation} is a pixmap or string that is not part of a buffer's
14 text but is displayed next to a particular location in a buffer.
15 Annotations can be displayed intermixed with text, in any whitespace at
16 the beginning or end of a line, or in a special area at the left or
17 right side of the frame called a @dfn{margin}, whose size is
18 controllable.  Annotations are implemented using extents
19 (@pxref{Extents}); but you can work with annotations without knowing how
20 extents work.
21
22 @menu
23 * Annotation Basics::           Introduction to annotations.
24 * Annotation Primitives::       Creating and deleting annotations.
25 * Annotation Properties::       Retrieving and changing the characteristics
26                                   of an annotation.
27 * Margin Primitives::           Controlling the size of the margins.
28 * Locating Annotations::        Looking for annotations in a buffer.
29 * Annotation Hooks::            Hooks called at certain times during an
30                                   annotation's lifetime.
31 @end menu
32
33 @node Annotation Basics
34 @section Annotation Basics
35
36 @cindex margin
37 Marginal annotations are notes associated with a particular location in
38 a buffer.  They may be displayed in a margin created on the left-hand or
39 right-hand side of the frame, in any whitespace at the beginning or end
40 of a line, or inside of the text itself.  Every annotation may have an
41 associated action to be performed when the annotation is selected.  The
42 term @dfn{annotation} is used to refer to an individual note.  The term
43 @dfn{margin} is generically used to refer to the whitespace before the
44 first character on a line or after the last character on a line.
45
46 Each annotation has the following characteristics:
47 @table @var
48 @item glyph
49 This is a glyph object and is used as the displayed representation
50 of the annotation.
51 @item down-glyph
52 If given, this glyph is used as the displayed representation
53 of the annotation when the mouse is pressed down over the annotation.
54 @item face
55 The face with which to display the glyph.
56 @item side
57 Which side of the text (left or right) the annotation is displayed at.
58 @item action
59 If non-@code{nil}, this field must contain a function capable of being
60 the first argument to @code{funcall}.  This function is normally
61 evaluated with a single argument, the value of the @var{data} field,
62 each time the annotation is selected.  However, if the @var{with-event}
63 parameter to @code{make-annotation} is non-@code{nil}, the function
64 is called with two arguments.  The first argument is the same as
65 before, and the second argument is the event (a button-up event,
66 usually) that activated the annotation.
67 @item data
68 Not used internally.  This field can contain any elisp object.  It is
69 passed as the first argument to @var{action} described above.
70 @item menu
71 A menu displayed when the right mouse button is pressed over the
72 annotation.
73 @end table
74
75 @cindex outside margin
76 @cindex inside margin
77 The margin is divided into @dfn{outside} and @dfn{inside}.  The outside
78 margin is space on the left or right side of the frame which normal text
79 cannot be displayed in.  The inside margin is that space between the
80 leftmost or rightmost point at which text can be displayed and where the
81 first or last character actually is.
82
83 @cindex layout types
84 There are four different @dfn{layout types} which affect the exact
85 location an annotation appears.
86
87 @table @code
88 @item outside-margin
89 The annotation is placed in the outside margin area. as close as
90 possible to the edge of the frame.  If the outside margin is not wide
91 enough for an annotation to fit, it is not displayed.
92
93 @item inside-margin
94 The annotation is placed in the inside margin area, as close as possible
95 to the edge of the frame.  If the inside margin is not wide enough for
96 the annotation to fit, it will be displayed using any available outside
97 margin space if and only if the specifier @code{use-left-overflow} or
98 @code{use-right-overflow} (depending on which side the annotation
99 appears in) is non-@code{nil}.
100
101 @item whitespace
102 The annotation is placed in the inside margin area, as close as possible
103 to the first or last non-whitespace character on a line.  If the inside
104 margin is not wide enough for the annotation to fit, it will be
105 displayed if and only if the specifier @code{use-left-overflow} or
106 @code{use-right-overflow} (depending on which side the annotation
107 appears in) is non-@code{nil}.
108
109 @item text
110 The annotation is placed at the position it is inserted.  It will create
111 enough space for itself inside of the text area.  It does not take up a
112 place in the logical buffer, only in the display of the buffer.
113 @end table
114
115 @cindex layout policy
116 The current layout policy is that all @code{whitespace} annotations are
117 displayed first.  Next, all @code{inside-margin} annotations are
118 displayed using any remaining space.  Finally as many
119 @code{outside-margin} annotations are displayed as possible.  The
120 @code{text} annotations will always display as they create their own
121 space to display in.
122
123
124 @node Annotation Primitives
125 @section Annotation Primitives
126
127 @defun make-annotation glyph &optional position layout buffer with-event d-glyph rightp
128 This function creates a marginal annotation at position @var{position} in
129 @var{buffer}.  The annotation is displayed using @var{glyph}, which
130 should be a glyph object or a string, and is positioned using layout
131 policy @var{layout}.  If @var{position} is @code{nil}, point is used.  If
132 @var{layout} is @code{nil}, @code{whitespace} is used.  If @var{buffer}
133 is @code{nil}, the current buffer is used.
134
135 If @var{with-event} is non-@code{nil}, then when an annotation is
136 activated, the triggering event is passed as the second arg to the
137 annotation function.  If @var{d-glyph} is non-@code{nil} then it is used
138 as the glyph that will be displayed when button1 is down.  If
139 @var{rightp} is non-@code{nil} then the glyph will be displayed on the
140 right side of the buffer instead of the left.
141
142 The newly created annotation is returned.
143 @end defun
144
145 @defun delete-annotation annotation
146 This function removes @var{annotation} from its buffer.  This does not
147 modify the buffer text.
148 @end defun
149
150 @defun annotationp annotation
151 This function returns @code{t} if @var{annotation} is an annotation,
152 @code{nil} otherwise.
153 @end defun
154
155 @node Annotation Properties
156 @section Annotation Properties
157
158 @defun annotation-glyph annotation
159 This function returns the glyph object used to display @var{annotation}.
160 @end defun
161
162 @defun set-annotation-glyph annotation glyph &optional layout side
163 This function sets the glyph of @var{annotation} to @var{glyph}, which
164 should be a glyph object.  If @var{layout} is non-@code{nil}, set the
165 layout policy of @var{annotation} to @var{layout}.  If @var{side} is
166 @code{left} or @code{right}, change the side of the buffer at which the
167 annotation is displayed to the given side.  The new value of
168 @code{annotation-glyph} is returned.
169 @end defun
170
171 @defun annotation-down-glyph annotation
172 This function returns the glyph used to display @var{annotation} when
173 the left mouse button is depressed on the annotation.
174 @end defun
175
176 @defun set-annotation-down-glyph annotation glyph
177 This function returns the glyph used to display @var{annotation} when
178 the left mouse button is depressed on the annotation to @var{glyph},
179 which should be a glyph object.
180 @end defun
181
182 @defun annotation-face annotation
183 This function returns the face associated with @var{annotation}.
184 @end defun
185
186 @defun set-annotation-face annotation face
187 This function sets the face associated with @var{annotation} to
188 @var{face}.
189 @end defun
190
191 @defun annotation-layout annotation
192 This function returns the layout policy of @var{annotation}.
193 @end defun
194
195 @defun set-annotation-layout annotation layout
196 This function sets the layout policy of @var{annotation} to
197 @var{layout}.
198 @end defun
199
200 @defun annotation-side annotation
201 This function returns the side of the buffer that @var{annotation} is
202 displayed on.  Return value is a symbol, either @code{left} or
203 @code{right}.
204 @end defun
205
206 @defun annotation-data annotation
207 This function returns the data associated with @var{annotation}.
208 @end defun
209
210 @defun set-annotation-data annotation data
211 This function sets the data field of @var{annotation} to @var{data}.
212 @var{data} is returned.
213 @end defun
214
215 @defun annotation-action annotation
216 This function returns the action associated with @var{annotation}.
217 @end defun
218
219 @defun set-annotation-action annotation action
220 This function sets the action field of @var{annotation} to @var{action}.
221 @var{action} is returned..
222 @end defun
223
224 @defun annotation-menu annotation
225 This function returns the menu associated with @var{annotation}.
226 @end defun
227
228 @defun set-annotation-menu annotation menu
229 This function sets the menu associated with @var{annotation} to
230 @var{menu}.  This menu will be displayed when the right mouse button is
231 pressed over the annotation.
232 @end defun
233
234 @defun annotation-visible annotation
235 This function returns @code{t} if there is enough available space to
236 display @var{annotation}, @code{nil} otherwise.
237 @end defun
238
239 @defun annotation-width annotation
240 This function returns the width of @var{annotation} in pixels.
241 @end defun
242
243 @defun hide-annotation annotation
244 This function removes @var{annotation}'s glyph, making it invisible.
245 @end defun
246
247 @defun reveal-annotation annotation
248 This function restores @var{annotation}'s glyph, making it visible.
249 @end defun
250
251
252 @node Locating Annotations
253 @section Locating Annotations
254
255 @defun annotations-in-region start end buffer
256 This function returns a list of all annotations in @var{buffer} which
257 are between @var{start} and @var{end} inclusively.
258 @end defun
259
260 @defun annotations-at &optional position buffer
261 This function returns a list of all annotations at @var{position} in
262 @var{buffer}.  If @var{position} is @code{nil} point is used.  If
263 @var{buffer} is @code{nil} the current buffer is used.
264 @end defun
265
266 @defun annotation-list &optional buffer
267 This function returns a list of all annotations in @var{buffer}.  If
268 @var{buffer} is @code{nil}, the current buffer is used.
269 @end defun
270
271 @defun all-annotations
272 This function returns a list of all annotations in all buffers in
273 existence.
274 @end defun
275
276
277 @node Margin Primitives
278 @section Margin Primitives
279 @cindex margin width
280
281 The margin widths are controllable on a buffer-local, window-local,
282 frame-local, device-local, or device-type-local basis through the
283 use of specifiers.  @xref{Specifiers}.
284
285 @defvr Specifier left-margin-width
286 This is a specifier variable controlling the width of the left outside
287 margin, in characters.  Use @code{set-specifier} to change its value.
288 @end defvr
289
290 @defvr Specifier right-margin-width
291 This is a specifier variable controlling the width of the right outside
292 margin, in characters.  Use @code{set-specifier} to change its value.
293 @end defvr
294
295 @defvr Specifier use-left-overflow
296 If non-@code{nil}, use the left outside margin as extra whitespace when
297 displaying @code{whitespace} and @code{inside-margin} annotations.
298 Defaults to @code{nil}.  This is a specifier variable; use
299 @code{set-specifier} to change its value.
300 @end defvr
301
302 @defvr Specifier use-right-overflow
303 If non-@code{nil}, use the right outside margin as extra whitespace when
304 displaying @code{whitespace} and @code{inside-margin} annotations.
305 Defaults to @code{nil}.  This is a specifier variable; use
306 @code{set-specifier} to change its value.
307 @end defvr
308
309 @defun window-left-margin-pixel-width &optional window
310 This function returns the width in pixels of the left outside margin of
311 @var{window}.  If @var{window} is @code{nil}, the selected window is
312 assumed.
313 @end defun
314
315 @defun window-right-margin-pixel-width &optional window
316 This function returns the width in pixels of the right outside margin of
317 @var{window}.  If @var{window} is @code{nil}, the selected window is
318 assumed.
319 @end defun
320
321 The margin colors are controlled by the faces @code{left-margin} and
322 @code{right-margin}.  These can be set using the X resources
323 @code{Emacs.left-margin.background} and
324 @code{Emacs.left-margin.foreground}; likewise for the right margin.
325
326
327 @node Annotation Hooks
328 @section Annotation Hooks
329 @cindex annotation hooks
330
331 The following three hooks are provided for use with the marginal annotations:
332
333 @table @code
334 @item before-delete-annotation-hook
335 This hook is called immediately before an annotation is destroyed.  It
336 is passed a single argument, the annotation being destroyed.
337
338 @item after-delete-annotation-hook
339 This normal hook is called immediately after an annotation is destroyed.
340
341 @item make-annotation-hook
342 This hook is called immediately after an annotation is created.  It is
343 passed a single argument, the newly created annotation.
344 @end table