source: release/1.6/source/cocoa-ide/hemlock/doc/cim/cim.mss

Last change on this file was 6, checked in by Gary Byers, 21 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 169.2 KB
Line 
1@make[Manual] @comment{-*- Dictionary: /afs/cs/project/clisp/docs/hem/hem; Mode: spell; Package: Hemlock; Log: /usr/lisp/scribe/hem/hem-docs.log -*-}
2@Device[postscript]
3@style(FontFamily = TimesRoman)
4@Style(Spacing = 1.2 lines)
5@Style(StringMax = 5000)
6@style(Hyphenation = On)
7@style(Date="March 1952")
8@use(database "/afs/cs/project/clisp/docs/database/")
9@Style [DoubleSided]
10@Libraryfile[ArpaCredit]
11@Libraryfile[Hem]
12@Libraryfile[Spice]
13@Libraryfile[Uttir]
14
15@String(ReportTitle "Hemlock Command Implementor's Manual")
16
17@comment<
18@begin[TitlePage]
19@begin[TitleBox]
20>
21@blankspace(1.3inches)
22@heading[Hemlock Command Implementor's Manual]
23
24@center[
25@b<Bill Chiles>
26@b<Rob MacLachlan>
27
28@b<@value[date]>
29
30@b<CMU-CS-89-134-R1>
31]
32@comment<@end[TitleBox]>
33@blankspace(2lines)
34@begin[Center]
35School of Computer Science
36Carnegie Mellon University
37Pittsburgh, PA 15213
38@end[Center]
39
40@blankspace(2lines)
41@begin[Center]
42This is a revised version of Technical Report CMU-CS-87-159.
43@end[Center]
44@heading[Abstract]
45@begin(Text, indent 0)
46This document describes how to write commands for the @Hemlock text editor, as
47of version M3.2. @Hemlock is a customizable, extensible text editor whose
48initial command set closely resembles that of ITS/TOPS-20 @Emacs. @Hemlock is
49written in the CMU Common Lisp and has been ported to other implementations.
50@end(Text)
51
52@blankspace(0.5in)
53@begin[ResearchCredit]
54@arpacredit[Contract=Basic87-90]
55@end[ResearchCredit]
56@comment<@end[TitlePage]>
57
58
59@commandstring(dash = "@Y[M]")
60
61
62@Tabclear
63
64@chapter(Introduction)
65
66 @hemlock is a text editor which follows in the tradition of editors
67such as EMACS and the Lisp Machine editor ZWEI. In its basic form,
68@hemlock has almost the same command set as EMACS, and similar
69features such as multiple buffers and windows, extended commands,
70and built in documentation.
71
72Both user extensions and the original commands are written in Lisp,
73therefore a command implementor will have a working knowledge of this
74language. Users not familiar with Lisp need not despair however. Many
75users of Multics EMACS, another text editor written in Lisp, came to learn
76Lisp simply for the purpose of writing their own editor extensions, and
77found, to their surprise, that it was really pretty easy to write simple
78commands.
79
80This document describes the Common Lisp functions, macros and data structures
81that are used to implement new commands. The basic editor consists of a set of
82Lisp utility functions for manipulating buffers and the other data structures
83of the editor as well as handling the display. All user level commands are
84written in terms of these functions. To find out how to define commands see
85chapter @ref[commands].
86
87@chapter(Representation of Text)
88@index (Lines)
89@section(Lines)
90In @hemlock all text is in some @i[line]. Text is broken into lines wherever
91it contains a newline character; newline characters are never stored, but are
92assumed to exist between every pair of lines. The implicit newline character
93is treated as a single character by the text primitives.
94
95@defun[fun {linep}, args {@i[line]}]
96This function returns @true if @i[line] is a @f[line] object, otherwise @nil.
97@enddefun
98
99@defun[fun {line-string}, args {@i[line]}]
100Given a @i(line), this function returns as a simple string the characters in
101the line. This is @f[setf]'able to set the @f[line-string] to any string that
102does not contain newline characters. It is an error to destructively modify
103the result of @f[line-string] or to destructively modify any string after the
104@f[line-string] of some line has been set to that string.
105@enddefun
106
107@defun[fun {line-previous}, args {@i[line]}]
108@defun1[fun {line-next}, args {@i[line]}]
109Given a @i(line), @f[line-previous] returns the previous line or @nil if there
110is no previous line. Similarly, @f[line-next] returns the line following
111@i[line] or @nil.
112@enddefun
113
114@defun[fun {line-buffer}, args {@i[line]}]
115This function returns the buffer which contains this @i(line). Since a
116line may not be associated with any buffer, in which case @f[line-buffer]
117returns @nil.
118@enddefun
119
120@defun[fun {line-length}, args {@i[line]}]
121This function returns the number of characters in the @i(line). This excludes
122the newline character at the end.
123@enddefun
124
125@defun[fun {line-character}, args {@i[line] @i[index]}]
126This function returns the character at position @i[index] within @i[line]. It
127is an error for @i[index] to be greater than the length of the line or less
128than zero. If @i[index] is equal to the length of the line, this returns a
129@f[#\newline] character.
130@enddefun
131
132@defun[fun {line-plist}, args {@i[line]}]
133This function returns the property-list for @i[line]. @f[setf], @f[getf],
134@f[putf] and @f[remf] can be used to change properties. This is typically used
135in conjunction with @f[line-signature] to cache information about the line's
136contents.
137@enddefun
138
139@defun[fun {line-signature}, args {@i[line]}]
140This function returns an object that serves as a signature for a @i[line]'s
141contents. It is guaranteed that any modification of text on the line will
142result in the signature changing so that it is not @f[eql] to any previous
143value. The signature may change even when the text remains unmodified, but
144this does not happen often.
145@enddefun
146
147
148@section(Marks)
149@label[marks]
150@index (Marks)
151A mark indicates a specific position within the text represented by a line and
152a character position within that line. Although a mark is sometimes loosely
153referred to as pointing to some character, it in fact points between
154characters. If the @f[charpos] is zero, the previous character is the newline
155character separating the previous line from the mark's @f[line]. If the
156charpos is equal to the number of characters in the line, the next character is
157the newline character separating the current line from the next. If the mark's
158line has no previous line, a mark with @f[charpos] of zero has no previous
159character; if the mark's line has no next line, a mark with @f[charpos] equal
160to the length of the line has no next character.
161
162This section discusses the very basic operations involving marks, but a lot of
163@hemlock programming is built on altering some text at a mark. For more
164extended uses of marks see chapter @ref[doing-stuff].
165
166
167@subsection(Kinds of Marks)
168@index (Permanent marks)
169@index (Temporary marks)
170A mark may have one of two lifetimes: @i[temporary] or @i[permanent].
171Permanent marks remain valid after arbitrary operations on the text; temporary
172marks do not. Temporary marks are used because less bookkeeping overhead is
173involved in their creation and use. If a temporary mark is used after the text
174it points to has been modified results will be unpredictable. Permanent marks
175continue to point between the same two characters regardless of insertions and
176deletions made before or after them.
177
178There are two different kinds of permanent marks which differ only in their
179behavior when text is inserted @i(at the position of the mark); text is
180inserted to the left of a @i[left-inserting] mark and to the right of
181@i[right-inserting] mark.
182
183
184@subsection(Mark Functions)
185@defun[fun {markp}, args {@i[mark]}]
186This function returns @true if @i[mark] is a @f[mark] object, otherwise @nil.
187@enddefun
188
189@defun[fun {mark-line}, args {@i[mark]}]
190This function returns the line to which @i(mark) points.
191@enddefun
192
193@defun[fun {mark-charpos}, args {@i[mark]}]
194This function returns the character position of the character after @i(mark).
195If @i[mark]'s line has no next line, this returns the length of the line as
196usual; however, there is actually is no character after the mark.
197@enddefun
198
199@defun[fun {mark-kind}, args {@i[mark]}]
200This function returns one of @kwd[right-inserting], @kwd[left-inserting] or
201@kwd[temporary] depending on the mark's kind. A corresponding @f[setf] form
202changes the mark's kind.
203@enddefun
204
205@defun[fun {previous-character}, args {@i[mark]}]
206@defun1[fun {next-character}, args {@i[mark]}]
207This function returns the character immediately before (after) the position of
208the @i[mark], or @nil if there is no previous (next) character. These
209characters may be set with @f[setf] when they exist; the @f[setf] methods for
210these forms signal errors when there is no previous or next character.
211@enddefun
212
213
214@subsection(Making Marks)
215@defun[fun {mark}, args {@i[line] @i[charpos] @optional @i[kind]}]
216This function returns a mark object that points to the @i(charpos)'th character
217of the @i(line). @i(Kind) is the kind of mark to create, one of
218@kwd[temporary], @kwd[left-inserting], or @kwd[right-inserting]. The default
219is @kwd[temporary].
220@enddefun
221
222@defun[fun {copy-mark}, args {@i[mark] @optional @i[kind]}]
223This function returns a new mark pointing to the same position and of the same
224kind, or of kind @i[kind] if it is supplied.
225@enddefun
226
227@defun[fun {delete-mark}, args {@i[mark]}]
228This function deletes @i(mark). Delete any permanent marks when you are
229finished using it.
230@enddefun
231
232@Defmac[Fun {with-mark}, Args
233 {(@Mstar<(@i[mark] @i[pos] @mopt[@i(kind)])>) @Mstar<@i[form]>}]
234 This macro binds to each variable @i[mark] a mark of kind @i[kind], which
235defaults to @kwd[temporary], pointing to the same position as the mark @i[pos].
236On exit from the scope the mark is deleted. The value of the last @i[form] is
237the value returned.
238@enddefmac
239
240
241@subsection(Moving Marks)
242@index(Moving marks)
243These functions destructively modify marks to point to new positions. Other
244sections of this document describe mark moving routines specific to higher
245level text forms than characters and lines, such as words, sentences,
246paragraphs, Lisp forms, etc.
247
248@defun[fun {move-to-position}, args {@i[mark] @i[charpos] @optional @i[line]}]
249This function changes the @i(mark) to point to the given character position on
250the line @i(line). @i(Line) defaults to @i[mark]'s line.
251@enddefun
252
253@defun[fun {move-mark}, args {@i[mark] @i[new-position]}]
254This function moves @i[mark] to the same position as the mark @i[new-position]
255and returns it.
256@enddefun
257
258@defun[fun {line-start}, args {@i[mark] @optional @i[line]}]
259@defun1[fun {line-end}, args {@i[mark] @optional @i[line]}]
260This function changes @i[mark] to point to the beginning or the end of @i(line)
261and returns it. @i[Line] defaults to @i[mark]'s line.
262@enddefun
263
264@defun[fun {buffer-start}, args {@i[mark] @optional @i[buffer]}]
265@defun1[fun {buffer-end}, args {@i[mark] @optional @i[buffer]}]
266These functions change @i[mark] to point to the beginning or end of @i[buffer],
267which defaults to the buffer @i[mark] currently points into. If @i[buffer] is
268unsupplied, then it is an error for @i[mark] to be disassociated from any
269buffer.
270@enddefun
271
272@defun[fun {mark-before}, args {@i[mark]}]
273@defun1[fun {mark-after}, args {@i[mark]}]
274These functions change @i[mark] to point one character before or after the
275current position. If there is no character before/after the current position,
276then they return @nil and leave @i[mark] unmodified.
277@enddefun
278
279@defun[fun {character-offset}, args {@i[mark] @i[n]}]
280This function changes @i[mark] to point @i[n] characters after (@i[n] before if
281@i[n] is negative) the current position. If there are less than @i[n]
282characters after (before) the @i[mark], then this returns @nil and @i[mark] is
283unmodified.
284@enddefun
285
286@defun[fun {line-offset}, args {@i[mark] @i[n] @optional @i[charpos]}]
287This function changes @i[mark] to point @i[n] lines after (@i[n] before if
288@i[n] is negative) the current position. The character position of the
289resulting mark is
290@lisp
291(min (line-length @i(resulting-line)) (mark-charpos @i(mark)))
292@endlisp
293if @i[charpos] is unspecified, or
294@lisp
295(min (line-length @i(resulting-line)) @i(charpos))
296@endlisp
297if it is. As with @funref(character-offset), if there are not @i[n] lines then
298@nil is returned and @i[mark] is not modified.
299@enddefun
300
301
302@section(Regions)
303@index (Regions)
304A region is simply a pair of marks: a starting mark and an ending mark.
305The text in a region consists of the characters following the starting
306mark and preceding the ending mark (keep in mind that a mark points between
307characters on a line, not at them).
308
309By modifying the starting or ending mark in a region it is possible to
310produce regions with a start and end which are out of order or even in
311different buffers. The use of such regions is undefined and may
312result in arbitrarily bad behavior.
313
314
315@subsection(Region Functions)
316@defun[fun {region}, args {@i[start] @i[end]}]
317This function returns a region constructed from the marks @i[start] and
318@i[end]. It is an error for the marks to point to non-contiguous lines or for
319@i(start) to come after @i(end).
320@enddefun
321
322@defun[fun {regionp}, args {@i[region]}]
323This function returns @true if @i[region] is a @f[region] object, otherwise
324@nil.
325@enddefun
326
327@defun[fun {make-empty-region}]
328This function returns a region with start and end marks pointing to the start
329of one empty line. The start mark is a @kwd[right-inserting] mark, and the end
330is a @kwd[left-inserting] mark.
331@enddefun
332
333@defun[fun {copy-region}, args {@i[region]}]
334This function returns a region containing a copy of the text in the specified
335@i[region]. The resulting region is completely disjoint from @i[region] with
336respect to data references @dash marks, lines, text, etc.
337@enddefun
338
339@defun[fun {region-to-string}, args {@i[region]}]
340@defun1[fun {string-to-region}, args {@i[string]}]
341These functions coerce regions to Lisp strings and vice versa. Within the
342string, lines are delimited by newline characters.
343@enddefun
344
345@defun[fun {line-to-region}, args {@i[line]}]
346This function returns a region containing all the characters on @i[line]. The
347first mark is @kwd[right-inserting] and the last is @kwd[left-inserting].
348@enddefun
349
350@defun[fun {region-start}, args {@i[region]}]
351@defun1[fun {region-end}, args {@i[region]}]
352This function returns the start or end mark of @i(region).
353@enddefun
354
355@defun[fun {region-bounds}, args {@i[region]}]
356This function returns as multiple-values the starting and ending marks of
357@i[region].
358@enddefun
359
360@defun[fun {set-region-bounds}, args {@i[region] @i[start] @i[end]}]
361This function sets the start and end of region to @i[start] and @i[end]. It is
362an error for @i[start] to be after or in a different buffer from @i[end].
363@enddefun
364
365@index(Counting lines and characters)
366@defun[fun {count-lines}, args {@i[region]}]
367This function returns the number of lines in the @i(region), first and last
368lines inclusive. A newline is associated with the line it follows, thus a
369region containing some number of non-newline characters followed by one newline
370is one line, but if a newline were added at the beginning, it would be two
371lines.
372@enddefun
373
374@defun[fun {count-characters}, args {@i[region]}]
375This function returns the number of characters in a given @i(region). This
376counts line breaks as one character.
377@enddefun
378
379@defun[fun {check-region-query-size}, args {@i[region]}]
380@defhvar1[var {Region Query Size}, val {30}]
381@f[check-region-query-size] counts the lines in @i[region], and if their number
382exceeds the @hid[Region Query Size] threshold, it prompts the user for
383confirmation. This should be used in commands that perform destructive
384operations and are not undoable. If the user responds negatively, then this
385signals an editor-error, aborting whatever command was in progress.
386@enddefun
387
388
389
390@chapter(Buffers)
391@index (Buffers)
392@label[buffers]
393A buffer is an environment within @hemlock consisting of:
394@begin(enumerate)
395A name.
396
397A piece of text.
398
399A current focus of attention, the point.
400
401An associated file (optional).
402
403A write protect flag.
404
405Some variables (page @pageref[variables]).
406
407Some key bindings (page @pageref[key-bindings]).
408
409Some collection of modes (page @pageref[modes]).
410
411Some windows in which it is displayed (page @pageref[windows]).
412
413A list of modeline fields (optional).
414@end(enumerate)
415
416
417@section (The Current Buffer)
418@index (Current buffer)
419@defun[fun {current-buffer}]
420@defhvar1[var {Set Buffer Hook}]
421@defhvar1[var {After Set Buffer Hook}]
422@f[current-buffer] returns the current buffer object. Usually this is the
423buffer that @funref[current-window] is displaying. This value may be changed
424with @f[setf], and the @f[setf] method invokes @hid[Set Buffer Hook] before the
425change occurs with the new value. After the change occurs, the method invokes
426@hid[After Set Buffer Hook] with the old value.
427@enddefun
428
429@defun[fun {current-point}]
430This function returns the @f[buffer-point] of the current buffer.
431This is such a common idiom in commands that it is defined despite
432its trivial implementation.
433@enddefun
434
435@defun[fun {current-mark}]
436@defun1[fun {pop-buffer-mark}]
437@defun1[fun {push-buffer-mark}, args {@i[mark] @optional @i[activate-region]}]
438@index(Buffer mark stack)
439@index(Mark stack)
440@label(mark-stack)
441@f[current-mark] returns the top of the current buffer's mark stack. There
442always is at least one mark at the beginning of the buffer's region, and all
443marks returned are right-inserting.
444
445@f[pop-buffer-mark] pops the current buffer's mark stack, returning the mark.
446If the stack becomes empty, this pushes a new mark on the stack pointing to the
447buffer's start. This always deactivates the current region (see section
448@ref[active-regions]).
449
450@f[push-buffer-mark] pushes @i[mark] into the current buffer's mark stack,
451ensuring that the mark is right-inserting. If @i[mark] does not point into the
452current buffer, this signals an error. Optionally, the current region is made
453active, but this never deactivates the current region (see section
454@ref[active-regions]). @i[Mark] is returned.
455@enddefun
456
457@defvar[var {buffer-list}]
458This variable holds a list of all the buffer objects made with @f[make-buffer].
459@enddefvar
460
461@defvar[var {buffer-names}]
462This variable holds a @f[string-table] (page @pageref(string-tables)) of all the
463names of the buffers in @var[buffer-list]. The values of the entries are the
464corresponding buffer objects.
465@enddefvar
466
467@defvar[var {buffer-history}]
468This is a list of buffer objects ordered from those most recently selected to
469those selected farthest in the past. When someone makes a buffer, an element
470of @hid[Make Buffer Hook] adds this buffer to the end of this list. When
471someone deletes a buffer, an element of @hid[Delete Buffer Hook] removes the
472buffer from this list. Each buffer occurs in this list exactly once, but it
473never contains the @var[echo-area-buffer].
474@enddefvar
475
476@defun[fun {change-to-buffer}, args {@i[buffer]}]
477This switches to @i[buffer] in the @f[current-window] maintaining
478@f[buffer-history].
479@enddefun
480
481@defun[fun {previous-buffer}]
482This returns the first buffer from @var[buffer-history] that is not the
483@f[current-buffer]. If none can be found, then this returns @nil.
484@enddefun
485
486
487@section(Buffer Functions)
488@defun[fun {make-buffer}, args {@i[name]}, keys {[modes][modeline-fields][delete-hook]}]
489@defhvar1[var {Make Buffer Hook}]
490@defhvar1[var {Default Modeline Fields}]
491@f[make-buffer] creates and returns a buffer with the given @i(name). If a
492buffer named @i[name] already exists, @nil is returned. @i[Modes] is a list of
493modes which should be in effect in the buffer, major mode first, followed by
494any minor modes. If this is omitted then the buffer is created with the list
495of modes contained in @hvarref[Default Modes]. @i[Modeline-fields] is a list
496of modeline-field objects (see section @ref[modelines]) which may be @nil.
497@f[delete-hook] is a list of delete hooks specific to this buffer, and
498@f[delete-buffer] invokes these along with @hid[Delete Buffer Hook].
499
500Buffers created with @f[make-buffer] are entered into the list
501@var[buffer-list], and their names are inserted into the
502string-table @var[buffer-names]. When a buffer is created the hook
503@hid[Make Buffer Hook] is invoked with the new buffer.
504@enddefun
505
506@defun[fun {bufferp}, args {@i[buffer]}]
507Returns @true if @i[buffer] is a @f[buffer] object, otherwise @nil.
508@enddefun
509
510@defun[fun {buffer-name}, args {@i[buffer]}]
511@defhvar1[var {Buffer Name Hook}]
512@f[buffer-name] returns the name, which is a string, of the given @i(buffer).
513The corresponding @f[setf] method invokes @hid[Buffer Name Hook] with
514@i[buffer] and the new name and then sets the buffer's name. When the user
515supplies a name for which a buffer already exists, the @f[setf] method signals
516an error.
517@enddefun
518
519@defun[fun {buffer-region}, args {@i[buffer]}]
520Returns the @i[buffer]'s region. This can be set with @f[setf]. Note, this
521returns the region that contains all the text in a buffer, not the
522@funref[current-region].
523@enddefun
524
525@defun[fun {buffer-pathname}, args {@i[buffer]}]
526@defhvar1[var {Buffer Pathname Hook}]
527@f[buffer-pathname] returns the pathname of the file associated with
528the given @i(buffer), or nil if it has no associated file. This is
529the truename of the file as of the most recent time it was read or
530written. There is a @f[setf] form to change the pathname. When the
531pathname is changed the hook @hid[Buffer Pathname Hook] is invoked
532with the buffer and new value.
533@enddefun
534
535@defun[fun {buffer-write-date}, args {@i[buffer]}]
536Returns the write date for the file associated with the buffer in universal
537time format. When this the @f[buffer-pathname] is set, use @f[setf] to set
538this to the corresponding write date, or to @nil if the date is unknown or
539there is no file.
540@enddefun
541
542@defun[fun {buffer-point}, args {@i[buffer]}]
543Returns the mark which is the current location within @i[buffer]. To
544move the point, use @f[move-mark] or @funref[move-to-position] rather
545than setting @f[buffer-point] with @f[setf].
546@enddefun
547
548@defun[fun {buffer-mark}, args {@i[buffer]}]
549@index(Buffer mark stack)
550@index(Mark stack)
551This function returns the top of @i[buffer]'s mark stack. There always
552is at least one mark at the beginning of @i[buffer]'s region, and all marks
553returned are right-inserting.
554@enddefun
555
556@defun[fun {buffer-start-mark}, args {@i[buffer]}]
557@defun1[fun {buffer-end-mark}, args {@i[buffer]}]
558These functions return the start and end marks of @i[buffer]'s region:
559@Begin[ProgramExample]
560(buffer-start-mark buffer) <==>
561 (region-start (buffer-region buffer))
562and
563(buffer-end-mark buffer) <==>
564 (region-end (buffer-region buffer))
565@End[ProgramExample]
566@enddefun
567
568@defun[fun {buffer-writable}, args {@i[buffer]}]
569@defhvar1[var "Buffer Writable Hook"]
570This function returns @true if you can modify the @i(buffer), @nil if you
571cannot. If a buffer is not writable, then any attempt to alter text in the
572buffer results in an error. There is a @f[setf] method to change this value.
573
574The @f[setf] method invokes the functions in @hid[Buffer Writable Hook] on the
575buffer and new value before storing the new value.
576@enddefun
577
578@defun[fun {buffer-modified}, args {@i[buffer]}]
579@defhvar1[var "Buffer Modified Hook"]
580@f[buffer-modified] returns @true if the @i[buffer] has been modified, @nil if
581it hasn't. This attribute is set whenever a text-altering operation is
582performed on a buffer. There is a @f[setf] method to change this value.
583
584The @f[setf] method invokes the functions in @hid[Buffer Modified Hook] with
585the buffer whenever the value of the modified flag changes.
586@enddefun
587
588@defmac[fun {with-writable-buffer}, args {(@i[buffer]) @rest @i[forms]}]
589This macro executes @i[forms] with @i[buffer]'s writable status set. After
590@i[forms] execute, this resets the @i[buffer]'s writable and modified status.
591@enddefmac
592
593@defun[fun {buffer-signature}, args {@i[buffer]}]
594This function returns an arbitrary number which reflects the buffer's current
595@i[signature]. The result is @f[eql] to a previous result if and only if the
596buffer has not been modified between the calls.
597@enddefun
598
599@defun[fun {buffer-variables}, args {@i[buffer]}]
600This function returns a string-table (page @pageref[string-tables]) containing
601the names of the buffer's local variables. See chapter @ref[variables].
602@enddefun
603
604@defun[fun {buffer-modes}, args {@i[buffer]}]
605This function returns the list of the names of the modes active in @i[buffer].
606The major mode is first, followed by any minor modes. See chapter @ref[modes].
607@enddefun
608
609@defun[fun {buffer-windows}, args {@i[buffer]}]
610This function returns the list of all the windows in which the buffer may be
611displayed. This list may include windows which are not currently visible. See
612page @pageref[windows] for a discussion of windows.
613@enddefun
614
615@defun[fun {buffer-delete-hook}, args {@i[buffer]}]
616This function returns the list of buffer specific functions @f[delete-buffer]
617invokes when deleting a buffer. This is @f[setf]'able.
618@enddefun
619
620@defun[fun {delete-buffer}, args {@i[buffer]}]
621@defhvar1[var {Delete Buffer Hook}]
622@f[delete-buffer] removes @i[buffer] from @varref[buffer-list] and its name
623from @varref[buffer-names]. Before @i[buffer] is deleted, this invokes the
624functions on @i[buffer] returned by @f[buffer-delete-hook] and those found in
625@hid[Delete Buffer Hook]. If @i[buffer] is the @f[current-buffer], or if it is
626displayed in any windows, then this function signals an error.
627@enddefun
628
629@defun[fun {delete-buffer-if-possible}, args {@i[buffer]}]
630This uses @f[delete-buffer] to delete @i[buffer] if at all possible. If
631@i[buffer] is the @f[current-buffer], then this sets the @f[current-buffer] to
632the first distinct buffer in @f[buffer-history]. If @i[buffer] is displayed in
633any windows, then this makes each window display the same distinct buffer.
634@enddefun
635
636
637@section(Modelines)
638@index(Modelines)
639@label(modelines)
640
641A Buffer may specify a modeline, a line of text which is displayed across the
642bottom of a window to indicate status information. Modelines are described as
643a list of @f[modeline-field] objects which have individual update functions and
644are optionally fixed-width. These have an @f[eql] name for convenience in
645referencing and updating, but the name must be unique for all created
646modeline-field objects. When creating a modeline-field with a specified width,
647the result of the update function is either truncated or padded on the right to
648meet the constraint. All modeline-field functions must return simple strings
649with standard characters, and these take a buffer and a window as arguments.
650Modeline-field objects are typically shared amongst, or aliased by, different
651buffers' modeline fields lists. These lists are unique allowing fields to
652behave the same wherever they occur, but different buffers may display these
653fields in different arrangements.
654
655Whenever one of the following changes occurs, all of a buffer's modeline fields
656are updated:
657@Begin[Itemize]
658A buffer's major mode is set.
659
660One of a buffer's minor modes is turned on or off.
661
662A buffer is renamed.
663
664A buffer's pathname changes.
665
666A buffer's modified status changes.
667
668A window's buffer is changed.
669@End[Itemize]
670
671The policy is that whenever one of these changes occurs, it is guaranteed that
672the modeline will be updated before the next trip through redisplay.
673Furthermore, since the system cannot know what modeline-field objects the
674user has added whose update functions rely on these values, or how he has
675changed @hid[Default Modeline Fields], we must update all the fields. When any
676but the last occurs, the modeline-field update function is invoked once for
677each window into the buffer. When a window's buffer changes, each
678modeline-field update function is invoked once; other windows' modeline
679fields should not be affected due to a given window's buffer changing.
680
681The user should note that modelines can be updated at any time, so update
682functions should be careful to avoid needless delays (for example, waiting for
683a local area network to determine information).
684
685@defun[fun {make-modeline-field}, keys {[name][width][function]}]
686@defun1[fun {modeline-field-p}, args @i(modeline-field)]
687@defun1[fun {modeline-field-name}, args @i(modeline-field)]
688@f[make-modeline-field] returns a modeline-field object with @i[name],
689@i[width], and @i[function]. @i[Width] defaults to @nil meaning that the field
690is variable width; otherwise, the programmer must supply this as a positive
691integer. @i[Function] must take a buffer and window as arguments and return a
692@f[simple-string] containing only standard characters. If @i[name] already
693names a modeline-field object, then this signals an error.
694
695@f[modeline-field-name] returns the name field of a modeline-field object. If
696this is set with @f[setf], and the new name already names a modeline-field,
697then the @f[setf] method signals an error.
698
699@f[modeline-field-p] returns @true or @nil, depending on whether its argument
700is a @f[modeline-field] object.
701@enddefun
702
703@defun[fun {modeline-field}, args {@i[name]}]
704This returns the modeline-field object named @i[name]. If none exists, this
705returns nil.
706@enddefun
707
708@defun[fun {modeline-field-function}, args {@i[modeline-field]}]
709Returns the function called when updating the @i[modeline-field]. When this is
710set with @f[setf], the @f[setf] method updates @i[modeline-field] for all
711windows on all buffers that contain the given field, so the next trip through
712redisplay will reflect the change. All modeline-field functions must return
713simple strings with standard characters, and they take a buffer and a window
714as arguments.
715@enddefun
716
717@defun[fun {modeline-field-width}, args {@i[modeline-field]}]
718Returns the width to which @i[modeline-field] is constrained, or @nil
719indicating that it is variable width. When this is set with @f[setf], the
720@f[setf] method updates all modeline-fields for all windows on all buffers that
721contain the given field, so the next trip through redisplay will reflect the
722change. All the fields for any such modeline display must be updated, which is
723not the case when setting a modeline-field's function.
724@enddefun
725
726@defun[fun {buffer-modeline-fields}, args {@i[buffer]}]
727Returns a copy of the list of @i[buffer]'s modeline-field objects. This list
728can be destructively modified without affecting display of @i[buffer]'s
729modeline, but modifying any particular field's components (for example, width
730or function) causes the changes to be reflected the next trip through redisplay
731in every modeline display that uses the modified modeline-field. When this is
732set with @f[setf], @f[update-modeline-fields] is called for each window into
733@i[buffer].
734@enddefun
735
736@defun[fun {buffer-modeline-field-p}, args {@i[buffer] @i[field]}]
737If @i[field], a modeline-field or the name of one, is in buffer's list of
738modeline-field objects, it is returned; otherwise, this returns nil.
739@enddefun
740
741@defun[fun {update-modeline-fields}, args {@i[buffer] @i[window]}]
742This invokes each modeline-field object's function from @i[buffer]'s list,
743passing @i[buffer] and @i[window]. The results are collected regarding each
744modeline-field object's width as appropriate, and the window is marked so
745the next trip through redisplay will reflect the changes. If window does not
746display modelines, then no computation occurs.
747@enddefun
748
749@defun[fun {update-modeline-field}, args {@i[buffer] @i[window] @i[field-or-name]}]
750This invokes the modeline-field object's function for @i[field-or-name], which
751is a modeline-field object or the name of one for @i[buffer]. This passes
752@i[buffer] and @i[window] to the update function. The result is applied to the
753@i[window]'s modeline display using the modeline-field object's width, and the
754window is marked so the next trip through redisplay will reflect the changes.
755If the window does not display modelines, then no computation occurs. If
756@i[field-or-name] is not found in @i[buffer]'s list of modeline-field objects,
757then this signals an error. See @f[buffer-modeline-field-p] above.
758@enddefun
759
760
761
762@chapter(Altering and Searching Text)
763@label[doing-stuff]
764
765@section(Altering Text)
766@index(Altering text)
767@index(Inserting)
768@index(Deleting)
769A note on marks and text alteration: @kwd[temporary] marks are invalid
770after any change has been made to the text the mark points to; it is an
771error to use a temporary mark after such a change has been made. If
772text is deleted which has permanent marks pointing into it then they
773are left pointing to the position where the text was.
774
775@defun[fun {insert-character}, args {@i[mark] @i[character]}]
776@defun1[fun {insert-string}, args {@i[mark] @i[string]}]
777@defun1[fun {insert-region}, args {@i[mark] @i[region]}]
778Inserts @i[character], @i[string] or @i[region] at @i[mark].
779@f[insert-character] signals an error if @i[character] is not
780@f[string-char-p]. If @i[string] or @i[region] is empty, and @i[mark] is in
781some buffer, then @hemlock leaves @f[buffer-modified] of @i[mark]'s buffer
782unaffected.
783@enddefun
784
785@defun[fun {ninsert-region}, args {@i[mark] @i[region]}]
786Like @f[insert-region], inserts the @i[region] at the @i[mark]'s position,
787destroying the source region. This must be used with caution, since if anyone
788else can refer to the source region bad things will happen. In particular, one
789should make sure the region is not linked into any existing buffer. If
790@i[region] is empty, and @i[mark] is in some buffer, then @hemlock leaves
791@f[buffer-modified] of @i[mark]'s buffer unaffected.
792@enddefun
793
794@defun[fun {delete-characters}, args {@i[mark] @i[n]}]
795This deletes @i[n] characters after the @i[mark] (or -@i[n] before if @i[n] is
796negative). If @i[n] characters after (or -@i[n] before) the @i[mark] do not
797exist, then this returns @nil; otherwise, it returns @true. If @i[n] is zero,
798and @i[mark] is in some buffer, then @hemlock leaves @f[buffer-modified] of
799@i[mark]'s buffer unaffected.
800@enddefun
801
802@defun[fun {delete-region}, args {@i[region]}]
803This deletes @i[region]. This is faster than @f[delete-and-save-region]
804(below) because no lines are copied. If @i[region] is empty and contained in
805some buffer's @f[buffer-region], then @hemlock leaves @f[buffer-modified] of
806the buffer unaffected.
807@enddefun
808
809@defun[fun {delete-and-save-region}, args {@i[region]}]
810This deletes @i[region] and returns a region containing the original
811@i[region]'s text. If @i[region] is empty and contained in some buffer's
812@f[buffer-region], then @hemlock leaves @f[buffer-modified] of the buffer
813unaffected. In this case, this returns a distinct empty region.
814@enddefun
815
816@defun[fun {filter-region}, args {@i[function] @i[region]}]
817Destructively modifies @i[region] by replacing the text
818of each line with the result of the application of @i[function] to a
819string containing that text. @i[Function] must obey the following
820restrictions:
821@begin[enumerate]
822The argument may not be destructively modified.
823
824The return value may not contain newline characters.
825
826The return value may not be destructively modified after it is
827returned from @i[function].
828@end[enumerate]
829The strings are passed in order, and are always simple strings.
830
831Using this function, a region could be uppercased by doing:
832@lisp
833(filter-region #'string-upcase region)
834@endlisp
835@enddefun
836
837
838@section(Text Predicates)
839@defun[fun {start-line-p}, args {@i[mark]}]
840Returns @true if the @i(mark) points before the first character in a line,
841@nil otherwise.
842@enddefun
843
844@defun[fun {end-line-p}, args {@i[mark]}]
845Returns @true if the @i(mark) points after the last character in a line and
846before the newline, @nil otherwise.
847@enddefun
848
849@defun[fun {empty-line-p}, args {@i[mark]}]
850Return @true of the line which @i[mark] points to contains no characters.
851@enddefun
852
853@defun[fun {blank-line-p}, args {@i[line]}]
854Returns @true if @i[line] contains only characters with a
855@hid[Whitespace] attribute of 1. See chapter @ref[character-attributes] for
856discussion of character attributes.
857@enddefun
858
859@defun[fun {blank-before-p}, args {@i[mark]}]
860@defun1[fun {blank-after-p}, args {@i[mark]}]
861These functions test if all the characters preceding or following
862@i[mark] on the line it is on have a @hid[Whitespace] attribute of @f[1].
863@enddefun
864
865@defun[fun {same-line-p}, args {@i[mark1] @i[mark2]}]
866Returns @true if @i(mark1) and @i(mark2) point to the same line, or @nil
867otherwise; That is,
868@example[(same-line-p a b) <==> (eq (mark-line a) (mark-line b))]
869@enddefun
870
871@defun[fun {mark<}, funlabel {mark-LSS}, args {@i[mark1] @i[mark2]}]
872@defun1[fun {mark<=}, funlabel {mark-LEQ}, args {@i[mark1] @i[mark2]}]
873@defun1[fun {mark=}, funlabel {mark-EQL}, args {@i[mark1] @i[mark2]}]
874@defun1[fun {mark/=}, funlabel {mark-NEQ}, args {@i[mark1] @i[mark2]}]
875@defun1[fun {mark>=}, funlabel {mark-GEQ}, args {@i[mark1] @i[mark2]}]
876@defun1[fun {mark>}, funlabel {mark-GTR}, args {@i[mark1] @i[mark2]}]
877These predicates test the relative ordering of two marks in a piece of
878text, that is a mark is @f[mark>] another if it points to a position
879after it. If the marks point into different, non-connected pieces of
880text, such as different buffers, then it is an error to test their
881ordering; for such marks @f[mark=] is always false and @f[mark/=] is
882always true.
883@enddefun
884
885@defun[fun {line<}, funlabel {line-LSS}, args {@i[line1] @i[line2]}]
886@defun1[fun {line<=}, funlabel {line-LEQ}, args {@i[line1] @i[line2]}]
887@defun1[fun {line>=}, funlabel {line-GEQ}, args {@i[line1] @i[line2]}]
888@defun1[fun {line>}, funlabel {line-GTR}, args {@i[line1] @i[line2]}]
889These predicates test the ordering of @i[line1] and @i[line2]. If the
890lines are in unconnected pieces of text it is an error to test their
891ordering.
892@enddefun
893
894@defun[fun {lines-related}, args {@i[line1] @i[line2]}]
895This function returns @true if @i[line1] and @i[line2] are in the same
896piece of text, or @nil otherwise.
897@enddefun
898
899@defun[fun {first-line-p}, args {@i[mark]}]
900@defun1[fun {last-line-p}, args {@i[mark]}]
901@f[first-line-p] returns @true if there is no line before the line
902@i[mark] is on, and @nil otherwise. @i[Last-line-p] similarly tests
903tests whether there is no line after @i[mark].
904@enddefun
905
906
907@section(Kill Ring)
908@index(Kill ring)
909@label(kill-ring)
910
911@defvar[var {kill-ring}]
912This is a ring (see section @ref[rings]) of regions deleted from buffers.
913Some commands save affected regions on the kill ring before performing
914modifications. You should consider making the command undoable (see section
915@ref[undo]), but this is a simple way of achieving a less satisfactory means
916for the user to recover.
917@enddefvar
918
919@defun[fun {kill-region}, args {@i[region] @i[current-type]}]
920This kills @i[region] saving it in @var[kill-ring]. @i[Current-type] is either
921@kwd[kill-forward] or @kwd[kill-backward]. When the @funref[last-command-type]
922is one of these, this adds @i[region] to the beginning or end, respectively, of
923the top of @var[kill-ring]. The result of calling this is undoable using the
924command @hid[Undo] (see the @i[Hemlock User's Manual]). This sets
925@f[last-command-type] to @i[current-type], and it interacts with
926@f[kill-characters].
927@enddefun
928
929@defun[fun {kill-characters}, args {@i[mark] @i[count]}]
930@defhvar1[var {Character Deletion Threshold}, val {5}]
931@f[kill-characters] kills @i[count] characters after @i[mark] if @i[count] is
932positive, otherwise before @i[mark] if @i[count] is negative. When @i[count]
933is greater than or equal to @hid[Character Deletion Threshold], the killed
934characters are saved on @var[kill-ring]. This may be called multiple times
935contiguously (that is, without @funref[last-command-type] being set) to
936accumulate an effective count for purposes of comparison with the threshold.
937
938This sets @f[last-command-type], and it interacts with @f[kill-region]. When
939this adds a new region to @var[kill-ring], it sets @f[last-command-type] to
940@kwd[kill-forward] (if @i[count] is positive) or @kwd[kill-backward] (if
941@i[count] is negative). When @f[last-command-type] is @kwd[kill-forward] or
942@kwd[kill-backward], this adds the killed characters to the beginning (if
943@i[count] is negative) or the end (if @i[count] is positive) of the top of
944@var[kill-ring], and it sets @f[last-command-type] as if it added a new region
945to @var[kill-ring]. When the kill ring is unaffected, this sets
946@f[last-command-type] to @kwd[char-kill-forward] or @kwd[char-kill-backward]
947depending on whether @i[count] is positive or negative, respectively.
948
949This returns mark if it deletes characters. If there are not @i[count]
950characters in the appropriate direction, this returns nil.
951@enddefun
952
953
954@section(Active Regions)
955@index(Active regions)
956@label(active-regions)
957
958Every buffer has a mark stack (page @pageref[mark-stack]) and a mark known as
959the point where most text altering nominally occurs. Between the top of the
960mark stack, the @f[current-mark], and the @f[current-buffer]'s point, the
961@f[current-point], is what is known as the @f[current-region]. Certain
962commands signal errors when the user tries to operate on the @f[current-region]
963without its having been activated. If the user turns off this feature, then
964the @f[current-region] is effectively always active.
965
966When writing a command that marks a region of text, the programmer should make
967sure to activate the region. This typically occurs naturally from the
968primitives that you use to mark regions, but sometimes you must explicitly
969activate the region. These commands should be written this way, so they do not
970require the user to separately mark an area and then activate it. Commands
971that modify regions do not have to worry about deactivating the region since
972modifying a buffer automatically deactivates the region. Commands that insert
973text often activate the region ephemerally; that is, the region is active for
974the immediately following command, allowing the user wants to delete the region
975inserted, fill it, or whatever.
976
977Once a marking command makes the region active, it remains active until:
978@begin[itemize]
979a command uses the region,
980
981a command modifies the buffer,
982
983a command changes the current window or buffer,
984
985a command signals an editor-error,
986
987or the user types @binding[C-g].
988@end[itemize]
989
990@defhvar[var "Active Regions Enabled", val {t}]
991When this variable is non-@nil, some primitives signal an editor-error if
992the region is not active. This may be set to @nil for more traditional @emacs
993region semantics.
994@enddefhvar
995
996@defvar[var {ephemerally-active-command-types}]
997This is a list of command types (see section @ref[command-types]), and its
998initial value is the list of @kwd[ephemerally-active] and @kwd[unkill]. When
999the previous command's type is one of these, the @f[current-region] is active
1000for the currently executing command only, regardless of whether it does
1001something to deactivate the region. However, the current command may activate
1002the region for future commands. @kwd[ephemerally-active] is a default command
1003type that may be used to ephemerally activate the region, and @kwd[unkill] is
1004the type used by two commands, @hid[Un-kill] and @hid[Rotate Kill Ring] (what
1005users typically think of as @binding[C-y] and @binding[M-y]).
1006@enddefvar
1007
1008@defun[fun {activate-region}]
1009This makes the @f[current-region] active.
1010@enddefun
1011
1012@defun[fun {deactivate-region}]
1013After invoking this the @f[current-region] is no longer active.
1014@enddefun
1015
1016@defun[fun {region-active-p}]
1017Returns whether the @f[current-region] is active, including ephemerally. This
1018ignores @hid[Active Regions Enabled].
1019@enddefun
1020
1021@defun[fun {check-region-active}]
1022This signals an editor-error when active regions are enabled, and the
1023@f[current-region] is not active.
1024@enddefun
1025
1026@defun[fun {current-region},
1027 args {@optional @i[error-if-not-active] @i[deactivate-region]}]
1028This returns a region formed with @f[current-mark] and @f[current-point],
1029optionally signaling an editor-error if the current region is not active.
1030@i[Error-if-not-active] defaults to @true. Each call returns a distinct region
1031object. Depending on @i[deactivate-region] (defaults to @true), fetching the
1032current region deactivates it. @hemlock primitives are free to modify text
1033regardless of whether the region is active, so a command that checks for this
1034can deactivate the region whenever it is convenient.
1035@enddefun
1036
1037
1038@section(Searching and Replacing)
1039@index(Searching)
1040@index(Replacing)
1041
1042Before using any of these functions to do a character search, look at character
1043attributes (page @pageref[character-attributes]). They provide a facility
1044similar to the syntax table in real EMACS. Syntax tables are a powerful,
1045general, and efficient mechanism for assigning meanings to characters in
1046various modes.
1047
1048@defcon[var {search-char-code-limit}]
1049An exclusive upper limit for the char-code of characters given to the searching
1050functions. The result of searches for characters with a char-code greater than
1051or equal to this limit is ill-defined, but it is @i[not] an error to do such
1052searches.
1053@enddefcon
1054
1055@defun[fun {new-search-pattern},
1056args {@i[kind] @i[direction] @i[pattern] @optional @i[result-search-pattern]}]
1057
1058Returns a @i[search-pattern] object which can be given to the @f[find-pattern]
1059and @f[replace-pattern] functions. A search-pattern is a specification of a
1060particular sort of search to do. @i[direction] is either @kwd[forward] or
1061@kwd[backward], indicating the direction to search in. @i[kind] specifies the
1062kind of search pattern to make, and @i[pattern] is a thing which specifies what
1063to search for.
1064
1065The interpretation of @i[pattern] depends on the @i[kind] of pattern being
1066made. Currently defined kinds of search pattern are:
1067@begin(description)
1068@kwd[string-insensitive]@\Does a case-insensitive string search,
1069@i[pattern] being the string to search for.
1070
1071@kwd[string-sensitive]@\Does a case-sensitive string search for
1072@i[pattern].
1073
1074@kwd[character]@\Finds an occurrence of the character @i[pattern].
1075This is case sensitive.
1076
1077@kwd[not-character]@\Find a character which is not the character
1078@i[pattern].
1079
1080@kwd[test]@\Finds a character which satisfies the function @i[pattern].
1081This function may not be applied an any particular fashion, so it
1082should depend only on what its argument is, and should have no
1083side-effects.
1084
1085@kwd[test-not]@\Similar to as @kwd[test], except it finds a character that
1086fails the test.
1087
1088@kwd[any]@\Finds a character that is in the string @i[pattern].
1089
1090@kwd[not-any]@\Finds a character that is not in the string @i[pattern].
1091@end(description)
1092
1093@i[result-search-pattern], if supplied, is a search-pattern to
1094destructively modify to produce the new pattern. Where reasonable
1095this should be supplied, since some kinds of search patterns may
1096involve large data structures.
1097@enddefun
1098
1099@defun[fun {search-pattern-p}, args {@i[search-pattern]}]
1100Returns @true if @i[search-pattern] is a @f[search-pattern] object, otherwise
1101@nil.
1102@enddefun
1103
1104@defun[fun {get-search-pattern}, args {@i[string] @i[direction]}]
1105@defvar1[var {last-search-pattern}]
1106@defvar1[var {last-search-string}]
1107@f[get-search-pattern] interfaces to a default search string and pattern that
1108search and replacing commands can use. These commands then share a default
1109when prompting for what to search or replace, and save on consing a search
1110pattern each time they execute. This uses @hid[Default Search Kind] (see the
1111@i[Hemlock User's Manual]) when updating the pattern object. This returns the
1112pattern, so you probably don't need to refer to @var[last-search-pattern], but
1113@var[last-search-string] is useful when prompting.
1114@enddefun
1115
1116@defun[fun {find-pattern}, args {@i[mark] @i[search-pattern]}]
1117Find the next match of @i[search-pattern] starting at @i[mark]. If a
1118match is found then @i[mark] is altered to point before the matched text
1119and the number of characters matched is returned. If no match is
1120found then @nil is returned and @i[mark] is not modified.
1121@enddefun
1122
1123@defun[fun {replace-pattern}, args
1124 {@i[mark] @i[search-pattern] @i[replacement] @optional @i[n]}]
1125Replace @i[n] matches of @i[search-pattern] with the string
1126@i[replacement] starting at @i[mark]. If @i[n] is @nil (the default)
1127then replace all matches. A mark pointing before the last replacement
1128done is returned.
1129@enddefun
1130
1131
1132
1133@Chapter(The Current Environment)
1134@label(current-environment)
1135@index(Current environment)
1136
1137@section(Different Scopes)
1138 In @hemlock the values of @i[variables] (page @pageref[variables]),
1139@i[key-bindings] (page @pageref(key-bindings)) and
1140@i[character-attributes] (page @pageref[character-attributes]) may
1141depend on the @funref(current-buffer) and the modes
1142active in it. There are three possible scopes for
1143@hemlock values:
1144@begin(description)
1145@i[buffer local]@\The value is present only if the buffer it is local
1146to is the @f[current-buffer].
1147
1148@i[mode local]@\The value is present only when the mode it is local to
1149is active in the @f[current-buffer].
1150
1151@i[global]@\The value is always present unless shadowed by a buffer or
1152mode local value.
1153@end(description)
1154
1155
1156@section(Shadowing)
1157 It is possible for there to be a conflict between different values
1158for the same thing in different scopes. For example, there be might a
1159global binding for a given variable and also a local binding in the
1160current buffer. Whenever there is a conflict shadowing occurs,
1161permitting only one of the values to be visible in the current
1162environment.
1163
1164 The process of resolving such a conflict can be described as a
1165search down a list of places where the value might be defined, returning
1166the first value found. The order for the search is as follows:
1167@begin(enumerate)
1168Local values in the current buffer.
1169
1170Mode local values in the minor modes of the current buffer, in order
1171from the highest precedence mode to the lowest precedence mode. The
1172order of minor modes with equal precedences is undefined.
1173
1174Mode local values in the current buffer's major mode.
1175
1176Global values.
1177@end(enumerate)
1178
1179
1180
1181@chapter(Hemlock Variables)
1182@index (Hemlock variables)
1183@label(variables)
1184@hemlock implements a system of variables separate from normal Lisp variables
1185for the following reasons:
1186@begin(enumerate)
1187@hemlock has different scoping rules which are useful in an editor. @hemlock
1188variables can be local to a @i(buffer) (page @pageref[buffers]) or a @i(mode)
1189(page @pageref[modes]).
1190
1191@hemlock variables have @i(hooks) (page @pageref[hooks]), lists of functions
1192called when someone sets the variable. See @f[variable-value] for the
1193arguments @hemlock passes to these hook functions.
1194
1195There is a database of variable names and documentation which makes it easier
1196to find out what variables exist and what their values mean.
1197@end(enumerate)
1198
1199
1200@section(Variable Names)
1201To the user, a variable name is a case insensitive string. This
1202string is referred to as the @i[string name] of the variable. A
1203string name is conventionally composed of words separated by spaces.
1204
1205In Lisp code a variable name is a symbol. The name of this symbol is
1206created by replacing any spaces in the string name with hyphens. This
1207symbol name is always interned in the @hemlock package and referring
1208to a symbol with the same name in the wrong package is an error.
1209
1210@defvar[var {global-variable-names}]
1211This variable holds a string-table of the names of all the global @hemlock
1212variables. The value of each entry is the symbol name of the variable.
1213@enddefvar
1214
1215@defun[fun {current-variable-tables}]
1216This function returns a list of variable tables currently established,
1217globally, in the @f[current-buffer], and by the modes of the
1218@f[current-buffer]. This list is suitable for use with
1219@f[prompt-for-variable].
1220@enddefun
1221
1222
1223@section(Variable Functions)
1224In the following descriptions @i[name] is the symbol name of the variable.
1225
1226@defun[fun {defhvar}, args {@i[string-name] @i[documentation]},
1227 keys {[mode][buffer][hooks][value]}]
1228 This function defines a @hemlock variable. Functions that take a variable
1229name signal an error when the variable is undefined.
1230@begin(description)
1231@i[string-name]@\The string name of the variable to define.
1232
1233@i[documentation]@\The documentation string for the variable.
1234
1235@multiple{
1236@kwd[mode],
1237@kwd[buffer]}@\
1238 If @i[buffer] is supplied, the variable is local to that buffer. If @i[mode]
1239is supplied, it is local to that mode. If neither is supplied, it is global.
1240
1241@kwd[value]@\
1242 This is the initial value for the variable, which defaults to @nil.
1243
1244@kwd[hooks]@\
1245 This is the initial list of functions to call when someone sets the variable's
1246value. These functions execute before @hemlock establishes the new value. See
1247@f[variable-value] for the arguments passed to the hook functions.
1248@end(description)
1249If a variable with the same name already exists in the same place, then
1250@f[defhvar] sets its hooks and value from @i[hooks] and @i[value] if the user
1251supplies these keywords.
1252@enddefun
1253
1254@defun[fun {variable-value}, args {@i[name] @optional @i[kind] @i[where]}]
1255This function returns the value of a @hemlock variable in some place.
1256The following values for @i[kind] are defined:
1257@begin[description]
1258@kwd[current]@\
1259 Return the value present in the current environment, taking into consideration
1260any mode or buffer local variables. This is the default.
1261
1262@kwd[global]@\
1263 Return the global value.
1264
1265@kwd[mode]@\
1266 Return the value in the mode named @i[where].
1267
1268@kwd[buffer]@\
1269 Return the value in the buffer @i[where].
1270@end[description]
1271When set with @f[setf], @hemlock sets the value of the specified variable and
1272invokes the functions in its hook list with @i[name], @i[kind], @i[where], and
1273the new value.
1274@enddefun
1275
1276@defun[fun {variable-documentation}, args
1277 {@i[name] @optional @i[kind] @i[where]}]
1278@defun1[fun {variable-hooks}, args
1279 {@i[name] @optional @i[kind] @i[where]}]
1280@defun1[fun {variable-name}, args
1281 {@i[name] @optional @i[kind] @i[where]}]
1282These function return the documentation, hooks and string name of a
1283@hemlock variable. The @i[kind] and @i[where] arguments are the same
1284as for @f[variable-value]. The documentation and hook list may be set
1285using @f[setf].
1286@enddefun
1287
1288@defun[fun {string-to-variable}, args {@i[string]}]
1289This function converts a string into the corresponding variable symbol
1290name. @i[String] need not be the name of an actual @hemlock variable.
1291@enddefun
1292
1293@defmac[fun {value}, args {@i[name]}]
1294@defmac1[fun {setv}, args {@i[name] @i[new-value]}]
1295These macros get and set the current value of the @hemlock variable
1296@i[name]. @i[Name] is not evaluated. There is a @f[setf] form for
1297@f[value].
1298@enddefmac
1299
1300@Defmac[Fun {hlet}, Args {(@Mstar<(@i[var] @i[value])>) @Mstar<@i[form]>}]
1301This macro is very similar to @f[let] in effect; within its scope each
1302of the @hemlock variables @i[var] have the respective @i[value]s, but
1303after the scope is exited by any means the binding is removed. This
1304does not cause any hooks to be invoked. The value of the last
1305@i[form] is returned.
1306@enddefmac
1307
1308@defun[fun {hemlock-bound-p}, args {@i[name] @optional @i[kind] @i[where]}]
1309Returns @true if @i[name] is defined as a @hemlock variable in the
1310place specified by @i[kind] and @i[where], or @nil otherwise.
1311@enddefun
1312
1313@defun[fun {delete-variable}, args {@i(name) @optional @i[kind] @i[where]}]
1314@defhvar1[var {Delete Variable Hook}]
1315@f[delete-variable] makes the @hemlock variable @i[name] no longer
1316defined in the specified place. @i[Kind] and @i[where] have the same
1317meanings as they do for @f[variable-value], except that @kwd[current]
1318is not available, and the default for @i[kind] is @kwd[global]
1319
1320An error will be signaled if no such variable exists. The hook,
1321@hid[Delete Variable Hook] is invoked with the same arguments before the
1322variable is deleted.
1323@enddefun
1324
1325
1326@section(Hooks)
1327@index(Hooks)
1328@label[hooks]
1329@hemlock actions such as setting variables, changing buffers, changing windows,
1330turning modes on and off, etc., often have hooks associated with them. A hook
1331is a list of functions called before the system performs the action. The
1332manual describes the object specific hooks with the rest of the operations
1333defined on these objects.
1334
1335Often hooks are stored in @hemlock variables, @hid[Delete Buffer Hook] and
1336@hid[Set Window Hook] for example. This leads to a minor point of confusion
1337because these variables have hooks that the system executes when someone
1338changes their values. These hook functions @hemlock invokes when someone sets
1339a variable are an example of a hook stored in an object instead of a @hemlock
1340variable. These are all hooks for editor activity, but @hemlock keeps them in
1341different kinds of locations. This is why some of the routines in this section
1342have a special interpretation of the hook @i[place] argument.
1343
1344@defmac[fun {add-hook}, args {@i[place] @i[hook-fun]}]
1345@defmac1[fun {remove-hook}, args {@i[place] @i[hook-fun]}]
1346These macros add or remove a hook function in some @i[place]. If @i[hook-fun]
1347already exists in @i[place], this call has no effect. If @i[place] is a
1348symbol, then it is a @hemlock variable; otherwise, it is a generalized variable
1349or storage location. Here are two examples:
1350@Begin[ProgramExample]
1351(add-hook delete-buffer-hook 'remove-buffer-from-menu)
1352
1353(add-hook (variable-hooks 'check-mail-interval)
1354 'reschedule-mail-check)
1355@End[ProgramExample]
1356@enddefmac
1357
1358@defmac[fun {invoke-hook}, args {@i[place] @rest @i[args]}]
1359This macro calls all the functions in @i[place]. If @i[place] is a symbol,
1360then it is a @hemlock variable; otherwise, it is a generalized variable.
1361@enddefun
1362
1363
1364
1365@chapter(Commands)
1366@index (Commands)
1367@label[commands]
1368
1369
1370@section(Introduction)
1371The way that the user tells @hemlock to do something is by invoking a
1372@i(command). Commands have three attributes:
1373@begin(description)
1374@i[name]@\A command's name provides a way to refer to it. Command
1375names are usually capitalized words separated by spaces, such as
1376@hid[Forward Word].
1377
1378@i[documentation]@\The documentation for a command is used by
1379on-line help facilities.
1380
1381@i[function]@\A command is implemented by a Lisp function, which is callable
1382from Lisp.
1383@end(description)
1384
1385@defvar[var {command-names}]
1386Holds a string-table (page @pageref[string-tables]) associating
1387command names to command objects. Whenever a new command is defined
1388it is entered in this table.
1389@enddefvar
1390
1391
1392@subsection(Defining Commands)
1393
1394@defmac[fun {defcommand}, args
1395{@^@mgroup<@i[command-name] @MOR (@i[command-name] @i[function-name])> @i[lambda-list]
1396@\@i[command-doc] @i[function-doc] @mstar<@i[form]>}]
1397
1398Defines a command named @i[name]. @f[defcommand] creates a function to
1399implement the command from the @i[lambda-list] and @i[form]'s supplied. The
1400@i[lambda-list] must specify one required argument, see section
1401@ref[invoking-commands-as-functions], which by convention is typically named
1402@f[p]. If the caller does not specify @i[function-name], @f[defcommand]
1403creates the command name by replacing all spaces with hyphens and appending
1404"@f[-command]". @i[Function-doc] becomes the documentation for the function
1405and should primarily describe issues involved in calling the command as a
1406function, such as what any additional arguments are. @i[Command-doc] becomes
1407the command documentation for the command. @enddefmac
1408
1409@defun[fun {make-command}, args
1410 {@i[name] @i[documentation] @i[function]}]
1411Defines a new command named @i[name], with command documentation
1412@I[documentation] and function @i[function]. The command in entered
1413in the string-table @varref[command-names], with the command object as
1414its value. Normally command implementors will use the @f[defcommand]
1415macro, but this permits access to the command definition mechanism at
1416a lower level, which is occasionally useful.
1417@enddefun
1418
1419@defun[fun {commandp}, args {@i[command]}]
1420Returns @true if @i[command] is a @f[command] object, otherwise @nil.
1421@enddefun
1422
1423@defun[fun {command-documentation}, args {@i[command]}]
1424@defun1[fun {command-function}, args {@i[command]}]
1425@defun1[fun {command-name}, args {@i[command]}]
1426Returns the documentation, function, or name for @i[command]. These
1427may be set with @f[setf].
1428@enddefun
1429
1430
1431@subsection(Command Documentation)
1432@i[Command documentation] is a description of what the command does
1433when it is invoked as an extended command or from a key. Command
1434documentation may be either a string or a function. If the
1435documentation is a string then the first line should briefly summarize
1436the command, with remaining lines filling the details. Example:
1437@lisp
1438(defcommand "Forward Character" (p)
1439 "Move the point forward one character.
1440 With prefix argument move that many characters, with negative
1441 argument go backwards."
1442 "Move the point of the current buffer forward p characters."
1443 . . .)
1444@endlisp
1445
1446Command documentation may also be a function of one argument. The
1447function is called with either @kwd[short] or @kwd[full], indicating
1448that the function should return a short documentation string or do
1449something to document the command fully.
1450
1451
1452@section(The Command Interpreter)
1453@index[Interpreter, command]
1454@index[Invocation, command]
1455@index[Command interpreter]
1456
1457The @i[command interpreter] is a function which reads key-events (see section
1458@ref[key-events-intro]) from the keyboard and dispatches to different commands
1459on the basis of what the user types. When the command interpreter executes a
1460command, we say it @i[invokes] the command. The command interpreter also
1461provides facilities for communication between commands contiguously running
1462commands, such as a last command type register. It also takes care of
1463resetting communication mechanisms, clearing the echo area, displaying partial
1464keys typed slowly by the user, etc.
1465
1466@defvar[var {invoke-hook}]
1467This variable contains a function the command interpreter calls when it wants
1468to invoke a command. The function receives the command and the prefix argument
1469as arguments. The initial value is a function which simply funcalls the
1470@f[command-function] of the command with the supplied prefix argument. This is
1471useful for implementing keyboard macros and similar things.
1472@enddefhvar
1473
1474@defhvar[var "Command Abort Hook"]
1475The command interpreter invokes the function in this variable whenever someone
1476aborts a command (for example, if someone called @f[editor-error]).
1477@enddefhvar
1478
1479When @hemlock initially starts the command interpreter is in control, but
1480commands may read from the keyboard themselves and assign whatever
1481interpretation they will to the key-events read. Commands may call the command
1482interpreter recursively using the function @funref[recursive-edit].
1483
1484
1485@subsection(Editor Input)
1486@label[key-events-intro]
1487@index[key-events]
1488
1489The canonical representation of editor input is a key-event structure. Users
1490can bind commands to keys (see section @ref[key-bindings]), which are non-zero
1491length sequences of key-events. A key-event consists of an identifying token
1492known as a @i[keysym] and a field of bits representing modifiers. Users define
1493keysyms, integers between 0 and 65535 inclusively, by supplying names that
1494reflect the legends on their keyboard's keys. Users define modifier names
1495similarly, but the system chooses the bit and mask for recognizing the
1496modifier. You can use keysym and modifier names to textually specify
1497key-events and Hemlock keys in a @f[#k] syntax. The following are some
1498examples:
1499@begin[programexample]
1500 #k"C-u"
1501 #k"Control-u"
1502 #k"c-m-z"
1503 #k"control-x meta-d"
1504 #k"a"
1505 #k"A"
1506 #k"Linefeed"
1507@end[programexample]
1508This is convenient for use within code and in init files containing
1509@f[bind-key] calls.
1510
1511The @f[#k] syntax is delimited by double quotes, but the system parses the
1512contents rather than reading it as a Common Lisp string. Within the double
1513quotes, spaces separate multiple key-events. A single key-event optionally
1514starts with modifier names terminated by hyphens. Modifier names are
1515alphabetic sequences of characters which the system uses case-insensitively.
1516Following modifiers is a keysym name, which is case-insensitive if it consists
1517of multiple characters, but if the name consists of only a single character,
1518then it is case-sensitive.
1519
1520You can escape special characters @dash hyphen, double quote, open angle
1521bracket, close angle bracket, and space @dash with a backslash, and you can
1522specify a backslash by using two contiguously. You can use angle brackets to
1523enclose a keysym name with many special characters in it. Between angle
1524brackets appearing in a keysym name position, there are only two special
1525characters, the closing angle bracket and backslash.
1526
1527For more information on key-events see section @ref[key-events].
1528
1529
1530
1531@subsection(Binding Commands to Keys)
1532@label[Key-Bindings]
1533@Index[Key Bindings]
1534
1535The command interpreter determines which command to invoke on the basis of
1536@i[key bindings]. A key binding is an association between a command and a
1537sequence of key-events (see section @ref[key-events-intro]. A sequence of
1538key-events is called a @i[key] and is represented by a single key-event or a
1539sequence (list or vector) of key-events.
1540
1541Since key bindings may be local to a mode or buffer, the current environment
1542(page @pageref[current-environment]) determines the set of key bindings in
1543effect at any given time. When the command interpreter tries to find the
1544binding for a key, it first checks if there is a local binding in the
1545@w[@funref[current-buffer]], then if there is a binding in each of the minor
1546modes and the major mode for the current buffer @w[(page @pageref[modes])], and
1547finally checks to see if there is a global binding. If no binding is found,
1548then the command interpreter beeps or flashes the screen to indicate this.
1549
1550@defun[fun {bind-key}, args
1551 {@i(name) @i(key) @optional @i[kind] @i[where]}]
1552 This function associates command @i[name] and @i[key] in some environment.
1553@i[Key] is either a key-event or a sequence of key-events. There are three
1554possible values of @i[kind]:
1555@begin(description)
1556@kwd[global]@\
1557 The default, make a global key binding.
1558
1559@kwd[mode]@\
1560 Make a mode specific key binding in the mode whose name is @i[where].
1561
1562@kwd[buffer]@\
1563 Make a binding which is local to buffer @i[where].
1564@end(description)
1565
1566This processes @i[key] for key translations before establishing the binding.
1567See section @ref[key-trans].
1568
1569If the key is some prefix of a key binding which already exists in the
1570specified place, then the new one will override the old one, effectively
1571deleting it.
1572
1573@f[ext:do-alpha-key-events] is useful for setting up bindings in certain new
1574modes.
1575@enddefun
1576
1577@defun[fun {command-bindings}, args {@i[command]}]
1578This function returns a list of the places where @i[command] is bound. A place
1579is specified as a list of the key (always a vector), the kind of binding, and
1580where (either the mode or buffer to which the binding is local, or @nil if it
1581is a global).
1582@enddefun
1583
1584@defun[fun {delete-key-binding}, args {@i[key] @optional @i[kind] @i[where]}]
1585This function removes the binding of @i[key] in some place. @i[Key] is either
1586a key-event or a sequence of key-events. @i[kind] is the kind of binding to
1587delete, one of @kwd[global] (the default), @kwd[mode] or @kwd[buffer]. If
1588@i[kind] is @kwd[mode], @i[where] is the mode name, and if @i[kind] is
1589@kwd[buffer], then @i[where] is the buffer.
1590
1591This function signals an error if @i[key] is unbound.
1592
1593This processes @i[key] for key translations before deleting the binding. See
1594section @ref[key-trans].
1595@enddefun
1596
1597@defun[fun {get-command}, args {@i[key] @optional @i[kind] @i[where]}]
1598This function returns the command bound to @i[key], returning @nil if it is
1599unbound. @i[Key] is either a key-event or a sequence of key-events. If
1600@i[key] is an initial subsequence of some keys, then this returns the keyword
1601@kwd[prefix]. There are four cases of @i[kind]:
1602@begin(description)
1603@kwd[current]@\
1604 Return the current binding of @i[key] using the current buffer's search list.
1605If there are any transparent key bindings for @i[key], then they are returned
1606in a list as a second value.
1607
1608@kwd[global]@\
1609 Return the global binding of @i[key]. This is the default.
1610
1611@kwd[mode]@\
1612 Return the binding of @i[key] in the mode named @i[where].
1613
1614@kwd[buffer]@\
1615 Return the binding of @i[key] local to the buffer @i[where].
1616@end(description)
1617
1618This processes @i[key] for key translations before looking for any binding.
1619See section @ref[key-trans].
1620@enddefun
1621
1622@defun[fun {map-bindings}, Args {@i[function] @i[kind] @optional @i[where]}]
1623This function maps over the key bindings in some place. For each binding, this
1624passes @i[function] the key and the command bound to it. @i[Kind] and
1625@i[where] are the same as in @f[bind-key]. The key is not guaranteed to remain
1626valid after a given iteration.
1627@enddefmac
1628
1629
1630@subsection[Key Translation]
1631@index[bit-prefix keys]
1632@index[key translation]
1633@index[translating keys]
1634@label[key-trans]
1635Key translation is a process that the command interpreter applies to keys
1636before doing anything else. There are two kinds of key translations:
1637substitution and bit-prefix. In either case, the command interpreter
1638translates a key when a specified key-event sequence appears in a key.
1639
1640In a substitution translation, the system replaces the matched subsequence with
1641another key-event sequence. Key translation is not recursively applied to the
1642substituted key-events.
1643
1644In a bit-prefix translation, the system removes the matched subsequence and
1645effectively sets the specified bits in the next key-event in the key.
1646
1647While translating a key, if the system encounters an incomplete final
1648subsequence of key-events, it aborts the translation process. This happens
1649when those last key-events form a prefix of some translation. It also happens
1650when they translate to a bit-prefix, but there is no following key-event to
1651which the system can apply the indicated modifier. If there is a binding for
1652this partially untranslated key, then the command interpreter will invoke that
1653command; otherwise, it will wait for the user to type more key-events.
1654
1655@defun[fun {key-translation}, args {@i[key]}]
1656This form is @f[setf]'able and allows users to register key translations that
1657the command interpreter will use as users type key-events.
1658
1659This function returns the key translation for @i[key], returning @nil if there
1660is none. @i[Key] is either a key-event or a sequence of key-events. If
1661@i[key] is a prefix of a translation, then this returns @kwd[prefix].
1662
1663A key translation is either a key or modifier specification. The bits
1664translations have a list form: @w<@f[(:bits {]@i[bit-name]@f[}*)]>.
1665
1666Whenever @i[key] appears as a subsequence of a key argument to the binding
1667manipulation functions, that portion will be replaced with the translation.
1668@enddefun
1669
1670
1671
1672@subsection[Transparent Key Bindings]
1673@label[transparent-key-bindings]
1674@index[Transparent key bindings]
1675
1676Key bindings local to a mode may be @i[transparent]. A transparent key
1677binding does not shadow less local key bindings, but rather indicates that
1678the bound command should be invoked before the first normal key binding.
1679Transparent key bindings are primarily useful for implementing minor modes
1680such as auto fill and word abbreviation. There may be several transparent
1681key bindings for a given key, in which case all of the commands bound are
1682invoked in the order they were found. If there no normal key binding for a
1683key typed, then the command interpreter acts as though the key is unbound
1684even if there are transparent key bindings.
1685
1686The @kwd[transparent-p] argument to @funref[defmode] determines whether the
1687key bindings in a mode are transparent or not.
1688
1689
1690@subsection (Interactive)
1691@index (Keyboard macro vs. interactive)
1692@index (Interactive vs. keyboard macro)
1693@Hemlock supports keyboard macros. A user may enter a mode where the editor
1694records his actions, and when the user exits this mode, the command @hid[Last
1695Keyboard Macro] plays back the actions. Some commands behave differently when
1696invoked as part of the definition of a keyboard macro. For example, when used
1697in a keyboard macro, a command that @f[message]'s useless user confirmation
1698will slow down the repeated invocations of @hid[Last Keyboard Macro] because
1699the command will pause on each execution to make sure the user sees the
1700message. This can be eliminated with the use of @f[interactive]. As another
1701example, some commands conditionally signal an editor-error versus simply
1702beeping the device depending on whether it executes on behalf of the user or a
1703keyboard macro.
1704
1705@defun[fun {interactive}]
1706This returns @true when the user invoked the command directly.
1707@enddefun
1708
1709
1710@section(Command Types)
1711@index(Command types)
1712@label(command-types)
1713In many editors the behavior of a command depends on the kind of command
1714invoked before it. @hemlock provides a mechanism to support this known as
1715@i(command type).
1716
1717@defun[fun {last-command-type}]
1718This returns the command type of the last command invoked. If this is set with
1719@f[setf], the supplied value becomes the value of @f[last-command-type] until
1720the next command completes. If the previous command did not set
1721@f[last-command-type], then its value is @nil. Normally a command type is a
1722keyword. The command type is not cleared after a command is invoked due to a
1723transparent key binding.
1724@enddefun
1725
1726
1727@section(Command Arguments)
1728@label[invoking-commands-as-functions]
1729There are three ways in which a command may be invoked: It may be bound to a
1730key which has been typed, it may be invoked as an extended command, or it may
1731be called as a Lisp function. Ideally commands should be written in such a way
1732that they will behave sensibly no matter which way they are invoked. The
1733functions which implement commands must obey certain conventions about argument
1734passing if the command is to function properly.
1735
1736
1737@subsection(The Prefix Argument)
1738@index(Prefix arguments)
1739Whenever a command is invoked it is passed as its first argument what
1740is known as the @i[prefix argument]. The prefix argument is always
1741either an integer or @nil. When a command uses this value it is
1742usually as a repeat count, or some conceptually similar function.
1743
1744@defun[fun {prefix-argument}]
1745This function returns the current value of the prefix argument. When
1746set with @f[setf], the new value becomes the prefix argument for the
1747next command.
1748@enddefun
1749
1750If the prefix argument is not set by the previous command then the
1751prefix argument for a command is @nil. The prefix argument is not cleared
1752after a command is invoked due to a transparent key binding.
1753
1754
1755@subsection(Lisp Arguments)
1756It is often desirable to call commands from Lisp code, in which case
1757arguments which would otherwise be prompted for are passed as optional
1758arguments following the prefix argument. A command should prompt for
1759any arguments not supplied.
1760
1761
1762@section(Recursive Edits)
1763@index(Recursive edits)
1764@defmac[fun {use-buffer}, args {@i[buffer] @mstar<@i[form]>}]
1765The effect of this is similar to setting the current-buffer to @i[buffer]
1766during the evaluation of @i[forms]. There are restrictions placed on what the
1767code can expect about its environment. In particular, the value of any global
1768binding of a @hemlock variable which is also a mode local variable of some mode
1769is ill-defined; if the variable has a global binding it will be bound, but the
1770value may not be the global value. It is also impossible to nest
1771@f[use-buffer]'s in different buffers. The reason for using @f[use-buffer] is
1772that it may be significantly faster than changing @f[current-buffer] to
1773@i[buffer] and back.
1774@enddefmac
1775
1776@defun[fun {recursive-edit}, args {@optional @i[handle-abort]}]
1777@defhvar1[var {Enter Recursive Edit Hook}]
1778@index[aborting]
1779@f[recursive-edit] invokes the command interpreter. The command interpreter
1780will read from the keyboard and invoke commands until it is terminated with
1781either @f[exit-recursive-edit] or @f[abort-recursive-edit].
1782
1783Normally, an editor-error or @bf[C-g] aborts the command in progress and
1784returns control to the top-level command loop. If @f[recursive-edit] is used
1785with @i[handle-abort] true, then @f[editor-error] or @bf[C-g] will only abort
1786back to the recursive command loop.
1787
1788Before the command interpreter is entered the hook
1789@hid[Enter Recursive Edit Hook] is invoked.
1790@enddefun
1791
1792@defun[fun {in-recursive-edit}]
1793This returns whether the calling point is dynamically within a recursive edit
1794context.
1795@enddefun
1796
1797@defun[fun {exit-recursive-edit}, args {@optional @i[values-list]}]
1798@defhvar1[var {Exit Recursive Edit Hook}]
1799@f[exit-recursive-edit] exits a recursive edit returning as multiple values
1800each element of @i[values-list], which defaults to @nil. This invokes
1801@hid[Exit Recursive Edit Hook] after exiting the command interpreter. If no
1802recursive edit is in progress, then this signals an error.
1803@enddefun
1804
1805@defun[fun {abort-recursive-edit}, args {@rest @i[args]}]
1806@defhvar1[var {Abort Recursive Edit Hook}]
1807@f[abort-recursive-edit] terminates a recursive edit by applying
1808@funref[editor-error] to @i[args] after exiting the command interpreter. This
1809invokes @hid[Abort Recursive Edit Hook] with @i[args] before aborting the
1810recursive edit . If no recursive edit is in progress, then this signals an
1811error.
1812@enddefun
1813
1814
1815
1816@Chapter(Modes)
1817@label[modes]
1818@index (Modes)
1819A mode is a collection of @hemlock values which may be present in the current
1820environment @w<(page @pageref(current-environment))> depending on the editing
1821task at hand. Examples of typical modes are @hid[Lisp], for editing Lisp code,
1822and @hid[Echo Area], for prompting in the echo area.
1823
1824
1825@section(Mode Hooks)
1826 When a mode is added to or removed from a buffer, its @i[mode hook]
1827is invoked. The hook functions take two arguments, the buffer
1828involved and @true if the mode is being added or @nil if it is being
1829removed.
1830
1831Mode hooks are typically used to make a mode do something additional to
1832what it usually does. One might, for example, make a text mode hook
1833that turned on auto-fill mode when you entered.
1834
1835
1836@section(Major and Minor Modes)
1837There are two kinds of modes, @i[major] modes and @i[minor] modes. A buffer
1838always has exactly one major mode, but it may have any number of minor modes.
1839Major modes may have mode character attributes while minor modes may not.
1840
1841A major mode is usually used to change the environment in some major way, such
1842as to install special commands for editing some language. Minor modes
1843generally change some small attribute of the environment, such as whether lines
1844are automatically broken when they get too long. A minor mode should work
1845regardless of what major mode and minor modes are in effect.
1846
1847@defhvar[var {Default Modes}, val {("Fundamental" "Save")}]
1848This variable contains a list of mode names which are instantiated in a
1849buffer when no other information is available.
1850@enddefhvar
1851
1852@defvar[var {mode-names}]
1853Holds a string-table of the names of all the modes.
1854@enddefvar
1855
1856@defcom[com "Illegal"]
1857This is a useful command to bind in modes that wish to shadow global bindings
1858by making them effectively illegal. Also, although less likely, minor modes
1859may shadow major mode bindings with this. This command calls @f[editor-error].
1860@enddefcom
1861
1862
1863@section(Mode Functions)
1864
1865@defun[fun {defmode}, args {@i[name]},
1866 keys {[setup-function][cleanup-function][major-p]},
1867 morekeys {[precedence][transparent-p][documentation]}]
1868This function defines a new mode named @i[name], and enters it in
1869@varref[mode-names]. If @i[major-p] is supplied and is not @nil
1870then the mode is a major mode; otherwise it is a minor mode.
1871
1872@i[Setup-function] and @i[cleanup-function] are functions which are
1873invoked with the buffer affected, after the mode is turned on, and
1874before it is turned off, respectively. These functions typically are
1875used to make buffer-local key or variable bindings and to remove them
1876when the mode is turned off.
1877
1878@i[Precedence] is only meaningful for a minor mode. The precedence of a
1879minor mode determines the order in which it in a buffer's list of modes.
1880When searching for values in the current environment, minor modes are
1881searched in order, so the precedence of a minor mode determines which value
1882is found when there are several definitions.
1883
1884@i[Transparent-p] determines whether key bindings local to the defined mode
1885are transparent. Transparent key bindings are invoked in addition to the
1886first normal key binding found rather than shadowing less local key bindings.
1887
1888@i[Documentation] is some introductory text about the mode. Commands such as
1889@hid[Describe Mode] use this.
1890@enddefun
1891
1892@defun[fun {mode-documentation}, args {@i[name]}]
1893This function returns the documentation for the mode named @i[name].
1894@enddefun
1895
1896@defun[fun {buffer-major-mode}, args {@i[buffer]}]
1897@defhvar1[var {Buffer Major Mode Hook}]
1898@f[buffer-major-mode] returns the name of @i[buffer]'s major mode.
1899The major mode may be changed with @f[setf]; then
1900 @hid[Buffer Major Mode Hook] is invoked with
1901@i[buffer] and the new mode.
1902@enddefun
1903
1904@defun[fun {buffer-minor-mode}, args {@i[buffer] @i[name]}]
1905@defhvar1[var {Buffer Minor Mode Hook}]
1906@f[buffer-minor-mode] returns @true if the minor mode @i[name] is active
1907in @i[buffer], @nil otherwise. A minor mode may be turned on or off
1908by using @f[setf]; then @hid[Buffer Minor Mode Hook] is
1909invoked with @i[buffer], @i[name] and the new value.
1910@enddefun
1911
1912@defun[fun {mode-variables}, args {@i[name]}]
1913Returns the string-table of mode local variables.
1914@enddefun
1915
1916@defun[fun {mode-major-p}, args {@i[name]}]
1917Returns @true if @i[name] is the name of a major mode, or @nil if
1918it is the name of a minor mode. It is an error for @i[name] not to be
1919the name of a mode.
1920@enddefun
1921
1922
1923
1924@chapter(Character Attributes)
1925@label(character-attributes)
1926@index(Character attributes)
1927@index(Syntax tables)
1928
1929@section(Introduction)
1930Character attributes provide a global database of information about characters.
1931This facility is similar to, but more general than, the @i[syntax tables] of
1932other editors such as @f[EMACS]. For example, you should use character
1933attributes for commands that need information regarding whether a character is
1934@i[whitespace] or not. Use character attributes for these reasons:
1935@begin(enumerate)
1936If this information is all in one place, then it is easy the change the
1937behavior of the editor by changing the syntax table, much easier than it would
1938be if character constants were wired into commands.
1939
1940This centralization of information avoids needless duplication of effort.
1941
1942The syntax table primitives are probably faster than anything that can be
1943written above the primitive level.
1944@end(enumerate)
1945
1946Note that an essential part of the character attribute scheme is that
1947@i[character attributes are global and are there for the user to change.]
1948Information about characters which is internal to some set of commands (and
1949which the user should not know about) should not be maintained as a character
1950attribute. For such uses various character searching abilities are provided by
1951the function @funref[find-pattern].
1952
1953@defcon[var {syntax-char-code-limit}]
1954The exclusive upper bound on character codes which are significant in
1955the character attribute functions. Font and bits are always ignored.
1956@enddefcon
1957
1958
1959@section(Character Attribute Names)
1960
1961As for @hemlock variables, character attributes have a user visible
1962string name, but are referred to in Lisp code as a symbol. The string
1963name, which is typically composed of capitalized words separated by
1964spaces, is translated into a keyword by replacing all spaces with
1965hyphens and interning this string in the keyword package. The
1966attribute named @hid[Ada Syntax] would thus become @kwd[ada-syntax].
1967
1968@defvar[var {character-attribute-names}]
1969Whenever a character attribute is defined, its name is entered in
1970this string table (page @pageref[string-tables]), with the
1971corresponding keyword as the value.
1972@enddefvar
1973
1974
1975@section(Character Attribute Functions)
1976
1977@defun[fun {defattribute}, args
1978 {@i[name] @i[documentation] @optional @i[type] @i[initial-value]}]
1979 This function defines a new character attribute with @i[name], a
1980simple-string. Character attribute operations take attribute arguments as a
1981keyword whose name is @i[name] uppercased with spaces replaced by hyphens.
1982
1983@i[Documentation] describes the uses of the character attribute.
1984
1985@i[Type], which defaults to @w<@f[(mod 2)]>, specifies what type the values of
1986the character attribute are. Values of a character attribute may be of any
1987type which may be specified to @f[make-array]. @i[Initial-value] (default
1988@f[0]) is the value which all characters will initially have for this
1989attribute.
1990@enddefun
1991
1992@defun[fun {character-attribute-name}, args {@i[attribute]}]
1993@defun1[fun {character-attribute-documentation}, args {@i[attribute]}]
1994These functions return the name or documentation for @i[attribute].
1995@enddefun
1996
1997@defun[fun {character-attribute}, args {@i[attribute] @i[character]}]
1998@defhvar1[var {Character Attribute Hook}]
1999@f[character-attribute] returns the value of @i[attribute] for @i[character].
2000This signals an error if @i[attribute] is undefined.
2001
2002@f[setf] will set a character's attributes. This @f[setf] method invokes the
2003functions in @hid[Character Attribute Hook] on the attribute and character
2004before it makes the change.
2005
2006If @i[character] is @nil, then the value of the attribute for the beginning or
2007end of the buffer can be accessed or set. The buffer beginning and end thus
2008become a sort of fictitious character, which simplifies the use of character
2009attributes in many cases.
2010@enddefun
2011
2012@defun[fun {character-attribute-p}, args {@i[symbol]}]
2013This function returns @true if @i[symbol] is the name of a character attribute,
2014@nil otherwise.
2015@enddefun
2016
2017@defun[fun {shadow-attribute}, args
2018{@i[attribute] @i[character] @i[value] @i[mode]}]
2019@defhvar1[var {Shadow Attribute Hook}]
2020This function establishes @i[value] as the value of @i[character]'s
2021@i[attribute] attribute when in the mode @i[mode]. @i[Mode] must be the name
2022of a major mode. @hid[Shadow Attribute Hook] is invoked with the same
2023arguments when this function is called. If the value for an attribute is set
2024while the value is shadowed, then only the shadowed value is affected, not the
2025global one.
2026@enddefun
2027
2028@defun[fun {unshadow-attribute}, args {@i[attribute] @i[character] @i[mode]}]
2029@defhvar1[var {Unshadow Attribute Hook}]
2030Make the value of @i[attribute] for @i[character] no longer be shadowed in
2031@i[mode]. @hid[Unshadow Attribute Hook] is invoked with the same arguments
2032when this function is called.
2033@enddefun
2034
2035@defun[fun {find-attribute},
2036 args {@i[mark] @i[attribute] @optional @i[test]}]
2037@defun1[fun {reverse-find-attribute},
2038 args {@i[mark] @i[attribute] @optional @i[test]}]
2039 These functions find the next (or previous) character with some value for the
2040character attribute @i[attribute] starting at @i[mark]. They pass @i[Test] one
2041argument, the value of @i[attribute] for the character tested. If the test
2042succeeds, then these routines modify @i[mark] to point before (after for
2043@f[reverse-find-attribute]) the character which satisfied the test. If no
2044characters satisfy the test, then these return @nil, and @i[mark] remains
2045unmodified. @i[Test] defaults to @f[not zerop]. There is no guarantee that
2046the test is applied in any particular fashion, so it should have no side
2047effects and depend only on its argument.
2048@enddefun
2049
2050
2051@section(Character Attribute Hooks)
2052
2053It is often useful to use the character attribute mechanism as an abstract
2054interface to other information about characters which in fact is stored
2055elsewhere. For example, some implementation of @hemlock might decide to define
2056a @hid[Print Representation] attribute which controls how a character is
2057displayed on the screen.
2058
2059To make this easy to do, each attribute has a list of hook functions
2060which are invoked with the attribute, character and new value whenever
2061the current value changes for any reason.
2062
2063@defun[fun {character-attribute-hooks}, args {@i[attribute]}]
2064Return the current hook list for @i[attribute]. This may be set with
2065@f[setf]. The @f[add-hook] and @macref[remove-hook] macros should
2066be used to manipulate these lists.
2067@enddefun
2068
2069
2070@section (System Defined Character Attributes)
2071@label(sys-def-chars)
2072These are predefined in @hemlock:
2073@begin[description]
2074@hid[Whitespace]@\
2075A value of @f[1] indicates the character is whitespace.
2076
2077@hid[Word Delimiter]@\
2078A value of @f[1] indicates the character separates words (see section
2079@ref[text-functions]).
2080
2081@hid[Digit]@\
2082A value of @f[1] indicates the character is a base ten digit. This may be
2083shadowed in modes or buffers to mean something else.
2084
2085@hid[Space]@\
2086This is like @hid[Whitespace], but it should not include @binding[Newline].
2087@hemlock uses this primarily for handling indentation on a line.
2088
2089@hid[Sentence Terminator]@\
2090A value of @f[1] indicates these characters terminate sentences (see section
2091@ref[text-functions]).
2092
2093@hid[Sentence Closing Char]@\
2094A value of @f[1] indicates these delimiting characters, such as @binding["]
2095or @binding[)], may follow a @hid[Sentence Terminator] (see section
2096@ref[text-functions]).
2097
2098@hid[Paragraph Delimiter]@\
2099A value of @f[1] indicates these characters delimit paragraphs when they begin
2100a line (see section @ref[text-functions]).
2101
2102@hid[Page Delimiter]@\
2103A value of @f[1] indicates this character separates logical pages (see section
2104@ref[logical-pages]) when it begins a line.
2105
2106@hid[Scribe Syntax]@\
2107This uses the following symbol values:
2108@begin[multiple]
2109@begin[description]
2110@nil@\These characters have no interesting properties.
2111
2112@kwd[escape]@\This is @binding[@@] for the Scribe formatting language.
2113
2114@kwd[open-paren]@\These characters begin delimited text.
2115
2116@kwd[close-paren]@\These characters end delimited text.
2117
2118@kwd[space]@\These characters can terminate the name of a formatting command.
2119
2120@kwd[newline]@\These characters can terminate the name of a formatting command.
2121@end[description]
2122@end[multiple]
2123
2124
2125@hid[Lisp Syntax]@\
2126This uses symbol values from the following:
2127@begin[multiple]
2128@begin[description]
2129@nil@\These characters have no interesting properties.
2130
2131@kwd[space]@\These characters act like whitespace and should not include
2132@binding[Newline].
2133
2134@kwd[newline]@\This is the @binding[Newline] character.
2135
2136@kwd[open-paren]@\This is @binding[(] character.
2137
2138@kwd[close-paren]@\This is @binding[)] character.
2139
2140@kwd[prefix]@\This is a character that is a part of any form it precedes @dash
2141for example, the single quote, @binding['].
2142
2143@kwd[string-quote]@\This is the character that quotes a string literal,
2144@binding["].@comment["]
2145
2146@kwd[char-quote]@\This is the character that escapes a single character,
2147@binding[\].
2148
2149@kwd[comment]@\This is the character that makes a comment with the rest of the
2150line, @binding[;].
2151
2152@kwd[constituent]@\These characters are constitute symbol names.
2153@end[description]
2154@end[multiple]
2155
2156@end[description]
2157
2158
2159
2160@chapter (Controlling the Display)
2161@section (Windows)
2162@tag[windows]
2163@index(Windows)
2164@index(modelines)
2165
2166A window is a mechanism for displaying part of a buffer on some physical
2167device. A window is a way to view a buffer but is not synonymous with one; a
2168buffer may be viewed in any number of windows. A window may have a
2169@i[modeline] which is a line of text displayed across the bottom of a window to
2170indicate status information, typically related to the buffer displayed.
2171
2172
2173@section (The Current Window)
2174@index (Current window)
2175@defun[fun {current-window}, args {}]
2176@defhvar1[var {Set Window Hook}]
2177@f[current-window] returns the window in which the cursor is currently
2178displayed. The cursor always tracks the buffer-point of the corresponding
2179buffer. If the point is moved to a position which would be off the screen the
2180recentering process is invoked. Recentering shifts the starting point of the
2181window so that the point is once again displayed. The current window may be
2182changed with @f[setf]. Before the current window is changed, the hook @hid[Set
2183Window Hook] is invoked with the new value.
2184@enddefun
2185
2186@defvar[var {window-list}]
2187Holds a list of all the window objects made with @funref[make-window].
2188@enddefvar
2189
2190
2191@section(Window Functions)
2192
2193@defun[fun {make-window}, args {@i[mark]},
2194 keys {[modelinep][window][ask-user]},
2195 morekeys {[x][y][width][height]},
2196 morekeys {[proportion]}]
2197@defhvar1[var {Default Window Width}]
2198@defhvar1[var {Default Window Height}]
2199@defhvar1[var {Make Window Hook}]
2200
2201@comment[NOTE, we purposefully do not document the font-family or device
2202 arguments since we don't officially support fonts or devices.]
2203
2204@f[make-window] returns a window displaying text starting at @i[mark], which
2205must point into a buffer. If it could not make a window on the device, it
2206returns nil. The default action is to make the new window a proportion of the
2207@f[current-window]'s height to make room for the new window.
2208
2209@i[Modelinep] specifies whether the window should display buffer modelines.
2210
2211@i[Window] is a device dependent window to be used with the Hemlock window.
2212The device may not support this argument. @i[Window] becomes the parent window
2213for a new group of windows that behave in a stack orientation as windows do on
2214the terminal.
2215
2216If @i[ask-user] is non-@nil, @hemlock prompts the user for the missing
2217dimensions (@i[x], @i[y], @i[width], and @i[height]) to make a new group of
2218windows, as with the @i[window] argument. The device may not support this
2219argument. Non-null values other than @f[t] may have device dependent meanings.
2220@i[X] and @i[y] are in pixel units, but @i[width] and @i[height] are characters
2221units. @hid[Default Window Width] and @hid[Default Window Height] are the
2222default values for the @i[width] and @i[height] arguments.
2223
2224@i[Proportion] determines what proportion of the @f[current-window]'s height
2225the new window will use. The @f[current-window] retains whatever space left
2226after accommodating the new one. The default is to split the window in half.
2227
2228This invokes @hid[Make Window Hook] with the new window.
2229@enddefun
2230
2231@defun[fun {windowp}, args {@i[window]}]
2232This function returns @true if @i[window] is a @f[window] object, otherwise
2233@nil.
2234@enddefun
2235
2236@defun[fun {delete-window}, args {@i[window]}]
2237@defhvar1[var {Delete Window Hook}]
2238@f[delete-window] makes @i[window] go away, first invoking @hid[Delete Window
2239Hook] with @i[window].
2240@enddefun
2241
2242@defun[fun {window-buffer}, args {@i[window]}]
2243@defhvar1[var {Window Buffer Hook}]
2244@f[window-buffer] returns the buffer from which the window displays
2245text. This may be changed with @f[setf], in which case the hook
2246@hid[Window Buffer Hook] is invoked beforehand with the window and the
2247new buffer.
2248@enddefun
2249
2250@defun[fun {window-display-start}, args {@i[window]}]
2251@defun1[fun {window-display-end}, args {@i[window]}]
2252@f[window-display-start] returns the mark that points before the first
2253character displayed in @i[window]. Note that if @i[window] is the current
2254window, then moving the start may not prove much, since recentering may move it
2255back to approximately where it was originally.
2256
2257@f[window-display-end] is similar, but points after the last character
2258displayed. Moving the end is meaningless, since redisplay always moves it to
2259after the last character.
2260@enddefun
2261
2262@defun[fun {window-display-recentering}, args {@i[window]}]
2263This function returns whether redisplay will ensure the buffer's point of
2264@i[window]'s buffer is visible after redisplay. This is @f[setf]'able, and
2265changing @i[window]'s buffer sets this to @nil via @hid[Window Buffer Hook].
2266@enddefun
2267
2268@defun[fun {window-point}, args {@i[window]}]
2269This function returns as a mark the position in the buffer where the cursor is
2270displayed. This may be set with @f[setf]. If @i[window] is the current
2271window, then setting the point will have little effect; it is forced to track
2272the buffer point. When the window is not current, the window point is the
2273position that the buffer point will be moved to when the window becomes
2274current.
2275@enddefun
2276
2277@defun[fun {center-window}, args {@i[window] @i[mark]}]
2278This function attempts to adjust window's display start so the that @i[mark] is
2279vertically centered within the window.
2280@enddefun
2281
2282@defun[fun {scroll-window}, args {@i[window] @i[n]}]
2283This function scrolls the window down @i[n] display lines; if @i[n] is negative
2284scroll up. Leave the cursor at the same text position unless we scroll it off
2285the screen, in which case the cursor is moved to the end of the window closest
2286to its old position.
2287@enddefun
2288
2289@defun[fun {displayed-p}, args {@i[mark] @i[window]}]
2290Returns @true if either the character before or the character after @i[mark]
2291is being displayed in @i[window], or @nil otherwise.
2292@enddefun
2293
2294@defun[fun {window-height}, args {@i[window]}]
2295@defun1[fun {window-width}, args {@i[window]}]
2296Height or width of the area of the window used for displaying the
2297buffer, in character positions. These values may be changed with
2298@f[setf], but the setting attempt may fail, in which case nothing is done.
2299@enddefun
2300
2301@defun[fun {next-window}, args {@i[window]}]
2302@defun1[fun {previous-window}, args {@i[window]}]
2303Return the next or previous window of @i[window]. The exact meaning of next
2304and previous depends on the device displaying the window. It should be
2305possible to cycle through all the windows displayed on a device using either
2306next or previous (implying that these functions wrap around.)
2307@enddefun
2308
2309
2310@section(Cursor Positions)
2311@index(Cursor positions)
2312A cursor position is an absolute position within a window's coordinate
2313system. The origin is in the upper-left-hand corner and the unit
2314is character positions.
2315
2316@defun[fun {mark-to-cursorpos}, args {@i[mark] @i[window]}]
2317Returns as multiple values the @f[X] and @f[Y] position on which
2318@i[mark] is being displayed in @i[window], or @nil if it is not within the
2319bounds displayed.
2320@enddefun
2321
2322@defun[fun {cursorpos-to-mark}, args {@i[X] @i[Y] @i[window]}]
2323Returns as a mark the text position which corresponds to the given
2324(@i[X], @i[Y]) position within window, or @nil if that
2325position does not correspond to any text within @i[window].
2326@enddefun
2327
2328@defun[fun {last-key-event-cursorpos}]
2329Interprets mouse input. It returns as multiple values the (@i[X], @i[Y])
2330position and the window where the pointing device was the last time some key
2331event happened. If the information is unavailable, this returns @nil.
2332@enddefun
2333
2334@defun[fun {mark-column}, args {@i[mark]}]
2335This function returns the @i[X] position at which @i[mark] would be displayed,
2336supposing its line was displayed on an infinitely wide screen. This takes into
2337consideration strange characters such as tabs.
2338@enddefun
2339
2340@defun[fun {move-to-column}, args {@i[mark] @i[column] @optional @i[line]}]
2341This function is analogous to @funref[move-to-position], except that
2342it moves @i[mark] to the position on @i[line] which corresponds to the
2343specified @i[column]. @i[Line] defaults to the line that @i[mark] is
2344currently on. If the line would not reach to the specified column,
2345then @nil is returned and @i[mark] is not modified. Note that since a
2346character may be displayed on more than one column on the screen,
2347several different values of @i[column] may cause @i[mark] to be moved
2348to the same position.
2349@enddefun
2350
2351@defun[fun {show-mark}, args {@i[mark] @i[window] @i[time]}]
2352This function highlights the position of @i[mark] within @i[window] for
2353@i[time] seconds, possibly by moving the cursor there. The wait may be aborted
2354if there is pending input. If @i[mark] is positioned outside the text
2355displayed by @i[window], then this returns @nil, otherwise @true.
2356@enddefun
2357
2358
2359@section(Redisplay)
2360Redisplay translates changes in the internal representation of text into
2361changes on the screen. Ideally this process finds the minimal transformation
2362to make the screen correspond to the text in order to maximize the speed of
2363redisplay.
2364
2365@defun[fun {redisplay}]
2366@defhvar1[var "Redisplay Hook"]
2367@f[redisplay] executes the redisplay process, and @hemlock typically invokes
2368this whenever it looks for input. The redisplay process frequently checks for
2369input, and if it detects any, it aborts. The return value is interpreted as
2370follows:
2371@begin[description]
2372@false@\No update was needed.
2373
2374@true@\Update was needed, and completed successfully.
2375
2376@kwd[editor-input]@\Update is needed, but was aborted due to pending input.
2377@end[description]
2378
2379This function invokes the functions in @hid[Redisplay Hook] on the current
2380window after computing screen transformations but before executing them. After
2381invoking the hook, this recomputes the redisplay and then executes it on the
2382current window.
2383
2384For the current window and any window with @f[window-display-recentering] set,
2385@f[redisplay] ensures the buffer's point for the window's buffer is visible
2386after redisplay.
2387@enddefun
2388
2389@defun[fun {redisplay-all}]
2390This causes all editor windows to be completely redisplayed. For the current
2391window and any window with @f[window-display-recentering] set, this ensures the
2392buffer's point for the window's buffer is visible after redisplay. The return
2393values are the same as for redisplay, except that @false is never returned.
2394@enddefun
2395
2396@defun[fun {editor-finish-output}, args {@i[window]}]
2397This makes sure the editor is synchronized with respect to redisplay output to
2398@i[window]. This may do nothing on some devices.
2399@enddefun
2400
2401
2402
2403@chapter(Logical Key-Events)
2404@label[logical-key-events]
2405@index[Logical key-events]
2406
2407
2408@section[Introduction]
2409Some primitives such as @funref[prompt-for-key] and commands such as EMACS
2410query replace read key-events directly from the keyboard instead of using the
2411command interpreter. To encourage consistency between these commands and to
2412make them portable and easy to customize, there is a mechanism for defining
2413@i[logical key-events].
2414
2415A logical key-event is a keyword which stands for some set of key-events. The
2416system globally interprets these key-events as indicators a particular action.
2417For example, the @kwd[help] logical key-event represents the set of key-events
2418that request help in a given @hemlock implementation. This mapping is a
2419many-to-many mapping, not one-to-one, so a given logical key-event may have
2420multiple corresponding actual key-events. Also, any key-event may represent
2421different logical key-events.
2422
2423
2424@section[Logical Key-Event Functions]
2425
2426@defvar[var {logical-key-event-names}]
2427This variable holds a string-table mapping all logical key-event names to the
2428keyword identifying the logical key-event.
2429@enddefvar
2430
2431@defun[fun {define-logical-key-event}, args {@i[string-name] @i[documentation]}]
2432 This function defines a new logical key-event with name @i[string-name], a
2433simple-string. Logical key-event operations take logical key-events arguments
2434as a keyword whose name is @i[string-name] uppercased with spaces replaced by
2435hyphens.
2436
2437@i[Documentation] describes the action indicated by the logical key-event.
2438@enddefun
2439
2440@defun[fun {logical-key-event-key-events}, args {@i[keyword]}]
2441This function returns the list of key-events representing the logical key-event
2442@i[keyword].
2443@enddefun
2444
2445@defun[fun {logical-key-event-name}, args {@i[keyword]}]
2446@defun1[fun {logical-key-event-documentation}, args {@i[keyword]}]
2447These functions return the string name and documentation given to
2448@f[define-logical-key-event] for logical key-event @i[keyword].
2449@enddefun
2450
2451@defun[fun {logical-key-event-p}, args {@i[key-event] @i[keyword]}]
2452This function returns @f[t] if @i[key-event] is the logical key-event
2453@i[keyword]. This is @f[setf]'able establishing or disestablishing key-events
2454as particular logical key-events. It is a error for @i[keyword] to be an
2455undefined logical key-event.
2456@enddefun
2457
2458
2459@section[System Defined Logical Key-Events]
2460There are many default logical key-events, some of which are used by functions
2461documented in this manual. If a command wants to read a single key-event
2462command that fits one of these descriptions then the key-event read should be
2463compared to the corresponding logical key-event instead of explicitly
2464mentioning the particular key-event in the code. In many cases you can use the
2465@macref[command-case] macro. It makes logical key-events easy to use and takes
2466care of prompting and displaying help messages.
2467
2468@begin[description]
2469@kwd[yes]@\
2470 Indicates the prompter should take the action under consideration.
2471
2472@kwd[no]@\
2473 Indicates the prompter should NOT take the action under consideration.
2474
2475@kwd[do-all]@\
2476 Indicates the prompter should repeat the action under consideration as many
2477times as possible.
2478
2479@kwd[do-once]@\
2480 Indicates the prompter should execute the action under consideration once and
2481then exit.
2482
2483@kwd[exit]@\
2484 Indicates the prompter should terminate its activity in a normal fashion.
2485
2486@kwd[abort]@\
2487 Indicates the prompter should terminate its activity without performing any
2488closing actions of convenience, for example.
2489
2490@kwd[keep]@\
2491 Indicates the prompter should preserve something.
2492
2493@kwd[help]@\
2494 Indicates the prompter should display some help information.
2495
2496@kwd[confirm]@\
2497 Indicates the prompter should take any input provided or use the default if
2498the user entered nothing.
2499
2500@kwd[quote]@\
2501 Indicates the prompter should take the following key-event as itself without
2502any sort of command interpretation.
2503
2504@kwd[recursive-edit]@\
2505 Indicates the prompter should enter a recursive edit in the current context.
2506
2507@kwd[cancel]@\
2508 Indicates the prompter should cancel the effect of a previous key-event input.
2509
2510@kwd[forward-search]@\
2511 Indicates the prompter should search forward in the current context.
2512
2513@kwd[backward-search]@\
2514 Indicates the prompter should search backward in the current context.
2515@end[description]
2516
2517@blankspace(1 line)
2518Define a new logical key-event whenever:
2519@begin[enumerate]
2520The key-event concerned represents a general class of actions, and
2521several commands may want to take a similar action of this type.
2522
2523The exact key-event a command implementor chooses may generate violent taste
2524disputes among users, and then the users can trivially change the command in
2525their init files.
2526
2527You are using @f[command-case] which prevents implementors from specifying
2528non-standard characters for dispatching in otherwise possibly portable code,
2529and you can define and set the logical key-event in a site dependent file where
2530you can mention implementation dependent characters.
2531@end[enumerate]
2532
2533
2534
2535@chapter(The Echo Area)
2536
2537@hemlock provides a number of facilities for displaying information and
2538prompting the user for it. Most of these work through a small window displayed
2539at the bottom of the screen. This is called the echo area and is supported by
2540a buffer and a window. This buffer's modeline (see section @ref[modelines]) is
2541referred to as the status line, which, unlike other buffers' modelines, is used
2542to show general status about the editor, Lisp, or world.
2543
2544@defhvar[var {Default Status Line Fields}]
2545This is the initial list of modeline-field objects stored in the echo area
2546buffer.
2547@enddefhvar
2548
2549@defhvar[var "Echo Area Height", val {3}]
2550This variable determines the initial height in lines of the echo area window.
2551@enddefhvar
2552
2553
2554@section(Echo Area Functions)
2555It is considered poor taste to perform text operations on the echo area buffer
2556to display messages; the @f[message] function should be used instead. A
2557command must use this function or set @funref[buffer-modified] for the
2558@hid[Echo Area] buffer to @nil to cause @hemlock to leave text in the echo area
2559after the command's execution.
2560
2561@defun[fun {clear-echo-area}]
2562Clears the echo area.
2563@enddefun
2564
2565@defun[fun {message}, args {@i[control-string] @rest @i[format-arguments]}]
2566@defun1[fun {loud-message}, args {@i[control-string] @rest @i[format-arguments]}]
2567@defhvar1[var {Message Pause}, val {0.5}]
2568Displays a message in the echo area. The message is always displayed on a
2569fresh line. @f[message] pauses for @hid[Message Pause] seconds before
2570returning to assure that messages are not displayed too briefly to be seen.
2571Because of this, @f[message] is the best way to display text in the echo area.
2572
2573@f[loud-message] is like @f[message], but it first clears the echo area and
2574beeps.
2575@enddefun
2576
2577@defvar[var {echo-area-window}]
2578@defvar1[var {echo-area-buffer}]
2579@f[echo-area-buffer] contains the buffer object for the echo area, which is
2580named @hid[Echo Area]. This buffer is usually in @hid[Echo Area] mode.
2581@f[echo-area-window] contains a window displaying @f[echo-area-buffer]. Its
2582modeline is the status line, see the beginning of this chapter.
2583@enddefvar
2584
2585@defvar[var {echo-area-stream}]
2586@index (Echo area)
2587This is a buffered @hemlock output stream
2588(@pageref[make-hemlock-output-stream-fun]) which inserts text written to it at
2589the point of the echo area buffer. Since this stream is buffered a
2590@f[force-output] must be done when output is complete to assure that it is
2591displayed.
2592@enddefvar
2593
2594
2595@section(Prompting Functions)
2596@index(Prompting functions)
2597Most of the prompting functions accept the following keyword arguments:
2598@begin(description)
2599@kwd[must-exist] @\If @kwd[must-exist] has a non-@nil value then the
2600user is prompted until a valid response is obtained. If
2601@kwd[must-exist] is @nil then return as a string whatever is input.
2602The default is @true.
2603
2604@kwd[default] @\If null input is given when the user is prompted
2605then this value is returned. If no default is given then
2606some input must be given before anything interesting will happen.
2607
2608@kwd[default-string] @\If a @kwd[default] is given then this is a
2609string to be printed to indicate what the default is. The default is
2610some representation of the value for @kwd[default], for example for a
2611buffer it is the name of the buffer.
2612
2613@kwd[prompt] @\This is the prompt string to display.
2614
2615@kwd[help] @\@multiple{
2616This is similar to @kwd[prompt], except that it is displayed when
2617the help command is typed during input. @comment{If there is some known number
2618of options as in keyword parses, then they may be displayed, depending
2619on the setting of @hvarref[Help Show Options].}
2620
2621This may also be a function. When called with no arguments, it should either
2622return a string which is the help text or perform some action to help the user,
2623returning @Nil.}
2624@end(description)
2625
2626@defun[fun {prompt-for-buffer}, keys {[prompt][help][must-exist][default]},
2627 morekeys {[default-string]}]
2628Prompts with completion for a buffer name and returns the corresponding buffer.
2629If @i[must-exist] is @nil, then it returns the input string if it is not a
2630buffer name. This refuses to accept the empty string as input when
2631@kwd[default] and @kwd[default-string] are @nil. @kwd[default-string] may be
2632used to supply a default buffer name when @kwd[default] is @nil, but when
2633@kwd[must-exist] is non-@nil, it must name an already existing buffer.
2634@enddefun
2635
2636@defmac[fun {command-case}, Args {(@mstar<@i[key] @i[value]>) @Mstar<(@Mgroup"(@MSTAR'@i[tag]') @MOR @i[tag]" @i[help] @MSTAR'@i[form]')>}]
2637 This macro is analogous to the Common Lisp @f[case] macro. Commands such as
2638@hid[Query Replace] use this to get a key-event, translate it to a character,
2639and then to dispatch on the character to some case. In addition to character
2640dispatching, this supports logical key-events @w<(page
2641@pageref[logical-key-events])> by using the input key-event directly without
2642translating it to a character. Since the description of this macro is rather
2643complex, first consider the following example:
2644@lisp
2645(defcommand "Save All Buffers" (p)
2646 "Give the User a chance to save each modified buffer."
2647 "Give the User a chance to save each modified buffer."
2648 (dolist (b *buffer-list*)
2649 (select-buffer-command () b)
2650 (when (buffer-modified b)
2651 (command-case (:prompt "Save this buffer: [Y] "
2652 :help "Save buffer, or do something else:")
2653 ((:yes :confirm)
2654 "Save this buffer and go on to the next."
2655 (save-file-command () b))
2656 (:no "Skip saving this buffer, and go on to the next.")
2657 (:recursive-edit
2658 "Go into a recursive edit in this buffer."
2659 (do-recursive-edit) (reprompt))
2660 ((:exit #\p) "Punt this silly loop."
2661 (return nil))))))
2662@endlisp
2663
2664@f[command-case] prompts for a key-event and then executes the code in the
2665first branch with a logical key-event or a character (called @i[tags]) matching
2666the input. Each character must be a standard-character, one that satisfies the
2667Common Lisp @f[standard-char-p] predicate, and the dispatching mechanism
2668compares the input key-event to any character tags by mapping the key-event to
2669a character with @f[ext:key-event-char]. If the tag is a logical key-event,
2670then the search for an appropriate case compares the key-event read with the
2671tag using @f[logical-key-event-p].
2672
2673All uses of @f[command-case] have two default cases, @kwd[help] and
2674@kwd[abort]. You can override these easily by specifying your own branches
2675that include these logical key-event tags. The @kwd[help] branch displays in a
2676pop-up window the a description of the valid responses using the variously
2677specified help strings. The @kwd[abort] branch signals an editor-error.
2678
2679The @i[key]/@i[value] arguments control the prompting. The following are valid
2680values:
2681@begin[description]
2682@kwd[help]@\
2683 The default @kwd[help] case displays this string in a pop-up window. In
2684addition it formats a description of the valid input including each case's
2685@i[help] string.
2686
2687@kwd[prompt]@\
2688 This is the prompt used when reading the key-event.
2689
2690@kwd[change-window]@\
2691 If this is non-nil (the default), then the echo area window becomes the
2692current window while the prompting mechanism reads a key-event. Sometimes it
2693is desirable to maintain the current window since it may be easier for users to
2694answer the question if they can see where the current point is.
2695
2696@kwd[bind]@\
2697 This specifies a variable to which the prompting mechanism binds the input
2698key-event. Any case may reference this variable. If you wish to know what
2699character corresponds to the key-event, use @f[ext:key-event-char].
2700@end(description)
2701
2702Instead of specifying a tag or list of tags, you may use @true. This becomes
2703the default branch, and its forms execute if no other branch is taken,
2704including the default @kwd[help] and @kwd[abort] cases. This option has no
2705@i[help] string, and the default @kwd[help] case does not describe the default
2706branch. Every @f[command-case] has a default branch; if none is specified, the
2707macro includes one that @f[system:beep]'s and @f[reprompt]'s (see below).
2708
2709Within the body of @f[command-case], there is a defined @f[reprompt] macro.
2710It causes the prompting mechanism and dispatching mechanism to immediately
2711repeat without further execution in the current branch.
2712@enddefmac
2713
2714
2715@defun[fun {prompt-for-key-event}, keys {[prompt][change-window]}]
2716This function prompts for a key-event returning immediately when the user types
2717the next key-event. @macref[command-case] is more useful for most purposes.
2718When appropriate, use logical key-events @w<(page
2719@pageref[logical-key-events])>.
2720@enddefun
2721
2722@defun[fun {prompt-for-key}, keys {[prompt][help][must-exist][default]},
2723 morekeys {[default-string]}]
2724 This function prompts for a @i[key], a vector of key-events, suitable for
2725passing to any of the functions that manipulate key bindings @w<(page
2726@pageref[key-bindings])>. If @i[must-exist] is true, then the key must be
2727bound in the current environment, and the command currently bound is returned
2728as the second value.
2729@enddefun
2730
2731@defun[fun {prompt-for-file}, keys {[prompt][help][must-exist][default]},
2732 morekeys {[default-string]}]
2733 This function prompts for an acceptable filename in some system dependent
2734fashion. "Acceptable" means that it is a legal filename, and it exists if
2735@i[must-exist] is non-@nil. @f[prompt-for-file] returns a Common Lisp
2736pathname.
2737
2738If the file exists as entered, then this returns it, otherwise it is merged
2739with @i[default] as by @f[merge-pathnames].
2740@enddefun
2741
2742@defun[fun {prompt-for-integer}, keys {[prompt][help][must-exist][default]},
2743 morekeys {[default-string]}]
2744 This function prompts for a possibly signed integer. If @i[must-exist] is
2745@nil, then @f[prompt-for-integer] returns the input as a string if it is not a
2746valid integer.
2747@enddefun
2748
2749@defun[fun {prompt-for-keyword}, args {@i[string-tables]},
2750 keys {[prompt][help][must-exist]},
2751 morekeys {[default][default-string]}]
2752 This function prompts for a keyword with completion, using the string tables
2753in the list @i[string-tables]. If @I[must-exist] is non-@nil, then the result
2754must be an unambiguous prefix of a string in one of the @i[string-tables], and
2755the returns the complete string even if only a prefix of the full string was
2756typed. In addition, this returns the value of the corresponding entry in the
2757string table as the second value.
2758
2759If @i[must-exist] is @nil, then this function returns the string exactly as
2760entered. The difference between @f[prompt-for-keyword] with @i[must-exist]
2761@nil, and @f[prompt-for-string], is the user may complete the input using the
2762@hid<Complete Parse> and @hid<Complete Field> commands.
2763@enddefun
2764
2765@defun[fun {prompt-for-expression},
2766 keys {[prompt][help][must-exist][default]},
2767 morekeys {[default-string]}]
2768 This function reads a Lisp expression. If @i[must-exist] is @nil, and a read
2769error occurs, then this returns the string typed.
2770@enddefun
2771
2772@defun[fun {prompt-for-string}, keys
2773{[prompt][help][default][default-string]}]
2774 This function prompts for a string; this cannot fail.
2775@enddefun
2776
2777@defun[fun {prompt-for-variable}, keys {[prompt][help][must-exist][default]},
2778 morekeys {[default-string]}]
2779 This function prompts for a variable name. If @i[must-exist] is non-@nil,
2780then the string must be a variable @i[defined in the current environment], in
2781which case the symbol name of the variable found is returned as the second
2782value.
2783@enddefun
2784
2785@defun[fun {prompt-for-y-or-n}, keys {[prompt][help][must-exist][default]},
2786 morekeys {[default-string]}]
2787 This prompts for @binding[y], @binding[Y], @binding[n], or @binding[N],
2788returning @true or @nil without waiting for confirmation. When the user types
2789a confirmation key, this returns @i[default] if it is supplied. If
2790@i[must-exist] is @nil, this returns whatever key-event the user first types;
2791however, if the user types one of the above key-events, this returns @true or
2792@nil. This is analogous to the Common Lisp function @f[y-or-n-p].
2793@enddefun
2794
2795@defun[fun {prompt-for-yes-or-no}, keys {[prompt][help][must-exist][default]},
2796 morekeys {[default-string]}]
2797 This function is to @f[prompt-for-y-or-n] as @f[yes-or-no-p] is to
2798@f[y-or-n-p]. "Yes" or "No" must be typed out in full and
2799confirmation must be given.
2800@enddefun
2801
2802
2803@section(Control of Parsing Behavior)
2804
2805@defhvar[var {Beep On Ambiguity}, val {@true}]
2806If this variable is true, then an attempt to complete a parse which is
2807ambiguous will result in a "beep".
2808@enddefhvar
2809
2810
2811@begin(comment)
2812@hemlock provides for limited control of parsing routine behaviour The
2813character attribute @hid[Parse Field Separator] is a boolean attribute, a value
2814of @f[1] indicating that the character is a field separator recognized by the
2815@hid<Complete Field> command.
2816@end(comment)
2817
2818@begin(comment)
2819@defhvar[var {Help Show Options}]
2820During a keyword or similar parse, typing the help command may cause a
2821list of options to be displayed. If displaying the help would take up
2822more lines than the value of this variable then confirmation will be
2823asked for before they will be displayed.
2824@enddefhvar
2825@end(comment)
2826
2827
2828
2829@section(Defining New Prompting Functions)
2830Prompting functions are implemented as a recursive edit in the
2831@hid[Echo Area] buffer. Completion, help, and other parsing features
2832are implemented by commands which are bound in @hid[Echo Area Mode].
2833
2834A prompting function passes information down into the recursive edit
2835by binding a collection of special variables.
2836
2837@defvar[var {parse-verification-function}]
2838The system binds this to a function that @comref[Confirm Parse] calls. It does
2839most of the work when parsing prompted input. @comref[Confirm Parse] passes
2840one argument, which is the string that was in @var<parse-input-region> when the
2841user invokes the command. The function should return a list of values which
2842are to be the result of the recursive edit, or @nil indicating that the parse
2843failed. In order to return zero values, a non-@nil second value may be
2844returned along with a @nil first value.
2845@enddefvar
2846
2847@defvar[var {parse-string-tables}]
2848This is the list of @f[string-table]s, if any, that pertain to this parse.
2849@enddefvar
2850
2851@defvar[var {parse-value-must-exist}]
2852This is bound to the value of the @kwd[must-exist] argument, and is
2853referred to by the verification function, and possibly some of the
2854commands.
2855@enddefvar
2856
2857@defvar[var {parse-default}]
2858When prompting the user, this is bound to a string representing the default
2859object, the value supplied as the @kwd[default] argument. @hid<Confirm Parse>
2860supplies this to the parse verification function when the
2861@var<parse-input-region> is empty.
2862@enddefvar
2863
2864@defvar[var {parse-default-string}]
2865When prompting the user, if @var[parse-default] is @nil, @hemlock displays this
2866string as a representation of the default object; for example, when prompting
2867for a buffer, this variable would be bound to the buffer name.
2868@enddefvar
2869
2870@defvar[var {parse-type}]
2871The kind of parse in progress, one of @kwd[file], @kwd[keyword] or
2872@kwd[string]. This tells the completion commands how to do completion, with
2873@kwd[string] disabling completion.
2874@enddefvar
2875
2876@defvar[var {parse-prompt}]
2877The prompt being used for the current parse.
2878@enddefvar
2879
2880@defvar[var {parse-help}]
2881The help string or function being used for the current parse.
2882@enddefvar
2883
2884@defvar[var {parse-starting-mark}]
2885This variable holds a mark in the @varref[echo-area-buffer] which
2886is the position at which the parse began.
2887@enddefvar
2888
2889@defvar[var {parse-input-region}]
2890This variable holds a region with @var[parse-starting-mark] as its
2891start and the end of the echo-area buffer as its end. When
2892@hid[Confirm Parse] is called, the text in this region is the text
2893that will be parsed.
2894@enddefvar
2895
2896
2897@section(Some Echo Area Commands)
2898
2899These are some of the @hid[Echo Area] commands that coordinate with the
2900prompting routines. @Hemlock binds other commands specific to the @hid[Echo
2901Area], but they are uninteresting to mention here, such as deleting to the
2902beginning of the line or deleting backwards a word.
2903
2904@defcom[com {Help On Parse},
2905 stuff (bound to @bf[Home, C-_] in @hid[Echo Area] mode)]
2906Display the help text for the parse currently in progress.
2907@enddefcom
2908
2909@defcom[com {Complete Keyword},
2910 stuff (bound to @bf[Escape] in @hid[Echo Area] mode)]
2911This attempts to complete the current region as a keyword in
2912@var[string-tables]. It signals an editor-error if the input is ambiguous
2913or incorrect.
2914@enddefcom
2915
2916@defcom[com {Complete Field},
2917 stuff (bound to @bf[Space] in @hid[Echo Area] mode)]
2918Similar to @hid[Complete Keyword], but only attempts to complete up to and
2919including the first character in the keyword with a non-zero
2920@kwd[parse-field-separator] attribute. If
2921there is no field separator then attempt to complete the entire keyword.
2922If it is not a keyword parse then just self-insert.
2923@enddefcom
2924
2925@defcom[com {Confirm Parse},
2926 stuff (bound to @bf[Return] in @hid[Echo Area] mode)]
2927If @var[string-tables] is non-@nil find the string in the region in
2928them. Call @var[parse-verification-function] with the current input.
2929If it returns a non-@nil value then that is returned as the value of
2930the parse. A parse may return a @nil value if the verification
2931function returns a non-@nil second value.
2932@enddefcom
2933
2934
2935
2936@chapter (Files)
2937@index (Files)
2938This chapter discusses ways to read and write files at various levels @dash at
2939marks, into regions, and into buffers. This also treats automatic mechanisms
2940that affect the state of buffers in which files are read.
2941
2942@section (File Options and Type Hooks)
2943@index (File options)
2944@index (Type hooks)
2945@index (File type hooks)
2946The user specifies file options with a special syntax on the first line of a
2947file. If the first line contains the string "@f[-*-]", then @hemlock
2948interprets the text between the first such occurrence and the second, which
2949must be contained in one line , as a list of @w{"@f<@i[option]: @i[value]>"}
2950pairs separated by semicolons. The following is a typical example:
2951@begin[programexample]
2952;;; -*- Mode: Lisp, Editor; Package: Hemlock -*-
2953@end[programexample]
2954See the @i[Hemlock User's Manual] for more details and predefined options.
2955
2956File type hooks are executed when @hemlock reads a file into a buffer based on
2957the type of the pathname. When the user specifies a @hid[Mode] file option
2958that turns on a major mode, @hemlock ignores type hooks. This mechanism is
2959mostly used as a simple means for turning on some appropriate default major
2960mode.
2961
2962@defmac[fun {define-file-option}, args
2963{@i[name] (@i[buffer] @i[value]) @mstar<@i[declaration]> @mstar<@i[form]>}]
2964This defines a new file option with the string name @i[name]. @i[Buffer] and
2965@i[value] specify variable names for the buffer and the option value string,
2966and @i[form]'s are evaluated with these bound.
2967@enddefmac
2968
2969@defmac[fun {define-file-type-hook}, args
2970{@i[type-list] (@i[buffer] @i[type]) @mstar<@i[declaration]> @mstar<@i[form]>}]
2971
2972This defines some code that @f[process-file-options] (below) executes when the
2973file options fail to set a major mode. This associates each type, a
2974@f[simple-string], in @i[type-list] with a routine that binds @i[buffer] to the
2975buffer the file is in and @i[type] to the type of the pathname.
2976@enddefmac
2977
2978@defun[fun {process-file-options}, args {@i[buffer] @optional @i[pathname]}]
2979This checks for file options in buffer and invokes handlers if there are any.
2980@i[Pathname] defaults to @i[buffer]'s pathname but may be @nil. If there is no
2981@hid[Mode] file option that specifies a major mode, and @i[pathname] has a
2982type, then this tries to invoke the appropriate file type hook.
2983@f[read-buffer-file] calls this.
2984@enddefun
2985
2986
2987@section (Pathnames and Buffers)
2988There is no good way to uniquely identify buffer names and pathnames. However,
2989@hemlock has one way of mapping pathnames to buffer names that should be used
2990for consistency among customizations and primitives. Independent of this,
2991@hemlock provides a means for consistently generating prompting defaults when
2992asking the user for pathnames.
2993
2994@defun[fun {pathname-to-buffer-name}, args {@i[pathname]}]
2995This function returns a string of the form "@f[file-namestring]
2996@f[directory-namestring]".
2997@enddefun
2998
2999@defhvar[var "Pathname Defaults", val {(pathname "gazonk.del")}]
3000@defhvar1[var "Last Resort Pathname Defaults Function"]
3001@defhvar1[var "Last Resort Pathname Defaults", val {(pathname "gazonk")}]
3002These variables control the computation of default pathnames when needed for
3003promting the user. @hid[Pathname Defaults] is a @i[sticky] default.
3004See the @i[Hemlock User's Manual] for more details.
3005@enddefhvar
3006
3007@defun[fun {buffer-default-pathname}, args {@i[buffer]}]
3008This returns @hid[Buffer Pathname] if it is bound. If it is not bound, and
3009@i[buffer]'s name is composed solely of alphnumeric characters, then return a
3010pathname formed from @i[buffer]'s name. If @i[buffer]'s name has other
3011characters in it, then return the value of @hid[Last Resort Pathname Defaults
3012Function] called on @i[buffer].
3013@enddefun
3014
3015@section (File Groups)
3016@index (File groups)
3017File groups provide a simple way of collecting the files that compose a system
3018and naming that collection. @Hemlock supports commands for searching,
3019replacing, and compiling groups.
3020
3021@defvar[var {active-file-group}]
3022This is the list of files that constitute the currently selected file group.
3023If this is @nil, then there is no current group.
3024@enddefvar
3025
3026@defmac[fun {do-active-group}, args {@mstar<@i[form]>}]
3027@defhvar1[var "Group Find File", val {nil}]
3028@defhvar1[var "Group Save File Confirm", val {t}]
3029@f[do-active-group] iterates over @var[active-file-group] executing the forms
3030once for each file. While the forms are executing, the file is in the current
3031buffer, and the point is at the beginning. If there is no active group, this
3032signals an editor-error.
3033
3034This reads each file into its own buffer using @f[find-file-buffer]. Since
3035unwanted buffers may consume large amounts of memory, @hid[Group Find File]
3036controls whether to delete the buffer after executing the forms. When the
3037variable is false, this deletes the buffer if it did not previously exist;
3038however, regardless of this variable, if the user leaves the buffer modified,
3039the buffer persists after the forms have completed. Whenever this processes a
3040buffer that already existed, it saves the location of the buffer's point before
3041and restores it afterwards.
3042
3043After processing a buffer, if it is modified, @f[do-active-group] tries to save
3044it. If @hid[Group Save File Confirm] is non-@nil, it asks for confirmation.
3045@enddefmac
3046
3047
3048@section (File Reading and Writing)
3049Common Lisp pathnames are used by the file primitives. For probing, checking
3050write dates, and so forth, all of the Common Lisp file functions are available.
3051
3052@defun[fun {read-file}, args {@i[pathname] @i[mark]}]
3053This inserts the file named by @i[pathname] at @i[mark].
3054@enddefun
3055
3056@defun[fun {write-file}, args {@i[region] @i[pathname]},
3057 keys {[keep-backup][access][append]}]
3058@defhvar1[var {Keep Backup Files}, val {@nil}]
3059This function writes the contents of @i[region] to the file named by
3060@i[pathname]. This writes @i[region] using a stream as if it were opened with
3061@kwd[if-exists] supplied as @kwd[rename-and-delete].
3062
3063When @i[keep-backup], which defaults to the value of @hid[Keep Backup Files],
3064is non-@nil, this opens the stream as if @kwd[if-exists] were @kwd[rename]. If
3065@i[append] is non-@nil, this writes the file as if it were opened with
3066@kwd[if-exists] supplied as @kwd[append].
3067
3068This signals an error if both @i[append] and @i[keep-backup] are supplied as
3069non-@nil.
3070
3071@i[Access] is an implementation dependent value that is suitable for setting
3072@i[pathname]'s access or protection bits.
3073@enddefun
3074
3075
3076@defun[fun {write-buffer-file}, args {@i[buffer] @i[pathname]}]
3077@defhvar1[var {Write File Hook}]
3078@defhvar1[var {Add Newline at EOF on Writing File}, val {@kwd[ask-user]}]
3079@f[write-buffer-file] writes @i[buffer] to the file named by @i[pathname]
3080including the following:
3081@begin[itemize]
3082It assumes pathname is somehow related to @i[buffer]'s pathname: if the
3083@i[buffer]'s write date is not the same as @i[pathname]'s, then this prompts
3084the user for confirmation before overwriting the file.
3085
3086It consults @hid[Add Newline at EOF on Writing File] (see @i[Hemlock User's
3087Manual] for possible values) and interacts with the user if necessary.
3088
3089It sets @hid[Pathname Defaults], and after using @f[write-file], marks
3090@i[buffer] unmodified.
3091
3092It updates @i[Buffer]'s pathname and write date.
3093
3094It renames the buffer according to the new pathname if possible.
3095
3096It invokes @hid[Write File Hook].
3097@end[itemize]
3098
3099@hid[Write File Hook] is a list of functions that take the newly written buffer
3100as an argument.
3101@enddefun
3102
3103
3104@defun[fun {read-buffer-file}, args {@i[pathname] @i[buffer]}]
3105@defhvar1[var {Read File Hook}]
3106@f[read-buffer-file] deletes @i[buffer]'s region and uses @f[read-file] to read
3107@i[pathname] into it, including the following:
3108@begin[itemize]
3109It sets @i[buffer]'s write date to the file's write date if the file exists;
3110otherwise, it @f[message]'s that this is a new file and sets @i[buffer]'s write
3111date to @nil.
3112
3113It moves @i[buffer]'s point to the beginning.
3114
3115It sets @i[buffer]'s unmodified status.
3116
3117It sets @i[buffer]'s pathname to the result of probing @i[pathname] if the file
3118exists; otherwise, this function sets @i[buffer]'s pathname to the result of
3119merging @i[pathname] with @f[default-directory].
3120
3121It sets @hid[Pathname Defaults] to the result of the previous item.
3122
3123It processes the file options.
3124
3125It invokes @hid[Read File Hook].
3126@end[itemize]
3127
3128@hid[Read File Hook] is a list functions that take two arguments @dash the
3129buffer read into and whether the file existed, @true if so.
3130@enddefun
3131
3132
3133@defun[fun {find-file-buffer}, args {@i[pathname]}]
3134This returns a buffer assoicated with the @i[pathname], reading the file into a
3135new buffer if necessary. This returns a second value indicating whether a new
3136buffer was created, @true if so. If the file has already been read, this
3137checks to see if the file has been modified on disk since it was read, giving
3138the user various recovery options. This is the basis of the @hid[Find File]
3139command.
3140@enddefun
3141
3142
3143
3144@chapter (Hemlock's Lisp Environment)
3145
3146@index (Lisp environment)
3147This chapter is sort of a catch all for any functions and variables
3148which concern @hemlock's interaction with the outside world.
3149
3150@section(Entering and Leaving the Editor)
3151
3152@defun[fun {ed}, args {@optional @i[x]}]
3153@defhvar1[var "Entry Hook"]
3154@f[ed] enters the editor. It is basically as specified in Common Lisp. If
3155@i[x] is supplied and is a symbol, the definition of @i[x] is put into a
3156buffer, and that buffer is selected. If @i[x] is a pathname, the file
3157specified by @i[x] is visited in a new buffer. If @i[x] is not supplied or
3158@nil, the editor is entered in the same state as when last exited.
3159
3160The @hid[Entry Hook] is invoked each time the editor is entered.
3161@enddefhvar
3162
3163@defun[fun {exit-hemlock}, args {@optional @i[value]}]
3164@defhvar1[var {Exit Hook}]
3165@f[exit-hemlock] leaves @hemlock and return to Lisp; @i[value] is the
3166value to return, which defaults to @true. The hook
3167@hvarref[Exit Hook] is invoked before this is done.
3168@enddefun
3169
3170@defun[fun {pause-hemlock}]
3171@f[pause-hemlock] suspends the editor process and returns control to the shell.
3172When the process is resumed, it will still be running @hemlock.
3173@enddefun
3174
3175
3176@section(Keyboard Input)
3177@index(I/O)
3178@index[keyboard input]
3179@index[input, keyboard]
3180
3181Keyboard input interacts with a number of other parts of the editor. Since the
3182command loop works by reading from the keyboard, keyboard input is the initial
3183cause of everything that happens. Also, @hemlock redisplays in the low-level
3184input loop when there is no available input from the user.
3185
3186
3187@defvar[var {editor-input}]
3188@defvar1[var {real-editor-input}]
3189@defhvar1[var "Input Hook"]
3190@defhvar1[var "Abort Hook"]
3191@index[aborting]
3192@var[editor-input] is an object on which @hemlock's I/O routines operate. You
3193can get input, clear input, return input, and listen for input. Input appears
3194as key-events.
3195
3196@var[real-editor-input] holds the initial value of @var[editor-input]. This is
3197useful for reading from the user when @var[editor-input] is rebound (such as
3198within a keyboard macro.)
3199
3200@Hemlock invokes the functions in @hid[Input Hook] each time someone reads a
3201key-event from @var[real-editor-input]. These take no arguments.
3202@enddefvar
3203
3204@defun[fun {get-key-event}, args {@i[editor-input] @optional @i[ignore-abort-attempts-p]}]
3205This function returns a key-event as soon as it is available on
3206@i[editor-input]. @i[Editor-input] is either @var[editor-input] or
3207@var[real-editor-input]. @i[Ignore-abort-attempts-p] indicates whether
3208@binding[C-g] and @binding[C-G] throw to the editor's top-level command loop;
3209when this is non-nil, this function returns those key-events when the user
3210types them. Otherwise, it aborts the editor's current state, returning to the
3211command loop.
3212
3213When the user aborts, @Hemlock invokes the functions in @hid[Abort Hook].
3214These functions take no arguments. When aborting, @Hemlock ignores the
3215@hid[Input Hook].
3216@enddefun
3217
3218
3219@defun[fun {unget-key-event}, args {@i[key-event] @i[editor-input]}]
3220This function returns @i[key-event] to @i[editor-input], so the next invocation
3221of @f[get-key-event] will return @i[key-event]. If @i[key-event] is
3222@f[#k"C-g"] or @f[#k"C-G"], then whether @f[get-key-event] returns it depends
3223on that function's second argument. @i[Editor-input] is either
3224@var[editor-input] or @var[real-editor-input].
3225@enddefun
3226
3227@defun[fun {clear-editor-input}, args {@i[editor-input]}]
3228This function flushes any pending input on @i[editor-input]. @i[Editor-input]
3229is either @var[editor-input] or @var[real-editor-input].
3230@enddefun
3231
3232@defun[fun {listen-editor-input}, args {@i[editor-input]}]
3233This function returns whether there is any input available on @i[editor-input].
3234@i[Editor-input] is either @var[editor-input] or @var[real-editor-input].
3235@enddefun
3236
3237@defun[fun {editor-sleep}, args {@i[time]}]
3238Return either after @i[time] seconds have elapsed or when input is available on
3239@var[editor-input].
3240@enddefun
3241
3242@defvar[var {key-event-history}]
3243This is a @hemlock ring buffer (see page @pageref[rings]) that holds the last
324460 key-events read from the keyboard.
3245@enddefvar
3246
3247@defvar[var {last-key-event-typed}]
3248Commands use this variable to realize the last key-event the user typed to
3249invoke the commands. Before @hemlock ever reads any input, the value is @nil.
3250This variable usually holds the last key-event read from the keyboard, but it
3251is also maintained within keyboard macros allowing commands to behave the same
3252on each repetition as they did in the recording invocation.
3253@enddefvar
3254
3255@defvar[var {input-transcript}]
3256If this is non-@nil then it should be an adjustable vector with a fill-pointer.
3257When it is non-@nil, @hemlock pushes all input read onto this vector.
3258@enddefvar
3259
3260
3261
3262@section(Hemlock Streams)
3263It is possible to create streams which output to or get input from a buffer.
3264This mechanism is quite powerful and permits easy interfacing of @hemlock to
3265Lisp.
3266
3267@defun[fun {make-hemlock-output-stream}, args
3268 {@i[mark] @optional @i[buffered]}]
3269@defun1[fun {hemlock-output-stream-p}, args {@i[object]}]
3270@f[make-hemlock-output-stream] returns a stream that inserts at the permanent
3271mark @i[mark] all output directed to it. @i[Buffered] controls whether the
3272stream is buffered or not, and its valid values are the following keywords:
3273@begin[description]
3274@kwd[none]@\No buffering is done. This is the default.
3275
3276@kwd[line]@\The buffer is flushed whenever a newline is written or
3277when it is explicitly done with @f[force-output].
3278
3279@kwd[full]@\The screen is only brought up to date when it is
3280explicitly done with @f[force-output]
3281@end[description]
3282
3283@f[hemlock-output-stream-p] returns @true if @i[object] is a
3284@f[hemlock-output-stream] object.
3285@enddefun
3286
3287@defun[fun {make-hemlock-region-stream}, args {@i[region]}]
3288@defun1[fun {hemlock-region-stream-p}, args {@i[object]}]
3289@f[make-hemlock-region-stream] returns a stream from which the text in
3290@i[region] can be read. @f[hemlock-region-stream-p] returns @true if
3291@i[object] is a @f[hemlock-region-stream] object.
3292@enddefun
3293
3294@defmac[fun {with-input-from-region}, args
3295{(@i[var] @i[region]) @mstar<@i[declaration]> @mstar<@i[form]>}]
3296While evaluating @i[form]s, binds @i[var] to a stream which returns input
3297from @i[region].
3298@enddefmac
3299
3300@defmac[fun {with-output-to-mark}, args
3301{(@i[var] @i[mark] @mopt<@i"buffered">) @mstar<@i[declaration]> @mstar<@i[form]>}]
3302 During the evaluation of the @i[form]s, binds @i[var] to a stream which
3303inserts output at the permanent @i[mark]. @i[Buffered] has the same meaning as
3304for @f[make-hemlock-output-stream].
3305@enddefmac
3306
3307@defmac[fun {with-pop-up-display}, args {(@i[var] @key @i[height name]) @mstar<@i[declaration]> @mstar<@i[form]>}]
3308@defvar1[var {random-typeout-buffers}]
3309 This macro executes @i[forms] in a context with @i[var] bound to a stream.
3310@Hemlock collects output to this stream and tries to pop up a display of the
3311appropriate height containing all the output. When @i[height] is supplied,
3312@Hemlock creates the pop-up display immediately, forcing output on line breaks.
3313The system saves the output in a buffer named @i[name], which defaults to
3314@hid[Random Typeout]. When the window is the incorrect height, the display
3315mechanism will scroll the window with more-style prompting. This is useful
3316for displaying information of temporary interest.
3317
3318When a buffer with name @i[name] already exists and was not previously created
3319by @f[with-pop-up-display], @Hemlock signals an error.
3320
3321@var[random-typeout-buffers] is an association list mapping random typeout
3322buffers to the streams that operate on the buffers.
3323@enddefmac
3324
3325
3326@section (Interface to the Error System)
3327The error system interface is minimal. There is a simple editor-error
3328condition which is a subtype of error and a convenient means for signaling
3329them. @Hemlock also provides a standard handler for error conditions while in
3330the editor.
3331
3332@defun[fun {editor-error-format-string}, args {@i[condition]}]
3333@defun1[fun {editor-error-format-arguments}, args {@i[condition]}]
3334Handlers for editor-error conditions can access the condition object with
3335these.
3336@enddefun
3337
3338@defun[fun {editor-error}, args {@rest @i[args]}]
3339This function is called to signal minor errors within Hemlock; these are errors
3340that a normal user could encounter in the course of editing such as a search
3341failing or an attempt to delete past the end of the buffer. This function
3342@f[signal]'s an editor-error condition formed from @i[args], which are @nil or
3343a @f[format] string possibly followed by @f[format] arguments. @Hemlock
3344invokes commands in a dynamic context with an editor-error condition handler
3345bound. This default handler beeps or flashes (or both) the display. If the
3346condition passed to the handler has a non-@nil string slot, the handler also
3347invokes @f[message] on it. The command in progress is always aborted, and this
3348function never returns.
3349@enddefun
3350
3351@defmac[fun {handle-lisp-errors}, args {@mstar<@i[form]>}]
3352Within the body of this macro any Lisp errors that occur are handled in some
3353fashion more gracefully than simply dumping the user in the debugger. This
3354macro should be wrapped around code which may get an error due to some action
3355of the user @dash for example, evaluating code fragments on the behalf of and
3356supplied by the user. Using this in a command allows the established handler
3357to shadow the default editor-error handler, so commands should take care to
3358signal user errors (calls to @f[editor-errors]) outside of this context.
3359@enddefmac
3360
3361
3362@section (Definition Editing)
3363@index (Definition editing)
3364@hemlock provides commands for finding the definition of a function, macro, or
3365command and placing the user at the definition in a buffer. This, of course,
3366is implementation dependent, and if an implementation does not associate a
3367source file with a routine, or if @hemlock cannot get at the information, then
3368these commands do not work. If the Lisp system does not store an absolute
3369pathname, independent of the machine on which the maintainer built the system,
3370then users need a way of translating a source pathname to one that will be able
3371to locate the source.
3372
3373@defun[fun {add-definition-dir-translation}, args {@i[dir1] @i[dir2]}]
3374This maps directory pathname @i[dir1] to @i[dir2]. Successive invocations
3375using the same @i[dir1] push into a translation list. When @hemlock seeks a
3376definition source file, and it has a translation, then it tries the
3377translations in order. This is useful if your sources are on various machines,
3378some of which may be down. When @hemlock tries to find a translation, it first
3379looks for translations of longer directory pathnames, finding more specific
3380translations before shorter, more general ones.
3381@enddefun
3382
3383@defun[fun {delete-definition-dir-translation}, args {@i[dir]}]
3384This deletes the mapping of @i[dir] to all directories to which it has been
3385mapped.
3386@enddefun
3387
3388
3389@section (Event Scheduling)
3390@index (Event scheduling)
3391@index (Scheduling events)
3392The mechanism described in this chapter is only operative when the Lisp process
3393is actually running inside of @hemlock, within the @f[ed] function. The
3394designers intended its use to be associated with the editor, such as with
3395auto-saving files, reminding the user, etc.
3396
3397@defun[fun {schedule-event}, args {@i[time] @i[function] @optional @i[repeat]}]
3398This causes @hemlock to call @i[function] after @i[time] seconds have passed,
3399optionally repeating every @i[time] seconds. @i[Repeat] defaults to @true.
3400This is a rough mechanism since commands can take an arbitrary amount of time
3401to run; @hemlock invokes @i[function] at the first possible moment after
3402@i[time] has elapsed. @i[Function] takes the time in seconds that has elapsed
3403since the last time it was called (or since it was scheduled for the first
3404invocation).
3405@enddefun
3406
3407@defun[fun {remove-scheduled-event}, args {@i[function]}]
3408This removes @i[function] from the scheduling queue. @i[Function] does not
3409have to be in the queue.
3410@enddefun
3411
3412
3413@section (Miscellaneous)
3414
3415@defun[fun {in-lisp}, args {@mstar<@i[form]>}]
3416@index[Evaluating Lisp code]
3417This evaluates @i[form]'s inside @f[handle-lisp-errors]. It also binds
3418@var[package] to the package named by @hid[Current Package] if it is non-@nil.
3419Use this when evaluating Lisp code on behalf of the user.
3420@enddefun
3421
3422@defmac[fun {do-alpha-chars}, args {(@i[var] @i[kind] [@i[result]]) @mstar<@i[form]>}]
3423This iterates over alphabetic characters in Common Lisp binding @i[var] to each
3424character in order as specified under character relations in @i[Common Lisp the
3425Language]. @i[Kind] is one of @kwd[lower], @kwd[upper], or @kwd[both]. When
3426the user supplies @kwd[both], lowercase characters are processed first.
3427@enddefmac
3428
3429
3430
3431@chapter (High-Level Text Primitives)
3432This chapter discusses primitives that operate on higher level text forms than
3433characters and words. For English text, there are functions that know about
3434sentence and paragraph structures, and for Lisp sources, there are functions
3435that understand this language. This chapter also describes mechanisms for
3436organizing file sections into @i[logical pages] and for formatting text forms.
3437
3438
3439@section (Indenting Text)
3440@index (Indenting)
3441@label(indenting)
3442
3443@defhvar[var "Indent Function", val {tab-to-tab-stop}]
3444The value of this variable determines how indentation is done, and it is a
3445function which is passed a mark as its argument. The function should indent
3446the line that the mark points to. The function may move the mark around on
3447the line. The mark will be @f[:left-inserting]. The default simply inserts a
3448@binding[tab] character at the mark. A function for @hid[Lisp] mode probably
3449moves the mark to the beginning of the line, deletes horizontal whitespace, and
3450computes some appropriate indentation for Lisp code.
3451@enddefhvar
3452
3453@defhvar[var "Indent with Tabs", val {indent-using-tabs}]
3454@defhvar1[var "Spaces per Tab", val {8}]
3455@hid[Indent with Tabs] holds a function that takes a mark and a number of
3456spaces. The function will insert a maximum number of tabs and a minimum number
3457of spaces at mark to move the specified number of columns. The default
3458definition uses @hid[Spaces per Tab] to determine the size of a tab. @i[Note,]
3459@hid[Spaces per Tab] @i[is not used everywhere in @hemlock yet, so changing
3460this variable could have unexpected results.]
3461@enddefhvar
3462
3463@defun[fun {indent-region}, args {@i[region]}]
3464@defun1[fun {indent-region-for-commands}, args {@i[region]}]
3465@f[indent-region] invokes the value of @hid[Indent Function] on every line of
3466region. @f[indent-region-for-commands] uses @f[indent-region] but first saves
3467the region for the @hid[Undo] command.
3468@enddefun
3469
3470@defun[fun {delete-horizontal-space}, args {@i[mark]}]
3471This deletes all characters with a @hid[Space] attribute (see section
3472@ref[sys-def-chars]) of @f[1].
3473@enddefun
3474
3475
3476@section (Lisp Text Buffers)
3477@index (Lisp text functions)
3478@hemlock bases its Lisp primitives on parsing a block of the buffer and
3479annotating lines as to what kind of Lisp syntax occurs on the line or what kind
3480of form a mark might be in (for example, string, comment, list, etc.). These
3481do not work well if the block of parsed forms is exceeded when moving marks
3482around these forms, but the block that gets parsed is somewhat programmable.
3483
3484There is also a notion of a @i[top level form] which this documentation often
3485uses synonymously with @i[defun], meaning a Lisp form occurring in a source
3486file delimited by parentheses with the opening parenthesis at the beginning of
3487some line. The names of the functions include this inconsistency.
3488
3489@defun[fun {pre-command-parse-check}, args {@i[mark] @i[for-sure]}]
3490@defhvar1[var {Parse Start Function}, val {start-of-parse-block}]
3491@defhvar1[var {Parse End Function}, val {end-of-parse-block}]
3492@defhvar1[var {Minimum Lines Parsed}, val {50}]
3493@defhvar1[var {Maximum Lines Parsed}, val {500}]
3494@defhvar1[var {Defun Parse Goal}, val {2}]
3495@f[pre-command-parse-check] calls @hid[Parse Start Function] and @hid[Parse End
3496Function] on @i[mark] to get two marks. It then parses all the lines between
3497the marks including the complete lines they point into. When @i[for-sure] is
3498non-@nil, this parses the area regardless of any cached information about the
3499lines. Every command that uses the following routines calls this before doing
3500so.
3501
3502The default values of the start and end variables use @hid[Minimum Lines
3503Parsed], @hid[Maximum Lines Parsed], and @hid[Defun Parse Goal] to determine
3504how big a region to parse. These two functions always include at least the
3505minimum number of lines before and after the mark passed to them. They try to
3506include @hid[Defun Parse Goal] number of top level forms before and after the
3507mark passed them, but these functions never return marks that include more than
3508the maximum number of lines before or after the mark passed to them.
3509@enddefun
3510
3511@defun[fun {form-offset}, args {@i[mark] @i[count]}]
3512This tries to move @i[mark] @i[count] forms forward if positive or -@i[count]
3513forms backwards if negative. @i[Mark] is always moved. If there were enough
3514forms in the appropriate direction, this returns @i[mark], otherwise nil.
3515@enddefun
3516
3517@defun[fun {top-level-offset}, args {@i[mark] @i[count]}]
3518This tries to move @i[mark] @i[count] top level forms forward if positive or
3519-@i[count] top level forms backwards if negative. If there were enough top
3520level forms in the appropriate direction, this returns @i[mark], otherwise nil.
3521@i[Mark] is moved only if this is successful.
3522@enddefun
3523
3524@defun[fun {mark-top-level-form}, args {@i[mark1] @i[mark2]}]
3525This moves @i[mark1] and @i[mark2] to the beginning and end, respectively, of
3526the current or next top level form. @i[Mark1] is used as a reference to start
3527looking. The marks may be altered even if unsuccessful. If successful, return
3528@i[mark2], else nil. @i[Mark2] is left at the beginning of the line following
3529the top level form if possible, but if the last line has text after the closing
3530parenthesis, this leaves the mark immediately after the form.
3531@enddefun
3532
3533@defun[fun {defun-region}, args {@i[mark]}]
3534This returns a region around the current or next defun with respect to
3535@i[mark]. @i[Mark] is not used to form the region. If there is no appropriate
3536top level form, this signals an editor-error. This calls
3537@f[pre-command-parse-check] first.
3538@enddefun
3539
3540@defun[fun {inside-defun-p}, args {@i[mark]}]
3541@defun1[fun {start-defun-p}, args {@i[mark]}]
3542These return, respectively, whether @i[mark] is inside a top level form or at
3543the beginning of a line immediately before a character whose @hid[Lisp Syntax]
3544(see section @ref[sys-def-chars]) value is @kwd[opening-paren].
3545@enddefun
3546
3547@defun[fun {forward-up-list}, args {@i[mark]}]
3548@defun1[fun {backward-up-list}, args {@i[mark]}]
3549Respectively, these move @i[mark] immediately past a character whose @hid[Lisp
3550Syntax] (see section @ref[sys-def-chars]) value is @kwd[closing-paren] or
3551immediately before a character whose @hid[Lisp Syntax] value is
3552@kwd[opening-paren].
3553@enddefun
3554
3555@defun[fun {valid-spot}, args {@i[mark] @i[forwardp]}]
3556This returns @true or @nil depending on whether the character indicated by
3557@i[mark] is a valid spot. When @i[forwardp] is set, use the character after
3558mark and vice versa. Valid spots exclude commented text, inside strings, and
3559character quoting.
3560@enddefun
3561
3562@defun[fun {defindent}, args {@i[name] @i[count]}]
3563This defines the function with @i[name] to have @i[count] special arguments.
3564@f[indent-for-lisp], the value of @hid[Indent Function] (see section
3565@ref[indenting]) in @hid[Lisp] mode, uses this to specially indent these
3566arguments. For example, @f[do] has two, @f[with-open-file] has one, etc.
3567There are many of these defined by the system including definitions for special
3568@hemlock forms. @i[Name] is a simple-string, case insensitive and purely
3569textual (that is, not read by the Lisp reader); therefore, @f["with-a-mumble"]
3570is distinct from @f["mumble:with-a-mumble"].
3571@enddefun
3572
3573
3574@section (English Text Buffers)
3575@index (English text functions)
3576@label(text-functions)
3577This section describes some routines that understand basic English language
3578forms.
3579
3580@defun[fun {word-offset}, args {@i[mark] @i[count]}]
3581This moves @i[mark] @i[count] words forward (if positive) or backwards (if
3582negative). If @i[mark] is in the middle of a word, that counts as one. If
3583there were @i[count] (-@i[count] if negative) words in the appropriate
3584direction, this returns @i[mark], otherwise nil. This always moves @i[mark].
3585A word lies between two characters whose @hid[Word Delimiter] attribute value
3586is @f[1] (see section @ref[sys-def-chars]).
3587@enddefun
3588
3589@defun[fun {sentence-offset}, args {@i[mark] @i[count]}]
3590This moves @i[mark] @i[count] sentences forward (if positive) or backwards (if
3591negative). If @i[mark] is in the middle of a sentence, that counts as one. If
3592there were @i[count] (-@i[count] if negative) sentences in the appropriate
3593direction, this returns @i[mark], otherwise nil. This always moves @i[mark].
3594
3595A sentence ends with a character whose @hid[Sentence Terminator] attribute is
3596@f[1] followed by two spaces, a newline, or the end of the buffer. The
3597terminating character is optionally followed by any number of characters whose
3598@hid[Sentence Closing Char] attribute is @f[1]. A sentence begins after a
3599previous sentence ends, at the beginning of a paragraph, or at the beginning of
3600the buffer.
3601@enddefun
3602
3603@defun[fun {paragraph-offset}, args {@i[mark] @i[count] @optional @i[prefix]}]
3604@defhvar1[var {Paragraph Delimiter Function}, var {default-para-delim-function}]
3605This moves @i[mark] @i[count] paragraphs forward (if positive) or backwards (if
3606negative). If @i[mark] is in the middle of a paragraph, that counts as one.
3607If there were @i[count] (-@i[count] if negative) paragraphs in the appropriate
3608direction, this returns @i[mark], otherwise nil. This only moves @i[mark] if
3609there were enough paragraphs.
3610
3611@hid[Paragraph Delimiter Function] holds a function that takes a mark,
3612typically at the beginning of a line, and returns whether or not the current
3613line should break the paragraph. @f[default-para-delim-function] returns @true
3614if the next character, the first on the line, has a @hid[Paragraph Delimiter]
3615attribute value of @f[1]. This is typically a space, for an indented
3616paragraph, or a newline, for a block style. Some modes require a more
3617complicated determinant; for example, @hid[Scribe] modes adds some characters
3618to the set and special cases certain formatting commands.
3619
3620@i[Prefix] defaults to @hid[Fill Prefix] (see section @ref[filling]), and the
3621right prefix is necessary to correctly skip paragraphs. If @i[prefix] is
3622non-@nil, and a line begins with @i[prefix], then the scanning process skips
3623the prefix before invoking the @hid[Paragraph Delimiter Function].
3624Note, when scanning for paragraph bounds, and @i[prefix] is non-@nil, lines are
3625potentially part of the paragraph regardless of whether they contain the prefix;
3626only the result of invoking the delimiter function matters.
3627
3628The programmer should be aware of an idiom for finding the end of the current
3629paragraph. Assume @f[paragraphp] is the result of moving @f[mark] one
3630paragraph, then the following correctly determines whether there actually is a
3631current paragraph:
3632@begin[programexample]
3633(or paragraphp
3634 (and (last-line-p mark)
3635 (end-line-p mark)
3636 (not (blank-line-p (mark-line mark)))))
3637@end[programexample]
3638In this example @f[mark] is at the end of the last paragraph in the buffer, and
3639there is no last newline character in the buffer. @f[paragraph-offset] would
3640have returned @nil since it could not skip any paragraphs since @f[mark] was at
3641the end of the current and last paragraph. However, you still have found a
3642current paragraph on which to operate. @f[mark-paragraph] understands this
3643problem.
3644@enddefun
3645
3646@defun[fun {mark-paragraph}, args {@f[mark1] @f[mark2]}]
3647This marks the next or current paragraph, setting @i[mark1] to the beginning
3648and @i[mark2] to the end. This uses @hid[Fill Prefix] (see section
3649@ref[filling]). @i[Mark1] is always on the first line of the paragraph,
3650regardless of whether the previous line is blank. @i[Mark2] is typically at
3651the beginning of the line after the line the paragraph ends on, this returns
3652@i[mark2] on success. If this cannot find a paragraph, then the marks are left
3653unmoved, and @nil is returned.
3654@enddefun
3655
3656
3657@section (Logical Pages)
3658@index (Logical pages)
3659@index (Page functions)
3660@label(logical-pages)
3661Logical pages are a way of dividing a file into coarse divisions. This is
3662analogous to dividing a paper into sections, and @hemlock provides primitives
3663for moving between the pages of a file and listing a directory of the page
3664titles. Pages are separated by @hid[Page Delimiter] characters (see section
3665@ref[sys-def-chars]) that appear at the beginning of a line.
3666
3667@defun[fun {goto-page}, args {@i[mark] @i[n]}]
3668This moves @i[mark] to the absolute page numbered @i[n]. If there are less
3669than @i[n] pages, it signals an editor-error. If it returns, it returns
3670@i[mark]. @hemlock numbers pages starting with one for the page delimited by
3671the beginning of the buffer and the first @hid[Page Delimiter] (or the end of
3672the buffer).
3673@enddefun
3674
3675@defun[fun {page-offset}, args {@i[mark] @i[n]}]
3676This moves mark forward @i[n] (-@i[n] backwards, if @i[n] is negative)
3677@hid[Page Delimiter] characters that are in the zero'th line position. If a
3678@hid[Page Delimiter] is the immediately next character after mark (or before
3679mark, if @i[n] is negative), then skip it before starting. This always moves
3680@i[mark], and if there were enough pages to move over, it returns @i[mark];
3681otherwise, it returns @nil.
3682@enddefun
3683
3684@defun[fun {page-directory}, args {@i[buffer]}]
3685This returns a list of each first non-blank line in @i[buffer] that follows a
3686@hid[Page Delimiter] character that is in the zero'th line position. This
3687includes the first line of the @i[buffer] as the first page title. If a page
3688is empty, then its title is the empty string.
3689@enddefun
3690
3691@defun[fun {display-page-directory}, args {@i[stream] @i[directory]}]
3692This writes the list of strings, @i[directory], to @i[stream], enumerating them
3693in a field three wide. The number and string are separated by two spaces, and
3694the first line contains headings for the page numbers and title strings.
3695@enddefun
3696
3697
3698@section (Filling)
3699@index (filling)
3700@label(filling)
3701Filling is an operation on text that breaks long lines at word boundaries
3702before a given column and merges shorter lines together in an attempt to make
3703each line roughly the specified length. This is different from justification
3704which tries to add whitespace in awkward places to make each line exactly the
3705same length. @Hemlock's filling optionally inserts a specified string at the
3706beginning of each line. Also, it eliminates extra whitespace between lines and
3707words, but it knows two spaces follow sentences (see section
3708@ref[text-functions]).
3709
3710@defhvar[var "Fill Column", val {75}]
3711@defhvar1[var "Fill Prefix", val {nil}]
3712These variables hold the default values of the prefix and column arguments to
3713@hemlock's filling primitives. If @hid[Fill Prefix] is @nil, then there is no
3714fill prefix.
3715@enddefhvar
3716
3717@defun[fun {fill-region}, args {@i[region] @optional @i[prefix] @i[column]}]
3718This deletes any blank lines in region and fills it according to prefix and
3719column. @i[Prefix] and @i[column] default to @hid[Fill Prefix] and @hid[Fill
3720Column].
3721@enddefun
3722
3723@defun[fun {fill-region-by-paragraphs},
3724 args {@i[region] @optional @i[prefix] @i[column]}]
3725This finds paragraphs (see section @ref[text-functions]) within region and
3726fills them with @f[fill-region]. This ignores blank lines between paragraphs.
3727@i[Prefix] and @i[column] default to @hid[Fill Prefix] and @hid[Fill Column].
3728@enddefun
3729
3730
3731
3732@chapter (Utilities)
3733@index (Utilities)
3734This chapter describes a number of utilities for manipulating some types of
3735objects @hemlock uses to record information. String-tables are used to store
3736names of variables, commands, modes, and buffers. Ring lists can be used to
3737provide a kill ring, recent command history, or other user-visible features.
3738
3739
3740@section(String-table Functions)
3741@index (String-tables)
3742@label(string-tables)
3743
3744String tables are similar to Common Lisp hash tables in that they associate a
3745value with an object. There are a few useful differences: in a string table
3746the key is always a case insensitive string, and primitives are provided to
3747facilitate keyword completion and recognition. Any type of string may be added
3748to a string table, but the string table functions always return
3749@f[simple-string]'s.
3750
3751A string entry in one of these tables may be thought of as being separated into
3752fields or keywords. The interface provides keyword completion and recognition
3753which is primarily used to implement some @hid[Echo Area] commands. These
3754routines perform a prefix match on a field-by-field basis allowing the
3755ambiguous specification of earlier fields while going on to enter later fields.
3756While string tables may use any @f[string-char] as a separator, the use of
3757characters other than @binding[space] may make the @hid[Echo Area] commands
3758fail or work unexpectedly.
3759
3760@defun[fun {make-string-table}, keys {[separator][initial-contents]}]
3761This function creates an empty string table that uses @i[separator] as the
3762character, which must be a @f[string-char], that distinguishes fields.
3763@i[Initial-contents] specifies an initial set of strings and their values in
3764the form of a dotted @f[a-list], for example:
3765@Begin[ProgramExample]
3766'(("Global" . t) ("Mode" . t) ("Buffer" . t))
3767@End[ProgramExample]
3768@enddefun
3769
3770@defun[fun {string-table-p}, args {@i[string-table]}]
3771This function returns @true if @i[string-table] is a @f[string-table] object,
3772otherwise @nil.
3773@enddefun
3774
3775@defun[fun {string-table-separator}, args {@i[string-table]}]
3776This function returns the separator character given to @f[make-string-table].
3777@enddefun
3778
3779@defun[fun {delete-string}, args {@i[string] @i[table]}]
3780@defun1[fun {clrstring}, args {@i[table]}]
3781@f[delete-string] removes any entry for @i[string] from the @f[string-table]
3782@i[table], returning @true if there was an entry. @f[clrstring] removes all
3783entries from @i[table].
3784@enddefun
3785
3786@defun[fun {getstring}, args {@i[string] @i[table]}]
3787This function returns as multiple values, first the value corresponding to the
3788string if it is found and @nil if it isn't, and second @true if it is found and
3789@nil if it isn't.
3790
3791This may be set with @f[setf] to add a new entry or to store a new value for a
3792string. It is an error to try to insert a string with more than one
3793field separator character occurring contiguously.
3794@enddefun
3795
3796@defun[fun {complete-string}, args {@i[string] @i[tables]}]
3797This function completes @i[string] as far as possible over the list of
3798@i[tables], returning five values. It is an error for @i[tables] to have
3799different separator characters. The five return values are as follows:
3800@begin[itemize]
3801The maximal completion of the string or @nil if there is none.
3802
3803An indication of the usefulness of the returned string:
3804@begin[description]
3805@kwd[none]@\
3806There is no completion of @i[string].
3807
3808@kwd[complete]@\
3809The completion is a valid entry, but other valid completions exist too. This
3810occurs when the supplied string is an entry as well as initial substring of
3811another entry.
3812
3813@kwd[unique]@\
3814The completion is a valid entry and unique.
3815
3816@kwd[ambiguous]@\
3817The completion is invalid; @f[get-string] would return @nil and @nil if given
3818the returned string.
3819@end[description]
3820
3821The value of the string when the completion is @kwd[unique] or @kwd[complete],
3822otherwise @nil.
3823
3824An index, or nil, into the completion returned, indicating where the addition
3825of a single field to @i[string] ends. The command @hid[Complete Field] uses
3826this when the completion contains the addition to @i[string] of more than one
3827field.
3828
3829An index to the separator following the first ambiguous field when the
3830completion is @kwd[ambiguous] or @kwd[complete], otherwise @nil.
3831@end[itemize]
3832@enddefun
3833
3834@defun[fun {find-ambiguous}, args {@i[string] @i[table]}]
3835@defun1[fun {find-containing}, args {@i[string] @i[table]}]
3836@f[find-ambiguous] returns a list in alphabetical order of all the
3837strings in @i[table] matching @i[string]. This considers an entry as matching
3838if each field in @i[string], taken in order, is an initial substring of the
3839entry's fields; entry may have fields remaining.
3840
3841@f[find-containing] is similar, but it ignores the order of the fields in
3842@i[string], returning all strings in @i[table] matching any permutation of the
3843fields in @i[string].
3844@enddefun
3845
3846@defmac[fun {do-strings}, args {(@i[string-var] @i[value-var] @i[table] @MOPT<@i[result]>) @mstar<@i[declaration]> @mstar<@i[tag] @MOR @i[statement]>}]
3847This macro iterates over the strings in @i[table] in alphabetical order. On
3848each iteration, it binds @i[string-var] to an entry's string and @i[value-var]
3849to an entry's value.
3850@enddefmac
3851
3852
3853@section (Ring Functions)
3854@index (Rings)
3855@label[rings]
3856There are various purposes in an editor for which a ring of values can be used,
3857so @hemlock provides a general ring buffer type. It is used for maintaining a
3858ring of killed regions (see section @ref[kill-ring]), a ring of marks (see
3859section @ref[mark-stack]), or a ring of command strings which various modes and
3860commands maintain as a history mechanism.
3861
3862@defun[fun {make-ring}, args {@i[length] @optional @i[delete-function]}]
3863Makes an empty ring object capable of holding up to @i[length] Lisp objects.
3864@i[Delete-function] is a function that each object is passed to before it falls
3865off the end. @i[Length] must be greater than zero.
3866@enddefun
3867
3868@defun[fun {ringp}, args {@i[ring]}]
3869Returns @true if @i[ring] is a @f[ring] object, otherwise @nil.
3870@enddefun
3871
3872@defun[fun {ring-length}, args {@i[ring]}]
3873Returns as multiple-values the number of elements which @i[ring]
3874currently holds and the maximum number of elements which it may hold.
3875@enddefun
3876
3877@defun[fun {ring-ref}, args {@i[ring] @i[index]}]
3878Returns the @i[index]'th item in the @i[ring], where zero is the index
3879of the most recently pushed. This may be set with @f[setf].
3880@enddefun
3881
3882@defun[fun {ring-push}, args {@i[object] @i[ring]}]
3883Pushes @i[object] into @i[ring], possibly causing the oldest item to
3884go away.
3885@enddefun
3886
3887@defun[fun {ring-pop}, args {@i[ring]}]
3888Removes the most recently pushed object from @i[ring] and returns it.
3889If the ring contains no elements then an error is signalled.
3890@enddefun
3891
3892@defun[fun {rotate-ring}, args {@i[ring] @i[offset]}]
3893With a positive @i[offset], rotates @i[ring] forward that many times.
3894In a forward rotation the index of each element is reduced by one,
3895except the one which initially had a zero index, which is made the
3896last element. A negative offset rotates the ring the other way.
3897@enddefun
3898
3899
3900@section (Undoing commands)
3901@index (Undo functions)
3902@label(undo)
3903
3904@defun[fun {save-for-undo}, args {@i[name] @i[method] @optional @i[cleanup] @i[method-undo] @i[buffer]}]
3905This saves information to undo a command. @i[Name] is a string to display when
3906prompting the user for confirmation when he invokes the @hid[Undo] command (for
3907example, @f["kill"] or @f["Fill Paragraph"]). @i[Method] is the function to
3908invoke to undo the effect of the command. @i[Method-undo] is a function that
3909undoes the undo function, or effectively re-establishes the state immediately
3910after invoking the command. If there is any existing undo information, this
3911invokes the @i[cleanup] function; typically @i[method] closes over or uses
3912permanent marks into a buffer, and the @i[cleanup] function should delete such
3913references. @i[Buffer] defaults to the @f[current-buffer], and the @hid[Undo]
3914command only invokes undo methods when they were saved for the buffer that is
3915current when the user invokes @hid[Undo].
3916@enddefun
3917
3918@defun[fun {make-region-undo}, args {@i[kind] @i[name] @i[region] @optional @i[mark-or-region]}]
3919This handles three common cases that commands fall into when setting up undo
3920methods, including cleanup and method-undo functions (see @f[save-for-undo]).
3921These cases are indicated by the @i[kind] argument:
3922@begin[description]
3923@kwd[twiddle]@\
3924Use this kind when a command modifies a region, and the undo information
3925indicates how to swap between two regions @dash the one before any modification
3926occurs and the resulting region. @i[Region] is the resulting region, and it
3927has permanent marks into the buffer. @i[Mark-or-region] is a region without
3928marks into the buffer (for example, the result of @f[copy-region]). As a
3929result of calling this, a first invocation of @hid[Undo] deletes @i[region],
3930saving it, and inserts @i[mark-or-region] where @i[region] used to be. The
3931undo method sets up for a second invocation of @hid[Undo] that will undo the
3932effect of the undo; that is, after two calls, the buffer is exactly as it was
3933after invoking the command. This activity is repeatable any number of times.
3934This establishes a cleanup method that deletes the two permanent marks into the
3935buffer used to locate the modified region.
3936
3937@kwd[insert]@\
3938Use this kind when a command has deleted a region, and the undo information
3939indicates how to re-insert the region. @i[Region] is the deleted and saved
3940region, and it does not contain marks into any buffer. @i[Mark-or-region] is a
3941permanent mark into the buffer where the undo method should insert @i[region].
3942As a result of calling this, a first invocation of @hid[Undo] inserts
3943@i[region] at @i[mark-or-region] and forms a region around the inserted text
3944with permanent marks into the buffer. This allows a second invocation of
3945@hid[Undo] to undo the effect of the undo; that is, after two calls, the buffer
3946is exactly as it was after invoking the command. This activity is repeatable
3947any number of times. This establishes a cleanup method that deletes either the
3948permanent mark into the buffer or the two permanent marks of the region,
3949depending on how many times the user used @hid[Undo].
3950
3951@kwd[delete]@\
3952Use this kind when a command has inserted a block of text, and the undo
3953information indicates how to delete the region. @i[Region] has permanent marks
3954into the buffer and surrounds the inserted text. Leave @i[Mark-or-region]
3955unspecified. As a result of calling this, a first invocation of @hid[Undo]
3956deletes @i[region], saving it, and establishes a permanent mark into the buffer
3957to remember where the @i[region] was. This allows a second invocation of
3958@hid[Undo] to undo the effect of the undo; that is, after two calls, the buffer
3959is exactly as it was after invoking the command. This activity is repeatable
3960any number of times. This establishes a cleanup method that deletes either the
3961permanent mark into the buffer or the two permanent marks of the region,
3962depending on how many times the user used @hid[Undo].
3963@end[description]
3964
3965@blankspace(1 line)
3966@i[Name] in all cases is an appropriate string indicating what the command did.
3967This is used by @hid[Undo] when prompting the user for confirmation before
3968calling the undo method. The string used by @hid[Undo] alternates between this
3969argument and something to indicate that the user is undoing an undo.
3970@enddefun
3971
3972
3973
3974@chapter (Miscellaneous)
3975This chapter is somewhat of a catch-all for comments and features that don't
3976fit well anywhere else.
3977
3978
3979@section (Generic Pointer Up)
3980@hid[Generic Pointer Up] is a @hemlock command bound to mouse up-clicks. It
3981invokes a function supplied with the interface described in this section. This
3982command allows different commands to be bound to the same down-click in various
3983modes with one command bound to the corresponding up-click.
3984
3985@defun[fun {supply-generic-pointer-up-function}, args {@i[function]}]
3986@index[Generic Pointer Up]
3987This function supplies a function that @hid[Generic Pointer Up] invokes the
3988next time it executes.
3989@enddefun
3990
3991
3992@section (Using View Mode)
3993@hid[View] mode supports scrolling through files automatically terminating the
3994buffer at end-of-file as well as commands for quitting the mode and popping
3995back to the buffer that spawned the @hid[View] mode buffer. Modes such as
3996@hid[Dired] and @hid[Lisp-Lib] use this to view files and description of
3997library entries.
3998
3999Modes that want similar commands should use @f[view-file-command] to view a
4000file and get a handle on the view buffer. To allow the @hid[View Return] and
4001@hid[View Quit] commands to return to the originating buffer, you must set the
4002variable @hid[View Return Function] in the viewing buffer to a function that
4003knows how to do this. Furthermore, since you now have a reference to the
4004originating buffer, you must add a buffer local delete hook to it that will
4005clear the view return function's reference. This needs to happen for two
4006reasons in case the user deletes the originating buffer:
4007@Begin[Enumerate]
4008You don't want the return function to go to a non-existing, invalid buffer.
4009
4010Since the viewing buffer still exists, its @hid[View Return Function] buffer
4011local variable still exists. This means the function still references the
4012deleted originating buffer, and garbage collection cannot reclaim the memory
4013locked down by the deleted buffer.
4014@End[Enumerate]
4015
4016The following is a piece of code that could implement part of @hid[Dired View
4017File] that uses two closures to accomplish that described above:
4018@Begin[ProgramExample]
4019(let* ((dired-buf (current-buffer))
4020 (buffer (view-file-command nil pathname)))
4021 (push #'(lambda (buffer)
4022 (declare (ignore buffer))
4023 (setf dired-buf nil))
4024 (buffer-delete-hook dired-buf))
4025 (setf (variable-value 'view-return-function :buffer buffer)
4026 #'(lambda ()
4027 (if dired-buf
4028 (change-to-buffer dired-buf)
4029 (dired-from-buffer-pathname-command nil)))))
4030@End[ProgramExample]
4031
4032The @hid[Dired] buffer's delete hook clears the return function's reference to
4033the @hid[Dired] buffer. The return function tests the variable to see if it
4034still holds a buffer when the function executes.
4035
4036
4037
4038@comment[@chapter (Auxiliary Systems)]
4039@include(aux-sys)
Note: See TracBrowser for help on using the repository browser.