| 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]
|
|---|
| 35 | School of Computer Science
|
|---|
| 36 | Carnegie Mellon University
|
|---|
| 37 | Pittsburgh, PA 15213
|
|---|
| 38 | @end[Center]
|
|---|
| 39 |
|
|---|
| 40 | @blankspace(2lines)
|
|---|
| 41 | @begin[Center]
|
|---|
| 42 | This is a revised version of Technical Report CMU-CS-87-159.
|
|---|
| 43 | @end[Center]
|
|---|
| 44 | @heading[Abstract]
|
|---|
| 45 | @begin(Text, indent 0)
|
|---|
| 46 | This document describes how to write commands for the @Hemlock text editor, as
|
|---|
| 47 | of version M3.2. @Hemlock is a customizable, extensible text editor whose
|
|---|
| 48 | initial command set closely resembles that of ITS/TOPS-20 @Emacs. @Hemlock is
|
|---|
| 49 | written 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
|
|---|
| 67 | such as EMACS and the Lisp Machine editor ZWEI. In its basic form,
|
|---|
| 68 | @hemlock has almost the same command set as EMACS, and similar
|
|---|
| 69 | features such as multiple buffers and windows, extended commands,
|
|---|
| 70 | and built in documentation.
|
|---|
| 71 |
|
|---|
| 72 | Both user extensions and the original commands are written in Lisp,
|
|---|
| 73 | therefore a command implementor will have a working knowledge of this
|
|---|
| 74 | language. Users not familiar with Lisp need not despair however. Many
|
|---|
| 75 | users of Multics EMACS, another text editor written in Lisp, came to learn
|
|---|
| 76 | Lisp simply for the purpose of writing their own editor extensions, and
|
|---|
| 77 | found, to their surprise, that it was really pretty easy to write simple
|
|---|
| 78 | commands.
|
|---|
| 79 |
|
|---|
| 80 | This document describes the Common Lisp functions, macros and data structures
|
|---|
| 81 | that are used to implement new commands. The basic editor consists of a set of
|
|---|
| 82 | Lisp utility functions for manipulating buffers and the other data structures
|
|---|
| 83 | of the editor as well as handling the display. All user level commands are
|
|---|
| 84 | written in terms of these functions. To find out how to define commands see
|
|---|
| 85 | chapter @ref[commands].
|
|---|
| 86 |
|
|---|
| 87 | @chapter(Representation of Text)
|
|---|
| 88 | @index (Lines)
|
|---|
| 89 | @section(Lines)
|
|---|
| 90 | In @hemlock all text is in some @i[line]. Text is broken into lines wherever
|
|---|
| 91 | it contains a newline character; newline characters are never stored, but are
|
|---|
| 92 | assumed to exist between every pair of lines. The implicit newline character
|
|---|
| 93 | is treated as a single character by the text primitives.
|
|---|
| 94 |
|
|---|
| 95 | @defun[fun {linep}, args {@i[line]}]
|
|---|
| 96 | This function returns @true if @i[line] is a @f[line] object, otherwise @nil.
|
|---|
| 97 | @enddefun
|
|---|
| 98 |
|
|---|
| 99 | @defun[fun {line-string}, args {@i[line]}]
|
|---|
| 100 | Given a @i(line), this function returns as a simple string the characters in
|
|---|
| 101 | the line. This is @f[setf]'able to set the @f[line-string] to any string that
|
|---|
| 102 | does not contain newline characters. It is an error to destructively modify
|
|---|
| 103 | the 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]}]
|
|---|
| 109 | Given a @i(line), @f[line-previous] returns the previous line or @nil if there
|
|---|
| 110 | is 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]}]
|
|---|
| 115 | This function returns the buffer which contains this @i(line). Since a
|
|---|
| 116 | line may not be associated with any buffer, in which case @f[line-buffer]
|
|---|
| 117 | returns @nil.
|
|---|
| 118 | @enddefun
|
|---|
| 119 |
|
|---|
| 120 | @defun[fun {line-length}, args {@i[line]}]
|
|---|
| 121 | This function returns the number of characters in the @i(line). This excludes
|
|---|
| 122 | the newline character at the end.
|
|---|
| 123 | @enddefun
|
|---|
| 124 |
|
|---|
| 125 | @defun[fun {line-character}, args {@i[line] @i[index]}]
|
|---|
| 126 | This function returns the character at position @i[index] within @i[line]. It
|
|---|
| 127 | is an error for @i[index] to be greater than the length of the line or less
|
|---|
| 128 | than 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]}]
|
|---|
| 133 | This 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
|
|---|
| 135 | in conjunction with @f[line-signature] to cache information about the line's
|
|---|
| 136 | contents.
|
|---|
| 137 | @enddefun
|
|---|
| 138 |
|
|---|
| 139 | @defun[fun {line-signature}, args {@i[line]}]
|
|---|
| 140 | This function returns an object that serves as a signature for a @i[line]'s
|
|---|
| 141 | contents. It is guaranteed that any modification of text on the line will
|
|---|
| 142 | result in the signature changing so that it is not @f[eql] to any previous
|
|---|
| 143 | value. The signature may change even when the text remains unmodified, but
|
|---|
| 144 | this does not happen often.
|
|---|
| 145 | @enddefun
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 | @section(Marks)
|
|---|
| 149 | @label[marks]
|
|---|
| 150 | @index (Marks)
|
|---|
| 151 | A mark indicates a specific position within the text represented by a line and
|
|---|
| 152 | a character position within that line. Although a mark is sometimes loosely
|
|---|
| 153 | referred to as pointing to some character, it in fact points between
|
|---|
| 154 | characters. If the @f[charpos] is zero, the previous character is the newline
|
|---|
| 155 | character separating the previous line from the mark's @f[line]. If the
|
|---|
| 156 | charpos is equal to the number of characters in the line, the next character is
|
|---|
| 157 | the newline character separating the current line from the next. If the mark's
|
|---|
| 158 | line has no previous line, a mark with @f[charpos] of zero has no previous
|
|---|
| 159 | character; if the mark's line has no next line, a mark with @f[charpos] equal
|
|---|
| 160 | to the length of the line has no next character.
|
|---|
| 161 |
|
|---|
| 162 | This 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
|
|---|
| 164 | extended uses of marks see chapter @ref[doing-stuff].
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 | @subsection(Kinds of Marks)
|
|---|
| 168 | @index (Permanent marks)
|
|---|
| 169 | @index (Temporary marks)
|
|---|
| 170 | A mark may have one of two lifetimes: @i[temporary] or @i[permanent].
|
|---|
| 171 | Permanent marks remain valid after arbitrary operations on the text; temporary
|
|---|
| 172 | marks do not. Temporary marks are used because less bookkeeping overhead is
|
|---|
| 173 | involved in their creation and use. If a temporary mark is used after the text
|
|---|
| 174 | it points to has been modified results will be unpredictable. Permanent marks
|
|---|
| 175 | continue to point between the same two characters regardless of insertions and
|
|---|
| 176 | deletions made before or after them.
|
|---|
| 177 |
|
|---|
| 178 | There are two different kinds of permanent marks which differ only in their
|
|---|
| 179 | behavior when text is inserted @i(at the position of the mark); text is
|
|---|
| 180 | inserted 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]}]
|
|---|
| 186 | This function returns @true if @i[mark] is a @f[mark] object, otherwise @nil.
|
|---|
| 187 | @enddefun
|
|---|
| 188 |
|
|---|
| 189 | @defun[fun {mark-line}, args {@i[mark]}]
|
|---|
| 190 | This function returns the line to which @i(mark) points.
|
|---|
| 191 | @enddefun
|
|---|
| 192 |
|
|---|
| 193 | @defun[fun {mark-charpos}, args {@i[mark]}]
|
|---|
| 194 | This function returns the character position of the character after @i(mark).
|
|---|
| 195 | If @i[mark]'s line has no next line, this returns the length of the line as
|
|---|
| 196 | usual; however, there is actually is no character after the mark.
|
|---|
| 197 | @enddefun
|
|---|
| 198 |
|
|---|
| 199 | @defun[fun {mark-kind}, args {@i[mark]}]
|
|---|
| 200 | This 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
|
|---|
| 202 | changes the mark's kind.
|
|---|
| 203 | @enddefun
|
|---|
| 204 |
|
|---|
| 205 | @defun[fun {previous-character}, args {@i[mark]}]
|
|---|
| 206 | @defun1[fun {next-character}, args {@i[mark]}]
|
|---|
| 207 | This function returns the character immediately before (after) the position of
|
|---|
| 208 | the @i[mark], or @nil if there is no previous (next) character. These
|
|---|
| 209 | characters may be set with @f[setf] when they exist; the @f[setf] methods for
|
|---|
| 210 | these 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]}]
|
|---|
| 216 | This function returns a mark object that points to the @i(charpos)'th character
|
|---|
| 217 | of 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
|
|---|
| 219 | is @kwd[temporary].
|
|---|
| 220 | @enddefun
|
|---|
| 221 |
|
|---|
| 222 | @defun[fun {copy-mark}, args {@i[mark] @optional @i[kind]}]
|
|---|
| 223 | This function returns a new mark pointing to the same position and of the same
|
|---|
| 224 | kind, or of kind @i[kind] if it is supplied.
|
|---|
| 225 | @enddefun
|
|---|
| 226 |
|
|---|
| 227 | @defun[fun {delete-mark}, args {@i[mark]}]
|
|---|
| 228 | This function deletes @i(mark). Delete any permanent marks when you are
|
|---|
| 229 | finished 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
|
|---|
| 235 | defaults to @kwd[temporary], pointing to the same position as the mark @i[pos].
|
|---|
| 236 | On exit from the scope the mark is deleted. The value of the last @i[form] is
|
|---|
| 237 | the value returned.
|
|---|
| 238 | @enddefmac
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 | @subsection(Moving Marks)
|
|---|
| 242 | @index(Moving marks)
|
|---|
| 243 | These functions destructively modify marks to point to new positions. Other
|
|---|
| 244 | sections of this document describe mark moving routines specific to higher
|
|---|
| 245 | level text forms than characters and lines, such as words, sentences,
|
|---|
| 246 | paragraphs, Lisp forms, etc.
|
|---|
| 247 |
|
|---|
| 248 | @defun[fun {move-to-position}, args {@i[mark] @i[charpos] @optional @i[line]}]
|
|---|
| 249 | This function changes the @i(mark) to point to the given character position on
|
|---|
| 250 | the 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]}]
|
|---|
| 254 | This function moves @i[mark] to the same position as the mark @i[new-position]
|
|---|
| 255 | and 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]}]
|
|---|
| 260 | This function changes @i[mark] to point to the beginning or the end of @i(line)
|
|---|
| 261 | and 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]}]
|
|---|
| 266 | These functions change @i[mark] to point to the beginning or end of @i[buffer],
|
|---|
| 267 | which defaults to the buffer @i[mark] currently points into. If @i[buffer] is
|
|---|
| 268 | unsupplied, then it is an error for @i[mark] to be disassociated from any
|
|---|
| 269 | buffer.
|
|---|
| 270 | @enddefun
|
|---|
| 271 |
|
|---|
| 272 | @defun[fun {mark-before}, args {@i[mark]}]
|
|---|
| 273 | @defun1[fun {mark-after}, args {@i[mark]}]
|
|---|
| 274 | These functions change @i[mark] to point one character before or after the
|
|---|
| 275 | current position. If there is no character before/after the current position,
|
|---|
| 276 | then they return @nil and leave @i[mark] unmodified.
|
|---|
| 277 | @enddefun
|
|---|
| 278 |
|
|---|
| 279 | @defun[fun {character-offset}, args {@i[mark] @i[n]}]
|
|---|
| 280 | This 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]
|
|---|
| 282 | characters after (before) the @i[mark], then this returns @nil and @i[mark] is
|
|---|
| 283 | unmodified.
|
|---|
| 284 | @enddefun
|
|---|
| 285 |
|
|---|
| 286 | @defun[fun {line-offset}, args {@i[mark] @i[n] @optional @i[charpos]}]
|
|---|
| 287 | This 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
|
|---|
| 289 | resulting mark is
|
|---|
| 290 | @lisp
|
|---|
| 291 | (min (line-length @i(resulting-line)) (mark-charpos @i(mark)))
|
|---|
| 292 | @endlisp
|
|---|
| 293 | if @i[charpos] is unspecified, or
|
|---|
| 294 | @lisp
|
|---|
| 295 | (min (line-length @i(resulting-line)) @i(charpos))
|
|---|
| 296 | @endlisp
|
|---|
| 297 | if 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)
|
|---|
| 304 | A region is simply a pair of marks: a starting mark and an ending mark.
|
|---|
| 305 | The text in a region consists of the characters following the starting
|
|---|
| 306 | mark and preceding the ending mark (keep in mind that a mark points between
|
|---|
| 307 | characters on a line, not at them).
|
|---|
| 308 |
|
|---|
| 309 | By modifying the starting or ending mark in a region it is possible to
|
|---|
| 310 | produce regions with a start and end which are out of order or even in
|
|---|
| 311 | different buffers. The use of such regions is undefined and may
|
|---|
| 312 | result in arbitrarily bad behavior.
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 | @subsection(Region Functions)
|
|---|
| 316 | @defun[fun {region}, args {@i[start] @i[end]}]
|
|---|
| 317 | This 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]}]
|
|---|
| 323 | This function returns @true if @i[region] is a @f[region] object, otherwise
|
|---|
| 324 | @nil.
|
|---|
| 325 | @enddefun
|
|---|
| 326 |
|
|---|
| 327 | @defun[fun {make-empty-region}]
|
|---|
| 328 | This function returns a region with start and end marks pointing to the start
|
|---|
| 329 | of one empty line. The start mark is a @kwd[right-inserting] mark, and the end
|
|---|
| 330 | is a @kwd[left-inserting] mark.
|
|---|
| 331 | @enddefun
|
|---|
| 332 |
|
|---|
| 333 | @defun[fun {copy-region}, args {@i[region]}]
|
|---|
| 334 | This 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
|
|---|
| 336 | respect 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]}]
|
|---|
| 341 | These functions coerce regions to Lisp strings and vice versa. Within the
|
|---|
| 342 | string, lines are delimited by newline characters.
|
|---|
| 343 | @enddefun
|
|---|
| 344 |
|
|---|
| 345 | @defun[fun {line-to-region}, args {@i[line]}]
|
|---|
| 346 | This function returns a region containing all the characters on @i[line]. The
|
|---|
| 347 | first 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]}]
|
|---|
| 352 | This function returns the start or end mark of @i(region).
|
|---|
| 353 | @enddefun
|
|---|
| 354 |
|
|---|
| 355 | @defun[fun {region-bounds}, args {@i[region]}]
|
|---|
| 356 | This 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]}]
|
|---|
| 361 | This function sets the start and end of region to @i[start] and @i[end]. It is
|
|---|
| 362 | an 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]}]
|
|---|
| 367 | This function returns the number of lines in the @i(region), first and last
|
|---|
| 368 | lines inclusive. A newline is associated with the line it follows, thus a
|
|---|
| 369 | region containing some number of non-newline characters followed by one newline
|
|---|
| 370 | is one line, but if a newline were added at the beginning, it would be two
|
|---|
| 371 | lines.
|
|---|
| 372 | @enddefun
|
|---|
| 373 |
|
|---|
| 374 | @defun[fun {count-characters}, args {@i[region]}]
|
|---|
| 375 | This function returns the number of characters in a given @i(region). This
|
|---|
| 376 | counts 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
|
|---|
| 382 | exceeds the @hid[Region Query Size] threshold, it prompts the user for
|
|---|
| 383 | confirmation. This should be used in commands that perform destructive
|
|---|
| 384 | operations and are not undoable. If the user responds negatively, then this
|
|---|
| 385 | signals an editor-error, aborting whatever command was in progress.
|
|---|
| 386 | @enddefun
|
|---|
| 387 |
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 | @chapter(Buffers)
|
|---|
| 391 | @index (Buffers)
|
|---|
| 392 | @label[buffers]
|
|---|
| 393 | A buffer is an environment within @hemlock consisting of:
|
|---|
| 394 | @begin(enumerate)
|
|---|
| 395 | A name.
|
|---|
| 396 |
|
|---|
| 397 | A piece of text.
|
|---|
| 398 |
|
|---|
| 399 | A current focus of attention, the point.
|
|---|
| 400 |
|
|---|
| 401 | An associated file (optional).
|
|---|
| 402 |
|
|---|
| 403 | A write protect flag.
|
|---|
| 404 |
|
|---|
| 405 | Some variables (page @pageref[variables]).
|
|---|
| 406 |
|
|---|
| 407 | Some key bindings (page @pageref[key-bindings]).
|
|---|
| 408 |
|
|---|
| 409 | Some collection of modes (page @pageref[modes]).
|
|---|
| 410 |
|
|---|
| 411 | Some windows in which it is displayed (page @pageref[windows]).
|
|---|
| 412 |
|
|---|
| 413 | A 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
|
|---|
| 423 | buffer that @funref[current-window] is displaying. This value may be changed
|
|---|
| 424 | with @f[setf], and the @f[setf] method invokes @hid[Set Buffer Hook] before the
|
|---|
| 425 | change 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}]
|
|---|
| 430 | This function returns the @f[buffer-point] of the current buffer.
|
|---|
| 431 | This is such a common idiom in commands that it is defined despite
|
|---|
| 432 | its 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
|
|---|
| 442 | always is at least one mark at the beginning of the buffer's region, and all
|
|---|
| 443 | marks returned are right-inserting.
|
|---|
| 444 |
|
|---|
| 445 | @f[pop-buffer-mark] pops the current buffer's mark stack, returning the mark.
|
|---|
| 446 | If the stack becomes empty, this pushes a new mark on the stack pointing to the
|
|---|
| 447 | buffer'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,
|
|---|
| 451 | ensuring that the mark is right-inserting. If @i[mark] does not point into the
|
|---|
| 452 | current buffer, this signals an error. Optionally, the current region is made
|
|---|
| 453 | active, 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}]
|
|---|
| 458 | This variable holds a list of all the buffer objects made with @f[make-buffer].
|
|---|
| 459 | @enddefvar
|
|---|
| 460 |
|
|---|
| 461 | @defvar[var {buffer-names}]
|
|---|
| 462 | This variable holds a @f[string-table] (page @pageref(string-tables)) of all the
|
|---|
| 463 | names of the buffers in @var[buffer-list]. The values of the entries are the
|
|---|
| 464 | corresponding buffer objects.
|
|---|
| 465 | @enddefvar
|
|---|
| 466 |
|
|---|
| 467 | @defvar[var {buffer-history}]
|
|---|
| 468 | This is a list of buffer objects ordered from those most recently selected to
|
|---|
| 469 | those selected farthest in the past. When someone makes a buffer, an element
|
|---|
| 470 | of @hid[Make Buffer Hook] adds this buffer to the end of this list. When
|
|---|
| 471 | someone deletes a buffer, an element of @hid[Delete Buffer Hook] removes the
|
|---|
| 472 | buffer from this list. Each buffer occurs in this list exactly once, but it
|
|---|
| 473 | never contains the @var[echo-area-buffer].
|
|---|
| 474 | @enddefvar
|
|---|
| 475 |
|
|---|
| 476 | @defun[fun {change-to-buffer}, args {@i[buffer]}]
|
|---|
| 477 | This switches to @i[buffer] in the @f[current-window] maintaining
|
|---|
| 478 | @f[buffer-history].
|
|---|
| 479 | @enddefun
|
|---|
| 480 |
|
|---|
| 481 | @defun[fun {previous-buffer}]
|
|---|
| 482 | This 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
|
|---|
| 492 | buffer named @i[name] already exists, @nil is returned. @i[Modes] is a list of
|
|---|
| 493 | modes which should be in effect in the buffer, major mode first, followed by
|
|---|
| 494 | any minor modes. If this is omitted then the buffer is created with the list
|
|---|
| 495 | of modes contained in @hvarref[Default Modes]. @i[Modeline-fields] is a list
|
|---|
| 496 | of 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 |
|
|---|
| 500 | Buffers created with @f[make-buffer] are entered into the list
|
|---|
| 501 | @var[buffer-list], and their names are inserted into the
|
|---|
| 502 | string-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]}]
|
|---|
| 507 | Returns @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).
|
|---|
| 513 | The 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
|
|---|
| 515 | supplies a name for which a buffer already exists, the @f[setf] method signals
|
|---|
| 516 | an error.
|
|---|
| 517 | @enddefun
|
|---|
| 518 |
|
|---|
| 519 | @defun[fun {buffer-region}, args {@i[buffer]}]
|
|---|
| 520 | Returns the @i[buffer]'s region. This can be set with @f[setf]. Note, this
|
|---|
| 521 | returns 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
|
|---|
| 528 | the given @i(buffer), or nil if it has no associated file. This is
|
|---|
| 529 | the truename of the file as of the most recent time it was read or
|
|---|
| 530 | written. There is a @f[setf] form to change the pathname. When the
|
|---|
| 531 | pathname is changed the hook @hid[Buffer Pathname Hook] is invoked
|
|---|
| 532 | with the buffer and new value.
|
|---|
| 533 | @enddefun
|
|---|
| 534 |
|
|---|
| 535 | @defun[fun {buffer-write-date}, args {@i[buffer]}]
|
|---|
| 536 | Returns the write date for the file associated with the buffer in universal
|
|---|
| 537 | time format. When this the @f[buffer-pathname] is set, use @f[setf] to set
|
|---|
| 538 | this to the corresponding write date, or to @nil if the date is unknown or
|
|---|
| 539 | there is no file.
|
|---|
| 540 | @enddefun
|
|---|
| 541 |
|
|---|
| 542 | @defun[fun {buffer-point}, args {@i[buffer]}]
|
|---|
| 543 | Returns the mark which is the current location within @i[buffer]. To
|
|---|
| 544 | move the point, use @f[move-mark] or @funref[move-to-position] rather
|
|---|
| 545 | than 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)
|
|---|
| 551 | This function returns the top of @i[buffer]'s mark stack. There always
|
|---|
| 552 | is at least one mark at the beginning of @i[buffer]'s region, and all marks
|
|---|
| 553 | returned are right-inserting.
|
|---|
| 554 | @enddefun
|
|---|
| 555 |
|
|---|
| 556 | @defun[fun {buffer-start-mark}, args {@i[buffer]}]
|
|---|
| 557 | @defun1[fun {buffer-end-mark}, args {@i[buffer]}]
|
|---|
| 558 | These 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))
|
|---|
| 562 | and
|
|---|
| 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"]
|
|---|
| 570 | This function returns @true if you can modify the @i(buffer), @nil if you
|
|---|
| 571 | cannot. If a buffer is not writable, then any attempt to alter text in the
|
|---|
| 572 | buffer results in an error. There is a @f[setf] method to change this value.
|
|---|
| 573 |
|
|---|
| 574 | The @f[setf] method invokes the functions in @hid[Buffer Writable Hook] on the
|
|---|
| 575 | buffer 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
|
|---|
| 581 | it hasn't. This attribute is set whenever a text-altering operation is
|
|---|
| 582 | performed on a buffer. There is a @f[setf] method to change this value.
|
|---|
| 583 |
|
|---|
| 584 | The @f[setf] method invokes the functions in @hid[Buffer Modified Hook] with
|
|---|
| 585 | the buffer whenever the value of the modified flag changes.
|
|---|
| 586 | @enddefun
|
|---|
| 587 |
|
|---|
| 588 | @defmac[fun {with-writable-buffer}, args {(@i[buffer]) @rest @i[forms]}]
|
|---|
| 589 | This 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]}]
|
|---|
| 594 | This 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
|
|---|
| 596 | buffer has not been modified between the calls.
|
|---|
| 597 | @enddefun
|
|---|
| 598 |
|
|---|
| 599 | @defun[fun {buffer-variables}, args {@i[buffer]}]
|
|---|
| 600 | This function returns a string-table (page @pageref[string-tables]) containing
|
|---|
| 601 | the names of the buffer's local variables. See chapter @ref[variables].
|
|---|
| 602 | @enddefun
|
|---|
| 603 |
|
|---|
| 604 | @defun[fun {buffer-modes}, args {@i[buffer]}]
|
|---|
| 605 | This function returns the list of the names of the modes active in @i[buffer].
|
|---|
| 606 | The major mode is first, followed by any minor modes. See chapter @ref[modes].
|
|---|
| 607 | @enddefun
|
|---|
| 608 |
|
|---|
| 609 | @defun[fun {buffer-windows}, args {@i[buffer]}]
|
|---|
| 610 | This function returns the list of all the windows in which the buffer may be
|
|---|
| 611 | displayed. This list may include windows which are not currently visible. See
|
|---|
| 612 | page @pageref[windows] for a discussion of windows.
|
|---|
| 613 | @enddefun
|
|---|
| 614 |
|
|---|
| 615 | @defun[fun {buffer-delete-hook}, args {@i[buffer]}]
|
|---|
| 616 | This function returns the list of buffer specific functions @f[delete-buffer]
|
|---|
| 617 | invokes 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
|
|---|
| 623 | from @varref[buffer-names]. Before @i[buffer] is deleted, this invokes the
|
|---|
| 624 | functions 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
|
|---|
| 626 | displayed in any windows, then this function signals an error.
|
|---|
| 627 | @enddefun
|
|---|
| 628 |
|
|---|
| 629 | @defun[fun {delete-buffer-if-possible}, args {@i[buffer]}]
|
|---|
| 630 | This 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
|
|---|
| 632 | the first distinct buffer in @f[buffer-history]. If @i[buffer] is displayed in
|
|---|
| 633 | any 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 |
|
|---|
| 641 | A Buffer may specify a modeline, a line of text which is displayed across the
|
|---|
| 642 | bottom of a window to indicate status information. Modelines are described as
|
|---|
| 643 | a list of @f[modeline-field] objects which have individual update functions and
|
|---|
| 644 | are optionally fixed-width. These have an @f[eql] name for convenience in
|
|---|
| 645 | referencing and updating, but the name must be unique for all created
|
|---|
| 646 | modeline-field objects. When creating a modeline-field with a specified width,
|
|---|
| 647 | the result of the update function is either truncated or padded on the right to
|
|---|
| 648 | meet the constraint. All modeline-field functions must return simple strings
|
|---|
| 649 | with standard characters, and these take a buffer and a window as arguments.
|
|---|
| 650 | Modeline-field objects are typically shared amongst, or aliased by, different
|
|---|
| 651 | buffers' modeline fields lists. These lists are unique allowing fields to
|
|---|
| 652 | behave the same wherever they occur, but different buffers may display these
|
|---|
| 653 | fields in different arrangements.
|
|---|
| 654 |
|
|---|
| 655 | Whenever one of the following changes occurs, all of a buffer's modeline fields
|
|---|
| 656 | are updated:
|
|---|
| 657 | @Begin[Itemize]
|
|---|
| 658 | A buffer's major mode is set.
|
|---|
| 659 |
|
|---|
| 660 | One of a buffer's minor modes is turned on or off.
|
|---|
| 661 |
|
|---|
| 662 | A buffer is renamed.
|
|---|
| 663 |
|
|---|
| 664 | A buffer's pathname changes.
|
|---|
| 665 |
|
|---|
| 666 | A buffer's modified status changes.
|
|---|
| 667 |
|
|---|
| 668 | A window's buffer is changed.
|
|---|
| 669 | @End[Itemize]
|
|---|
| 670 |
|
|---|
| 671 | The policy is that whenever one of these changes occurs, it is guaranteed that
|
|---|
| 672 | the modeline will be updated before the next trip through redisplay.
|
|---|
| 673 | Furthermore, since the system cannot know what modeline-field objects the
|
|---|
| 674 | user has added whose update functions rely on these values, or how he has
|
|---|
| 675 | changed @hid[Default Modeline Fields], we must update all the fields. When any
|
|---|
| 676 | but the last occurs, the modeline-field update function is invoked once for
|
|---|
| 677 | each window into the buffer. When a window's buffer changes, each
|
|---|
| 678 | modeline-field update function is invoked once; other windows' modeline
|
|---|
| 679 | fields should not be affected due to a given window's buffer changing.
|
|---|
| 680 |
|
|---|
| 681 | The user should note that modelines can be updated at any time, so update
|
|---|
| 682 | functions should be careful to avoid needless delays (for example, waiting for
|
|---|
| 683 | a 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
|
|---|
| 690 | is variable width; otherwise, the programmer must supply this as a positive
|
|---|
| 691 | integer. @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
|
|---|
| 693 | names 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
|
|---|
| 696 | this is set with @f[setf], and the new name already names a modeline-field,
|
|---|
| 697 | then the @f[setf] method signals an error.
|
|---|
| 698 |
|
|---|
| 699 | @f[modeline-field-p] returns @true or @nil, depending on whether its argument
|
|---|
| 700 | is a @f[modeline-field] object.
|
|---|
| 701 | @enddefun
|
|---|
| 702 |
|
|---|
| 703 | @defun[fun {modeline-field}, args {@i[name]}]
|
|---|
| 704 | This returns the modeline-field object named @i[name]. If none exists, this
|
|---|
| 705 | returns nil.
|
|---|
| 706 | @enddefun
|
|---|
| 707 |
|
|---|
| 708 | @defun[fun {modeline-field-function}, args {@i[modeline-field]}]
|
|---|
| 709 | Returns the function called when updating the @i[modeline-field]. When this is
|
|---|
| 710 | set with @f[setf], the @f[setf] method updates @i[modeline-field] for all
|
|---|
| 711 | windows on all buffers that contain the given field, so the next trip through
|
|---|
| 712 | redisplay will reflect the change. All modeline-field functions must return
|
|---|
| 713 | simple strings with standard characters, and they take a buffer and a window
|
|---|
| 714 | as arguments.
|
|---|
| 715 | @enddefun
|
|---|
| 716 |
|
|---|
| 717 | @defun[fun {modeline-field-width}, args {@i[modeline-field]}]
|
|---|
| 718 | Returns the width to which @i[modeline-field] is constrained, or @nil
|
|---|
| 719 | indicating 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
|
|---|
| 721 | contain the given field, so the next trip through redisplay will reflect the
|
|---|
| 722 | change. All the fields for any such modeline display must be updated, which is
|
|---|
| 723 | not the case when setting a modeline-field's function.
|
|---|
| 724 | @enddefun
|
|---|
| 725 |
|
|---|
| 726 | @defun[fun {buffer-modeline-fields}, args {@i[buffer]}]
|
|---|
| 727 | Returns a copy of the list of @i[buffer]'s modeline-field objects. This list
|
|---|
| 728 | can be destructively modified without affecting display of @i[buffer]'s
|
|---|
| 729 | modeline, but modifying any particular field's components (for example, width
|
|---|
| 730 | or function) causes the changes to be reflected the next trip through redisplay
|
|---|
| 731 | in every modeline display that uses the modified modeline-field. When this is
|
|---|
| 732 | set 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]}]
|
|---|
| 737 | If @i[field], a modeline-field or the name of one, is in buffer's list of
|
|---|
| 738 | modeline-field objects, it is returned; otherwise, this returns nil.
|
|---|
| 739 | @enddefun
|
|---|
| 740 |
|
|---|
| 741 | @defun[fun {update-modeline-fields}, args {@i[buffer] @i[window]}]
|
|---|
| 742 | This invokes each modeline-field object's function from @i[buffer]'s list,
|
|---|
| 743 | passing @i[buffer] and @i[window]. The results are collected regarding each
|
|---|
| 744 | modeline-field object's width as appropriate, and the window is marked so
|
|---|
| 745 | the next trip through redisplay will reflect the changes. If window does not
|
|---|
| 746 | display modelines, then no computation occurs.
|
|---|
| 747 | @enddefun
|
|---|
| 748 |
|
|---|
| 749 | @defun[fun {update-modeline-field}, args {@i[buffer] @i[window] @i[field-or-name]}]
|
|---|
| 750 | This invokes the modeline-field object's function for @i[field-or-name], which
|
|---|
| 751 | is 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
|
|---|
| 754 | window is marked so the next trip through redisplay will reflect the changes.
|
|---|
| 755 | If 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,
|
|---|
| 757 | then 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)
|
|---|
| 769 | A note on marks and text alteration: @kwd[temporary] marks are invalid
|
|---|
| 770 | after any change has been made to the text the mark points to; it is an
|
|---|
| 771 | error to use a temporary mark after such a change has been made. If
|
|---|
| 772 | text is deleted which has permanent marks pointing into it then they
|
|---|
| 773 | are 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]}]
|
|---|
| 778 | Inserts @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
|
|---|
| 781 | some buffer, then @hemlock leaves @f[buffer-modified] of @i[mark]'s buffer
|
|---|
| 782 | unaffected.
|
|---|
| 783 | @enddefun
|
|---|
| 784 |
|
|---|
| 785 | @defun[fun {ninsert-region}, args {@i[mark] @i[region]}]
|
|---|
| 786 | Like @f[insert-region], inserts the @i[region] at the @i[mark]'s position,
|
|---|
| 787 | destroying the source region. This must be used with caution, since if anyone
|
|---|
| 788 | else can refer to the source region bad things will happen. In particular, one
|
|---|
| 789 | should 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]}]
|
|---|
| 795 | This deletes @i[n] characters after the @i[mark] (or -@i[n] before if @i[n] is
|
|---|
| 796 | negative). If @i[n] characters after (or -@i[n] before) the @i[mark] do not
|
|---|
| 797 | exist, then this returns @nil; otherwise, it returns @true. If @i[n] is zero,
|
|---|
| 798 | and @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]}]
|
|---|
| 803 | This 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
|
|---|
| 805 | some buffer's @f[buffer-region], then @hemlock leaves @f[buffer-modified] of
|
|---|
| 806 | the buffer unaffected.
|
|---|
| 807 | @enddefun
|
|---|
| 808 |
|
|---|
| 809 | @defun[fun {delete-and-save-region}, args {@i[region]}]
|
|---|
| 810 | This 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
|
|---|
| 813 | unaffected. In this case, this returns a distinct empty region.
|
|---|
| 814 | @enddefun
|
|---|
| 815 |
|
|---|
| 816 | @defun[fun {filter-region}, args {@i[function] @i[region]}]
|
|---|
| 817 | Destructively modifies @i[region] by replacing the text
|
|---|
| 818 | of each line with the result of the application of @i[function] to a
|
|---|
| 819 | string containing that text. @i[Function] must obey the following
|
|---|
| 820 | restrictions:
|
|---|
| 821 | @begin[enumerate]
|
|---|
| 822 | The argument may not be destructively modified.
|
|---|
| 823 |
|
|---|
| 824 | The return value may not contain newline characters.
|
|---|
| 825 |
|
|---|
| 826 | The return value may not be destructively modified after it is
|
|---|
| 827 | returned from @i[function].
|
|---|
| 828 | @end[enumerate]
|
|---|
| 829 | The strings are passed in order, and are always simple strings.
|
|---|
| 830 |
|
|---|
| 831 | Using 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]}]
|
|---|
| 840 | Returns @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]}]
|
|---|
| 845 | Returns @true if the @i(mark) points after the last character in a line and
|
|---|
| 846 | before the newline, @nil otherwise.
|
|---|
| 847 | @enddefun
|
|---|
| 848 |
|
|---|
| 849 | @defun[fun {empty-line-p}, args {@i[mark]}]
|
|---|
| 850 | Return @true of the line which @i[mark] points to contains no characters.
|
|---|
| 851 | @enddefun
|
|---|
| 852 |
|
|---|
| 853 | @defun[fun {blank-line-p}, args {@i[line]}]
|
|---|
| 854 | Returns @true if @i[line] contains only characters with a
|
|---|
| 855 | @hid[Whitespace] attribute of 1. See chapter @ref[character-attributes] for
|
|---|
| 856 | discussion of character attributes.
|
|---|
| 857 | @enddefun
|
|---|
| 858 |
|
|---|
| 859 | @defun[fun {blank-before-p}, args {@i[mark]}]
|
|---|
| 860 | @defun1[fun {blank-after-p}, args {@i[mark]}]
|
|---|
| 861 | These 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]}]
|
|---|
| 866 | Returns @true if @i(mark1) and @i(mark2) point to the same line, or @nil
|
|---|
| 867 | otherwise; 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]}]
|
|---|
| 877 | These predicates test the relative ordering of two marks in a piece of
|
|---|
| 878 | text, that is a mark is @f[mark>] another if it points to a position
|
|---|
| 879 | after it. If the marks point into different, non-connected pieces of
|
|---|
| 880 | text, such as different buffers, then it is an error to test their
|
|---|
| 881 | ordering; for such marks @f[mark=] is always false and @f[mark/=] is
|
|---|
| 882 | always 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]}]
|
|---|
| 889 | These predicates test the ordering of @i[line1] and @i[line2]. If the
|
|---|
| 890 | lines are in unconnected pieces of text it is an error to test their
|
|---|
| 891 | ordering.
|
|---|
| 892 | @enddefun
|
|---|
| 893 |
|
|---|
| 894 | @defun[fun {lines-related}, args {@i[line1] @i[line2]}]
|
|---|
| 895 | This function returns @true if @i[line1] and @i[line2] are in the same
|
|---|
| 896 | piece 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
|
|---|
| 903 | tests 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}]
|
|---|
| 912 | This is a ring (see section @ref[rings]) of regions deleted from buffers.
|
|---|
| 913 | Some commands save affected regions on the kill ring before performing
|
|---|
| 914 | modifications. You should consider making the command undoable (see section
|
|---|
| 915 | @ref[undo]), but this is a simple way of achieving a less satisfactory means
|
|---|
| 916 | for the user to recover.
|
|---|
| 917 | @enddefvar
|
|---|
| 918 |
|
|---|
| 919 | @defun[fun {kill-region}, args {@i[region] @i[current-type]}]
|
|---|
| 920 | This 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]
|
|---|
| 922 | is one of these, this adds @i[region] to the beginning or end, respectively, of
|
|---|
| 923 | the top of @var[kill-ring]. The result of calling this is undoable using the
|
|---|
| 924 | command @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
|
|---|
| 932 | positive, otherwise before @i[mark] if @i[count] is negative. When @i[count]
|
|---|
| 933 | is greater than or equal to @hid[Character Deletion Threshold], the killed
|
|---|
| 934 | characters are saved on @var[kill-ring]. This may be called multiple times
|
|---|
| 935 | contiguously (that is, without @funref[last-command-type] being set) to
|
|---|
| 936 | accumulate an effective count for purposes of comparison with the threshold.
|
|---|
| 937 |
|
|---|
| 938 | This sets @f[last-command-type], and it interacts with @f[kill-region]. When
|
|---|
| 939 | this 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
|
|---|
| 945 | to @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]
|
|---|
| 947 | depending on whether @i[count] is positive or negative, respectively.
|
|---|
| 948 |
|
|---|
| 949 | This returns mark if it deletes characters. If there are not @i[count]
|
|---|
| 950 | characters in the appropriate direction, this returns nil.
|
|---|
| 951 | @enddefun
|
|---|
| 952 |
|
|---|
| 953 |
|
|---|
| 954 | @section(Active Regions)
|
|---|
| 955 | @index(Active regions)
|
|---|
| 956 | @label(active-regions)
|
|---|
| 957 |
|
|---|
| 958 | Every buffer has a mark stack (page @pageref[mark-stack]) and a mark known as
|
|---|
| 959 | the point where most text altering nominally occurs. Between the top of the
|
|---|
| 960 | mark 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
|
|---|
| 962 | commands signal errors when the user tries to operate on the @f[current-region]
|
|---|
| 963 | without its having been activated. If the user turns off this feature, then
|
|---|
| 964 | the @f[current-region] is effectively always active.
|
|---|
| 965 |
|
|---|
| 966 | When writing a command that marks a region of text, the programmer should make
|
|---|
| 967 | sure to activate the region. This typically occurs naturally from the
|
|---|
| 968 | primitives that you use to mark regions, but sometimes you must explicitly
|
|---|
| 969 | activate the region. These commands should be written this way, so they do not
|
|---|
| 970 | require the user to separately mark an area and then activate it. Commands
|
|---|
| 971 | that modify regions do not have to worry about deactivating the region since
|
|---|
| 972 | modifying a buffer automatically deactivates the region. Commands that insert
|
|---|
| 973 | text often activate the region ephemerally; that is, the region is active for
|
|---|
| 974 | the immediately following command, allowing the user wants to delete the region
|
|---|
| 975 | inserted, fill it, or whatever.
|
|---|
| 976 |
|
|---|
| 977 | Once a marking command makes the region active, it remains active until:
|
|---|
| 978 | @begin[itemize]
|
|---|
| 979 | a command uses the region,
|
|---|
| 980 |
|
|---|
| 981 | a command modifies the buffer,
|
|---|
| 982 |
|
|---|
| 983 | a command changes the current window or buffer,
|
|---|
| 984 |
|
|---|
| 985 | a command signals an editor-error,
|
|---|
| 986 |
|
|---|
| 987 | or the user types @binding[C-g].
|
|---|
| 988 | @end[itemize]
|
|---|
| 989 |
|
|---|
| 990 | @defhvar[var "Active Regions Enabled", val {t}]
|
|---|
| 991 | When this variable is non-@nil, some primitives signal an editor-error if
|
|---|
| 992 | the region is not active. This may be set to @nil for more traditional @emacs
|
|---|
| 993 | region semantics.
|
|---|
| 994 | @enddefhvar
|
|---|
| 995 |
|
|---|
| 996 | @defvar[var {ephemerally-active-command-types}]
|
|---|
| 997 | This is a list of command types (see section @ref[command-types]), and its
|
|---|
| 998 | initial value is the list of @kwd[ephemerally-active] and @kwd[unkill]. When
|
|---|
| 999 | the previous command's type is one of these, the @f[current-region] is active
|
|---|
| 1000 | for the currently executing command only, regardless of whether it does
|
|---|
| 1001 | something to deactivate the region. However, the current command may activate
|
|---|
| 1002 | the region for future commands. @kwd[ephemerally-active] is a default command
|
|---|
| 1003 | type that may be used to ephemerally activate the region, and @kwd[unkill] is
|
|---|
| 1004 | the type used by two commands, @hid[Un-kill] and @hid[Rotate Kill Ring] (what
|
|---|
| 1005 | users typically think of as @binding[C-y] and @binding[M-y]).
|
|---|
| 1006 | @enddefvar
|
|---|
| 1007 |
|
|---|
| 1008 | @defun[fun {activate-region}]
|
|---|
| 1009 | This makes the @f[current-region] active.
|
|---|
| 1010 | @enddefun
|
|---|
| 1011 |
|
|---|
| 1012 | @defun[fun {deactivate-region}]
|
|---|
| 1013 | After invoking this the @f[current-region] is no longer active.
|
|---|
| 1014 | @enddefun
|
|---|
| 1015 |
|
|---|
| 1016 | @defun[fun {region-active-p}]
|
|---|
| 1017 | Returns whether the @f[current-region] is active, including ephemerally. This
|
|---|
| 1018 | ignores @hid[Active Regions Enabled].
|
|---|
| 1019 | @enddefun
|
|---|
| 1020 |
|
|---|
| 1021 | @defun[fun {check-region-active}]
|
|---|
| 1022 | This 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]}]
|
|---|
| 1028 | This returns a region formed with @f[current-mark] and @f[current-point],
|
|---|
| 1029 | optionally 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
|
|---|
| 1031 | object. Depending on @i[deactivate-region] (defaults to @true), fetching the
|
|---|
| 1032 | current region deactivates it. @hemlock primitives are free to modify text
|
|---|
| 1033 | regardless of whether the region is active, so a command that checks for this
|
|---|
| 1034 | can deactivate the region whenever it is convenient.
|
|---|
| 1035 | @enddefun
|
|---|
| 1036 |
|
|---|
| 1037 |
|
|---|
| 1038 | @section(Searching and Replacing)
|
|---|
| 1039 | @index(Searching)
|
|---|
| 1040 | @index(Replacing)
|
|---|
| 1041 |
|
|---|
| 1042 | Before using any of these functions to do a character search, look at character
|
|---|
| 1043 | attributes (page @pageref[character-attributes]). They provide a facility
|
|---|
| 1044 | similar to the syntax table in real EMACS. Syntax tables are a powerful,
|
|---|
| 1045 | general, and efficient mechanism for assigning meanings to characters in
|
|---|
| 1046 | various modes.
|
|---|
| 1047 |
|
|---|
| 1048 | @defcon[var {search-char-code-limit}]
|
|---|
| 1049 | An exclusive upper limit for the char-code of characters given to the searching
|
|---|
| 1050 | functions. The result of searches for characters with a char-code greater than
|
|---|
| 1051 | or equal to this limit is ill-defined, but it is @i[not] an error to do such
|
|---|
| 1052 | searches.
|
|---|
| 1053 | @enddefcon
|
|---|
| 1054 |
|
|---|
| 1055 | @defun[fun {new-search-pattern},
|
|---|
| 1056 | args {@i[kind] @i[direction] @i[pattern] @optional @i[result-search-pattern]}]
|
|---|
| 1057 |
|
|---|
| 1058 | Returns a @i[search-pattern] object which can be given to the @f[find-pattern]
|
|---|
| 1059 | and @f[replace-pattern] functions. A search-pattern is a specification of a
|
|---|
| 1060 | particular 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
|
|---|
| 1062 | kind of search pattern to make, and @i[pattern] is a thing which specifies what
|
|---|
| 1063 | to search for.
|
|---|
| 1064 |
|
|---|
| 1065 | The interpretation of @i[pattern] depends on the @i[kind] of pattern being
|
|---|
| 1066 | made. 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].
|
|---|
| 1075 | This 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].
|
|---|
| 1081 | This function may not be applied an any particular fashion, so it
|
|---|
| 1082 | should depend only on what its argument is, and should have no
|
|---|
| 1083 | side-effects.
|
|---|
| 1084 |
|
|---|
| 1085 | @kwd[test-not]@\Similar to as @kwd[test], except it finds a character that
|
|---|
| 1086 | fails 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
|
|---|
| 1094 | destructively modify to produce the new pattern. Where reasonable
|
|---|
| 1095 | this should be supplied, since some kinds of search patterns may
|
|---|
| 1096 | involve large data structures.
|
|---|
| 1097 | @enddefun
|
|---|
| 1098 |
|
|---|
| 1099 | @defun[fun {search-pattern-p}, args {@i[search-pattern]}]
|
|---|
| 1100 | Returns @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
|
|---|
| 1108 | search and replacing commands can use. These commands then share a default
|
|---|
| 1109 | when prompting for what to search or replace, and save on consing a search
|
|---|
| 1110 | pattern 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
|
|---|
| 1112 | pattern, 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]}]
|
|---|
| 1117 | Find the next match of @i[search-pattern] starting at @i[mark]. If a
|
|---|
| 1118 | match is found then @i[mark] is altered to point before the matched text
|
|---|
| 1119 | and the number of characters matched is returned. If no match is
|
|---|
| 1120 | found 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]}]
|
|---|
| 1125 | Replace @i[n] matches of @i[search-pattern] with the string
|
|---|
| 1126 | @i[replacement] starting at @i[mark]. If @i[n] is @nil (the default)
|
|---|
| 1127 | then replace all matches. A mark pointing before the last replacement
|
|---|
| 1128 | done 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
|
|---|
| 1141 | depend on the @funref(current-buffer) and the modes
|
|---|
| 1142 | active 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
|
|---|
| 1146 | to is the @f[current-buffer].
|
|---|
| 1147 |
|
|---|
| 1148 | @i[mode local]@\The value is present only when the mode it is local to
|
|---|
| 1149 | is active in the @f[current-buffer].
|
|---|
| 1150 |
|
|---|
| 1151 | @i[global]@\The value is always present unless shadowed by a buffer or
|
|---|
| 1152 | mode local value.
|
|---|
| 1153 | @end(description)
|
|---|
| 1154 |
|
|---|
| 1155 |
|
|---|
| 1156 | @section(Shadowing)
|
|---|
| 1157 | It is possible for there to be a conflict between different values
|
|---|
| 1158 | for the same thing in different scopes. For example, there be might a
|
|---|
| 1159 | global binding for a given variable and also a local binding in the
|
|---|
| 1160 | current buffer. Whenever there is a conflict shadowing occurs,
|
|---|
| 1161 | permitting only one of the values to be visible in the current
|
|---|
| 1162 | environment.
|
|---|
| 1163 |
|
|---|
| 1164 | The process of resolving such a conflict can be described as a
|
|---|
| 1165 | search down a list of places where the value might be defined, returning
|
|---|
| 1166 | the first value found. The order for the search is as follows:
|
|---|
| 1167 | @begin(enumerate)
|
|---|
| 1168 | Local values in the current buffer.
|
|---|
| 1169 |
|
|---|
| 1170 | Mode local values in the minor modes of the current buffer, in order
|
|---|
| 1171 | from the highest precedence mode to the lowest precedence mode. The
|
|---|
| 1172 | order of minor modes with equal precedences is undefined.
|
|---|
| 1173 |
|
|---|
| 1174 | Mode local values in the current buffer's major mode.
|
|---|
| 1175 |
|
|---|
| 1176 | Global 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
|
|---|
| 1185 | for the following reasons:
|
|---|
| 1186 | @begin(enumerate)
|
|---|
| 1187 | @hemlock has different scoping rules which are useful in an editor. @hemlock
|
|---|
| 1188 | variables 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
|
|---|
| 1192 | called when someone sets the variable. See @f[variable-value] for the
|
|---|
| 1193 | arguments @hemlock passes to these hook functions.
|
|---|
| 1194 |
|
|---|
| 1195 | There is a database of variable names and documentation which makes it easier
|
|---|
| 1196 | to find out what variables exist and what their values mean.
|
|---|
| 1197 | @end(enumerate)
|
|---|
| 1198 |
|
|---|
| 1199 |
|
|---|
| 1200 | @section(Variable Names)
|
|---|
| 1201 | To the user, a variable name is a case insensitive string. This
|
|---|
| 1202 | string is referred to as the @i[string name] of the variable. A
|
|---|
| 1203 | string name is conventionally composed of words separated by spaces.
|
|---|
| 1204 |
|
|---|
| 1205 | In Lisp code a variable name is a symbol. The name of this symbol is
|
|---|
| 1206 | created by replacing any spaces in the string name with hyphens. This
|
|---|
| 1207 | symbol name is always interned in the @hemlock package and referring
|
|---|
| 1208 | to a symbol with the same name in the wrong package is an error.
|
|---|
| 1209 |
|
|---|
| 1210 | @defvar[var {global-variable-names}]
|
|---|
| 1211 | This variable holds a string-table of the names of all the global @hemlock
|
|---|
| 1212 | variables. The value of each entry is the symbol name of the variable.
|
|---|
| 1213 | @enddefvar
|
|---|
| 1214 |
|
|---|
| 1215 | @defun[fun {current-variable-tables}]
|
|---|
| 1216 | This function returns a list of variable tables currently established,
|
|---|
| 1217 | globally, 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)
|
|---|
| 1224 | In 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
|
|---|
| 1229 | name 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]
|
|---|
| 1239 | is 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
|
|---|
| 1246 | value. 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)
|
|---|
| 1249 | If 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
|
|---|
| 1251 | supplies these keywords.
|
|---|
| 1252 | @enddefun
|
|---|
| 1253 |
|
|---|
| 1254 | @defun[fun {variable-value}, args {@i[name] @optional @i[kind] @i[where]}]
|
|---|
| 1255 | This function returns the value of a @hemlock variable in some place.
|
|---|
| 1256 | The 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
|
|---|
| 1260 | any 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]
|
|---|
| 1271 | When set with @f[setf], @hemlock sets the value of the specified variable and
|
|---|
| 1272 | invokes the functions in its hook list with @i[name], @i[kind], @i[where], and
|
|---|
| 1273 | the 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]}]
|
|---|
| 1282 | These function return the documentation, hooks and string name of a
|
|---|
| 1283 | @hemlock variable. The @i[kind] and @i[where] arguments are the same
|
|---|
| 1284 | as for @f[variable-value]. The documentation and hook list may be set
|
|---|
| 1285 | using @f[setf].
|
|---|
| 1286 | @enddefun
|
|---|
| 1287 |
|
|---|
| 1288 | @defun[fun {string-to-variable}, args {@i[string]}]
|
|---|
| 1289 | This function converts a string into the corresponding variable symbol
|
|---|
| 1290 | name. @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]}]
|
|---|
| 1295 | These 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]>}]
|
|---|
| 1301 | This macro is very similar to @f[let] in effect; within its scope each
|
|---|
| 1302 | of the @hemlock variables @i[var] have the respective @i[value]s, but
|
|---|
| 1303 | after the scope is exited by any means the binding is removed. This
|
|---|
| 1304 | does 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]}]
|
|---|
| 1309 | Returns @true if @i[name] is defined as a @hemlock variable in the
|
|---|
| 1310 | place 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
|
|---|
| 1316 | defined in the specified place. @i[Kind] and @i[where] have the same
|
|---|
| 1317 | meanings as they do for @f[variable-value], except that @kwd[current]
|
|---|
| 1318 | is not available, and the default for @i[kind] is @kwd[global]
|
|---|
| 1319 |
|
|---|
| 1320 | An error will be signaled if no such variable exists. The hook,
|
|---|
| 1321 | @hid[Delete Variable Hook] is invoked with the same arguments before the
|
|---|
| 1322 | variable 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,
|
|---|
| 1330 | turning modes on and off, etc., often have hooks associated with them. A hook
|
|---|
| 1331 | is a list of functions called before the system performs the action. The
|
|---|
| 1332 | manual describes the object specific hooks with the rest of the operations
|
|---|
| 1333 | defined on these objects.
|
|---|
| 1334 |
|
|---|
| 1335 | Often 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
|
|---|
| 1337 | because these variables have hooks that the system executes when someone
|
|---|
| 1338 | changes their values. These hook functions @hemlock invokes when someone sets
|
|---|
| 1339 | a variable are an example of a hook stored in an object instead of a @hemlock
|
|---|
| 1340 | variable. These are all hooks for editor activity, but @hemlock keeps them in
|
|---|
| 1341 | different kinds of locations. This is why some of the routines in this section
|
|---|
| 1342 | have 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]}]
|
|---|
| 1346 | These macros add or remove a hook function in some @i[place]. If @i[hook-fun]
|
|---|
| 1347 | already exists in @i[place], this call has no effect. If @i[place] is a
|
|---|
| 1348 | symbol, then it is a @hemlock variable; otherwise, it is a generalized variable
|
|---|
| 1349 | or 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]}]
|
|---|
| 1359 | This macro calls all the functions in @i[place]. If @i[place] is a symbol,
|
|---|
| 1360 | then 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)
|
|---|
| 1371 | The 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
|
|---|
| 1375 | names 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
|
|---|
| 1379 | on-line help facilities.
|
|---|
| 1380 |
|
|---|
| 1381 | @i[function]@\A command is implemented by a Lisp function, which is callable
|
|---|
| 1382 | from Lisp.
|
|---|
| 1383 | @end(description)
|
|---|
| 1384 |
|
|---|
| 1385 | @defvar[var {command-names}]
|
|---|
| 1386 | Holds a string-table (page @pageref[string-tables]) associating
|
|---|
| 1387 | command names to command objects. Whenever a new command is defined
|
|---|
| 1388 | it 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 |
|
|---|
| 1398 | Defines a command named @i[name]. @f[defcommand] creates a function to
|
|---|
| 1399 | implement 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]
|
|---|
| 1403 | creates the command name by replacing all spaces with hyphens and appending
|
|---|
| 1404 | "@f[-command]". @i[Function-doc] becomes the documentation for the function
|
|---|
| 1405 | and should primarily describe issues involved in calling the command as a
|
|---|
| 1406 | function, such as what any additional arguments are. @i[Command-doc] becomes
|
|---|
| 1407 | the command documentation for the command. @enddefmac
|
|---|
| 1408 |
|
|---|
| 1409 | @defun[fun {make-command}, args
|
|---|
| 1410 | {@i[name] @i[documentation] @i[function]}]
|
|---|
| 1411 | Defines a new command named @i[name], with command documentation
|
|---|
| 1412 | @I[documentation] and function @i[function]. The command in entered
|
|---|
| 1413 | in the string-table @varref[command-names], with the command object as
|
|---|
| 1414 | its value. Normally command implementors will use the @f[defcommand]
|
|---|
| 1415 | macro, but this permits access to the command definition mechanism at
|
|---|
| 1416 | a lower level, which is occasionally useful.
|
|---|
| 1417 | @enddefun
|
|---|
| 1418 |
|
|---|
| 1419 | @defun[fun {commandp}, args {@i[command]}]
|
|---|
| 1420 | Returns @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]}]
|
|---|
| 1426 | Returns the documentation, function, or name for @i[command]. These
|
|---|
| 1427 | may 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
|
|---|
| 1433 | when it is invoked as an extended command or from a key. Command
|
|---|
| 1434 | documentation may be either a string or a function. If the
|
|---|
| 1435 | documentation is a string then the first line should briefly summarize
|
|---|
| 1436 | the 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 |
|
|---|
| 1446 | Command documentation may also be a function of one argument. The
|
|---|
| 1447 | function is called with either @kwd[short] or @kwd[full], indicating
|
|---|
| 1448 | that the function should return a short documentation string or do
|
|---|
| 1449 | something 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 |
|
|---|
| 1457 | The @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
|
|---|
| 1459 | on the basis of what the user types. When the command interpreter executes a
|
|---|
| 1460 | command, we say it @i[invokes] the command. The command interpreter also
|
|---|
| 1461 | provides facilities for communication between commands contiguously running
|
|---|
| 1462 | commands, such as a last command type register. It also takes care of
|
|---|
| 1463 | resetting communication mechanisms, clearing the echo area, displaying partial
|
|---|
| 1464 | keys typed slowly by the user, etc.
|
|---|
| 1465 |
|
|---|
| 1466 | @defvar[var {invoke-hook}]
|
|---|
| 1467 | This variable contains a function the command interpreter calls when it wants
|
|---|
| 1468 | to invoke a command. The function receives the command and the prefix argument
|
|---|
| 1469 | as 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
|
|---|
| 1471 | useful for implementing keyboard macros and similar things.
|
|---|
| 1472 | @enddefhvar
|
|---|
| 1473 |
|
|---|
| 1474 | @defhvar[var "Command Abort Hook"]
|
|---|
| 1475 | The command interpreter invokes the function in this variable whenever someone
|
|---|
| 1476 | aborts a command (for example, if someone called @f[editor-error]).
|
|---|
| 1477 | @enddefhvar
|
|---|
| 1478 |
|
|---|
| 1479 | When @hemlock initially starts the command interpreter is in control, but
|
|---|
| 1480 | commands may read from the keyboard themselves and assign whatever
|
|---|
| 1481 | interpretation they will to the key-events read. Commands may call the command
|
|---|
| 1482 | interpreter recursively using the function @funref[recursive-edit].
|
|---|
| 1483 |
|
|---|
| 1484 |
|
|---|
| 1485 | @subsection(Editor Input)
|
|---|
| 1486 | @label[key-events-intro]
|
|---|
| 1487 | @index[key-events]
|
|---|
| 1488 |
|
|---|
| 1489 | The canonical representation of editor input is a key-event structure. Users
|
|---|
| 1490 | can bind commands to keys (see section @ref[key-bindings]), which are non-zero
|
|---|
| 1491 | length sequences of key-events. A key-event consists of an identifying token
|
|---|
| 1492 | known as a @i[keysym] and a field of bits representing modifiers. Users define
|
|---|
| 1493 | keysyms, integers between 0 and 65535 inclusively, by supplying names that
|
|---|
| 1494 | reflect the legends on their keyboard's keys. Users define modifier names
|
|---|
| 1495 | similarly, but the system chooses the bit and mask for recognizing the
|
|---|
| 1496 | modifier. You can use keysym and modifier names to textually specify
|
|---|
| 1497 | key-events and Hemlock keys in a @f[#k] syntax. The following are some
|
|---|
| 1498 | examples:
|
|---|
| 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]
|
|---|
| 1508 | This is convenient for use within code and in init files containing
|
|---|
| 1509 | @f[bind-key] calls.
|
|---|
| 1510 |
|
|---|
| 1511 | The @f[#k] syntax is delimited by double quotes, but the system parses the
|
|---|
| 1512 | contents rather than reading it as a Common Lisp string. Within the double
|
|---|
| 1513 | quotes, spaces separate multiple key-events. A single key-event optionally
|
|---|
| 1514 | starts with modifier names terminated by hyphens. Modifier names are
|
|---|
| 1515 | alphabetic sequences of characters which the system uses case-insensitively.
|
|---|
| 1516 | Following modifiers is a keysym name, which is case-insensitive if it consists
|
|---|
| 1517 | of multiple characters, but if the name consists of only a single character,
|
|---|
| 1518 | then it is case-sensitive.
|
|---|
| 1519 |
|
|---|
| 1520 | You can escape special characters @dash hyphen, double quote, open angle
|
|---|
| 1521 | bracket, close angle bracket, and space @dash with a backslash, and you can
|
|---|
| 1522 | specify a backslash by using two contiguously. You can use angle brackets to
|
|---|
| 1523 | enclose a keysym name with many special characters in it. Between angle
|
|---|
| 1524 | brackets appearing in a keysym name position, there are only two special
|
|---|
| 1525 | characters, the closing angle bracket and backslash.
|
|---|
| 1526 |
|
|---|
| 1527 | For 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 |
|
|---|
| 1535 | The 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
|
|---|
| 1537 | sequence of key-events (see section @ref[key-events-intro]. A sequence of
|
|---|
| 1538 | key-events is called a @i[key] and is represented by a single key-event or a
|
|---|
| 1539 | sequence (list or vector) of key-events.
|
|---|
| 1540 |
|
|---|
| 1541 | Since 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
|
|---|
| 1543 | effect at any given time. When the command interpreter tries to find the
|
|---|
| 1544 | binding 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
|
|---|
| 1546 | modes and the major mode for the current buffer @w[(page @pageref[modes])], and
|
|---|
| 1547 | finally checks to see if there is a global binding. If no binding is found,
|
|---|
| 1548 | then 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
|
|---|
| 1554 | possible 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 |
|
|---|
| 1566 | This processes @i[key] for key translations before establishing the binding.
|
|---|
| 1567 | See section @ref[key-trans].
|
|---|
| 1568 |
|
|---|
| 1569 | If the key is some prefix of a key binding which already exists in the
|
|---|
| 1570 | specified place, then the new one will override the old one, effectively
|
|---|
| 1571 | deleting it.
|
|---|
| 1572 |
|
|---|
| 1573 | @f[ext:do-alpha-key-events] is useful for setting up bindings in certain new
|
|---|
| 1574 | modes.
|
|---|
| 1575 | @enddefun
|
|---|
| 1576 |
|
|---|
| 1577 | @defun[fun {command-bindings}, args {@i[command]}]
|
|---|
| 1578 | This function returns a list of the places where @i[command] is bound. A place
|
|---|
| 1579 | is specified as a list of the key (always a vector), the kind of binding, and
|
|---|
| 1580 | where (either the mode or buffer to which the binding is local, or @nil if it
|
|---|
| 1581 | is a global).
|
|---|
| 1582 | @enddefun
|
|---|
| 1583 |
|
|---|
| 1584 | @defun[fun {delete-key-binding}, args {@i[key] @optional @i[kind] @i[where]}]
|
|---|
| 1585 | This function removes the binding of @i[key] in some place. @i[Key] is either
|
|---|
| 1586 | a key-event or a sequence of key-events. @i[kind] is the kind of binding to
|
|---|
| 1587 | delete, 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 |
|
|---|
| 1591 | This function signals an error if @i[key] is unbound.
|
|---|
| 1592 |
|
|---|
| 1593 | This processes @i[key] for key translations before deleting the binding. See
|
|---|
| 1594 | section @ref[key-trans].
|
|---|
| 1595 | @enddefun
|
|---|
| 1596 |
|
|---|
| 1597 | @defun[fun {get-command}, args {@i[key] @optional @i[kind] @i[where]}]
|
|---|
| 1598 | This function returns the command bound to @i[key], returning @nil if it is
|
|---|
| 1599 | unbound. @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.
|
|---|
| 1605 | If there are any transparent key bindings for @i[key], then they are returned
|
|---|
| 1606 | in 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 |
|
|---|
| 1618 | This processes @i[key] for key translations before looking for any binding.
|
|---|
| 1619 | See section @ref[key-trans].
|
|---|
| 1620 | @enddefun
|
|---|
| 1621 |
|
|---|
| 1622 | @defun[fun {map-bindings}, Args {@i[function] @i[kind] @optional @i[where]}]
|
|---|
| 1623 | This function maps over the key bindings in some place. For each binding, this
|
|---|
| 1624 | passes @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
|
|---|
| 1626 | valid 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]
|
|---|
| 1635 | Key translation is a process that the command interpreter applies to keys
|
|---|
| 1636 | before doing anything else. There are two kinds of key translations:
|
|---|
| 1637 | substitution and bit-prefix. In either case, the command interpreter
|
|---|
| 1638 | translates a key when a specified key-event sequence appears in a key.
|
|---|
| 1639 |
|
|---|
| 1640 | In a substitution translation, the system replaces the matched subsequence with
|
|---|
| 1641 | another key-event sequence. Key translation is not recursively applied to the
|
|---|
| 1642 | substituted key-events.
|
|---|
| 1643 |
|
|---|
| 1644 | In a bit-prefix translation, the system removes the matched subsequence and
|
|---|
| 1645 | effectively sets the specified bits in the next key-event in the key.
|
|---|
| 1646 |
|
|---|
| 1647 | While translating a key, if the system encounters an incomplete final
|
|---|
| 1648 | subsequence of key-events, it aborts the translation process. This happens
|
|---|
| 1649 | when those last key-events form a prefix of some translation. It also happens
|
|---|
| 1650 | when they translate to a bit-prefix, but there is no following key-event to
|
|---|
| 1651 | which the system can apply the indicated modifier. If there is a binding for
|
|---|
| 1652 | this partially untranslated key, then the command interpreter will invoke that
|
|---|
| 1653 | command; otherwise, it will wait for the user to type more key-events.
|
|---|
| 1654 |
|
|---|
| 1655 | @defun[fun {key-translation}, args {@i[key]}]
|
|---|
| 1656 | This form is @f[setf]'able and allows users to register key translations that
|
|---|
| 1657 | the command interpreter will use as users type key-events.
|
|---|
| 1658 |
|
|---|
| 1659 | This function returns the key translation for @i[key], returning @nil if there
|
|---|
| 1660 | is 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 |
|
|---|
| 1663 | A key translation is either a key or modifier specification. The bits
|
|---|
| 1664 | translations have a list form: @w<@f[(:bits {]@i[bit-name]@f[}*)]>.
|
|---|
| 1665 |
|
|---|
| 1666 | Whenever @i[key] appears as a subsequence of a key argument to the binding
|
|---|
| 1667 | manipulation 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 |
|
|---|
| 1676 | Key bindings local to a mode may be @i[transparent]. A transparent key
|
|---|
| 1677 | binding does not shadow less local key bindings, but rather indicates that
|
|---|
| 1678 | the bound command should be invoked before the first normal key binding.
|
|---|
| 1679 | Transparent key bindings are primarily useful for implementing minor modes
|
|---|
| 1680 | such as auto fill and word abbreviation. There may be several transparent
|
|---|
| 1681 | key bindings for a given key, in which case all of the commands bound are
|
|---|
| 1682 | invoked in the order they were found. If there no normal key binding for a
|
|---|
| 1683 | key typed, then the command interpreter acts as though the key is unbound
|
|---|
| 1684 | even if there are transparent key bindings.
|
|---|
| 1685 |
|
|---|
| 1686 | The @kwd[transparent-p] argument to @funref[defmode] determines whether the
|
|---|
| 1687 | key 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
|
|---|
| 1694 | records his actions, and when the user exits this mode, the command @hid[Last
|
|---|
| 1695 | Keyboard Macro] plays back the actions. Some commands behave differently when
|
|---|
| 1696 | invoked as part of the definition of a keyboard macro. For example, when used
|
|---|
| 1697 | in a keyboard macro, a command that @f[message]'s useless user confirmation
|
|---|
| 1698 | will slow down the repeated invocations of @hid[Last Keyboard Macro] because
|
|---|
| 1699 | the command will pause on each execution to make sure the user sees the
|
|---|
| 1700 | message. This can be eliminated with the use of @f[interactive]. As another
|
|---|
| 1701 | example, some commands conditionally signal an editor-error versus simply
|
|---|
| 1702 | beeping the device depending on whether it executes on behalf of the user or a
|
|---|
| 1703 | keyboard macro.
|
|---|
| 1704 |
|
|---|
| 1705 | @defun[fun {interactive}]
|
|---|
| 1706 | This 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)
|
|---|
| 1713 | In many editors the behavior of a command depends on the kind of command
|
|---|
| 1714 | invoked before it. @hemlock provides a mechanism to support this known as
|
|---|
| 1715 | @i(command type).
|
|---|
| 1716 |
|
|---|
| 1717 | @defun[fun {last-command-type}]
|
|---|
| 1718 | This 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
|
|---|
| 1720 | the 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
|
|---|
| 1722 | keyword. The command type is not cleared after a command is invoked due to a
|
|---|
| 1723 | transparent key binding.
|
|---|
| 1724 | @enddefun
|
|---|
| 1725 |
|
|---|
| 1726 |
|
|---|
| 1727 | @section(Command Arguments)
|
|---|
| 1728 | @label[invoking-commands-as-functions]
|
|---|
| 1729 | There are three ways in which a command may be invoked: It may be bound to a
|
|---|
| 1730 | key which has been typed, it may be invoked as an extended command, or it may
|
|---|
| 1731 | be called as a Lisp function. Ideally commands should be written in such a way
|
|---|
| 1732 | that they will behave sensibly no matter which way they are invoked. The
|
|---|
| 1733 | functions which implement commands must obey certain conventions about argument
|
|---|
| 1734 | passing if the command is to function properly.
|
|---|
| 1735 |
|
|---|
| 1736 |
|
|---|
| 1737 | @subsection(The Prefix Argument)
|
|---|
| 1738 | @index(Prefix arguments)
|
|---|
| 1739 | Whenever a command is invoked it is passed as its first argument what
|
|---|
| 1740 | is known as the @i[prefix argument]. The prefix argument is always
|
|---|
| 1741 | either an integer or @nil. When a command uses this value it is
|
|---|
| 1742 | usually as a repeat count, or some conceptually similar function.
|
|---|
| 1743 |
|
|---|
| 1744 | @defun[fun {prefix-argument}]
|
|---|
| 1745 | This function returns the current value of the prefix argument. When
|
|---|
| 1746 | set with @f[setf], the new value becomes the prefix argument for the
|
|---|
| 1747 | next command.
|
|---|
| 1748 | @enddefun
|
|---|
| 1749 |
|
|---|
| 1750 | If the prefix argument is not set by the previous command then the
|
|---|
| 1751 | prefix argument for a command is @nil. The prefix argument is not cleared
|
|---|
| 1752 | after a command is invoked due to a transparent key binding.
|
|---|
| 1753 |
|
|---|
| 1754 |
|
|---|
| 1755 | @subsection(Lisp Arguments)
|
|---|
| 1756 | It is often desirable to call commands from Lisp code, in which case
|
|---|
| 1757 | arguments which would otherwise be prompted for are passed as optional
|
|---|
| 1758 | arguments following the prefix argument. A command should prompt for
|
|---|
| 1759 | any arguments not supplied.
|
|---|
| 1760 |
|
|---|
| 1761 |
|
|---|
| 1762 | @section(Recursive Edits)
|
|---|
| 1763 | @index(Recursive edits)
|
|---|
| 1764 | @defmac[fun {use-buffer}, args {@i[buffer] @mstar<@i[form]>}]
|
|---|
| 1765 | The effect of this is similar to setting the current-buffer to @i[buffer]
|
|---|
| 1766 | during the evaluation of @i[forms]. There are restrictions placed on what the
|
|---|
| 1767 | code can expect about its environment. In particular, the value of any global
|
|---|
| 1768 | binding of a @hemlock variable which is also a mode local variable of some mode
|
|---|
| 1769 | is ill-defined; if the variable has a global binding it will be bound, but the
|
|---|
| 1770 | value 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
|
|---|
| 1772 | that 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
|
|---|
| 1780 | will read from the keyboard and invoke commands until it is terminated with
|
|---|
| 1781 | either @f[exit-recursive-edit] or @f[abort-recursive-edit].
|
|---|
| 1782 |
|
|---|
| 1783 | Normally, an editor-error or @bf[C-g] aborts the command in progress and
|
|---|
| 1784 | returns control to the top-level command loop. If @f[recursive-edit] is used
|
|---|
| 1785 | with @i[handle-abort] true, then @f[editor-error] or @bf[C-g] will only abort
|
|---|
| 1786 | back to the recursive command loop.
|
|---|
| 1787 |
|
|---|
| 1788 | Before the command interpreter is entered the hook
|
|---|
| 1789 | @hid[Enter Recursive Edit Hook] is invoked.
|
|---|
| 1790 | @enddefun
|
|---|
| 1791 |
|
|---|
| 1792 | @defun[fun {in-recursive-edit}]
|
|---|
| 1793 | This returns whether the calling point is dynamically within a recursive edit
|
|---|
| 1794 | context.
|
|---|
| 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
|
|---|
| 1800 | each element of @i[values-list], which defaults to @nil. This invokes
|
|---|
| 1801 | @hid[Exit Recursive Edit Hook] after exiting the command interpreter. If no
|
|---|
| 1802 | recursive 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
|
|---|
| 1809 | invokes @hid[Abort Recursive Edit Hook] with @i[args] before aborting the
|
|---|
| 1810 | recursive edit . If no recursive edit is in progress, then this signals an
|
|---|
| 1811 | error.
|
|---|
| 1812 | @enddefun
|
|---|
| 1813 |
|
|---|
| 1814 |
|
|---|
| 1815 |
|
|---|
| 1816 | @Chapter(Modes)
|
|---|
| 1817 | @label[modes]
|
|---|
| 1818 | @index (Modes)
|
|---|
| 1819 | A mode is a collection of @hemlock values which may be present in the current
|
|---|
| 1820 | environment @w<(page @pageref(current-environment))> depending on the editing
|
|---|
| 1821 | task at hand. Examples of typical modes are @hid[Lisp], for editing Lisp code,
|
|---|
| 1822 | and @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]
|
|---|
| 1827 | is invoked. The hook functions take two arguments, the buffer
|
|---|
| 1828 | involved and @true if the mode is being added or @nil if it is being
|
|---|
| 1829 | removed.
|
|---|
| 1830 |
|
|---|
| 1831 | Mode hooks are typically used to make a mode do something additional to
|
|---|
| 1832 | what it usually does. One might, for example, make a text mode hook
|
|---|
| 1833 | that turned on auto-fill mode when you entered.
|
|---|
| 1834 |
|
|---|
| 1835 |
|
|---|
| 1836 | @section(Major and Minor Modes)
|
|---|
| 1837 | There are two kinds of modes, @i[major] modes and @i[minor] modes. A buffer
|
|---|
| 1838 | always has exactly one major mode, but it may have any number of minor modes.
|
|---|
| 1839 | Major modes may have mode character attributes while minor modes may not.
|
|---|
| 1840 |
|
|---|
| 1841 | A major mode is usually used to change the environment in some major way, such
|
|---|
| 1842 | as to install special commands for editing some language. Minor modes
|
|---|
| 1843 | generally change some small attribute of the environment, such as whether lines
|
|---|
| 1844 | are automatically broken when they get too long. A minor mode should work
|
|---|
| 1845 | regardless of what major mode and minor modes are in effect.
|
|---|
| 1846 |
|
|---|
| 1847 | @defhvar[var {Default Modes}, val {("Fundamental" "Save")}]
|
|---|
| 1848 | This variable contains a list of mode names which are instantiated in a
|
|---|
| 1849 | buffer when no other information is available.
|
|---|
| 1850 | @enddefhvar
|
|---|
| 1851 |
|
|---|
| 1852 | @defvar[var {mode-names}]
|
|---|
| 1853 | Holds a string-table of the names of all the modes.
|
|---|
| 1854 | @enddefvar
|
|---|
| 1855 |
|
|---|
| 1856 | @defcom[com "Illegal"]
|
|---|
| 1857 | This is a useful command to bind in modes that wish to shadow global bindings
|
|---|
| 1858 | by making them effectively illegal. Also, although less likely, minor modes
|
|---|
| 1859 | may 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]}]
|
|---|
| 1868 | This 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
|
|---|
| 1870 | then 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
|
|---|
| 1873 | invoked with the buffer affected, after the mode is turned on, and
|
|---|
| 1874 | before it is turned off, respectively. These functions typically are
|
|---|
| 1875 | used to make buffer-local key or variable bindings and to remove them
|
|---|
| 1876 | when the mode is turned off.
|
|---|
| 1877 |
|
|---|
| 1878 | @i[Precedence] is only meaningful for a minor mode. The precedence of a
|
|---|
| 1879 | minor mode determines the order in which it in a buffer's list of modes.
|
|---|
| 1880 | When searching for values in the current environment, minor modes are
|
|---|
| 1881 | searched in order, so the precedence of a minor mode determines which value
|
|---|
| 1882 | is found when there are several definitions.
|
|---|
| 1883 |
|
|---|
| 1884 | @i[Transparent-p] determines whether key bindings local to the defined mode
|
|---|
| 1885 | are transparent. Transparent key bindings are invoked in addition to the
|
|---|
| 1886 | first 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]}]
|
|---|
| 1893 | This 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.
|
|---|
| 1899 | The 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
|
|---|
| 1907 | in @i[buffer], @nil otherwise. A minor mode may be turned on or off
|
|---|
| 1908 | by using @f[setf]; then @hid[Buffer Minor Mode Hook] is
|
|---|
| 1909 | invoked with @i[buffer], @i[name] and the new value.
|
|---|
| 1910 | @enddefun
|
|---|
| 1911 |
|
|---|
| 1912 | @defun[fun {mode-variables}, args {@i[name]}]
|
|---|
| 1913 | Returns the string-table of mode local variables.
|
|---|
| 1914 | @enddefun
|
|---|
| 1915 |
|
|---|
| 1916 | @defun[fun {mode-major-p}, args {@i[name]}]
|
|---|
| 1917 | Returns @true if @i[name] is the name of a major mode, or @nil if
|
|---|
| 1918 | it is the name of a minor mode. It is an error for @i[name] not to be
|
|---|
| 1919 | the 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)
|
|---|
| 1930 | Character attributes provide a global database of information about characters.
|
|---|
| 1931 | This facility is similar to, but more general than, the @i[syntax tables] of
|
|---|
| 1932 | other editors such as @f[EMACS]. For example, you should use character
|
|---|
| 1933 | attributes for commands that need information regarding whether a character is
|
|---|
| 1934 | @i[whitespace] or not. Use character attributes for these reasons:
|
|---|
| 1935 | @begin(enumerate)
|
|---|
| 1936 | If this information is all in one place, then it is easy the change the
|
|---|
| 1937 | behavior of the editor by changing the syntax table, much easier than it would
|
|---|
| 1938 | be if character constants were wired into commands.
|
|---|
| 1939 |
|
|---|
| 1940 | This centralization of information avoids needless duplication of effort.
|
|---|
| 1941 |
|
|---|
| 1942 | The syntax table primitives are probably faster than anything that can be
|
|---|
| 1943 | written above the primitive level.
|
|---|
| 1944 | @end(enumerate)
|
|---|
| 1945 |
|
|---|
| 1946 | Note 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.]
|
|---|
| 1948 | Information about characters which is internal to some set of commands (and
|
|---|
| 1949 | which the user should not know about) should not be maintained as a character
|
|---|
| 1950 | attribute. For such uses various character searching abilities are provided by
|
|---|
| 1951 | the function @funref[find-pattern].
|
|---|
| 1952 |
|
|---|
| 1953 | @defcon[var {syntax-char-code-limit}]
|
|---|
| 1954 | The exclusive upper bound on character codes which are significant in
|
|---|
| 1955 | the character attribute functions. Font and bits are always ignored.
|
|---|
| 1956 | @enddefcon
|
|---|
| 1957 |
|
|---|
| 1958 |
|
|---|
| 1959 | @section(Character Attribute Names)
|
|---|
| 1960 |
|
|---|
| 1961 | As for @hemlock variables, character attributes have a user visible
|
|---|
| 1962 | string name, but are referred to in Lisp code as a symbol. The string
|
|---|
| 1963 | name, which is typically composed of capitalized words separated by
|
|---|
| 1964 | spaces, is translated into a keyword by replacing all spaces with
|
|---|
| 1965 | hyphens and interning this string in the keyword package. The
|
|---|
| 1966 | attribute named @hid[Ada Syntax] would thus become @kwd[ada-syntax].
|
|---|
| 1967 |
|
|---|
| 1968 | @defvar[var {character-attribute-names}]
|
|---|
| 1969 | Whenever a character attribute is defined, its name is entered in
|
|---|
| 1970 | this string table (page @pageref[string-tables]), with the
|
|---|
| 1971 | corresponding 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
|
|---|
| 1980 | simple-string. Character attribute operations take attribute arguments as a
|
|---|
| 1981 | keyword 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
|
|---|
| 1986 | the character attribute are. Values of a character attribute may be of any
|
|---|
| 1987 | type 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
|
|---|
| 1989 | attribute.
|
|---|
| 1990 | @enddefun
|
|---|
| 1991 |
|
|---|
| 1992 | @defun[fun {character-attribute-name}, args {@i[attribute]}]
|
|---|
| 1993 | @defun1[fun {character-attribute-documentation}, args {@i[attribute]}]
|
|---|
| 1994 | These 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].
|
|---|
| 2000 | This signals an error if @i[attribute] is undefined.
|
|---|
| 2001 |
|
|---|
| 2002 | @f[setf] will set a character's attributes. This @f[setf] method invokes the
|
|---|
| 2003 | functions in @hid[Character Attribute Hook] on the attribute and character
|
|---|
| 2004 | before it makes the change.
|
|---|
| 2005 |
|
|---|
| 2006 | If @i[character] is @nil, then the value of the attribute for the beginning or
|
|---|
| 2007 | end of the buffer can be accessed or set. The buffer beginning and end thus
|
|---|
| 2008 | become a sort of fictitious character, which simplifies the use of character
|
|---|
| 2009 | attributes in many cases.
|
|---|
| 2010 | @enddefun
|
|---|
| 2011 |
|
|---|
| 2012 | @defun[fun {character-attribute-p}, args {@i[symbol]}]
|
|---|
| 2013 | This 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}]
|
|---|
| 2020 | This 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
|
|---|
| 2022 | of a major mode. @hid[Shadow Attribute Hook] is invoked with the same
|
|---|
| 2023 | arguments when this function is called. If the value for an attribute is set
|
|---|
| 2024 | while the value is shadowed, then only the shadowed value is affected, not the
|
|---|
| 2025 | global one.
|
|---|
| 2026 | @enddefun
|
|---|
| 2027 |
|
|---|
| 2028 | @defun[fun {unshadow-attribute}, args {@i[attribute] @i[character] @i[mode]}]
|
|---|
| 2029 | @defhvar1[var {Unshadow Attribute Hook}]
|
|---|
| 2030 | Make 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
|
|---|
| 2032 | when 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
|
|---|
| 2040 | character attribute @i[attribute] starting at @i[mark]. They pass @i[Test] one
|
|---|
| 2041 | argument, the value of @i[attribute] for the character tested. If the test
|
|---|
| 2042 | succeeds, then these routines modify @i[mark] to point before (after for
|
|---|
| 2043 | @f[reverse-find-attribute]) the character which satisfied the test. If no
|
|---|
| 2044 | characters satisfy the test, then these return @nil, and @i[mark] remains
|
|---|
| 2045 | unmodified. @i[Test] defaults to @f[not zerop]. There is no guarantee that
|
|---|
| 2046 | the test is applied in any particular fashion, so it should have no side
|
|---|
| 2047 | effects and depend only on its argument.
|
|---|
| 2048 | @enddefun
|
|---|
| 2049 |
|
|---|
| 2050 |
|
|---|
| 2051 | @section(Character Attribute Hooks)
|
|---|
| 2052 |
|
|---|
| 2053 | It is often useful to use the character attribute mechanism as an abstract
|
|---|
| 2054 | interface to other information about characters which in fact is stored
|
|---|
| 2055 | elsewhere. For example, some implementation of @hemlock might decide to define
|
|---|
| 2056 | a @hid[Print Representation] attribute which controls how a character is
|
|---|
| 2057 | displayed on the screen.
|
|---|
| 2058 |
|
|---|
| 2059 | To make this easy to do, each attribute has a list of hook functions
|
|---|
| 2060 | which are invoked with the attribute, character and new value whenever
|
|---|
| 2061 | the current value changes for any reason.
|
|---|
| 2062 |
|
|---|
| 2063 | @defun[fun {character-attribute-hooks}, args {@i[attribute]}]
|
|---|
| 2064 | Return 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
|
|---|
| 2066 | be used to manipulate these lists.
|
|---|
| 2067 | @enddefun
|
|---|
| 2068 |
|
|---|
| 2069 |
|
|---|
| 2070 | @section (System Defined Character Attributes)
|
|---|
| 2071 | @label(sys-def-chars)
|
|---|
| 2072 | These are predefined in @hemlock:
|
|---|
| 2073 | @begin[description]
|
|---|
| 2074 | @hid[Whitespace]@\
|
|---|
| 2075 | A value of @f[1] indicates the character is whitespace.
|
|---|
| 2076 |
|
|---|
| 2077 | @hid[Word Delimiter]@\
|
|---|
| 2078 | A value of @f[1] indicates the character separates words (see section
|
|---|
| 2079 | @ref[text-functions]).
|
|---|
| 2080 |
|
|---|
| 2081 | @hid[Digit]@\
|
|---|
| 2082 | A value of @f[1] indicates the character is a base ten digit. This may be
|
|---|
| 2083 | shadowed in modes or buffers to mean something else.
|
|---|
| 2084 |
|
|---|
| 2085 | @hid[Space]@\
|
|---|
| 2086 | This 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]@\
|
|---|
| 2090 | A value of @f[1] indicates these characters terminate sentences (see section
|
|---|
| 2091 | @ref[text-functions]).
|
|---|
| 2092 |
|
|---|
| 2093 | @hid[Sentence Closing Char]@\
|
|---|
| 2094 | A value of @f[1] indicates these delimiting characters, such as @binding["]
|
|---|
| 2095 | or @binding[)], may follow a @hid[Sentence Terminator] (see section
|
|---|
| 2096 | @ref[text-functions]).
|
|---|
| 2097 |
|
|---|
| 2098 | @hid[Paragraph Delimiter]@\
|
|---|
| 2099 | A value of @f[1] indicates these characters delimit paragraphs when they begin
|
|---|
| 2100 | a line (see section @ref[text-functions]).
|
|---|
| 2101 |
|
|---|
| 2102 | @hid[Page Delimiter]@\
|
|---|
| 2103 | A 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]@\
|
|---|
| 2107 | This 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]@\
|
|---|
| 2126 | This 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
|
|---|
| 2141 | for 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
|
|---|
| 2150 | line, @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 |
|
|---|
| 2166 | A window is a mechanism for displaying part of a buffer on some physical
|
|---|
| 2167 | device. A window is a way to view a buffer but is not synonymous with one; a
|
|---|
| 2168 | buffer 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
|
|---|
| 2170 | indicate 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
|
|---|
| 2178 | displayed. The cursor always tracks the buffer-point of the corresponding
|
|---|
| 2179 | buffer. If the point is moved to a position which would be off the screen the
|
|---|
| 2180 | recentering process is invoked. Recentering shifts the starting point of the
|
|---|
| 2181 | window so that the point is once again displayed. The current window may be
|
|---|
| 2182 | changed with @f[setf]. Before the current window is changed, the hook @hid[Set
|
|---|
| 2183 | Window Hook] is invoked with the new value.
|
|---|
| 2184 | @enddefun
|
|---|
| 2185 |
|
|---|
| 2186 | @defvar[var {window-list}]
|
|---|
| 2187 | Holds 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
|
|---|
| 2205 | must point into a buffer. If it could not make a window on the device, it
|
|---|
| 2206 | returns 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.
|
|---|
| 2212 | The device may not support this argument. @i[Window] becomes the parent window
|
|---|
| 2213 | for a new group of windows that behave in a stack orientation as windows do on
|
|---|
| 2214 | the terminal.
|
|---|
| 2215 |
|
|---|
| 2216 | If @i[ask-user] is non-@nil, @hemlock prompts the user for the missing
|
|---|
| 2217 | dimensions (@i[x], @i[y], @i[width], and @i[height]) to make a new group of
|
|---|
| 2218 | windows, as with the @i[window] argument. The device may not support this
|
|---|
| 2219 | argument. 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
|
|---|
| 2221 | units. @hid[Default Window Width] and @hid[Default Window Height] are the
|
|---|
| 2222 | default values for the @i[width] and @i[height] arguments.
|
|---|
| 2223 |
|
|---|
| 2224 | @i[Proportion] determines what proportion of the @f[current-window]'s height
|
|---|
| 2225 | the new window will use. The @f[current-window] retains whatever space left
|
|---|
| 2226 | after accommodating the new one. The default is to split the window in half.
|
|---|
| 2227 |
|
|---|
| 2228 | This invokes @hid[Make Window Hook] with the new window.
|
|---|
| 2229 | @enddefun
|
|---|
| 2230 |
|
|---|
| 2231 | @defun[fun {windowp}, args {@i[window]}]
|
|---|
| 2232 | This 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
|
|---|
| 2239 | Hook] 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
|
|---|
| 2245 | text. 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
|
|---|
| 2247 | new 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
|
|---|
| 2253 | character displayed in @i[window]. Note that if @i[window] is the current
|
|---|
| 2254 | window, then moving the start may not prove much, since recentering may move it
|
|---|
| 2255 | back to approximately where it was originally.
|
|---|
| 2256 |
|
|---|
| 2257 | @f[window-display-end] is similar, but points after the last character
|
|---|
| 2258 | displayed. Moving the end is meaningless, since redisplay always moves it to
|
|---|
| 2259 | after the last character.
|
|---|
| 2260 | @enddefun
|
|---|
| 2261 |
|
|---|
| 2262 | @defun[fun {window-display-recentering}, args {@i[window]}]
|
|---|
| 2263 | This 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
|
|---|
| 2265 | changing @i[window]'s buffer sets this to @nil via @hid[Window Buffer Hook].
|
|---|
| 2266 | @enddefun
|
|---|
| 2267 |
|
|---|
| 2268 | @defun[fun {window-point}, args {@i[window]}]
|
|---|
| 2269 | This function returns as a mark the position in the buffer where the cursor is
|
|---|
| 2270 | displayed. This may be set with @f[setf]. If @i[window] is the current
|
|---|
| 2271 | window, then setting the point will have little effect; it is forced to track
|
|---|
| 2272 | the buffer point. When the window is not current, the window point is the
|
|---|
| 2273 | position that the buffer point will be moved to when the window becomes
|
|---|
| 2274 | current.
|
|---|
| 2275 | @enddefun
|
|---|
| 2276 |
|
|---|
| 2277 | @defun[fun {center-window}, args {@i[window] @i[mark]}]
|
|---|
| 2278 | This function attempts to adjust window's display start so the that @i[mark] is
|
|---|
| 2279 | vertically centered within the window.
|
|---|
| 2280 | @enddefun
|
|---|
| 2281 |
|
|---|
| 2282 | @defun[fun {scroll-window}, args {@i[window] @i[n]}]
|
|---|
| 2283 | This function scrolls the window down @i[n] display lines; if @i[n] is negative
|
|---|
| 2284 | scroll up. Leave the cursor at the same text position unless we scroll it off
|
|---|
| 2285 | the screen, in which case the cursor is moved to the end of the window closest
|
|---|
| 2286 | to its old position.
|
|---|
| 2287 | @enddefun
|
|---|
| 2288 |
|
|---|
| 2289 | @defun[fun {displayed-p}, args {@i[mark] @i[window]}]
|
|---|
| 2290 | Returns @true if either the character before or the character after @i[mark]
|
|---|
| 2291 | is 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]}]
|
|---|
| 2296 | Height or width of the area of the window used for displaying the
|
|---|
| 2297 | buffer, 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]}]
|
|---|
| 2303 | Return the next or previous window of @i[window]. The exact meaning of next
|
|---|
| 2304 | and previous depends on the device displaying the window. It should be
|
|---|
| 2305 | possible to cycle through all the windows displayed on a device using either
|
|---|
| 2306 | next or previous (implying that these functions wrap around.)
|
|---|
| 2307 | @enddefun
|
|---|
| 2308 |
|
|---|
| 2309 |
|
|---|
| 2310 | @section(Cursor Positions)
|
|---|
| 2311 | @index(Cursor positions)
|
|---|
| 2312 | A cursor position is an absolute position within a window's coordinate
|
|---|
| 2313 | system. The origin is in the upper-left-hand corner and the unit
|
|---|
| 2314 | is character positions.
|
|---|
| 2315 |
|
|---|
| 2316 | @defun[fun {mark-to-cursorpos}, args {@i[mark] @i[window]}]
|
|---|
| 2317 | Returns 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
|
|---|
| 2319 | bounds displayed.
|
|---|
| 2320 | @enddefun
|
|---|
| 2321 |
|
|---|
| 2322 | @defun[fun {cursorpos-to-mark}, args {@i[X] @i[Y] @i[window]}]
|
|---|
| 2323 | Returns as a mark the text position which corresponds to the given
|
|---|
| 2324 | (@i[X], @i[Y]) position within window, or @nil if that
|
|---|
| 2325 | position does not correspond to any text within @i[window].
|
|---|
| 2326 | @enddefun
|
|---|
| 2327 |
|
|---|
| 2328 | @defun[fun {last-key-event-cursorpos}]
|
|---|
| 2329 | Interprets mouse input. It returns as multiple values the (@i[X], @i[Y])
|
|---|
| 2330 | position and the window where the pointing device was the last time some key
|
|---|
| 2331 | event happened. If the information is unavailable, this returns @nil.
|
|---|
| 2332 | @enddefun
|
|---|
| 2333 |
|
|---|
| 2334 | @defun[fun {mark-column}, args {@i[mark]}]
|
|---|
| 2335 | This function returns the @i[X] position at which @i[mark] would be displayed,
|
|---|
| 2336 | supposing its line was displayed on an infinitely wide screen. This takes into
|
|---|
| 2337 | consideration strange characters such as tabs.
|
|---|
| 2338 | @enddefun
|
|---|
| 2339 |
|
|---|
| 2340 | @defun[fun {move-to-column}, args {@i[mark] @i[column] @optional @i[line]}]
|
|---|
| 2341 | This function is analogous to @funref[move-to-position], except that
|
|---|
| 2342 | it moves @i[mark] to the position on @i[line] which corresponds to the
|
|---|
| 2343 | specified @i[column]. @i[Line] defaults to the line that @i[mark] is
|
|---|
| 2344 | currently on. If the line would not reach to the specified column,
|
|---|
| 2345 | then @nil is returned and @i[mark] is not modified. Note that since a
|
|---|
| 2346 | character may be displayed on more than one column on the screen,
|
|---|
| 2347 | several different values of @i[column] may cause @i[mark] to be moved
|
|---|
| 2348 | to the same position.
|
|---|
| 2349 | @enddefun
|
|---|
| 2350 |
|
|---|
| 2351 | @defun[fun {show-mark}, args {@i[mark] @i[window] @i[time]}]
|
|---|
| 2352 | This 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
|
|---|
| 2354 | if there is pending input. If @i[mark] is positioned outside the text
|
|---|
| 2355 | displayed by @i[window], then this returns @nil, otherwise @true.
|
|---|
| 2356 | @enddefun
|
|---|
| 2357 |
|
|---|
| 2358 |
|
|---|
| 2359 | @section(Redisplay)
|
|---|
| 2360 | Redisplay translates changes in the internal representation of text into
|
|---|
| 2361 | changes on the screen. Ideally this process finds the minimal transformation
|
|---|
| 2362 | to make the screen correspond to the text in order to maximize the speed of
|
|---|
| 2363 | redisplay.
|
|---|
| 2364 |
|
|---|
| 2365 | @defun[fun {redisplay}]
|
|---|
| 2366 | @defhvar1[var "Redisplay Hook"]
|
|---|
| 2367 | @f[redisplay] executes the redisplay process, and @hemlock typically invokes
|
|---|
| 2368 | this whenever it looks for input. The redisplay process frequently checks for
|
|---|
| 2369 | input, and if it detects any, it aborts. The return value is interpreted as
|
|---|
| 2370 | follows:
|
|---|
| 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 |
|
|---|
| 2379 | This function invokes the functions in @hid[Redisplay Hook] on the current
|
|---|
| 2380 | window after computing screen transformations but before executing them. After
|
|---|
| 2381 | invoking the hook, this recomputes the redisplay and then executes it on the
|
|---|
| 2382 | current window.
|
|---|
| 2383 |
|
|---|
| 2384 | For 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
|
|---|
| 2386 | after redisplay.
|
|---|
| 2387 | @enddefun
|
|---|
| 2388 |
|
|---|
| 2389 | @defun[fun {redisplay-all}]
|
|---|
| 2390 | This causes all editor windows to be completely redisplayed. For the current
|
|---|
| 2391 | window and any window with @f[window-display-recentering] set, this ensures the
|
|---|
| 2392 | buffer's point for the window's buffer is visible after redisplay. The return
|
|---|
| 2393 | values are the same as for redisplay, except that @false is never returned.
|
|---|
| 2394 | @enddefun
|
|---|
| 2395 |
|
|---|
| 2396 | @defun[fun {editor-finish-output}, args {@i[window]}]
|
|---|
| 2397 | This 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]
|
|---|
| 2409 | Some primitives such as @funref[prompt-for-key] and commands such as EMACS
|
|---|
| 2410 | query replace read key-events directly from the keyboard instead of using the
|
|---|
| 2411 | command interpreter. To encourage consistency between these commands and to
|
|---|
| 2412 | make them portable and easy to customize, there is a mechanism for defining
|
|---|
| 2413 | @i[logical key-events].
|
|---|
| 2414 |
|
|---|
| 2415 | A logical key-event is a keyword which stands for some set of key-events. The
|
|---|
| 2416 | system globally interprets these key-events as indicators a particular action.
|
|---|
| 2417 | For example, the @kwd[help] logical key-event represents the set of key-events
|
|---|
| 2418 | that request help in a given @hemlock implementation. This mapping is a
|
|---|
| 2419 | many-to-many mapping, not one-to-one, so a given logical key-event may have
|
|---|
| 2420 | multiple corresponding actual key-events. Also, any key-event may represent
|
|---|
| 2421 | different logical key-events.
|
|---|
| 2422 |
|
|---|
| 2423 |
|
|---|
| 2424 | @section[Logical Key-Event Functions]
|
|---|
| 2425 |
|
|---|
| 2426 | @defvar[var {logical-key-event-names}]
|
|---|
| 2427 | This variable holds a string-table mapping all logical key-event names to the
|
|---|
| 2428 | keyword 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
|
|---|
| 2433 | simple-string. Logical key-event operations take logical key-events arguments
|
|---|
| 2434 | as a keyword whose name is @i[string-name] uppercased with spaces replaced by
|
|---|
| 2435 | hyphens.
|
|---|
| 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]}]
|
|---|
| 2441 | This 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]}]
|
|---|
| 2447 | These 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]}]
|
|---|
| 2452 | This 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
|
|---|
| 2454 | as particular logical key-events. It is a error for @i[keyword] to be an
|
|---|
| 2455 | undefined logical key-event.
|
|---|
| 2456 | @enddefun
|
|---|
| 2457 |
|
|---|
| 2458 |
|
|---|
| 2459 | @section[System Defined Logical Key-Events]
|
|---|
| 2460 | There are many default logical key-events, some of which are used by functions
|
|---|
| 2461 | documented in this manual. If a command wants to read a single key-event
|
|---|
| 2462 | command that fits one of these descriptions then the key-event read should be
|
|---|
| 2463 | compared to the corresponding logical key-event instead of explicitly
|
|---|
| 2464 | mentioning 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
|
|---|
| 2466 | care 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
|
|---|
| 2477 | times as possible.
|
|---|
| 2478 |
|
|---|
| 2479 | @kwd[do-once]@\
|
|---|
| 2480 | Indicates the prompter should execute the action under consideration once and
|
|---|
| 2481 | then 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
|
|---|
| 2488 | closing 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
|
|---|
| 2498 | the user entered nothing.
|
|---|
| 2499 |
|
|---|
| 2500 | @kwd[quote]@\
|
|---|
| 2501 | Indicates the prompter should take the following key-event as itself without
|
|---|
| 2502 | any 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)
|
|---|
| 2518 | Define a new logical key-event whenever:
|
|---|
| 2519 | @begin[enumerate]
|
|---|
| 2520 | The key-event concerned represents a general class of actions, and
|
|---|
| 2521 | several commands may want to take a similar action of this type.
|
|---|
| 2522 |
|
|---|
| 2523 | The exact key-event a command implementor chooses may generate violent taste
|
|---|
| 2524 | disputes among users, and then the users can trivially change the command in
|
|---|
| 2525 | their init files.
|
|---|
| 2526 |
|
|---|
| 2527 | You are using @f[command-case] which prevents implementors from specifying
|
|---|
| 2528 | non-standard characters for dispatching in otherwise possibly portable code,
|
|---|
| 2529 | and you can define and set the logical key-event in a site dependent file where
|
|---|
| 2530 | you 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
|
|---|
| 2538 | prompting the user for it. Most of these work through a small window displayed
|
|---|
| 2539 | at the bottom of the screen. This is called the echo area and is supported by
|
|---|
| 2540 | a buffer and a window. This buffer's modeline (see section @ref[modelines]) is
|
|---|
| 2541 | referred to as the status line, which, unlike other buffers' modelines, is used
|
|---|
| 2542 | to show general status about the editor, Lisp, or world.
|
|---|
| 2543 |
|
|---|
| 2544 | @defhvar[var {Default Status Line Fields}]
|
|---|
| 2545 | This is the initial list of modeline-field objects stored in the echo area
|
|---|
| 2546 | buffer.
|
|---|
| 2547 | @enddefhvar
|
|---|
| 2548 |
|
|---|
| 2549 | @defhvar[var "Echo Area Height", val {3}]
|
|---|
| 2550 | This variable determines the initial height in lines of the echo area window.
|
|---|
| 2551 | @enddefhvar
|
|---|
| 2552 |
|
|---|
| 2553 |
|
|---|
| 2554 | @section(Echo Area Functions)
|
|---|
| 2555 | It is considered poor taste to perform text operations on the echo area buffer
|
|---|
| 2556 | to display messages; the @f[message] function should be used instead. A
|
|---|
| 2557 | command 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
|
|---|
| 2559 | after the command's execution.
|
|---|
| 2560 |
|
|---|
| 2561 | @defun[fun {clear-echo-area}]
|
|---|
| 2562 | Clears 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}]
|
|---|
| 2568 | Displays a message in the echo area. The message is always displayed on a
|
|---|
| 2569 | fresh line. @f[message] pauses for @hid[Message Pause] seconds before
|
|---|
| 2570 | returning to assure that messages are not displayed too briefly to be seen.
|
|---|
| 2571 | Because 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
|
|---|
| 2574 | beeps.
|
|---|
| 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
|
|---|
| 2580 | named @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
|
|---|
| 2582 | modeline is the status line, see the beginning of this chapter.
|
|---|
| 2583 | @enddefvar
|
|---|
| 2584 |
|
|---|
| 2585 | @defvar[var {echo-area-stream}]
|
|---|
| 2586 | @index (Echo area)
|
|---|
| 2587 | This is a buffered @hemlock output stream
|
|---|
| 2588 | (@pageref[make-hemlock-output-stream-fun]) which inserts text written to it at
|
|---|
| 2589 | the 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
|
|---|
| 2591 | displayed.
|
|---|
| 2592 | @enddefvar
|
|---|
| 2593 |
|
|---|
| 2594 |
|
|---|
| 2595 | @section(Prompting Functions)
|
|---|
| 2596 | @index(Prompting functions)
|
|---|
| 2597 | Most 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
|
|---|
| 2600 | user is prompted until a valid response is obtained. If
|
|---|
| 2601 | @kwd[must-exist] is @nil then return as a string whatever is input.
|
|---|
| 2602 | The default is @true.
|
|---|
| 2603 |
|
|---|
| 2604 | @kwd[default] @\If null input is given when the user is prompted
|
|---|
| 2605 | then this value is returned. If no default is given then
|
|---|
| 2606 | some input must be given before anything interesting will happen.
|
|---|
| 2607 |
|
|---|
| 2608 | @kwd[default-string] @\If a @kwd[default] is given then this is a
|
|---|
| 2609 | string to be printed to indicate what the default is. The default is
|
|---|
| 2610 | some representation of the value for @kwd[default], for example for a
|
|---|
| 2611 | buffer it is the name of the buffer.
|
|---|
| 2612 |
|
|---|
| 2613 | @kwd[prompt] @\This is the prompt string to display.
|
|---|
| 2614 |
|
|---|
| 2615 | @kwd[help] @\@multiple{
|
|---|
| 2616 | This is similar to @kwd[prompt], except that it is displayed when
|
|---|
| 2617 | the help command is typed during input. @comment{If there is some known number
|
|---|
| 2618 | of options as in keyword parses, then they may be displayed, depending
|
|---|
| 2619 | on the setting of @hvarref[Help Show Options].}
|
|---|
| 2620 |
|
|---|
| 2621 | This may also be a function. When called with no arguments, it should either
|
|---|
| 2622 | return a string which is the help text or perform some action to help the user,
|
|---|
| 2623 | returning @Nil.}
|
|---|
| 2624 | @end(description)
|
|---|
| 2625 |
|
|---|
| 2626 | @defun[fun {prompt-for-buffer}, keys {[prompt][help][must-exist][default]},
|
|---|
| 2627 | morekeys {[default-string]}]
|
|---|
| 2628 | Prompts with completion for a buffer name and returns the corresponding buffer.
|
|---|
| 2629 | If @i[must-exist] is @nil, then it returns the input string if it is not a
|
|---|
| 2630 | buffer 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
|
|---|
| 2632 | used 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,
|
|---|
| 2639 | and then to dispatch on the character to some case. In addition to character
|
|---|
| 2640 | dispatching, this supports logical key-events @w<(page
|
|---|
| 2641 | @pageref[logical-key-events])> by using the input key-event directly without
|
|---|
| 2642 | translating it to a character. Since the description of this macro is rather
|
|---|
| 2643 | complex, 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
|
|---|
| 2665 | first branch with a logical key-event or a character (called @i[tags]) matching
|
|---|
| 2666 | the input. Each character must be a standard-character, one that satisfies the
|
|---|
| 2667 | Common Lisp @f[standard-char-p] predicate, and the dispatching mechanism
|
|---|
| 2668 | compares the input key-event to any character tags by mapping the key-event to
|
|---|
| 2669 | a character with @f[ext:key-event-char]. If the tag is a logical key-event,
|
|---|
| 2670 | then the search for an appropriate case compares the key-event read with the
|
|---|
| 2671 | tag using @f[logical-key-event-p].
|
|---|
| 2672 |
|
|---|
| 2673 | All 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
|
|---|
| 2675 | that include these logical key-event tags. The @kwd[help] branch displays in a
|
|---|
| 2676 | pop-up window the a description of the valid responses using the variously
|
|---|
| 2677 | specified help strings. The @kwd[abort] branch signals an editor-error.
|
|---|
| 2678 |
|
|---|
| 2679 | The @i[key]/@i[value] arguments control the prompting. The following are valid
|
|---|
| 2680 | values:
|
|---|
| 2681 | @begin[description]
|
|---|
| 2682 | @kwd[help]@\
|
|---|
| 2683 | The default @kwd[help] case displays this string in a pop-up window. In
|
|---|
| 2684 | addition 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
|
|---|
| 2692 | current window while the prompting mechanism reads a key-event. Sometimes it
|
|---|
| 2693 | is desirable to maintain the current window since it may be easier for users to
|
|---|
| 2694 | answer 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
|
|---|
| 2698 | key-event. Any case may reference this variable. If you wish to know what
|
|---|
| 2699 | character corresponds to the key-event, use @f[ext:key-event-char].
|
|---|
| 2700 | @end(description)
|
|---|
| 2701 |
|
|---|
| 2702 | Instead of specifying a tag or list of tags, you may use @true. This becomes
|
|---|
| 2703 | the default branch, and its forms execute if no other branch is taken,
|
|---|
| 2704 | including 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
|
|---|
| 2706 | branch. Every @f[command-case] has a default branch; if none is specified, the
|
|---|
| 2707 | macro includes one that @f[system:beep]'s and @f[reprompt]'s (see below).
|
|---|
| 2708 |
|
|---|
| 2709 | Within the body of @f[command-case], there is a defined @f[reprompt] macro.
|
|---|
| 2710 | It causes the prompting mechanism and dispatching mechanism to immediately
|
|---|
| 2711 | repeat without further execution in the current branch.
|
|---|
| 2712 | @enddefmac
|
|---|
| 2713 |
|
|---|
| 2714 |
|
|---|
| 2715 | @defun[fun {prompt-for-key-event}, keys {[prompt][change-window]}]
|
|---|
| 2716 | This function prompts for a key-event returning immediately when the user types
|
|---|
| 2717 | the next key-event. @macref[command-case] is more useful for most purposes.
|
|---|
| 2718 | When 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
|
|---|
| 2725 | passing 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
|
|---|
| 2727 | bound in the current environment, and the command currently bound is returned
|
|---|
| 2728 | as 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
|
|---|
| 2734 | fashion. "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
|
|---|
| 2736 | pathname.
|
|---|
| 2737 |
|
|---|
| 2738 | If the file exists as entered, then this returns it, otherwise it is merged
|
|---|
| 2739 | with @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
|
|---|
| 2746 | valid 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
|
|---|
| 2753 | in the list @i[string-tables]. If @I[must-exist] is non-@nil, then the result
|
|---|
| 2754 | must be an unambiguous prefix of a string in one of the @i[string-tables], and
|
|---|
| 2755 | the returns the complete string even if only a prefix of the full string was
|
|---|
| 2756 | typed. In addition, this returns the value of the corresponding entry in the
|
|---|
| 2757 | string table as the second value.
|
|---|
| 2758 |
|
|---|
| 2759 | If @i[must-exist] is @nil, then this function returns the string exactly as
|
|---|
| 2760 | entered. 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
|
|---|
| 2769 | error 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,
|
|---|
| 2780 | then the string must be a variable @i[defined in the current environment], in
|
|---|
| 2781 | which case the symbol name of the variable found is returned as the second
|
|---|
| 2782 | value.
|
|---|
| 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],
|
|---|
| 2788 | returning @true or @nil without waiting for confirmation. When the user types
|
|---|
| 2789 | a 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;
|
|---|
| 2791 | however, 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
|
|---|
| 2799 | confirmation must be given.
|
|---|
| 2800 | @enddefun
|
|---|
| 2801 |
|
|---|
| 2802 |
|
|---|
| 2803 | @section(Control of Parsing Behavior)
|
|---|
| 2804 |
|
|---|
| 2805 | @defhvar[var {Beep On Ambiguity}, val {@true}]
|
|---|
| 2806 | If this variable is true, then an attempt to complete a parse which is
|
|---|
| 2807 | ambiguous will result in a "beep".
|
|---|
| 2808 | @enddefhvar
|
|---|
| 2809 |
|
|---|
| 2810 |
|
|---|
| 2811 | @begin(comment)
|
|---|
| 2812 | @hemlock provides for limited control of parsing routine behaviour The
|
|---|
| 2813 | character attribute @hid[Parse Field Separator] is a boolean attribute, a value
|
|---|
| 2814 | of @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}]
|
|---|
| 2820 | During a keyword or similar parse, typing the help command may cause a
|
|---|
| 2821 | list of options to be displayed. If displaying the help would take up
|
|---|
| 2822 | more lines than the value of this variable then confirmation will be
|
|---|
| 2823 | asked for before they will be displayed.
|
|---|
| 2824 | @enddefhvar
|
|---|
| 2825 | @end(comment)
|
|---|
| 2826 |
|
|---|
| 2827 |
|
|---|
| 2828 |
|
|---|
| 2829 | @section(Defining New Prompting Functions)
|
|---|
| 2830 | Prompting functions are implemented as a recursive edit in the
|
|---|
| 2831 | @hid[Echo Area] buffer. Completion, help, and other parsing features
|
|---|
| 2832 | are implemented by commands which are bound in @hid[Echo Area Mode].
|
|---|
| 2833 |
|
|---|
| 2834 | A prompting function passes information down into the recursive edit
|
|---|
| 2835 | by binding a collection of special variables.
|
|---|
| 2836 |
|
|---|
| 2837 | @defvar[var {parse-verification-function}]
|
|---|
| 2838 | The system binds this to a function that @comref[Confirm Parse] calls. It does
|
|---|
| 2839 | most of the work when parsing prompted input. @comref[Confirm Parse] passes
|
|---|
| 2840 | one argument, which is the string that was in @var<parse-input-region> when the
|
|---|
| 2841 | user invokes the command. The function should return a list of values which
|
|---|
| 2842 | are to be the result of the recursive edit, or @nil indicating that the parse
|
|---|
| 2843 | failed. In order to return zero values, a non-@nil second value may be
|
|---|
| 2844 | returned along with a @nil first value.
|
|---|
| 2845 | @enddefvar
|
|---|
| 2846 |
|
|---|
| 2847 | @defvar[var {parse-string-tables}]
|
|---|
| 2848 | This 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}]
|
|---|
| 2852 | This is bound to the value of the @kwd[must-exist] argument, and is
|
|---|
| 2853 | referred to by the verification function, and possibly some of the
|
|---|
| 2854 | commands.
|
|---|
| 2855 | @enddefvar
|
|---|
| 2856 |
|
|---|
| 2857 | @defvar[var {parse-default}]
|
|---|
| 2858 | When prompting the user, this is bound to a string representing the default
|
|---|
| 2859 | object, the value supplied as the @kwd[default] argument. @hid<Confirm Parse>
|
|---|
| 2860 | supplies this to the parse verification function when the
|
|---|
| 2861 | @var<parse-input-region> is empty.
|
|---|
| 2862 | @enddefvar
|
|---|
| 2863 |
|
|---|
| 2864 | @defvar[var {parse-default-string}]
|
|---|
| 2865 | When prompting the user, if @var[parse-default] is @nil, @hemlock displays this
|
|---|
| 2866 | string as a representation of the default object; for example, when prompting
|
|---|
| 2867 | for a buffer, this variable would be bound to the buffer name.
|
|---|
| 2868 | @enddefvar
|
|---|
| 2869 |
|
|---|
| 2870 | @defvar[var {parse-type}]
|
|---|
| 2871 | The 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}]
|
|---|
| 2877 | The prompt being used for the current parse.
|
|---|
| 2878 | @enddefvar
|
|---|
| 2879 |
|
|---|
| 2880 | @defvar[var {parse-help}]
|
|---|
| 2881 | The help string or function being used for the current parse.
|
|---|
| 2882 | @enddefvar
|
|---|
| 2883 |
|
|---|
| 2884 | @defvar[var {parse-starting-mark}]
|
|---|
| 2885 | This variable holds a mark in the @varref[echo-area-buffer] which
|
|---|
| 2886 | is the position at which the parse began.
|
|---|
| 2887 | @enddefvar
|
|---|
| 2888 |
|
|---|
| 2889 | @defvar[var {parse-input-region}]
|
|---|
| 2890 | This variable holds a region with @var[parse-starting-mark] as its
|
|---|
| 2891 | start 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
|
|---|
| 2893 | that will be parsed.
|
|---|
| 2894 | @enddefvar
|
|---|
| 2895 |
|
|---|
| 2896 |
|
|---|
| 2897 | @section(Some Echo Area Commands)
|
|---|
| 2898 |
|
|---|
| 2899 | These are some of the @hid[Echo Area] commands that coordinate with the
|
|---|
| 2900 | prompting routines. @Hemlock binds other commands specific to the @hid[Echo
|
|---|
| 2901 | Area], but they are uninteresting to mention here, such as deleting to the
|
|---|
| 2902 | beginning 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)]
|
|---|
| 2906 | Display 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)]
|
|---|
| 2911 | This attempts to complete the current region as a keyword in
|
|---|
| 2912 | @var[string-tables]. It signals an editor-error if the input is ambiguous
|
|---|
| 2913 | or incorrect.
|
|---|
| 2914 | @enddefcom
|
|---|
| 2915 |
|
|---|
| 2916 | @defcom[com {Complete Field},
|
|---|
| 2917 | stuff (bound to @bf[Space] in @hid[Echo Area] mode)]
|
|---|
| 2918 | Similar to @hid[Complete Keyword], but only attempts to complete up to and
|
|---|
| 2919 | including the first character in the keyword with a non-zero
|
|---|
| 2920 | @kwd[parse-field-separator] attribute. If
|
|---|
| 2921 | there is no field separator then attempt to complete the entire keyword.
|
|---|
| 2922 | If 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)]
|
|---|
| 2927 | If @var[string-tables] is non-@nil find the string in the region in
|
|---|
| 2928 | them. Call @var[parse-verification-function] with the current input.
|
|---|
| 2929 | If it returns a non-@nil value then that is returned as the value of
|
|---|
| 2930 | the parse. A parse may return a @nil value if the verification
|
|---|
| 2931 | function returns a non-@nil second value.
|
|---|
| 2932 | @enddefcom
|
|---|
| 2933 |
|
|---|
| 2934 |
|
|---|
| 2935 |
|
|---|
| 2936 | @chapter (Files)
|
|---|
| 2937 | @index (Files)
|
|---|
| 2938 | This chapter discusses ways to read and write files at various levels @dash at
|
|---|
| 2939 | marks, into regions, and into buffers. This also treats automatic mechanisms
|
|---|
| 2940 | that 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)
|
|---|
| 2946 | The user specifies file options with a special syntax on the first line of a
|
|---|
| 2947 | file. If the first line contains the string "@f[-*-]", then @hemlock
|
|---|
| 2948 | interprets the text between the first such occurrence and the second, which
|
|---|
| 2949 | must be contained in one line , as a list of @w{"@f<@i[option]: @i[value]>"}
|
|---|
| 2950 | pairs separated by semicolons. The following is a typical example:
|
|---|
| 2951 | @begin[programexample]
|
|---|
| 2952 | ;;; -*- Mode: Lisp, Editor; Package: Hemlock -*-
|
|---|
| 2953 | @end[programexample]
|
|---|
| 2954 | See the @i[Hemlock User's Manual] for more details and predefined options.
|
|---|
| 2955 |
|
|---|
| 2956 | File type hooks are executed when @hemlock reads a file into a buffer based on
|
|---|
| 2957 | the type of the pathname. When the user specifies a @hid[Mode] file option
|
|---|
| 2958 | that turns on a major mode, @hemlock ignores type hooks. This mechanism is
|
|---|
| 2959 | mostly used as a simple means for turning on some appropriate default major
|
|---|
| 2960 | mode.
|
|---|
| 2961 |
|
|---|
| 2962 | @defmac[fun {define-file-option}, args
|
|---|
| 2963 | {@i[name] (@i[buffer] @i[value]) @mstar<@i[declaration]> @mstar<@i[form]>}]
|
|---|
| 2964 | This 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,
|
|---|
| 2966 | and @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 |
|
|---|
| 2972 | This defines some code that @f[process-file-options] (below) executes when the
|
|---|
| 2973 | file 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
|
|---|
| 2975 | buffer 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]}]
|
|---|
| 2979 | This 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
|
|---|
| 2982 | type, 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)
|
|---|
| 2988 | There 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
|
|---|
| 2990 | for consistency among customizations and primitives. Independent of this,
|
|---|
| 2991 | @hemlock provides a means for consistently generating prompting defaults when
|
|---|
| 2992 | asking the user for pathnames.
|
|---|
| 2993 |
|
|---|
| 2994 | @defun[fun {pathname-to-buffer-name}, args {@i[pathname]}]
|
|---|
| 2995 | This 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")}]
|
|---|
| 3002 | These variables control the computation of default pathnames when needed for
|
|---|
| 3003 | promting the user. @hid[Pathname Defaults] is a @i[sticky] default.
|
|---|
| 3004 | See the @i[Hemlock User's Manual] for more details.
|
|---|
| 3005 | @enddefhvar
|
|---|
| 3006 |
|
|---|
| 3007 | @defun[fun {buffer-default-pathname}, args {@i[buffer]}]
|
|---|
| 3008 | This 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
|
|---|
| 3010 | pathname formed from @i[buffer]'s name. If @i[buffer]'s name has other
|
|---|
| 3011 | characters in it, then return the value of @hid[Last Resort Pathname Defaults
|
|---|
| 3012 | Function] called on @i[buffer].
|
|---|
| 3013 | @enddefun
|
|---|
| 3014 |
|
|---|
| 3015 | @section (File Groups)
|
|---|
| 3016 | @index (File groups)
|
|---|
| 3017 | File groups provide a simple way of collecting the files that compose a system
|
|---|
| 3018 | and naming that collection. @Hemlock supports commands for searching,
|
|---|
| 3019 | replacing, and compiling groups.
|
|---|
| 3020 |
|
|---|
| 3021 | @defvar[var {active-file-group}]
|
|---|
| 3022 | This is the list of files that constitute the currently selected file group.
|
|---|
| 3023 | If 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
|
|---|
| 3030 | once for each file. While the forms are executing, the file is in the current
|
|---|
| 3031 | buffer, and the point is at the beginning. If there is no active group, this
|
|---|
| 3032 | signals an editor-error.
|
|---|
| 3033 |
|
|---|
| 3034 | This reads each file into its own buffer using @f[find-file-buffer]. Since
|
|---|
| 3035 | unwanted buffers may consume large amounts of memory, @hid[Group Find File]
|
|---|
| 3036 | controls whether to delete the buffer after executing the forms. When the
|
|---|
| 3037 | variable is false, this deletes the buffer if it did not previously exist;
|
|---|
| 3038 | however, regardless of this variable, if the user leaves the buffer modified,
|
|---|
| 3039 | the buffer persists after the forms have completed. Whenever this processes a
|
|---|
| 3040 | buffer that already existed, it saves the location of the buffer's point before
|
|---|
| 3041 | and restores it afterwards.
|
|---|
| 3042 |
|
|---|
| 3043 | After processing a buffer, if it is modified, @f[do-active-group] tries to save
|
|---|
| 3044 | it. If @hid[Group Save File Confirm] is non-@nil, it asks for confirmation.
|
|---|
| 3045 | @enddefmac
|
|---|
| 3046 |
|
|---|
| 3047 |
|
|---|
| 3048 | @section (File Reading and Writing)
|
|---|
| 3049 | Common Lisp pathnames are used by the file primitives. For probing, checking
|
|---|
| 3050 | write dates, and so forth, all of the Common Lisp file functions are available.
|
|---|
| 3051 |
|
|---|
| 3052 | @defun[fun {read-file}, args {@i[pathname] @i[mark]}]
|
|---|
| 3053 | This 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}]
|
|---|
| 3059 | This 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 |
|
|---|
| 3063 | When @i[keep-backup], which defaults to the value of @hid[Keep Backup Files],
|
|---|
| 3064 | is 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 |
|
|---|
| 3068 | This signals an error if both @i[append] and @i[keep-backup] are supplied as
|
|---|
| 3069 | non-@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]
|
|---|
| 3080 | including the following:
|
|---|
| 3081 | @begin[itemize]
|
|---|
| 3082 | It 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
|
|---|
| 3084 | the user for confirmation before overwriting the file.
|
|---|
| 3085 |
|
|---|
| 3086 | It consults @hid[Add Newline at EOF on Writing File] (see @i[Hemlock User's
|
|---|
| 3087 | Manual] for possible values) and interacts with the user if necessary.
|
|---|
| 3088 |
|
|---|
| 3089 | It sets @hid[Pathname Defaults], and after using @f[write-file], marks
|
|---|
| 3090 | @i[buffer] unmodified.
|
|---|
| 3091 |
|
|---|
| 3092 | It updates @i[Buffer]'s pathname and write date.
|
|---|
| 3093 |
|
|---|
| 3094 | It renames the buffer according to the new pathname if possible.
|
|---|
| 3095 |
|
|---|
| 3096 | It 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
|
|---|
| 3100 | as 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]
|
|---|
| 3109 | It sets @i[buffer]'s write date to the file's write date if the file exists;
|
|---|
| 3110 | otherwise, it @f[message]'s that this is a new file and sets @i[buffer]'s write
|
|---|
| 3111 | date to @nil.
|
|---|
| 3112 |
|
|---|
| 3113 | It moves @i[buffer]'s point to the beginning.
|
|---|
| 3114 |
|
|---|
| 3115 | It sets @i[buffer]'s unmodified status.
|
|---|
| 3116 |
|
|---|
| 3117 | It sets @i[buffer]'s pathname to the result of probing @i[pathname] if the file
|
|---|
| 3118 | exists; otherwise, this function sets @i[buffer]'s pathname to the result of
|
|---|
| 3119 | merging @i[pathname] with @f[default-directory].
|
|---|
| 3120 |
|
|---|
| 3121 | It sets @hid[Pathname Defaults] to the result of the previous item.
|
|---|
| 3122 |
|
|---|
| 3123 | It processes the file options.
|
|---|
| 3124 |
|
|---|
| 3125 | It invokes @hid[Read File Hook].
|
|---|
| 3126 | @end[itemize]
|
|---|
| 3127 |
|
|---|
| 3128 | @hid[Read File Hook] is a list functions that take two arguments @dash the
|
|---|
| 3129 | buffer read into and whether the file existed, @true if so.
|
|---|
| 3130 | @enddefun
|
|---|
| 3131 |
|
|---|
| 3132 |
|
|---|
| 3133 | @defun[fun {find-file-buffer}, args {@i[pathname]}]
|
|---|
| 3134 | This returns a buffer assoicated with the @i[pathname], reading the file into a
|
|---|
| 3135 | new buffer if necessary. This returns a second value indicating whether a new
|
|---|
| 3136 | buffer was created, @true if so. If the file has already been read, this
|
|---|
| 3137 | checks to see if the file has been modified on disk since it was read, giving
|
|---|
| 3138 | the user various recovery options. This is the basis of the @hid[Find File]
|
|---|
| 3139 | command.
|
|---|
| 3140 | @enddefun
|
|---|
| 3141 |
|
|---|
| 3142 |
|
|---|
| 3143 |
|
|---|
| 3144 | @chapter (Hemlock's Lisp Environment)
|
|---|
| 3145 |
|
|---|
| 3146 | @index (Lisp environment)
|
|---|
| 3147 | This chapter is sort of a catch all for any functions and variables
|
|---|
| 3148 | which 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
|
|---|
| 3156 | buffer, and that buffer is selected. If @i[x] is a pathname, the file
|
|---|
| 3157 | specified 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 |
|
|---|
| 3160 | The @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
|
|---|
| 3166 | value 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.
|
|---|
| 3172 | When 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 |
|
|---|
| 3181 | Keyboard input interacts with a number of other parts of the editor. Since the
|
|---|
| 3182 | command loop works by reading from the keyboard, keyboard input is the initial
|
|---|
| 3183 | cause of everything that happens. Also, @hemlock redisplays in the low-level
|
|---|
| 3184 | input 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
|
|---|
| 3193 | can get input, clear input, return input, and listen for input. Input appears
|
|---|
| 3194 | as key-events.
|
|---|
| 3195 |
|
|---|
| 3196 | @var[real-editor-input] holds the initial value of @var[editor-input]. This is
|
|---|
| 3197 | useful for reading from the user when @var[editor-input] is rebound (such as
|
|---|
| 3198 | within a keyboard macro.)
|
|---|
| 3199 |
|
|---|
| 3200 | @Hemlock invokes the functions in @hid[Input Hook] each time someone reads a
|
|---|
| 3201 | key-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]}]
|
|---|
| 3205 | This 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;
|
|---|
| 3209 | when this is non-nil, this function returns those key-events when the user
|
|---|
| 3210 | types them. Otherwise, it aborts the editor's current state, returning to the
|
|---|
| 3211 | command loop.
|
|---|
| 3212 |
|
|---|
| 3213 | When the user aborts, @Hemlock invokes the functions in @hid[Abort Hook].
|
|---|
| 3214 | These 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]}]
|
|---|
| 3220 | This function returns @i[key-event] to @i[editor-input], so the next invocation
|
|---|
| 3221 | of @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
|
|---|
| 3223 | on 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]}]
|
|---|
| 3228 | This function flushes any pending input on @i[editor-input]. @i[Editor-input]
|
|---|
| 3229 | is either @var[editor-input] or @var[real-editor-input].
|
|---|
| 3230 | @enddefun
|
|---|
| 3231 |
|
|---|
| 3232 | @defun[fun {listen-editor-input}, args {@i[editor-input]}]
|
|---|
| 3233 | This 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]}]
|
|---|
| 3238 | Return 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}]
|
|---|
| 3243 | This is a @hemlock ring buffer (see page @pageref[rings]) that holds the last
|
|---|
| 3244 | 60 key-events read from the keyboard.
|
|---|
| 3245 | @enddefvar
|
|---|
| 3246 |
|
|---|
| 3247 | @defvar[var {last-key-event-typed}]
|
|---|
| 3248 | Commands use this variable to realize the last key-event the user typed to
|
|---|
| 3249 | invoke the commands. Before @hemlock ever reads any input, the value is @nil.
|
|---|
| 3250 | This variable usually holds the last key-event read from the keyboard, but it
|
|---|
| 3251 | is also maintained within keyboard macros allowing commands to behave the same
|
|---|
| 3252 | on each repetition as they did in the recording invocation.
|
|---|
| 3253 | @enddefvar
|
|---|
| 3254 |
|
|---|
| 3255 | @defvar[var {input-transcript}]
|
|---|
| 3256 | If this is non-@nil then it should be an adjustable vector with a fill-pointer.
|
|---|
| 3257 | When it is non-@nil, @hemlock pushes all input read onto this vector.
|
|---|
| 3258 | @enddefvar
|
|---|
| 3259 |
|
|---|
| 3260 |
|
|---|
| 3261 |
|
|---|
| 3262 | @section(Hemlock Streams)
|
|---|
| 3263 | It is possible to create streams which output to or get input from a buffer.
|
|---|
| 3264 | This mechanism is quite powerful and permits easy interfacing of @hemlock to
|
|---|
| 3265 | Lisp.
|
|---|
| 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
|
|---|
| 3271 | mark @i[mark] all output directed to it. @i[Buffered] controls whether the
|
|---|
| 3272 | stream 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
|
|---|
| 3277 | when it is explicitly done with @f[force-output].
|
|---|
| 3278 |
|
|---|
| 3279 | @kwd[full]@\The screen is only brought up to date when it is
|
|---|
| 3280 | explicitly 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]>}]
|
|---|
| 3296 | While evaluating @i[form]s, binds @i[var] to a stream which returns input
|
|---|
| 3297 | from @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
|
|---|
| 3303 | inserts output at the permanent @i[mark]. @i[Buffered] has the same meaning as
|
|---|
| 3304 | for @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
|
|---|
| 3311 | appropriate height containing all the output. When @i[height] is supplied,
|
|---|
| 3312 | @Hemlock creates the pop-up display immediately, forcing output on line breaks.
|
|---|
| 3313 | The 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
|
|---|
| 3315 | mechanism will scroll the window with more-style prompting. This is useful
|
|---|
| 3316 | for displaying information of temporary interest.
|
|---|
| 3317 |
|
|---|
| 3318 | When a buffer with name @i[name] already exists and was not previously created
|
|---|
| 3319 | by @f[with-pop-up-display], @Hemlock signals an error.
|
|---|
| 3320 |
|
|---|
| 3321 | @var[random-typeout-buffers] is an association list mapping random typeout
|
|---|
| 3322 | buffers to the streams that operate on the buffers.
|
|---|
| 3323 | @enddefmac
|
|---|
| 3324 |
|
|---|
| 3325 |
|
|---|
| 3326 | @section (Interface to the Error System)
|
|---|
| 3327 | The error system interface is minimal. There is a simple editor-error
|
|---|
| 3328 | condition which is a subtype of error and a convenient means for signaling
|
|---|
| 3329 | them. @Hemlock also provides a standard handler for error conditions while in
|
|---|
| 3330 | the editor.
|
|---|
| 3331 |
|
|---|
| 3332 | @defun[fun {editor-error-format-string}, args {@i[condition]}]
|
|---|
| 3333 | @defun1[fun {editor-error-format-arguments}, args {@i[condition]}]
|
|---|
| 3334 | Handlers for editor-error conditions can access the condition object with
|
|---|
| 3335 | these.
|
|---|
| 3336 | @enddefun
|
|---|
| 3337 |
|
|---|
| 3338 | @defun[fun {editor-error}, args {@rest @i[args]}]
|
|---|
| 3339 | This function is called to signal minor errors within Hemlock; these are errors
|
|---|
| 3340 | that a normal user could encounter in the course of editing such as a search
|
|---|
| 3341 | failing 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
|
|---|
| 3343 | a @f[format] string possibly followed by @f[format] arguments. @Hemlock
|
|---|
| 3344 | invokes commands in a dynamic context with an editor-error condition handler
|
|---|
| 3345 | bound. This default handler beeps or flashes (or both) the display. If the
|
|---|
| 3346 | condition passed to the handler has a non-@nil string slot, the handler also
|
|---|
| 3347 | invokes @f[message] on it. The command in progress is always aborted, and this
|
|---|
| 3348 | function never returns.
|
|---|
| 3349 | @enddefun
|
|---|
| 3350 |
|
|---|
| 3351 | @defmac[fun {handle-lisp-errors}, args {@mstar<@i[form]>}]
|
|---|
| 3352 | Within the body of this macro any Lisp errors that occur are handled in some
|
|---|
| 3353 | fashion more gracefully than simply dumping the user in the debugger. This
|
|---|
| 3354 | macro should be wrapped around code which may get an error due to some action
|
|---|
| 3355 | of the user @dash for example, evaluating code fragments on the behalf of and
|
|---|
| 3356 | supplied by the user. Using this in a command allows the established handler
|
|---|
| 3357 | to shadow the default editor-error handler, so commands should take care to
|
|---|
| 3358 | signal 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
|
|---|
| 3365 | command and placing the user at the definition in a buffer. This, of course,
|
|---|
| 3366 | is implementation dependent, and if an implementation does not associate a
|
|---|
| 3367 | source file with a routine, or if @hemlock cannot get at the information, then
|
|---|
| 3368 | these commands do not work. If the Lisp system does not store an absolute
|
|---|
| 3369 | pathname, independent of the machine on which the maintainer built the system,
|
|---|
| 3370 | then users need a way of translating a source pathname to one that will be able
|
|---|
| 3371 | to locate the source.
|
|---|
| 3372 |
|
|---|
| 3373 | @defun[fun {add-definition-dir-translation}, args {@i[dir1] @i[dir2]}]
|
|---|
| 3374 | This maps directory pathname @i[dir1] to @i[dir2]. Successive invocations
|
|---|
| 3375 | using the same @i[dir1] push into a translation list. When @hemlock seeks a
|
|---|
| 3376 | definition source file, and it has a translation, then it tries the
|
|---|
| 3377 | translations in order. This is useful if your sources are on various machines,
|
|---|
| 3378 | some of which may be down. When @hemlock tries to find a translation, it first
|
|---|
| 3379 | looks for translations of longer directory pathnames, finding more specific
|
|---|
| 3380 | translations before shorter, more general ones.
|
|---|
| 3381 | @enddefun
|
|---|
| 3382 |
|
|---|
| 3383 | @defun[fun {delete-definition-dir-translation}, args {@i[dir]}]
|
|---|
| 3384 | This deletes the mapping of @i[dir] to all directories to which it has been
|
|---|
| 3385 | mapped.
|
|---|
| 3386 | @enddefun
|
|---|
| 3387 |
|
|---|
| 3388 |
|
|---|
| 3389 | @section (Event Scheduling)
|
|---|
| 3390 | @index (Event scheduling)
|
|---|
| 3391 | @index (Scheduling events)
|
|---|
| 3392 | The mechanism described in this chapter is only operative when the Lisp process
|
|---|
| 3393 | is actually running inside of @hemlock, within the @f[ed] function. The
|
|---|
| 3394 | designers intended its use to be associated with the editor, such as with
|
|---|
| 3395 | auto-saving files, reminding the user, etc.
|
|---|
| 3396 |
|
|---|
| 3397 | @defun[fun {schedule-event}, args {@i[time] @i[function] @optional @i[repeat]}]
|
|---|
| 3398 | This causes @hemlock to call @i[function] after @i[time] seconds have passed,
|
|---|
| 3399 | optionally repeating every @i[time] seconds. @i[Repeat] defaults to @true.
|
|---|
| 3400 | This is a rough mechanism since commands can take an arbitrary amount of time
|
|---|
| 3401 | to 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
|
|---|
| 3403 | since the last time it was called (or since it was scheduled for the first
|
|---|
| 3404 | invocation).
|
|---|
| 3405 | @enddefun
|
|---|
| 3406 |
|
|---|
| 3407 | @defun[fun {remove-scheduled-event}, args {@i[function]}]
|
|---|
| 3408 | This removes @i[function] from the scheduling queue. @i[Function] does not
|
|---|
| 3409 | have 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]
|
|---|
| 3417 | This 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.
|
|---|
| 3419 | Use 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]>}]
|
|---|
| 3423 | This iterates over alphabetic characters in Common Lisp binding @i[var] to each
|
|---|
| 3424 | character in order as specified under character relations in @i[Common Lisp the
|
|---|
| 3425 | Language]. @i[Kind] is one of @kwd[lower], @kwd[upper], or @kwd[both]. When
|
|---|
| 3426 | the user supplies @kwd[both], lowercase characters are processed first.
|
|---|
| 3427 | @enddefmac
|
|---|
| 3428 |
|
|---|
| 3429 |
|
|---|
| 3430 |
|
|---|
| 3431 | @chapter (High-Level Text Primitives)
|
|---|
| 3432 | This chapter discusses primitives that operate on higher level text forms than
|
|---|
| 3433 | characters and words. For English text, there are functions that know about
|
|---|
| 3434 | sentence and paragraph structures, and for Lisp sources, there are functions
|
|---|
| 3435 | that understand this language. This chapter also describes mechanisms for
|
|---|
| 3436 | organizing 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}]
|
|---|
| 3444 | The value of this variable determines how indentation is done, and it is a
|
|---|
| 3445 | function which is passed a mark as its argument. The function should indent
|
|---|
| 3446 | the line that the mark points to. The function may move the mark around on
|
|---|
| 3447 | the 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
|
|---|
| 3449 | moves the mark to the beginning of the line, deletes horizontal whitespace, and
|
|---|
| 3450 | computes 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
|
|---|
| 3456 | spaces. The function will insert a maximum number of tabs and a minimum number
|
|---|
| 3457 | of spaces at mark to move the specified number of columns. The default
|
|---|
| 3458 | definition 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
|
|---|
| 3460 | this 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
|
|---|
| 3466 | region. @f[indent-region-for-commands] uses @f[indent-region] but first saves
|
|---|
| 3467 | the region for the @hid[Undo] command.
|
|---|
| 3468 | @enddefun
|
|---|
| 3469 |
|
|---|
| 3470 | @defun[fun {delete-horizontal-space}, args {@i[mark]}]
|
|---|
| 3471 | This 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
|
|---|
| 3479 | annotating lines as to what kind of Lisp syntax occurs on the line or what kind
|
|---|
| 3480 | of form a mark might be in (for example, string, comment, list, etc.). These
|
|---|
| 3481 | do not work well if the block of parsed forms is exceeded when moving marks
|
|---|
| 3482 | around these forms, but the block that gets parsed is somewhat programmable.
|
|---|
| 3483 |
|
|---|
| 3484 | There is also a notion of a @i[top level form] which this documentation often
|
|---|
| 3485 | uses synonymously with @i[defun], meaning a Lisp form occurring in a source
|
|---|
| 3486 | file delimited by parentheses with the opening parenthesis at the beginning of
|
|---|
| 3487 | some 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
|
|---|
| 3496 | Function] on @i[mark] to get two marks. It then parses all the lines between
|
|---|
| 3497 | the marks including the complete lines they point into. When @i[for-sure] is
|
|---|
| 3498 | non-@nil, this parses the area regardless of any cached information about the
|
|---|
| 3499 | lines. Every command that uses the following routines calls this before doing
|
|---|
| 3500 | so.
|
|---|
| 3501 |
|
|---|
| 3502 | The default values of the start and end variables use @hid[Minimum Lines
|
|---|
| 3503 | Parsed], @hid[Maximum Lines Parsed], and @hid[Defun Parse Goal] to determine
|
|---|
| 3504 | how big a region to parse. These two functions always include at least the
|
|---|
| 3505 | minimum number of lines before and after the mark passed to them. They try to
|
|---|
| 3506 | include @hid[Defun Parse Goal] number of top level forms before and after the
|
|---|
| 3507 | mark passed them, but these functions never return marks that include more than
|
|---|
| 3508 | the 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]}]
|
|---|
| 3512 | This tries to move @i[mark] @i[count] forms forward if positive or -@i[count]
|
|---|
| 3513 | forms backwards if negative. @i[Mark] is always moved. If there were enough
|
|---|
| 3514 | forms in the appropriate direction, this returns @i[mark], otherwise nil.
|
|---|
| 3515 | @enddefun
|
|---|
| 3516 |
|
|---|
| 3517 | @defun[fun {top-level-offset}, args {@i[mark] @i[count]}]
|
|---|
| 3518 | This 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
|
|---|
| 3520 | level 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]}]
|
|---|
| 3525 | This moves @i[mark1] and @i[mark2] to the beginning and end, respectively, of
|
|---|
| 3526 | the current or next top level form. @i[Mark1] is used as a reference to start
|
|---|
| 3527 | looking. 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
|
|---|
| 3529 | the top level form if possible, but if the last line has text after the closing
|
|---|
| 3530 | parenthesis, this leaves the mark immediately after the form.
|
|---|
| 3531 | @enddefun
|
|---|
| 3532 |
|
|---|
| 3533 | @defun[fun {defun-region}, args {@i[mark]}]
|
|---|
| 3534 | This 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
|
|---|
| 3536 | top 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]}]
|
|---|
| 3542 | These return, respectively, whether @i[mark] is inside a top level form or at
|
|---|
| 3543 | the 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]}]
|
|---|
| 3549 | Respectively, these move @i[mark] immediately past a character whose @hid[Lisp
|
|---|
| 3550 | Syntax] (see section @ref[sys-def-chars]) value is @kwd[closing-paren] or
|
|---|
| 3551 | immediately 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]}]
|
|---|
| 3556 | This 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
|
|---|
| 3558 | mark and vice versa. Valid spots exclude commented text, inside strings, and
|
|---|
| 3559 | character quoting.
|
|---|
| 3560 | @enddefun
|
|---|
| 3561 |
|
|---|
| 3562 | @defun[fun {defindent}, args {@i[name] @i[count]}]
|
|---|
| 3563 | This 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
|
|---|
| 3566 | arguments. For example, @f[do] has two, @f[with-open-file] has one, etc.
|
|---|
| 3567 | There 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
|
|---|
| 3569 | textual (that is, not read by the Lisp reader); therefore, @f["with-a-mumble"]
|
|---|
| 3570 | is 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)
|
|---|
| 3577 | This section describes some routines that understand basic English language
|
|---|
| 3578 | forms.
|
|---|
| 3579 |
|
|---|
| 3580 | @defun[fun {word-offset}, args {@i[mark] @i[count]}]
|
|---|
| 3581 | This moves @i[mark] @i[count] words forward (if positive) or backwards (if
|
|---|
| 3582 | negative). If @i[mark] is in the middle of a word, that counts as one. If
|
|---|
| 3583 | there were @i[count] (-@i[count] if negative) words in the appropriate
|
|---|
| 3584 | direction, this returns @i[mark], otherwise nil. This always moves @i[mark].
|
|---|
| 3585 | A word lies between two characters whose @hid[Word Delimiter] attribute value
|
|---|
| 3586 | is @f[1] (see section @ref[sys-def-chars]).
|
|---|
| 3587 | @enddefun
|
|---|
| 3588 |
|
|---|
| 3589 | @defun[fun {sentence-offset}, args {@i[mark] @i[count]}]
|
|---|
| 3590 | This moves @i[mark] @i[count] sentences forward (if positive) or backwards (if
|
|---|
| 3591 | negative). If @i[mark] is in the middle of a sentence, that counts as one. If
|
|---|
| 3592 | there were @i[count] (-@i[count] if negative) sentences in the appropriate
|
|---|
| 3593 | direction, this returns @i[mark], otherwise nil. This always moves @i[mark].
|
|---|
| 3594 |
|
|---|
| 3595 | A 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
|
|---|
| 3597 | terminating character is optionally followed by any number of characters whose
|
|---|
| 3598 | @hid[Sentence Closing Char] attribute is @f[1]. A sentence begins after a
|
|---|
| 3599 | previous sentence ends, at the beginning of a paragraph, or at the beginning of
|
|---|
| 3600 | the 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}]
|
|---|
| 3605 | This moves @i[mark] @i[count] paragraphs forward (if positive) or backwards (if
|
|---|
| 3606 | negative). If @i[mark] is in the middle of a paragraph, that counts as one.
|
|---|
| 3607 | If there were @i[count] (-@i[count] if negative) paragraphs in the appropriate
|
|---|
| 3608 | direction, this returns @i[mark], otherwise nil. This only moves @i[mark] if
|
|---|
| 3609 | there were enough paragraphs.
|
|---|
| 3610 |
|
|---|
| 3611 | @hid[Paragraph Delimiter Function] holds a function that takes a mark,
|
|---|
| 3612 | typically at the beginning of a line, and returns whether or not the current
|
|---|
| 3613 | line should break the paragraph. @f[default-para-delim-function] returns @true
|
|---|
| 3614 | if the next character, the first on the line, has a @hid[Paragraph Delimiter]
|
|---|
| 3615 | attribute value of @f[1]. This is typically a space, for an indented
|
|---|
| 3616 | paragraph, or a newline, for a block style. Some modes require a more
|
|---|
| 3617 | complicated determinant; for example, @hid[Scribe] modes adds some characters
|
|---|
| 3618 | to the set and special cases certain formatting commands.
|
|---|
| 3619 |
|
|---|
| 3620 | @i[Prefix] defaults to @hid[Fill Prefix] (see section @ref[filling]), and the
|
|---|
| 3621 | right prefix is necessary to correctly skip paragraphs. If @i[prefix] is
|
|---|
| 3622 | non-@nil, and a line begins with @i[prefix], then the scanning process skips
|
|---|
| 3623 | the prefix before invoking the @hid[Paragraph Delimiter Function].
|
|---|
| 3624 | Note, when scanning for paragraph bounds, and @i[prefix] is non-@nil, lines are
|
|---|
| 3625 | potentially part of the paragraph regardless of whether they contain the prefix;
|
|---|
| 3626 | only the result of invoking the delimiter function matters.
|
|---|
| 3627 |
|
|---|
| 3628 | The programmer should be aware of an idiom for finding the end of the current
|
|---|
| 3629 | paragraph. Assume @f[paragraphp] is the result of moving @f[mark] one
|
|---|
| 3630 | paragraph, then the following correctly determines whether there actually is a
|
|---|
| 3631 | current 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]
|
|---|
| 3638 | In this example @f[mark] is at the end of the last paragraph in the buffer, and
|
|---|
| 3639 | there is no last newline character in the buffer. @f[paragraph-offset] would
|
|---|
| 3640 | have returned @nil since it could not skip any paragraphs since @f[mark] was at
|
|---|
| 3641 | the end of the current and last paragraph. However, you still have found a
|
|---|
| 3642 | current paragraph on which to operate. @f[mark-paragraph] understands this
|
|---|
| 3643 | problem.
|
|---|
| 3644 | @enddefun
|
|---|
| 3645 |
|
|---|
| 3646 | @defun[fun {mark-paragraph}, args {@f[mark1] @f[mark2]}]
|
|---|
| 3647 | This marks the next or current paragraph, setting @i[mark1] to the beginning
|
|---|
| 3648 | and @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,
|
|---|
| 3650 | regardless of whether the previous line is blank. @i[Mark2] is typically at
|
|---|
| 3651 | the 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
|
|---|
| 3653 | unmoved, and @nil is returned.
|
|---|
| 3654 | @enddefun
|
|---|
| 3655 |
|
|---|
| 3656 |
|
|---|
| 3657 | @section (Logical Pages)
|
|---|
| 3658 | @index (Logical pages)
|
|---|
| 3659 | @index (Page functions)
|
|---|
| 3660 | @label(logical-pages)
|
|---|
| 3661 | Logical pages are a way of dividing a file into coarse divisions. This is
|
|---|
| 3662 | analogous to dividing a paper into sections, and @hemlock provides primitives
|
|---|
| 3663 | for moving between the pages of a file and listing a directory of the page
|
|---|
| 3664 | titles. 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]}]
|
|---|
| 3668 | This moves @i[mark] to the absolute page numbered @i[n]. If there are less
|
|---|
| 3669 | than @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
|
|---|
| 3671 | the beginning of the buffer and the first @hid[Page Delimiter] (or the end of
|
|---|
| 3672 | the buffer).
|
|---|
| 3673 | @enddefun
|
|---|
| 3674 |
|
|---|
| 3675 | @defun[fun {page-offset}, args {@i[mark] @i[n]}]
|
|---|
| 3676 | This 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
|
|---|
| 3679 | mark, 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];
|
|---|
| 3681 | otherwise, it returns @nil.
|
|---|
| 3682 | @enddefun
|
|---|
| 3683 |
|
|---|
| 3684 | @defun[fun {page-directory}, args {@i[buffer]}]
|
|---|
| 3685 | This 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
|
|---|
| 3687 | includes the first line of the @i[buffer] as the first page title. If a page
|
|---|
| 3688 | is empty, then its title is the empty string.
|
|---|
| 3689 | @enddefun
|
|---|
| 3690 |
|
|---|
| 3691 | @defun[fun {display-page-directory}, args {@i[stream] @i[directory]}]
|
|---|
| 3692 | This writes the list of strings, @i[directory], to @i[stream], enumerating them
|
|---|
| 3693 | in a field three wide. The number and string are separated by two spaces, and
|
|---|
| 3694 | the first line contains headings for the page numbers and title strings.
|
|---|
| 3695 | @enddefun
|
|---|
| 3696 |
|
|---|
| 3697 |
|
|---|
| 3698 | @section (Filling)
|
|---|
| 3699 | @index (filling)
|
|---|
| 3700 | @label(filling)
|
|---|
| 3701 | Filling is an operation on text that breaks long lines at word boundaries
|
|---|
| 3702 | before a given column and merges shorter lines together in an attempt to make
|
|---|
| 3703 | each line roughly the specified length. This is different from justification
|
|---|
| 3704 | which tries to add whitespace in awkward places to make each line exactly the
|
|---|
| 3705 | same length. @Hemlock's filling optionally inserts a specified string at the
|
|---|
| 3706 | beginning of each line. Also, it eliminates extra whitespace between lines and
|
|---|
| 3707 | words, 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}]
|
|---|
| 3712 | These 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
|
|---|
| 3714 | fill prefix.
|
|---|
| 3715 | @enddefhvar
|
|---|
| 3716 |
|
|---|
| 3717 | @defun[fun {fill-region}, args {@i[region] @optional @i[prefix] @i[column]}]
|
|---|
| 3718 | This deletes any blank lines in region and fills it according to prefix and
|
|---|
| 3719 | column. @i[Prefix] and @i[column] default to @hid[Fill Prefix] and @hid[Fill
|
|---|
| 3720 | Column].
|
|---|
| 3721 | @enddefun
|
|---|
| 3722 |
|
|---|
| 3723 | @defun[fun {fill-region-by-paragraphs},
|
|---|
| 3724 | args {@i[region] @optional @i[prefix] @i[column]}]
|
|---|
| 3725 | This finds paragraphs (see section @ref[text-functions]) within region and
|
|---|
| 3726 | fills 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)
|
|---|
| 3734 | This chapter describes a number of utilities for manipulating some types of
|
|---|
| 3735 | objects @hemlock uses to record information. String-tables are used to store
|
|---|
| 3736 | names of variables, commands, modes, and buffers. Ring lists can be used to
|
|---|
| 3737 | provide 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 |
|
|---|
| 3744 | String tables are similar to Common Lisp hash tables in that they associate a
|
|---|
| 3745 | value with an object. There are a few useful differences: in a string table
|
|---|
| 3746 | the key is always a case insensitive string, and primitives are provided to
|
|---|
| 3747 | facilitate keyword completion and recognition. Any type of string may be added
|
|---|
| 3748 | to a string table, but the string table functions always return
|
|---|
| 3749 | @f[simple-string]'s.
|
|---|
| 3750 |
|
|---|
| 3751 | A string entry in one of these tables may be thought of as being separated into
|
|---|
| 3752 | fields or keywords. The interface provides keyword completion and recognition
|
|---|
| 3753 | which is primarily used to implement some @hid[Echo Area] commands. These
|
|---|
| 3754 | routines perform a prefix match on a field-by-field basis allowing the
|
|---|
| 3755 | ambiguous specification of earlier fields while going on to enter later fields.
|
|---|
| 3756 | While string tables may use any @f[string-char] as a separator, the use of
|
|---|
| 3757 | characters other than @binding[space] may make the @hid[Echo Area] commands
|
|---|
| 3758 | fail or work unexpectedly.
|
|---|
| 3759 |
|
|---|
| 3760 | @defun[fun {make-string-table}, keys {[separator][initial-contents]}]
|
|---|
| 3761 | This function creates an empty string table that uses @i[separator] as the
|
|---|
| 3762 | character, which must be a @f[string-char], that distinguishes fields.
|
|---|
| 3763 | @i[Initial-contents] specifies an initial set of strings and their values in
|
|---|
| 3764 | the 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]}]
|
|---|
| 3771 | This function returns @true if @i[string-table] is a @f[string-table] object,
|
|---|
| 3772 | otherwise @nil.
|
|---|
| 3773 | @enddefun
|
|---|
| 3774 |
|
|---|
| 3775 | @defun[fun {string-table-separator}, args {@i[string-table]}]
|
|---|
| 3776 | This 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
|
|---|
| 3783 | entries from @i[table].
|
|---|
| 3784 | @enddefun
|
|---|
| 3785 |
|
|---|
| 3786 | @defun[fun {getstring}, args {@i[string] @i[table]}]
|
|---|
| 3787 | This function returns as multiple values, first the value corresponding to the
|
|---|
| 3788 | string 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 |
|
|---|
| 3791 | This may be set with @f[setf] to add a new entry or to store a new value for a
|
|---|
| 3792 | string. It is an error to try to insert a string with more than one
|
|---|
| 3793 | field separator character occurring contiguously.
|
|---|
| 3794 | @enddefun
|
|---|
| 3795 |
|
|---|
| 3796 | @defun[fun {complete-string}, args {@i[string] @i[tables]}]
|
|---|
| 3797 | This 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
|
|---|
| 3799 | different separator characters. The five return values are as follows:
|
|---|
| 3800 | @begin[itemize]
|
|---|
| 3801 | The maximal completion of the string or @nil if there is none.
|
|---|
| 3802 |
|
|---|
| 3803 | An indication of the usefulness of the returned string:
|
|---|
| 3804 | @begin[description]
|
|---|
| 3805 | @kwd[none]@\
|
|---|
| 3806 | There is no completion of @i[string].
|
|---|
| 3807 |
|
|---|
| 3808 | @kwd[complete]@\
|
|---|
| 3809 | The completion is a valid entry, but other valid completions exist too. This
|
|---|
| 3810 | occurs when the supplied string is an entry as well as initial substring of
|
|---|
| 3811 | another entry.
|
|---|
| 3812 |
|
|---|
| 3813 | @kwd[unique]@\
|
|---|
| 3814 | The completion is a valid entry and unique.
|
|---|
| 3815 |
|
|---|
| 3816 | @kwd[ambiguous]@\
|
|---|
| 3817 | The completion is invalid; @f[get-string] would return @nil and @nil if given
|
|---|
| 3818 | the returned string.
|
|---|
| 3819 | @end[description]
|
|---|
| 3820 |
|
|---|
| 3821 | The value of the string when the completion is @kwd[unique] or @kwd[complete],
|
|---|
| 3822 | otherwise @nil.
|
|---|
| 3823 |
|
|---|
| 3824 | An index, or nil, into the completion returned, indicating where the addition
|
|---|
| 3825 | of a single field to @i[string] ends. The command @hid[Complete Field] uses
|
|---|
| 3826 | this when the completion contains the addition to @i[string] of more than one
|
|---|
| 3827 | field.
|
|---|
| 3828 |
|
|---|
| 3829 | An index to the separator following the first ambiguous field when the
|
|---|
| 3830 | completion 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
|
|---|
| 3837 | strings in @i[table] matching @i[string]. This considers an entry as matching
|
|---|
| 3838 | if each field in @i[string], taken in order, is an initial substring of the
|
|---|
| 3839 | entry'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
|
|---|
| 3843 | fields 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]>}]
|
|---|
| 3847 | This macro iterates over the strings in @i[table] in alphabetical order. On
|
|---|
| 3848 | each iteration, it binds @i[string-var] to an entry's string and @i[value-var]
|
|---|
| 3849 | to an entry's value.
|
|---|
| 3850 | @enddefmac
|
|---|
| 3851 |
|
|---|
| 3852 |
|
|---|
| 3853 | @section (Ring Functions)
|
|---|
| 3854 | @index (Rings)
|
|---|
| 3855 | @label[rings]
|
|---|
| 3856 | There are various purposes in an editor for which a ring of values can be used,
|
|---|
| 3857 | so @hemlock provides a general ring buffer type. It is used for maintaining a
|
|---|
| 3858 | ring of killed regions (see section @ref[kill-ring]), a ring of marks (see
|
|---|
| 3859 | section @ref[mark-stack]), or a ring of command strings which various modes and
|
|---|
| 3860 | commands maintain as a history mechanism.
|
|---|
| 3861 |
|
|---|
| 3862 | @defun[fun {make-ring}, args {@i[length] @optional @i[delete-function]}]
|
|---|
| 3863 | Makes 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
|
|---|
| 3865 | off the end. @i[Length] must be greater than zero.
|
|---|
| 3866 | @enddefun
|
|---|
| 3867 |
|
|---|
| 3868 | @defun[fun {ringp}, args {@i[ring]}]
|
|---|
| 3869 | Returns @true if @i[ring] is a @f[ring] object, otherwise @nil.
|
|---|
| 3870 | @enddefun
|
|---|
| 3871 |
|
|---|
| 3872 | @defun[fun {ring-length}, args {@i[ring]}]
|
|---|
| 3873 | Returns as multiple-values the number of elements which @i[ring]
|
|---|
| 3874 | currently holds and the maximum number of elements which it may hold.
|
|---|
| 3875 | @enddefun
|
|---|
| 3876 |
|
|---|
| 3877 | @defun[fun {ring-ref}, args {@i[ring] @i[index]}]
|
|---|
| 3878 | Returns the @i[index]'th item in the @i[ring], where zero is the index
|
|---|
| 3879 | of the most recently pushed. This may be set with @f[setf].
|
|---|
| 3880 | @enddefun
|
|---|
| 3881 |
|
|---|
| 3882 | @defun[fun {ring-push}, args {@i[object] @i[ring]}]
|
|---|
| 3883 | Pushes @i[object] into @i[ring], possibly causing the oldest item to
|
|---|
| 3884 | go away.
|
|---|
| 3885 | @enddefun
|
|---|
| 3886 |
|
|---|
| 3887 | @defun[fun {ring-pop}, args {@i[ring]}]
|
|---|
| 3888 | Removes the most recently pushed object from @i[ring] and returns it.
|
|---|
| 3889 | If the ring contains no elements then an error is signalled.
|
|---|
| 3890 | @enddefun
|
|---|
| 3891 |
|
|---|
| 3892 | @defun[fun {rotate-ring}, args {@i[ring] @i[offset]}]
|
|---|
| 3893 | With a positive @i[offset], rotates @i[ring] forward that many times.
|
|---|
| 3894 | In a forward rotation the index of each element is reduced by one,
|
|---|
| 3895 | except the one which initially had a zero index, which is made the
|
|---|
| 3896 | last 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]}]
|
|---|
| 3905 | This saves information to undo a command. @i[Name] is a string to display when
|
|---|
| 3906 | prompting the user for confirmation when he invokes the @hid[Undo] command (for
|
|---|
| 3907 | example, @f["kill"] or @f["Fill Paragraph"]). @i[Method] is the function to
|
|---|
| 3908 | invoke to undo the effect of the command. @i[Method-undo] is a function that
|
|---|
| 3909 | undoes the undo function, or effectively re-establishes the state immediately
|
|---|
| 3910 | after invoking the command. If there is any existing undo information, this
|
|---|
| 3911 | invokes the @i[cleanup] function; typically @i[method] closes over or uses
|
|---|
| 3912 | permanent marks into a buffer, and the @i[cleanup] function should delete such
|
|---|
| 3913 | references. @i[Buffer] defaults to the @f[current-buffer], and the @hid[Undo]
|
|---|
| 3914 | command only invokes undo methods when they were saved for the buffer that is
|
|---|
| 3915 | current 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]}]
|
|---|
| 3919 | This handles three common cases that commands fall into when setting up undo
|
|---|
| 3920 | methods, including cleanup and method-undo functions (see @f[save-for-undo]).
|
|---|
| 3921 | These cases are indicated by the @i[kind] argument:
|
|---|
| 3922 | @begin[description]
|
|---|
| 3923 | @kwd[twiddle]@\
|
|---|
| 3924 | Use this kind when a command modifies a region, and the undo information
|
|---|
| 3925 | indicates how to swap between two regions @dash the one before any modification
|
|---|
| 3926 | occurs and the resulting region. @i[Region] is the resulting region, and it
|
|---|
| 3927 | has permanent marks into the buffer. @i[Mark-or-region] is a region without
|
|---|
| 3928 | marks into the buffer (for example, the result of @f[copy-region]). As a
|
|---|
| 3929 | result of calling this, a first invocation of @hid[Undo] deletes @i[region],
|
|---|
| 3930 | saving it, and inserts @i[mark-or-region] where @i[region] used to be. The
|
|---|
| 3931 | undo method sets up for a second invocation of @hid[Undo] that will undo the
|
|---|
| 3932 | effect of the undo; that is, after two calls, the buffer is exactly as it was
|
|---|
| 3933 | after invoking the command. This activity is repeatable any number of times.
|
|---|
| 3934 | This establishes a cleanup method that deletes the two permanent marks into the
|
|---|
| 3935 | buffer used to locate the modified region.
|
|---|
| 3936 |
|
|---|
| 3937 | @kwd[insert]@\
|
|---|
| 3938 | Use this kind when a command has deleted a region, and the undo information
|
|---|
| 3939 | indicates how to re-insert the region. @i[Region] is the deleted and saved
|
|---|
| 3940 | region, and it does not contain marks into any buffer. @i[Mark-or-region] is a
|
|---|
| 3941 | permanent mark into the buffer where the undo method should insert @i[region].
|
|---|
| 3942 | As 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
|
|---|
| 3944 | with 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
|
|---|
| 3946 | is exactly as it was after invoking the command. This activity is repeatable
|
|---|
| 3947 | any number of times. This establishes a cleanup method that deletes either the
|
|---|
| 3948 | permanent mark into the buffer or the two permanent marks of the region,
|
|---|
| 3949 | depending on how many times the user used @hid[Undo].
|
|---|
| 3950 |
|
|---|
| 3951 | @kwd[delete]@\
|
|---|
| 3952 | Use this kind when a command has inserted a block of text, and the undo
|
|---|
| 3953 | information indicates how to delete the region. @i[Region] has permanent marks
|
|---|
| 3954 | into the buffer and surrounds the inserted text. Leave @i[Mark-or-region]
|
|---|
| 3955 | unspecified. As a result of calling this, a first invocation of @hid[Undo]
|
|---|
| 3956 | deletes @i[region], saving it, and establishes a permanent mark into the buffer
|
|---|
| 3957 | to 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
|
|---|
| 3959 | is exactly as it was after invoking the command. This activity is repeatable
|
|---|
| 3960 | any number of times. This establishes a cleanup method that deletes either the
|
|---|
| 3961 | permanent mark into the buffer or the two permanent marks of the region,
|
|---|
| 3962 | depending 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.
|
|---|
| 3967 | This is used by @hid[Undo] when prompting the user for confirmation before
|
|---|
| 3968 | calling the undo method. The string used by @hid[Undo] alternates between this
|
|---|
| 3969 | argument and something to indicate that the user is undoing an undo.
|
|---|
| 3970 | @enddefun
|
|---|
| 3971 |
|
|---|
| 3972 |
|
|---|
| 3973 |
|
|---|
| 3974 | @chapter (Miscellaneous)
|
|---|
| 3975 | This chapter is somewhat of a catch-all for comments and features that don't
|
|---|
| 3976 | fit 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
|
|---|
| 3981 | invokes a function supplied with the interface described in this section. This
|
|---|
| 3982 | command allows different commands to be bound to the same down-click in various
|
|---|
| 3983 | modes 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]
|
|---|
| 3987 | This function supplies a function that @hid[Generic Pointer Up] invokes the
|
|---|
| 3988 | next time it executes.
|
|---|
| 3989 | @enddefun
|
|---|
| 3990 |
|
|---|
| 3991 |
|
|---|
| 3992 | @section (Using View Mode)
|
|---|
| 3993 | @hid[View] mode supports scrolling through files automatically terminating the
|
|---|
| 3994 | buffer at end-of-file as well as commands for quitting the mode and popping
|
|---|
| 3995 | back 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
|
|---|
| 3997 | library entries.
|
|---|
| 3998 |
|
|---|
| 3999 | Modes that want similar commands should use @f[view-file-command] to view a
|
|---|
| 4000 | file 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
|
|---|
| 4002 | variable @hid[View Return Function] in the viewing buffer to a function that
|
|---|
| 4003 | knows how to do this. Furthermore, since you now have a reference to the
|
|---|
| 4004 | originating buffer, you must add a buffer local delete hook to it that will
|
|---|
| 4005 | clear the view return function's reference. This needs to happen for two
|
|---|
| 4006 | reasons in case the user deletes the originating buffer:
|
|---|
| 4007 | @Begin[Enumerate]
|
|---|
| 4008 | You don't want the return function to go to a non-existing, invalid buffer.
|
|---|
| 4009 |
|
|---|
| 4010 | Since the viewing buffer still exists, its @hid[View Return Function] buffer
|
|---|
| 4011 | local variable still exists. This means the function still references the
|
|---|
| 4012 | deleted originating buffer, and garbage collection cannot reclaim the memory
|
|---|
| 4013 | locked down by the deleted buffer.
|
|---|
| 4014 | @End[Enumerate]
|
|---|
| 4015 |
|
|---|
| 4016 | The following is a piece of code that could implement part of @hid[Dired View
|
|---|
| 4017 | File] 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 |
|
|---|
| 4032 | The @hid[Dired] buffer's delete hook clears the return function's reference to
|
|---|
| 4033 | the @hid[Dired] buffer. The return function tests the variable to see if it
|
|---|
| 4034 | still holds a buffer when the function executes.
|
|---|
| 4035 |
|
|---|
| 4036 |
|
|---|
| 4037 |
|
|---|
| 4038 | @comment[@chapter (Auxiliary Systems)]
|
|---|
| 4039 | @include(aux-sys)
|
|---|