1 This is ../info/lispref.info, produced by makeinfo version 4.6 from
4 INFO-DIR-SECTION XEmacs Editor
6 * Lispref: (lispref). XEmacs Lisp Reference Manual.
11 GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
21 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc. Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
25 Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
29 Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
34 Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
39 Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
46 Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
53 File: lispref.info, Node: Create/Delete Dirs, Next: Magic File Names, Prev: Contents of Directories, Up: Files
55 Creating and Deleting Directories
56 =================================
58 Most XEmacs Lisp file-manipulation functions get errors when used on
59 files that are directories. For example, you cannot delete a directory
60 with `delete-file'. These special functions exist to create and delete
63 - Command: make-directory dirname &optional parents
64 This function creates a directory named DIRNAME. Interactively,
65 the default choice of directory to create is the current default
66 directory for file names. That is useful when you have visited a
67 file in a nonexistent directory.
69 Non-interactively, optional argument PARENTS says whether to
70 create parent directories if they don't exist. (Interactively, this
73 - Command: delete-directory dirname
74 This function deletes the directory named DIRNAME. The function
75 `delete-file' does not work for files that are directories; you
76 must use `delete-directory' in that case.
79 File: lispref.info, Node: Magic File Names, Next: Partial Files, Prev: Create/Delete Dirs, Up: Files
81 Making Certain File Names "Magic"
82 =================================
84 You can implement special handling for certain file names. This is
85 called making those names "magic". You must supply a regular
86 expression to define the class of names (all those that match the
87 regular expression), plus a handler that implements all the primitive
88 XEmacs file operations for file names that do match.
90 The variable `file-name-handler-alist' holds a list of handlers,
91 together with regular expressions that determine when to apply each
92 handler. Each element has this form:
96 All the XEmacs primitives for file access and file name transformation
97 check the given file name against `file-name-handler-alist'. If the
98 file name matches REGEXP, the primitives handle that file by calling
101 The first argument given to HANDLER is the name of the primitive;
102 the remaining arguments are the arguments that were passed to that
103 operation. (The first of these arguments is typically the file name
104 itself.) For example, if you do this:
106 (file-exists-p FILENAME)
108 and FILENAME has handler HANDLER, then HANDLER is called like this:
110 (funcall HANDLER 'file-exists-p FILENAME)
112 Here are the operations that a magic file name handler gets to
115 `add-name-to-file', `copy-file', `delete-directory', `delete-file',
116 `diff-latest-backup-file', `directory-file-name', `directory-files',
117 `dired-compress-file', `dired-uncache', `expand-file-name',
118 `file-accessible-directory-p', `file-attributes', `file-directory-p',
119 `file-executable-p', `file-exists-p', `file-local-copy', `file-modes',
120 `file-name-all-completions', `file-name-as-directory',
121 `file-name-completion', `file-name-directory', `file-name-nondirectory',
122 `file-name-sans-versions', `file-newer-than-file-p', `file-readable-p',
123 `file-regular-p', `file-symlink-p', `file-truename', `file-writable-p',
124 `get-file-buffer', `insert-directory', `insert-file-contents', `load',
125 `make-directory', `make-symbolic-link', `rename-file', `set-file-modes',
126 `set-visited-file-modtime', `unhandled-file-name-directory',
127 `verify-visited-file-modtime', `write-region'.
129 Handlers for `insert-file-contents' typically need to clear the
130 buffer's modified flag, with `(set-buffer-modified-p nil)', if the
131 VISIT argument is non-`nil'. This also has the effect of unlocking the
132 buffer if it is locked.
134 The handler function must handle all of the above operations, and
135 possibly others to be added in the future. It need not implement all
136 these operations itself--when it has nothing special to do for a
137 certain operation, it can reinvoke the primitive, to handle the
138 operation "in the usual way". It should always reinvoke the primitive
139 for an operation it does not recognize. Here's one way to do this:
141 (defun my-file-handler (operation &rest args)
142 ;; First check for the specific operations
143 ;; that we have special handling for.
144 (cond ((eq operation 'insert-file-contents) ...)
145 ((eq operation 'write-region) ...)
147 ;; Handle any operation we don't know about.
148 (t (let ((inhibit-file-name-handlers
149 (cons 'my-file-handler
150 (and (eq inhibit-file-name-operation operation)
151 inhibit-file-name-handlers)))
152 (inhibit-file-name-operation operation))
153 (apply operation args)))))
155 When a handler function decides to call the ordinary Emacs primitive
156 for the operation at hand, it needs to prevent the primitive from
157 calling the same handler once again, thus leading to an infinite
158 recursion. The example above shows how to do this, with the variables
159 `inhibit-file-name-handlers' and `inhibit-file-name-operation'. Be
160 careful to use them exactly as shown above; the details are crucial for
161 proper behavior in the case of multiple handlers, and for operations
162 that have two file names that may each have handlers.
164 - Variable: inhibit-file-name-handlers
165 This variable holds a list of handlers whose use is presently
166 inhibited for a certain operation.
168 - Variable: inhibit-file-name-operation
169 The operation for which certain handlers are presently inhibited.
171 - Function: find-file-name-handler filename &optional operation
172 This function returns the handler function for file name FILENAME,
173 or `nil' if there is none. The argument OPERATION should be the
174 operation to be performed on the file--the value you will pass to
175 the handler as its first argument when you call it. The operation
176 is needed for comparison with `inhibit-file-name-operation'.
178 - Function: file-local-copy filename
179 This function copies file FILENAME to an ordinary non-magic file,
180 if it isn't one already.
182 If FILENAME specifies a "magic" file name, which programs outside
183 Emacs cannot directly read or write, this copies the contents to
184 an ordinary file and returns that file's name.
186 If FILENAME is an ordinary file name, not magic, then this function
187 does nothing and returns `nil'.
189 - Function: unhandled-file-name-directory filename
190 This function returns the name of a directory that is not magic.
191 It uses the directory part of FILENAME if that is not magic.
192 Otherwise, it asks the handler what to do.
194 This is useful for running a subprocess; every subprocess must
195 have a non-magic directory to serve as its current directory, and
196 this function is a good way to come up with one.
199 File: lispref.info, Node: Partial Files, Next: Format Conversion, Prev: Magic File Names, Up: Files
206 * Intro to Partial Files::
207 * Creating a Partial File::
208 * Detached Partial Files::
211 File: lispref.info, Node: Intro to Partial Files, Next: Creating a Partial File, Up: Partial Files
213 Intro to Partial Files
214 ----------------------
216 A "partial file" is a section of a buffer (called the "master buffer")
217 that is placed in its own buffer and treated as its own file. Changes
218 made to the partial file are not reflected in the master buffer until
219 the partial file is "saved" using the standard buffer save commands.
220 Partial files can be "reverted" (from the master buffer) just like
221 normal files. When a file part is active on a master buffer, that
222 section of the master buffer is marked as read-only. Two file parts on
223 the same master buffer are not allowed to overlap. Partial file
224 buffers are indicated by the words `File Part' in the modeline.
226 The master buffer knows about all the partial files that are active
227 on it, and thus killing or reverting the master buffer will be handled
228 properly. When the master buffer is saved, if there are any unsaved
229 partial files active on it then the user will be given the opportunity
230 to first save these files.
232 When a partial file buffer is first modified, the master buffer is
233 automatically marked as modified so that saving the master buffer will
237 File: lispref.info, Node: Creating a Partial File, Next: Detached Partial Files, Prev: Intro to Partial Files, Up: Partial Files
239 Creating a Partial File
240 -----------------------
242 - Command: make-file-part &optional start end name buffer
243 Make a file part on buffer BUFFER out of the region. Call it
244 NAME. This command creates a new buffer containing the contents
245 of the region and marks the buffer as referring to the specified
246 buffer, called the "master buffer". When the file-part buffer is
247 saved, its changes are integrated back into the master buffer.
248 When the master buffer is deleted, all file parts are deleted with
251 When called from a function, expects four arguments, START, END,
252 NAME, and BUFFER, all of which are optional and default to the
253 beginning of BUFFER, the end of BUFFER, a name generated from
254 BUFFER's name, and the current buffer, respectively.
257 File: lispref.info, Node: Detached Partial Files, Prev: Creating a Partial File, Up: Partial Files
259 Detached Partial Files
260 ----------------------
262 Every partial file has an extent in the master buffer associated with it
263 (called the "master extent"), marking where in the master buffer the
264 partial file begins and ends. If the text in master buffer that is
265 contained by the extent is deleted, then the extent becomes "detached",
266 meaning that it no longer refers to a specific region of the master
267 buffer. This can happen either when the text is deleted directly or
268 when the master buffer is reverted. Neither of these should happen in
269 normal usage because the master buffer should generally not be edited
272 Before doing any operation that references a partial file's master
273 extent, XEmacs checks to make sure that the extent is not detached. If
274 this is the case, XEmacs warns the user of this and the master extent is
275 deleted out of the master buffer, disconnecting the file part. The file
276 part's filename is cleared and thus must be explicitly specified if the
277 detached file part is to be saved.
280 File: lispref.info, Node: Format Conversion, Next: Files and MS-DOS, Prev: Partial Files, Up: Files
282 File Format Conversion
283 ======================
285 The variable `format-alist' defines a list of "file formats", which
286 describe textual representations used in files for the data (text,
287 text-properties, and possibly other information) in an Emacs buffer.
288 Emacs performs format conversion if appropriate when reading and writing
291 - Variable: format-alist
292 This list contains one format definition for each defined file
295 Each format definition is a list of this form:
297 (NAME DOC-STRING REGEXP FROM-FN TO-FN MODIFY MODE-FN)
299 Here is what the elements in a format definition mean:
302 The name of this format.
305 A documentation string for the format.
308 A regular expression which is used to recognize files represented
312 A function to call to decode data in this format (to convert file
313 data into the usual Emacs data representation).
315 The FROM-FN is called with two args, BEGIN and END, which specify
316 the part of the buffer it should convert. It should convert the
317 text by editing it in place. Since this can change the length of
318 the text, FROM-FN should return the modified end position.
320 One responsibility of FROM-FN is to make sure that the beginning
321 of the file no longer matches REGEXP. Otherwise it is likely to
325 A function to call to encode data in this format (to convert the
326 usual Emacs data representation into this format).
328 The TO-FN is called with two args, BEGIN and END, which specify
329 the part of the buffer it should convert. There are two ways it
330 can do the conversion:
332 * By editing the buffer in place. In this case, TO-FN should
333 return the end-position of the range of text, as modified.
335 * By returning a list of annotations. This is a list of
336 elements of the form `(POSITION . STRING)', where POSITION is
337 an integer specifying the relative position in the text to be
338 written, and STRING is the annotation to add there. The list
339 must be sorted in order of position when TO-FN returns it.
341 When `write-region' actually writes the text from the buffer
342 to the file, it intermixes the specified annotations at the
343 corresponding positions. All this takes place without
344 modifying the buffer.
347 A flag, `t' if the encoding function modifies the buffer, and
348 `nil' if it works by returning a list of annotations.
351 A mode function to call after visiting a file converted from this
354 The function `insert-file-contents' automatically recognizes file
355 formats when it reads the specified file. It checks the text of the
356 beginning of the file against the regular expressions of the format
357 definitions, and if it finds a match, it calls the decoding function for
358 that format. Then it checks all the known formats over again. It
359 keeps checking them until none of them is applicable.
361 Visiting a file, with `find-file-noselect' or the commands that use
362 it, performs conversion likewise (because it calls
363 `insert-file-contents'); it also calls the mode function for each
364 format that it decodes. It stores a list of the format names in the
365 buffer-local variable `buffer-file-format'.
367 - Variable: buffer-file-format
368 This variable states the format of the visited file. More
369 precisely, this is a list of the file format names that were
370 decoded in the course of visiting the current buffer's file. It
371 is always local in all buffers.
373 When `write-region' writes data into a file, it first calls the
374 encoding functions for the formats listed in `buffer-file-format', in
375 the order of appearance in the list.
377 - Command: format-write-file file format
378 This command writes the current buffer contents into the file FILE
379 in format FORMAT, and makes that format the default for future
380 saves of the buffer. The argument FORMAT is a list of format
383 - Command: format-find-file file format
384 This command finds the file FILE, converting it according to
385 format FORMAT. It also makes FORMAT the default if the buffer is
388 The argument FORMAT is a list of format names. If FORMAT is
389 `nil', no conversion takes place. Interactively, typing just
390 <RET> for FORMAT specifies `nil'.
392 - Command: format-insert-file file format &optional start end
393 This command inserts the contents of file FILE, converting it
394 according to format FORMAT. If START and END are non-`nil', they
395 specify which part of the file to read, as in
396 `insert-file-contents' (*note Reading from Files::).
398 The return value is like what `insert-file-contents' returns: a
399 list of the absolute file name and the length of the data inserted
402 The argument FORMAT is a list of format names. If FORMAT is
403 `nil', no conversion takes place. Interactively, typing just
404 <RET> for FORMAT specifies `nil'.
406 - Variable: auto-save-file-format
407 This variable specifies the format to use for auto-saving. Its
408 value is a list of format names, just like the value of
409 `buffer-file-format'; but it is used instead of
410 `buffer-file-format' for writing auto-save files. This variable
411 is always local in all buffers.
414 File: lispref.info, Node: Files and MS-DOS, Prev: Format Conversion, Up: Files
419 Emacs on MS-DOS makes a distinction between text files and binary
420 files. This is necessary because ordinary text files on MS-DOS use a
421 two character sequence between lines: carriage-return and linefeed
422 (CRLF). Emacs expects just a newline character (a linefeed) between
423 lines. When Emacs reads or writes a text file on MS-DOS, it needs to
424 convert the line separators. This means it needs to know which files
425 are text files and which are binary. It makes this decision when
426 visiting a file, and records the decision in the variable
427 `buffer-file-type' for use when the file is saved.
429 *Note MS-DOS Subprocesses::, for a related feature for subprocesses.
431 - Variable: buffer-file-type
432 This variable, automatically local in each buffer, records the
433 file type of the buffer's visited file. The value is `nil' for
434 text, `t' for binary.
436 - Function: find-buffer-file-type filename
437 This function determines whether file FILENAME is a text file or a
438 binary file. It returns `nil' for text, `t' for binary.
440 - User Option: file-name-buffer-file-type-alist
441 This variable holds an alist for distinguishing text files from
442 binary files. Each element has the form (REGEXP . TYPE), where
443 REGEXP is matched against the file name, and TYPE may be is `nil'
444 for text, `t' for binary, or a function to call to compute which.
445 If it is a function, then it is called with a single argument (the
446 file name) and should return `t' or `nil'.
448 - User Option: default-buffer-file-type
449 This variable specifies the default file type for files whose names
450 don't indicate anything in particular. Its value should be `nil'
451 for text, or `t' for binary.
453 - Command: find-file-text filename
454 Like `find-file', but treat the file as text regardless of its
457 - Command: find-file-binary filename
458 Like `find-file', but treat the file as binary regardless of its
462 File: lispref.info, Node: Backups and Auto-Saving, Next: Buffers, Prev: Files, Up: Top
464 Backups and Auto-Saving
465 ***********************
467 Backup files and auto-save files are two methods by which XEmacs tries
468 to protect the user from the consequences of crashes or of the user's
469 own errors. Auto-saving preserves the text from earlier in the current
470 editing session; backup files preserve file contents prior to the
475 * Backup Files:: How backup files are made; how their names are chosen.
476 * Auto-Saving:: How auto-save files are made; how their names are chosen.
477 * Reverting:: `revert-buffer', and how to customize what it does.
480 File: lispref.info, Node: Backup Files, Next: Auto-Saving, Up: Backups and Auto-Saving
485 A "backup file" is a copy of the old contents of a file you are
486 editing. XEmacs makes a backup file the first time you save a buffer
487 into its visited file. Normally, this means that the backup file
488 contains the contents of the file as it was before the current editing
489 session. The contents of the backup file normally remain unchanged once
492 Backups are usually made by renaming the visited file to a new name.
493 Optionally, you can specify that backup files should be made by copying
494 the visited file. This choice makes a difference for files with
495 multiple names; it also can affect whether the edited file remains owned
496 by the original owner or becomes owned by the user editing it.
498 By default, XEmacs makes a single backup file for each file edited.
499 You can alternatively request numbered backups; then each new backup
500 file gets a new name. You can delete old numbered backups when you
501 don't want them any more, or XEmacs can delete them automatically.
505 * Making Backups:: How XEmacs makes backup files, and when.
506 * Rename or Copy:: Two alternatives: renaming the old file or copying it.
507 * Numbered Backups:: Keeping multiple backups for each source file.
508 * Backup Names:: How backup file names are computed; customization.
511 File: lispref.info, Node: Making Backups, Next: Rename or Copy, Up: Backup Files
516 - Function: backup-buffer
517 This function makes a backup of the file visited by the current
518 buffer, if appropriate. It is called by `save-buffer' before
519 saving the buffer the first time.
521 - Variable: buffer-backed-up
522 This buffer-local variable indicates whether this buffer's file has
523 been backed up on account of this buffer. If it is non-`nil', then
524 the backup file has been written. Otherwise, the file should be
525 backed up when it is next saved (if backups are enabled). This is
526 a permanent local; `kill-local-variables' does not alter it.
528 - User Option: make-backup-files
529 This variable determines whether or not to make backup files. If
530 it is non-`nil', then XEmacs creates a backup of each file when it
531 is saved for the first time--provided that `backup-inhibited' is
534 The following example shows how to change the `make-backup-files'
535 variable only in the `RMAIL' buffer and not elsewhere. Setting it
536 `nil' stops XEmacs from making backups of the `RMAIL' file, which
537 may save disk space. (You would put this code in your `.emacs'
540 (add-hook 'rmail-mode-hook
544 (setq make-backup-files nil))))
546 - Variable: backup-enable-predicate
547 This variable's value is a function to be called on certain
548 occasions to decide whether a file should have backup files. The
549 function receives one argument, a file name to consider. If the
550 function returns `nil', backups are disabled for that file.
551 Otherwise, the other variables in this section say whether and how
554 The default value is this:
557 (or (< (length name) 5)
558 (not (string-equal "/tmp/"
559 (substring name 0 5)))))
561 - Variable: backup-inhibited
562 If this variable is non-`nil', backups are inhibited. It records
563 the result of testing `backup-enable-predicate' on the visited file
564 name. It can also coherently be used by other mechanisms that
565 inhibit backups based on which file is visited. For example, VC
566 sets this variable non-`nil' to prevent making backups for files
567 managed with a version control system.
569 This is a permanent local, so that changing the major mode does
570 not lose its value. Major modes should not set this
571 variable--they should set `make-backup-files' instead.
574 File: lispref.info, Node: Rename or Copy, Next: Numbered Backups, Prev: Making Backups, Up: Backup Files
576 Backup by Renaming or by Copying?
577 ---------------------------------
579 There are two ways that XEmacs can make a backup file:
581 * XEmacs can rename the original file so that it becomes a backup
582 file, and then write the buffer being saved into a new file.
583 After this procedure, any other names (i.e., hard links) of the
584 original file now refer to the backup file. The new file is owned
585 by the user doing the editing, and its group is the default for
586 new files written by the user in that directory.
588 * XEmacs can copy the original file into a backup file, and then
589 overwrite the original file with new contents. After this
590 procedure, any other names (i.e., hard links) of the original file
591 still refer to the current version of the file. The file's owner
592 and group will be unchanged.
594 The first method, renaming, is the default.
596 The variable `backup-by-copying', if non-`nil', says to use the
597 second method, which is to copy the original file and overwrite it with
598 the new buffer contents. The variable `file-precious-flag', if
599 non-`nil', also has this effect (as a sideline of its main
600 significance). *Note Saving Buffers::.
602 - Variable: backup-by-copying
603 If this variable is non-`nil', XEmacs always makes backup files by
606 The following two variables, when non-`nil', cause the second method
607 to be used in certain special cases. They have no effect on the
608 treatment of files that don't fall into the special cases.
610 - Variable: backup-by-copying-when-linked
611 If this variable is non-`nil', XEmacs makes backups by copying for
612 files with multiple names (hard links).
614 This variable is significant only if `backup-by-copying' is `nil',
615 since copying is always used when that variable is non-`nil'.
617 - Variable: backup-by-copying-when-mismatch
618 If this variable is non-`nil', XEmacs makes backups by copying in
619 cases where renaming would change either the owner or the group of
622 The value has no effect when renaming would not alter the owner or
623 group of the file; that is, for files which are owned by the user
624 and whose group matches the default for a new file created there
627 This variable is significant only if `backup-by-copying' is `nil',
628 since copying is always used when that variable is non-`nil'.
631 File: lispref.info, Node: Numbered Backups, Next: Backup Names, Prev: Rename or Copy, Up: Backup Files
633 Making and Deleting Numbered Backup Files
634 -----------------------------------------
636 If a file's name is `foo', the names of its numbered backup versions
637 are `foo.~V~', for various integers V, like this: `foo.~1~', `foo.~2~',
638 `foo.~3~', ..., `foo.~259~', and so on.
640 - User Option: version-control
641 This variable controls whether to make a single non-numbered backup
642 file or multiple numbered backups.
645 Make numbered backups if the visited file already has
646 numbered backups; otherwise, do not.
649 Do not make numbered backups.
652 Make numbered backups.
654 The use of numbered backups ultimately leads to a large number of
655 backup versions, which must then be deleted. XEmacs can do this
656 automatically or it can ask the user whether to delete them.
658 - User Option: kept-new-versions
659 The value of this variable is the number of newest versions to keep
660 when a new numbered backup is made. The newly made backup is
661 included in the count. The default value is 2.
663 - User Option: kept-old-versions
664 The value of this variable is the number of oldest versions to keep
665 when a new numbered backup is made. The default value is 2.
667 If there are backups numbered 1, 2, 3, 5, and 7, and both of these
668 variables have the value 2, then the backups numbered 1 and 2 are kept
669 as old versions and those numbered 5 and 7 are kept as new versions;
670 backup version 3 is excess. The function `find-backup-file-name'
671 (*note Backup Names::) is responsible for determining which backup
672 versions to delete, but does not delete them itself.
674 - User Option: delete-old-versions
675 If this variable is non-`nil', then saving a file deletes excess
676 backup versions silently. Otherwise, it asks the user whether to
679 - User Option: dired-kept-versions
680 This variable specifies how many of the newest backup versions to
681 keep in the Dired command `.' (`dired-clean-directory'). That's
682 the same thing `kept-new-versions' specifies when you make a new
683 backup file. The default value is 2.
686 File: lispref.info, Node: Backup Names, Prev: Numbered Backups, Up: Backup Files
691 The functions in this section are documented mainly because you can
692 customize the naming conventions for backup files by redefining them.
693 If you change one, you probably need to change the rest.
695 - Function: backup-file-name-p filename
696 This function returns a non-`nil' value if FILENAME is a possible
697 name for a backup file. A file with the name FILENAME need not
698 exist; the function just checks the name.
700 (backup-file-name-p "foo")
702 (backup-file-name-p "foo~")
705 The standard definition of this function is as follows:
707 (defun backup-file-name-p (file)
708 "Return non-nil if FILE is a backup file \
709 name (numeric or not)..."
710 (string-match "~$" file))
712 Thus, the function returns a non-`nil' value if the file name ends
713 with a `~'. (We use a backslash to split the documentation
714 string's first line into two lines in the text, but produce just
715 one line in the string itself.)
717 This simple expression is placed in a separate function to make it
718 easy to redefine for customization.
720 - Function: make-backup-file-name filename
721 This function returns a string that is the name to use for a
722 non-numbered backup file for file FILENAME. On Unix, this is just
723 FILENAME with a tilde appended.
725 The standard definition of this function is as follows:
727 (defun make-backup-file-name (file)
728 "Create the non-numeric backup file name for FILE.
732 You can change the backup-file naming convention by redefining this
733 function. The following example redefines `make-backup-file-name'
734 to prepend a `.' in addition to appending a tilde:
736 (defun make-backup-file-name (filename)
737 (concat "." filename "~"))
739 (make-backup-file-name "backups.texi")
742 - Function: find-backup-file-name filename
743 This function computes the file name for a new backup file for
744 FILENAME. It may also propose certain existing backup files for
745 deletion. `find-backup-file-name' returns a list whose CAR is the
746 name for the new backup file and whose CDR is a list of backup
747 files whose deletion is proposed.
749 Two variables, `kept-old-versions' and `kept-new-versions',
750 determine which backup versions should be kept. This function
751 keeps those versions by excluding them from the CDR of the value.
752 *Note Numbered Backups::.
754 In this example, the value says that `~rms/foo.~5~' is the name to
755 use for the new backup file, and `~rms/foo.~3~' is an "excess"
756 version that the caller should consider deleting now.
758 (find-backup-file-name "~rms/foo")
759 => ("~rms/foo.~5~" "~rms/foo.~3~")
761 - Function: file-newest-backup filename
762 This function returns the name of the most recent backup file for
763 FILENAME, or `nil' if that file has no backup files.
765 Some file comparison commands use this function so that they can
766 automatically compare a file with its most recent backup.
769 File: lispref.info, Node: Auto-Saving, Next: Reverting, Prev: Backup Files, Up: Backups and Auto-Saving
774 XEmacs periodically saves all files that you are visiting; this is
775 called "auto-saving". Auto-saving prevents you from losing more than a
776 limited amount of work if the system crashes. By default, auto-saves
777 happen every 300 keystrokes, or after around 30 seconds of idle time.
778 *Note Auto-Save: (xemacs)Auto Save, for information on auto-save for
779 users. Here we describe the functions used to implement auto-saving
780 and the variables that control them.
782 - Variable: buffer-auto-save-file-name
783 This buffer-local variable is the name of the file used for
784 auto-saving the current buffer. It is `nil' if the buffer should
787 buffer-auto-save-file-name
788 => "/xcssun/users/rms/lewis/#files.texi#"
790 - Command: auto-save-mode arg
791 When used interactively without an argument, this command is a
792 toggle switch: it turns on auto-saving of the current buffer if it
793 is off, and vice-versa. With an argument ARG, the command turns
794 auto-saving on if the value of ARG is `t', a nonempty list, or a
795 positive integer. Otherwise, it turns auto-saving off.
797 - Function: auto-save-file-name-p filename
798 This function returns a non-`nil' value if FILENAME is a string
799 that could be the name of an auto-save file. It works based on
800 knowledge of the naming convention for auto-save files: a name that
801 begins and ends with hash marks (`#') is a possible auto-save file
802 name. The argument FILENAME should not contain a directory part.
804 (make-auto-save-file-name)
805 => "/xcssun/users/rms/lewis/#files.texi#"
806 (auto-save-file-name-p "#files.texi#")
808 (auto-save-file-name-p "files.texi")
811 The standard definition of this function is as follows:
813 (defun auto-save-file-name-p (filename)
814 "Return non-nil if FILENAME can be yielded by..."
815 (string-match "^#.*#$" filename))
817 This function exists so that you can customize it if you wish to
818 change the naming convention for auto-save files. If you redefine
819 it, be sure to redefine the function `make-auto-save-file-name'
822 - Function: make-auto-save-file-name &optional filename
823 This function returns the file name to use for auto-saving the
824 current buffer. This is just the file name with hash marks (`#')
825 appended and prepended to it. This function does not look at the
826 variable `auto-save-visited-file-name' (described below); you
827 should check that before calling this function.
829 (make-auto-save-file-name)
830 => "/xcssun/users/rms/lewis/#backup.texi#"
832 The standard definition of this function is as follows:
834 (defun make-auto-save-file-name ()
835 "Return file name to use for auto-saves \
840 (file-name-directory buffer-file-name)
842 (file-name-nondirectory buffer-file-name)
845 (concat "#%" (buffer-name) "#"))))
847 This exists as a separate function so that you can redefine it to
848 customize the naming convention for auto-save files. Be sure to
849 change `auto-save-file-name-p' in a corresponding way.
851 - Variable: auto-save-visited-file-name
852 If this variable is non-`nil', XEmacs auto-saves buffers in the
853 files they are visiting. That is, the auto-save is done in the
854 same file that you are editing. Normally, this variable is `nil',
855 so auto-save files have distinct names that are created by
856 `make-auto-save-file-name'.
858 When you change the value of this variable, the value does not take
859 effect until the next time auto-save mode is reenabled in any given
860 buffer. If auto-save mode is already enabled, auto-saves continue
861 to go in the same file name until `auto-save-mode' is called again.
863 - Function: recent-auto-save-p
864 This function returns `t' if the current buffer has been
865 auto-saved since the last time it was read in or saved.
867 - Function: set-buffer-auto-saved
868 This function marks the current buffer as auto-saved. The buffer
869 will not be auto-saved again until the buffer text is changed
870 again. The function returns `nil'.
872 - User Option: auto-save-interval
873 The value of this variable is the number of characters that XEmacs
874 reads from the keyboard between auto-saves. Each time this many
875 more characters are read, auto-saving is done for all buffers in
878 - User Option: auto-save-timeout
879 The value of this variable is the number of seconds of idle time
880 that should cause auto-saving. Each time the user pauses for this
881 long, XEmacs auto-saves any buffers that need it. (Actually, the
882 specified timeout is multiplied by a factor depending on the size
883 of the current buffer.)
885 - Variable: auto-save-hook
886 This normal hook is run whenever an auto-save is about to happen.
888 - User Option: auto-save-default
889 If this variable is non-`nil', buffers that are visiting files
890 have auto-saving enabled by default. Otherwise, they do not.
892 - Command: do-auto-save &optional no-message current-only
893 This function auto-saves all buffers that need to be auto-saved.
894 It saves all buffers for which auto-saving is enabled and that
895 have been changed since the previous auto-save.
897 Normally, if any buffers are auto-saved, a message that says
898 `Auto-saving...' is displayed in the echo area while auto-saving is
899 going on. However, if NO-MESSAGE is non-`nil', the message is
902 If CURRENT-ONLY is non-`nil', only the current buffer is
905 - Function: delete-auto-save-file-if-necessary
906 This function deletes the current buffer's auto-save file if
907 `delete-auto-save-files' is non-`nil'. It is called every time a
910 - Variable: delete-auto-save-files
911 This variable is used by the function
912 `delete-auto-save-file-if-necessary'. If it is non-`nil', Emacs
913 deletes auto-save files when a true save is done (in the visited
914 file). This saves disk space and unclutters your directory.
916 - Function: rename-auto-save-file
917 This function adjusts the current buffer's auto-save file name if
918 the visited file name has changed. It also renames an existing
919 auto-save file. If the visited file name has not changed, this
920 function does nothing.
922 - Variable: buffer-saved-size
923 The value of this buffer-local variable is the length of the
924 current buffer as of the last time it was read in, saved, or
925 auto-saved. This is used to detect a substantial decrease in
926 size, and turn off auto-saving in response.
928 If it is -1, that means auto-saving is temporarily shut off in this
929 buffer due to a substantial deletion. Explicitly saving the buffer
930 stores a positive value in this variable, thus reenabling
931 auto-saving. Turning auto-save mode off or on also alters this
934 - Variable: auto-save-list-file-name
935 This variable (if non-`nil') specifies a file for recording the
936 names of all the auto-save files. Each time XEmacs does
937 auto-saving, it writes two lines into this file for each buffer
938 that has auto-saving enabled. The first line gives the name of
939 the visited file (it's empty if the buffer has none), and the
940 second gives the name of the auto-save file.
942 If XEmacs exits normally, it deletes this file. If XEmacs
943 crashes, you can look in the file to find all the auto-save files
944 that might contain work that was otherwise lost. The
945 `recover-session' command uses these files.
947 The default name for this file is in your home directory and
948 starts with `.saves-'. It also contains the XEmacs process ID and
952 File: lispref.info, Node: Reverting, Prev: Auto-Saving, Up: Backups and Auto-Saving
957 If you have made extensive changes to a file and then change your mind
958 about them, you can get rid of them by reading in the previous version
959 of the file with the `revert-buffer' command. *Note Reverting a
960 Buffer: (xemacs)Reverting.
962 - Command: revert-buffer &optional check-auto-save noconfirm
964 This command replaces the buffer text with the text of the visited
965 file on disk. This action undoes all changes since the file was
968 If the argument CHECK-AUTO-SAVE is non-`nil', and the latest
969 auto-save file is more recent than the visited file,
970 `revert-buffer' asks the user whether to use that instead.
971 Otherwise, it always uses the text of the visited file itself.
972 Interactively, CHECK-AUTO-SAVE is set if there is a numeric prefix
975 Normally, `revert-buffer' asks for confirmation before it changes
976 the buffer; but if the argument NOCONFIRM is non-`nil',
977 `revert-buffer' does not ask for confirmation.
979 Optional third argument PRESERVE-MODES non-`nil' means don't alter
980 the files modes. Normally we reinitialize them using
983 Reverting tries to preserve marker positions in the buffer by
984 using the replacement feature of `insert-file-contents'. If the
985 buffer contents and the file contents are identical before the
986 revert operation, reverting preserves all the markers. If they
987 are not identical, reverting does change the buffer; then it
988 preserves the markers in the unchanged text (if any) at the
989 beginning and end of the buffer. Preserving any additional
990 markers would be problematical.
992 You can customize how `revert-buffer' does its work by setting these
993 variables--typically, as buffer-local variables.
995 - Variable: revert-buffer-function
996 The value of this variable is the function to use to revert this
997 buffer. If non-`nil', it is called as a function with no
998 arguments to do the work of reverting. If the value is `nil',
999 reverting works the usual way.
1001 Modes such as Dired mode, in which the text being edited does not
1002 consist of a file's contents but can be regenerated in some other
1003 fashion, give this variable a buffer-local value that is a
1004 function to regenerate the contents.
1006 - Variable: revert-buffer-insert-file-contents-function
1007 The value of this variable, if non-`nil', is the function to use to
1008 insert the updated contents when reverting this buffer. The
1009 function receives two arguments: first the file name to use;
1010 second, `t' if the user has asked to read the auto-save file.
1012 - Variable: before-revert-hook
1013 This normal hook is run by `revert-buffer' before actually
1014 inserting the modified contents--but only if
1015 `revert-buffer-function' is `nil'.
1017 Font Lock mode uses this hook to record that the buffer contents
1018 are no longer fontified.
1020 - Variable: after-revert-hook
1021 This normal hook is run by `revert-buffer' after actually inserting
1022 the modified contents--but only if `revert-buffer-function' is
1025 Font Lock mode uses this hook to recompute the fonts for the
1026 updated buffer contents.
1029 File: lispref.info, Node: Buffers, Next: Windows, Prev: Backups and Auto-Saving, Up: Top
1034 A "buffer" is a Lisp object containing text to be edited. Buffers are
1035 used to hold the contents of files that are being visited; there may
1036 also be buffers that are not visiting files. While several buffers may
1037 exist at one time, exactly one buffer is designated the "current
1038 buffer" at any time. Most editing commands act on the contents of the
1039 current buffer. Each buffer, including the current buffer, may or may
1040 not be displayed in any window.
1044 * Buffer Basics:: What is a buffer?
1045 * Current Buffer:: Designating a buffer as current
1046 so primitives will access its contents.
1047 * Buffer Names:: Accessing and changing buffer names.
1048 * Buffer File Name:: The buffer file name indicates which file is visited.
1049 * Buffer Modification:: A buffer is "modified" if it needs to be saved.
1050 * Modification Time:: Determining whether the visited file was changed
1051 ``behind XEmacs's back''.
1052 * Read Only Buffers:: Modifying text is not allowed in a read-only buffer.
1053 * The Buffer List:: How to look at all the existing buffers.
1054 * Creating Buffers:: Functions that create buffers.
1055 * Killing Buffers:: Buffers exist until explicitly killed.
1056 * Indirect Buffers:: An indirect buffer shares text with some other buffer.
1059 File: lispref.info, Node: Buffer Basics, Next: Current Buffer, Up: Buffers
1064 A "buffer" is a Lisp object containing text to be edited. Buffers are
1065 used to hold the contents of files that are being visited; there may
1066 also be buffers that are not visiting files. While several buffers may
1067 exist at one time, exactly one buffer is designated the "current
1068 buffer" at any time. Most editing commands act on the contents of the
1069 current buffer. Each buffer, including the current buffer, may or may
1070 not be displayed in any windows.
1072 Buffers in Emacs editing are objects that have distinct names and hold
1073 text that can be edited. Buffers appear to Lisp programs as a special
1074 data type. You can think of the contents of a buffer as an extendible
1075 string; insertions and deletions may occur in any part of the buffer.
1078 A Lisp buffer object contains numerous pieces of information. Some
1079 of this information is directly accessible to the programmer through
1080 variables, while other information is accessible only through
1081 special-purpose functions. For example, the visited file name is
1082 directly accessible through a variable, while the value of point is
1083 accessible only through a primitive function.
1085 Buffer-specific information that is directly accessible is stored in
1086 "buffer-local" variable bindings, which are variable values that are
1087 effective only in a particular buffer. This feature allows each buffer
1088 to override the values of certain variables. Most major modes override
1089 variables such as `fill-column' or `comment-column' in this way. For
1090 more information about buffer-local variables and functions related to
1091 them, see *Note Buffer-Local Variables::.
1093 For functions and variables related to visiting files in buffers, see
1094 *Note Visiting Files:: and *Note Saving Buffers::. For functions and
1095 variables related to the display of buffers in windows, see *Note
1096 Buffers and Windows::.
1098 - Function: bufferp object
1099 This function returns `t' if OBJECT is a buffer, `nil' otherwise.
1102 File: lispref.info, Node: Current Buffer, Next: Buffer Names, Prev: Buffer Basics, Up: Buffers
1107 There are, in general, many buffers in an Emacs session. At any time,
1108 one of them is designated as the "current buffer". This is the buffer
1109 in which most editing takes place, because most of the primitives for
1110 examining or changing text in a buffer operate implicitly on the
1111 current buffer (*note Text::). Normally the buffer that is displayed on
1112 the screen in the selected window is the current buffer, but this is not
1113 always so: a Lisp program can designate any buffer as current
1114 temporarily in order to operate on its contents, without changing what
1115 is displayed on the screen.
1117 The way to designate a current buffer in a Lisp program is by calling
1118 `set-buffer'. The specified buffer remains current until a new one is
1121 When an editing command returns to the editor command loop, the
1122 command loop designates the buffer displayed in the selected window as
1123 current, to prevent confusion: the buffer that the cursor is in when
1124 Emacs reads a command is the buffer that the command will apply to.
1125 (*Note Command Loop::.) Therefore, `set-buffer' is not the way to
1126 switch visibly to a different buffer so that the user can edit it. For
1127 this, you must use the functions described in *Note Displaying
1130 However, Lisp functions that change to a different current buffer
1131 should not depend on the command loop to set it back afterwards.
1132 Editing commands written in XEmacs Lisp can be called from other
1133 programs as well as from the command loop. It is convenient for the
1134 caller if the subroutine does not change which buffer is current
1135 (unless, of course, that is the subroutine's purpose). Therefore, you
1136 should normally use `set-buffer' within a `save-excursion' that will
1137 restore the current buffer when your function is done (*note
1138 Excursions::). Here is an example, the code for the command
1139 `append-to-buffer' (with the documentation string abridged):
1141 (defun append-to-buffer (buffer start end)
1142 "Append to specified buffer the text of the region.
1144 (interactive "BAppend to buffer: \nr")
1145 (let ((oldbuf (current-buffer)))
1147 (set-buffer (get-buffer-create buffer))
1148 (insert-buffer-substring oldbuf start end))))
1150 This function binds a local variable to the current buffer, and then
1151 `save-excursion' records the values of point, the mark, and the
1152 original buffer. Next, `set-buffer' makes another buffer current.
1153 Finally, `insert-buffer-substring' copies the string from the original
1154 current buffer to the new current buffer.
1156 If the buffer appended to happens to be displayed in some window,
1157 the next redisplay will show how its text has changed. Otherwise, you
1158 will not see the change immediately on the screen. The buffer becomes
1159 current temporarily during the execution of the command, but this does
1160 not cause it to be displayed.
1162 If you make local bindings (with `let' or function arguments) for a
1163 variable that may also have buffer-local bindings, make sure that the
1164 same buffer is current at the beginning and at the end of the local
1165 binding's scope. Otherwise you might bind it in one buffer and unbind
1166 it in another! There are two ways to do this. In simple cases, you may
1167 see that nothing ever changes the current buffer within the scope of the
1168 binding. Otherwise, use `save-excursion' to make sure that the buffer
1169 current at the beginning is current again whenever the variable is
1172 It is not reliable to change the current buffer back with
1173 `set-buffer', because that won't do the job if a quit happens while the
1174 wrong buffer is current. Here is what _not_ to do:
1176 (let (buffer-read-only
1177 (obuf (current-buffer)))
1182 Using `save-excursion', as shown below, handles quitting, errors, and
1183 `throw', as well as ordinary evaluation.
1185 (let (buffer-read-only)
1190 - Function: current-buffer
1191 This function returns the current buffer.
1194 => #<buffer buffers.texi>
1196 - Function: set-buffer buffer-or-name
1197 This function makes BUFFER-OR-NAME the current buffer. It does
1198 not display the buffer in the currently selected window or in any
1199 other window, so the user cannot necessarily see the buffer. But
1200 Lisp programs can in any case work on it.
1202 BUFFER-OR-NAME must be a buffer or the name of an existing
1203 buffer-else an error is signaled. This function returns the buffer
1204 identified by BUFFER-OR-NAME.
1207 File: lispref.info, Node: Buffer Names, Next: Buffer File Name, Prev: Current Buffer, Up: Buffers
1212 Each buffer has a unique name, which is a string. Many of the
1213 functions that work on buffers accept either a buffer or a buffer name
1214 as an argument. Any argument called BUFFER-OR-NAME is of this sort,
1215 and an error is signaled if it is neither a string nor a buffer. Any
1216 argument called BUFFER must be an actual buffer object, not a name.
1218 Buffers that are ephemeral and generally uninteresting to the user
1219 have names starting with a space, so that the `list-buffers' and
1220 `buffer-menu' commands don't mention them. A name starting with space
1221 also initially disables recording undo information; see *Note Undo::.
1223 - Function: buffer-name &optional buffer
1224 This function returns the name of BUFFER as a string. If BUFFER
1225 is not supplied, it defaults to the current buffer.
1227 If `buffer-name' returns `nil', it means that BUFFER has been
1228 killed. *Note Killing Buffers::.
1233 (setq foo (get-buffer "temp"))
1242 - Command: rename-buffer newname &optional unique
1243 This function renames the current buffer to NEWNAME. An error is
1244 signaled if NEWNAME is not a string, or if there is already a
1245 buffer with that name. The function returns `nil'.
1247 Ordinarily, `rename-buffer' signals an error if NEWNAME is already
1248 in use. However, if UNIQUE is non-`nil', it modifies NEWNAME to
1249 make a name that is not in use. Interactively, you can make
1250 UNIQUE non-`nil' with a numeric prefix argument.
1252 One application of this command is to rename the `*shell*' buffer
1253 to some other name, thus making it possible to create a second
1254 shell buffer under the name `*shell*'.
1256 - Function: get-buffer buffer-or-name
1257 This function returns the buffer named BUFFER-OR-NAME. If
1258 BUFFER-OR-NAME is a string and there is no buffer with that name,
1259 the value is `nil'. If BUFFER-OR-NAME is actually a buffer, it is
1260 returned as given. (That is not very useful, so the argument is
1261 usually a name.) For example:
1263 (setq b (get-buffer "lewis"))
1267 (get-buffer "Frazzle-nots")
1270 See also the function `get-buffer-create' in *Note Creating
1273 - Function: generate-new-buffer-name starting-name &optional ignore
1274 This function returns a name that would be unique for a new
1275 buffer--but does not create the buffer. It starts with
1276 STARTING-NAME, and produces a name not currently in use for any
1277 buffer by appending a number inside of `<...>'.
1279 If IGNORE is given, it specifies a name that is okay to use (if it
1280 is in the sequence to be tried), even if a buffer with that name
1283 See the related function `generate-new-buffer' in *Note Creating
1287 File: lispref.info, Node: Buffer File Name, Next: Buffer Modification, Prev: Buffer Names, Up: Buffers
1292 The "buffer file name" is the name of the file that is visited in that
1293 buffer. When a buffer is not visiting a file, its buffer file name is
1294 `nil'. Most of the time, the buffer name is the same as the
1295 nondirectory part of the buffer file name, but the buffer file name and
1296 the buffer name are distinct and can be set independently. *Note
1299 - Function: buffer-file-name &optional buffer
1300 This function returns the absolute file name of the file that
1301 BUFFER is visiting. If BUFFER is not visiting any file,
1302 `buffer-file-name' returns `nil'. If BUFFER is not supplied, it
1303 defaults to the current buffer.
1305 (buffer-file-name (other-buffer))
1306 => "/usr/user/lewis/manual/files.texi"
1308 - Variable: buffer-file-name
1309 This buffer-local variable contains the name of the file being
1310 visited in the current buffer, or `nil' if it is not visiting a
1311 file. It is a permanent local, unaffected by
1312 `kill-local-variables'.
1315 => "/usr/user/lewis/manual/buffers.texi"
1317 It is risky to change this variable's value without doing various
1318 other things. See the definition of `set-visited-file-name' in
1319 `files.el'; some of the things done there, such as changing the
1320 buffer name, are not strictly necessary, but others are essential
1321 to avoid confusing XEmacs.
1323 - Variable: buffer-file-truename
1324 This buffer-local variable holds the truename of the file visited
1325 in the current buffer, or `nil' if no file is visited. It is a
1326 permanent local, unaffected by `kill-local-variables'. *Note
1329 - Variable: buffer-file-number
1330 This buffer-local variable holds the file number and directory
1331 device number of the file visited in the current buffer, or `nil'
1332 if no file or a nonexistent file is visited. It is a permanent
1333 local, unaffected by `kill-local-variables'. *Note Truenames::.
1335 The value is normally a list of the form `(FILENUM DEVNUM)'. This
1336 pair of numbers uniquely identifies the file among all files
1337 accessible on the system. See the function `file-attributes', in
1338 *Note File Attributes::, for more information about them.
1340 - Function: get-file-buffer filename
1341 This function returns the buffer visiting file FILENAME. If there
1342 is no such buffer, it returns `nil'. The argument FILENAME, which
1343 must be a string, is expanded (*note File Name Expansion::), then
1344 compared against the visited file names of all live buffers.
1346 (get-file-buffer "buffers.texi")
1347 => #<buffer buffers.texi>
1349 In unusual circumstances, there can be more than one buffer
1350 visiting the same file name. In such cases, this function returns
1351 the first such buffer in the buffer list.
1353 - Command: set-visited-file-name filename
1354 If FILENAME is a non-empty string, this function changes the name
1355 of the file visited in current buffer to FILENAME. (If the buffer
1356 had no visited file, this gives it one.) The _next time_ the
1357 buffer is saved it will go in the newly-specified file. This
1358 command marks the buffer as modified, since it does not (as far as
1359 XEmacs knows) match the contents of FILENAME, even if it matched
1360 the former visited file.
1362 If FILENAME is `nil' or the empty string, that stands for "no
1363 visited file". In this case, `set-visited-file-name' marks the
1364 buffer as having no visited file.
1366 When the function `set-visited-file-name' is called interactively,
1367 it prompts for FILENAME in the minibuffer.
1369 See also `clear-visited-file-modtime' and
1370 `verify-visited-file-modtime' in *Note Buffer Modification::.
1372 - Variable: list-buffers-directory
1373 This buffer-local variable records a string to display in a buffer
1374 listing in place of the visited file name, for buffers that don't
1375 have a visited file name. Dired buffers use this variable.
1378 File: lispref.info, Node: Buffer Modification, Next: Modification Time, Prev: Buffer File Name, Up: Buffers
1383 XEmacs keeps a flag called the "modified flag" for each buffer, to
1384 record whether you have changed the text of the buffer. This flag is
1385 set to `t' whenever you alter the contents of the buffer, and cleared
1386 to `nil' when you save it. Thus, the flag shows whether there are
1387 unsaved changes. The flag value is normally shown in the modeline
1388 (*note Modeline Variables::), and controls saving (*note Saving
1389 Buffers::) and auto-saving (*note Auto-Saving::).
1391 Some Lisp programs set the flag explicitly. For example, the
1392 function `set-visited-file-name' sets the flag to `t', because the text
1393 does not match the newly-visited file, even if it is unchanged from the
1394 file formerly visited.
1396 The functions that modify the contents of buffers are described in
1399 - Function: buffer-modified-p &optional buffer
1400 This function returns `t' if the buffer BUFFER has been modified
1401 since it was last read in from a file or saved, or `nil'
1402 otherwise. If BUFFER is not supplied, the current buffer is
1405 - Function: set-buffer-modified-p flag &optional buffer
1406 This function marks BUFFER as modified if FLAG is non-`nil', or as
1407 unmodified if the flag is `nil'. BUFFER defaults to the current
1410 Another effect of calling this function is to cause unconditional
1411 redisplay of the modeline for the current buffer. In fact, the
1412 function `redraw-modeline' works by doing this:
1414 (set-buffer-modified-p (buffer-modified-p))
1416 - Command: not-modified &optional arg
1417 This command marks the current buffer as unmodified, and not
1418 needing to be saved. (If ARG is non-`nil', the buffer is instead
1419 marked as modified.) Don't use this function in programs, since it
1420 prints a message in the echo area; use `set-buffer-modified-p'
1423 - Function: buffer-modified-tick &optional buffer
1424 This function returns BUFFER`s modification-count. This is a
1425 counter that increments every time the buffer is modified. If
1426 BUFFER is `nil' (or omitted), the current buffer is used.
1429 File: lispref.info, Node: Modification Time, Next: Read Only Buffers, Prev: Buffer Modification, Up: Buffers
1431 Comparison of Modification Time
1432 ===============================
1434 Suppose that you visit a file and make changes in its buffer, and
1435 meanwhile the file itself is changed on disk. At this point, saving the
1436 buffer would overwrite the changes in the file. Occasionally this may
1437 be what you want, but usually it would lose valuable information.
1438 XEmacs therefore checks the file's modification time using the functions
1439 described below before saving the file.
1441 - Function: verify-visited-file-modtime buffer
1442 This function compares what BUFFER has recorded for the
1443 modification time of its visited file against the actual
1444 modification time of the file as recorded by the operating system.
1445 The two should be the same unless some other process has written
1446 the file since XEmacs visited or saved it.
1448 The function returns `t' if the last actual modification time and
1449 XEmacs's recorded modification time are the same, `nil' otherwise.
1451 - Function: clear-visited-file-modtime
1452 This function clears out the record of the last modification time
1453 of the file being visited by the current buffer. As a result, the
1454 next attempt to save this buffer will not complain of a
1455 discrepancy in file modification times.
1457 This function is called in `set-visited-file-name' and other
1458 exceptional places where the usual test to avoid overwriting a
1459 changed file should not be done.
1461 - Function: visited-file-modtime
1462 This function returns the buffer's recorded last file modification
1463 time, as a list of the form `(HIGH . LOW)'. (This is the same
1464 format that `file-attributes' uses to return time values; see
1465 *Note File Attributes::.)
1467 - Function: set-visited-file-modtime &optional time
1468 This function updates the buffer's record of the last modification
1469 time of the visited file, to the value specified by TIME if TIME
1470 is not `nil', and otherwise to the last modification time of the
1473 If TIME is not `nil', it should have the form `(HIGH . LOW)' or
1474 `(HIGH LOW)', in either case containing two integers, each of
1475 which holds 16 bits of the time.
1477 This function is useful if the buffer was not read from the file
1478 normally, or if the file itself has been changed for some known
1481 - Function: ask-user-about-supersession-threat filename
1482 This function is used to ask a user how to proceed after an
1483 attempt to modify an obsolete buffer visiting file FILENAME. An
1484 "obsolete buffer" is an unmodified buffer for which the associated
1485 file on disk is newer than the last save-time of the buffer. This
1486 means some other program has probably altered the file.
1488 Depending on the user's answer, the function may return normally,
1489 in which case the modification of the buffer proceeds, or it may
1490 signal a `file-supersession' error with data `(FILENAME)', in which
1491 case the proposed buffer modification is not allowed.
1493 This function is called automatically by XEmacs on the proper
1494 occasions. It exists so you can customize XEmacs by redefining it.
1495 See the file `userlock.el' for the standard definition.
1497 See also the file locking mechanism in *Note File Locks::.
1500 File: lispref.info, Node: Read Only Buffers, Next: The Buffer List, Prev: Modification Time, Up: Buffers
1505 If a buffer is "read-only", then you cannot change its contents,
1506 although you may change your view of the contents by scrolling and
1509 Read-only buffers are used in two kinds of situations:
1511 * A buffer visiting a write-protected file is normally read-only.
1513 Here, the purpose is to show the user that editing the buffer with
1514 the aim of saving it in the file may be futile or undesirable.
1515 The user who wants to change the buffer text despite this can do
1516 so after clearing the read-only flag with `C-x C-q'.
1518 * Modes such as Dired and Rmail make buffers read-only when altering
1519 the contents with the usual editing commands is probably a mistake.
1521 The special commands of these modes bind `buffer-read-only' to
1522 `nil' (with `let') or bind `inhibit-read-only' to `t' around the
1523 places where they change the text.
1525 - Variable: buffer-read-only
1526 This buffer-local variable specifies whether the buffer is
1527 read-only. The buffer is read-only if this variable is non-`nil'.
1529 - Variable: inhibit-read-only
1530 If this variable is non-`nil', then read-only buffers and read-only
1531 characters may be modified. Read-only characters in a buffer are
1532 those that have non-`nil' `read-only' properties (either text
1533 properties or extent properties). *Note Extent Properties::, for
1534 more information about text properties and extent properties.
1536 If `inhibit-read-only' is `t', all `read-only' character
1537 properties have no effect. If `inhibit-read-only' is a list, then
1538 `read-only' character properties have no effect if they are members
1539 of the list (comparison is done with `eq').
1541 - Command: toggle-read-only &optional arg
1542 This command changes whether the current buffer is read-only.
1543 Interactively, if a prefix arg ARG is supplied, set the current
1544 buffer read only if and only if ARG is positive.
1546 This command is intended for interactive use only; don't use it in
1547 programs. At any given point in a program, you should know
1548 whether you want the read-only flag on or off; so you can set
1549 `buffer-read-only' explicitly to the proper value, `t' or `nil'.
1551 - Function: barf-if-buffer-read-only &optional buffer start end
1552 This function signals a `buffer-read-only' error if BUFFER is
1553 read-only. BUFFER defaults to the current buffer. *Note
1554 Interactive Call::, for another way to signal an error if the
1555 current buffer is read-only.
1557 If optional argument START is non-`nil', all extents in the buffer
1558 which overlap that part of the buffer are checked to ensure none
1559 has a `read-only' property. (Extents that lie completely within the
1560 range, however, are not checked.) END defaults to the value of
1563 If START and END are equal, the range checked is [START, END]
1564 (i.e. closed on both ends); otherwise, the range checked is
1565 (START, END) \(open on both ends), except that extents that lie
1566 completely within [START, END] are not checked. See
1567 `extent-in-region-p' for a fuller discussion.
1570 File: lispref.info, Node: The Buffer List, Next: Creating Buffers, Prev: Read Only Buffers, Up: Buffers
1575 The "buffer list" is a list of all live buffers. Creating a buffer
1576 adds it to this list, and killing a buffer deletes it. The order of
1577 the buffers in the list is based primarily on how recently each buffer
1578 has been displayed in the selected window. Buffers move to the front
1579 of the list when they are selected and to the end when they are buried.
1580 Several functions, notably `other-buffer', use this ordering. A
1581 buffer list displayed for the user also follows this order.
1583 Every frame has its own order for the buffer list. Switching to a
1584 new buffer inside of a particular frame changes the buffer list order
1585 for that frame, but does not affect the buffer list order of any other
1586 frames. In addition, there is a global, non-frame buffer list order
1587 that is independent of the buffer list orders for any particular frame.
1589 Note that the different buffer lists all contain the same elements.
1590 It is only the order of those elements that is different.
1592 - Function: buffer-list &optional frame
1593 This function returns a list of all buffers, including those whose
1594 names begin with a space. The elements are actual buffers, not
1595 their names. The order of the list is specific to FRAME, which
1596 defaults to the current frame. If FRAME is `t', the global,
1597 non-frame ordering is returned instead.
1600 => (#<buffer buffers.texi>
1601 #<buffer *Minibuf-1*> #<buffer buffer.c>
1602 #<buffer *Help*> #<buffer TAGS>)
1604 ;; Note that the name of the minibuffer
1605 ;; begins with a space!
1606 (mapcar (function buffer-name) (buffer-list))
1607 => ("buffers.texi" " *Minibuf-1*"
1608 "buffer.c" "*Help*" "TAGS")
1610 Buffers appear earlier in the list if they were current more
1613 This list is a copy of a list used inside XEmacs; modifying it has
1614 no effect on the buffers.
1616 - Function: other-buffer &optional buffer-or-name frame visible-ok
1617 This function returns the first buffer in the buffer list other
1618 than BUFFER-OR-NAME, in FRAME's ordering for the buffer list.
1619 (FRAME defaults to the current frame. If FRAME is `t', then the
1620 global, non-frame ordering is used.) Usually this is the buffer
1621 most recently shown in the selected window, aside from
1622 BUFFER-OR-NAME. Buffers are moved to the front of the list when
1623 they are selected and to the end when they are buried. Buffers
1624 whose names start with a space are not considered.
1626 If BUFFER-OR-NAME is not supplied (or if it is not a buffer), then
1627 `other-buffer' returns the first buffer on the buffer list that is
1628 not visible in any window in a visible frame.
1630 If the selected frame has a non-`nil' `buffer-predicate' property,
1631 then `other-buffer' uses that predicate to decide which buffers to
1632 consider. It calls the predicate once for each buffer, and if the
1633 value is `nil', that buffer is ignored. *Note X Frame
1636 If VISIBLE-OK is `nil', `other-buffer' avoids returning a buffer
1637 visible in any window on any visible frame, except as a last
1638 resort. If VISIBLE-OK is non-`nil', then it does not matter
1639 whether a buffer is displayed somewhere or not.
1641 If no suitable buffer exists, the buffer `*scratch*' is returned
1642 (and created, if necessary).
1644 Note that in FSF Emacs 19, there is no FRAME argument, and
1645 VISIBLE-OK is the second argument instead of the third.
1647 - Command: list-buffers &optional files-only
1648 This function displays a listing of the names of existing buffers.
1649 It clears the buffer `*Buffer List*', then inserts the listing
1650 into that buffer and displays it in a window. `list-buffers' is
1651 intended for interactive use, and is described fully in `The XEmacs
1652 Reference Manual'. It returns `nil'.
1654 - Command: bury-buffer &optional buffer-or-name before
1655 This function puts BUFFER-OR-NAME at the end of the buffer list
1656 without changing the order of any of the other buffers on the list.
1657 This buffer therefore becomes the least desirable candidate for
1658 `other-buffer' to return.
1660 If BUFFER-OR-NAME is `nil' or omitted, this means to bury the
1661 current buffer. In addition, if the buffer is displayed in the
1662 selected window, this switches to some other buffer (obtained using
1663 `other-buffer') in the selected window. But if the buffer is
1664 displayed in some other window, it remains displayed there.
1666 If you wish to replace a buffer in all the windows that display
1667 it, use `replace-buffer-in-windows'. *Note Buffers and Windows::.
1670 File: lispref.info, Node: Creating Buffers, Next: Killing Buffers, Prev: The Buffer List, Up: Buffers
1675 This section describes the two primitives for creating buffers.
1676 `get-buffer-create' creates a buffer if it finds no existing buffer
1677 with the specified name; `generate-new-buffer' always creates a new
1678 buffer and gives it a unique name.
1680 Other functions you can use to create buffers include
1681 `with-output-to-temp-buffer' (*note Temporary Displays::) and
1682 `create-file-buffer' (*note Visiting Files::). Starting a subprocess
1683 can also create a buffer (*note Processes::).
1685 - Function: get-buffer-create name
1686 This function returns a buffer named NAME. It returns an existing
1687 buffer with that name, if one exists; otherwise, it creates a new
1688 buffer. The buffer does not become the current buffer--this
1689 function does not change which buffer is current.
1691 An error is signaled if NAME is not a string.
1693 (get-buffer-create "foo")
1696 The major mode for the new buffer is set to Fundamental mode. The
1697 variable `default-major-mode' is handled at a higher level. *Note
1700 - Function: generate-new-buffer name
1701 This function returns a newly created, empty buffer, but does not
1702 make it current. If there is no buffer named NAME, then that is
1703 the name of the new buffer. If that name is in use, this function
1704 adds suffixes of the form `<N>' to NAME, where N is an integer.
1705 It tries successive integers starting with 2 until it finds an
1708 An error is signaled if NAME is not a string.
1710 (generate-new-buffer "bar")
1712 (generate-new-buffer "bar")
1714 (generate-new-buffer "bar")
1717 The major mode for the new buffer is set to Fundamental mode. The
1718 variable `default-major-mode' is handled at a higher level. *Note
1721 See the related function `generate-new-buffer-name' in *Note
1725 File: lispref.info, Node: Killing Buffers, Next: Indirect Buffers, Prev: Creating Buffers, Up: Buffers
1730 "Killing a buffer" makes its name unknown to XEmacs and makes its text
1731 space available for other use.
1733 The buffer object for the buffer that has been killed remains in
1734 existence as long as anything refers to it, but it is specially marked
1735 so that you cannot make it current or display it. Killed buffers retain
1736 their identity, however; two distinct buffers, when killed, remain
1737 distinct according to `eq'.
1739 If you kill a buffer that is current or displayed in a window, XEmacs
1740 automatically selects or displays some other buffer instead. This means
1741 that killing a buffer can in general change the current buffer.
1742 Therefore, when you kill a buffer, you should also take the precautions
1743 associated with changing the current buffer (unless you happen to know
1744 that the buffer being killed isn't current). *Note Current Buffer::.
1746 If you kill a buffer that is the base buffer of one or more indirect
1747 buffers, the indirect buffers are automatically killed as well.
1749 The `buffer-name' of a killed buffer is `nil'. To test whether a
1750 buffer has been killed, you can either use this feature or the function
1753 - Function: buffer-live-p object
1754 This function returns `t' if OBJECT is an editor buffer that has
1755 not been deleted, `nil' otherwise.
1757 - Command: kill-buffer buffer-or-name
1758 This function kills the buffer BUFFER-OR-NAME, freeing all its
1759 memory for use as space for other buffers. (Emacs version 18 and
1760 older was unable to return the memory to the operating system.)
1761 It returns `nil'. The argument BUFFER-OR-NAME may be a buffer or
1764 Any processes that have this buffer as the `process-buffer' are
1765 sent the `SIGHUP' signal, which normally causes them to terminate.
1766 (The basic meaning of `SIGHUP' is that a dialup line has been
1767 disconnected.) *Note Deleting Processes::.
1769 If the buffer is visiting a file and contains unsaved changes,
1770 `kill-buffer' asks the user to confirm before the buffer is killed.
1771 It does this even if not called interactively. To prevent the
1772 request for confirmation, clear the modified flag before calling
1773 `kill-buffer'. *Note Buffer Modification::.
1775 Killing a buffer that is already dead has no effect.
1777 (kill-buffer "foo.unchanged")
1779 (kill-buffer "foo.changed")
1781 ---------- Buffer: Minibuffer ----------
1782 Buffer foo.changed modified; kill anyway? (yes or no) yes
1783 ---------- Buffer: Minibuffer ----------
1787 - Variable: kill-buffer-query-functions
1788 After confirming unsaved changes, `kill-buffer' calls the functions
1789 in the list `kill-buffer-query-functions', in order of appearance,
1790 with no arguments. The buffer being killed is the current buffer
1791 when they are called. The idea is that these functions ask for
1792 confirmation from the user for various nonstandard reasons. If
1793 any of them returns `nil', `kill-buffer' spares the buffer's life.
1795 - Variable: kill-buffer-hook
1796 This is a normal hook run by `kill-buffer' after asking all the
1797 questions it is going to ask, just before actually killing the
1798 buffer. The buffer to be killed is current when the hook
1799 functions run. *Note Hooks::.
1801 - Variable: buffer-offer-save
1802 This variable, if non-`nil' in a particular buffer, tells
1803 `save-buffers-kill-emacs' and `save-some-buffers' to offer to save
1804 that buffer, just as they offer to save file-visiting buffers. The
1805 variable `buffer-offer-save' automatically becomes buffer-local
1806 when set for any reason. *Note Buffer-Local Variables::.
1809 File: lispref.info, Node: Indirect Buffers, Prev: Killing Buffers, Up: Buffers
1814 An "indirect buffer" shares the text of some other buffer, which is
1815 called the "base buffer" of the indirect buffer. In some ways it is
1816 the analogue, for buffers, of a symbolic link among files. The base
1817 buffer may not itself be an indirect buffer. One base buffer may have
1818 several "indirect children".
1820 The text of the indirect buffer is always identical to the text of
1821 its base buffer; changes made by editing either one are visible
1822 immediately in the other.
1824 But in all other respects, the indirect buffer and its base buffer
1825 are completely separate. They have different names, different values of
1826 point and mark, different narrowing, different markers and extents
1827 (though inserting or deleting text in either buffer relocates the
1828 markers and extents for both), different major modes, and different
1829 local variables. Unlike in FSF Emacs, XEmacs indirect buffers do not
1830 automatically share text properties among themselves and their base
1833 An indirect buffer cannot visit a file, but its base buffer can. If
1834 you try to save the indirect buffer, that actually works by saving the
1837 Killing an indirect buffer has no effect on its base buffer. Killing
1838 the base buffer kills all its indirect children.
1840 - Command: make-indirect-buffer base-buffer name
1841 This creates an indirect buffer named NAME whose base buffer is
1842 BASE-BUFFER. The argument BASE-BUFFER may be a buffer or a string.
1844 If BASE-BUFFER is an indirect buffer, its base buffer is used as
1845 the base for the new buffer.
1847 (make-indirect-buffer "*scratch*" "indirect")
1848 => #<buffer "indirect">
1850 - Function: buffer-base-buffer &optional buffer
1851 This function returns the base buffer of BUFFER. If BUFFER is not
1852 indirect, the value is `nil'. Otherwise, the value is another
1853 buffer, which is never an indirect buffer. If BUFFER is not
1854 supplied, it defaults to the current buffer.
1856 (buffer-base-buffer (get-buffer "indirect"))
1857 => #<buffer "*scratch*">
1859 - Function: buffer-indirect-children &optional buffer
1860 This function returns a list of all indirect buffers whose base
1861 buffer is BUFFER. If BUFFER is indirect, the return value will
1862 always be `nil'; see `make-indirect-buffer'. If BUFFER is not
1863 supplied, it defaults to the current buffer.
1865 (buffer-indirect-children (get-buffer "*scratch*"))
1866 => (#<buffer "indirect">)
1869 File: lispref.info, Node: Windows, Next: Frames, Prev: Buffers, Up: Top
1874 This chapter describes most of the functions and variables related to
1875 Emacs windows. See *Note Display::, for information on how text is
1876 displayed in windows.
1880 * Basic Windows:: Basic information on using windows.
1881 * Splitting Windows:: Splitting one window into two windows.
1882 * Deleting Windows:: Deleting a window gives its space to other windows.
1883 * Selecting Windows:: The selected window is the one that you edit in.
1884 * Cyclic Window Ordering:: Moving around the existing windows.
1885 * Buffers and Windows:: Each window displays the contents of a buffer.
1886 * Displaying Buffers:: Higher-lever functions for displaying a buffer
1887 and choosing a window for it.
1888 * Choosing Window:: How to choose a window for displaying a buffer.
1889 * Window Point:: Each window has its own location of point.
1890 * Window Start:: The display-start position controls which text
1891 is on-screen in the window.
1892 * Vertical Scrolling:: Moving text up and down in the window.
1893 * Horizontal Scrolling:: Moving text sideways on the window.
1894 * Size of Window:: Accessing the size of a window.
1895 * Position of Window:: Accessing the position of a window.
1896 * Resizing Windows:: Changing the size of a window.
1897 * Window Configurations:: Saving and restoring the state of the screen.
1900 File: lispref.info, Node: Basic Windows, Next: Splitting Windows, Up: Windows
1902 Basic Concepts of Emacs Windows
1903 ===============================
1905 A "window" in XEmacs is the physical area of the screen in which a
1906 buffer is displayed. The term is also used to refer to a Lisp object
1907 that represents that screen area in XEmacs Lisp. It should be clear
1908 from the context which is meant.
1910 XEmacs groups windows into frames. A frame represents an area of
1911 screen available for XEmacs to use. Each frame always contains at least
1912 one window, but you can subdivide it vertically or horizontally into
1913 multiple nonoverlapping Emacs windows.
1915 In each frame, at any time, one and only one window is designated as
1916 "selected within the frame". The frame's cursor appears in that
1917 window. At ant time, one frame is the selected frame; and the window
1918 selected within that frame is "the selected window". The selected
1919 window's buffer is usually the current buffer (except when `set-buffer'
1920 has been used). *Note Current Buffer::.
1922 For practical purposes, a window exists only while it is displayed in
1923 a frame. Once removed from the frame, the window is effectively deleted
1924 and should not be used, _even though there may still be references to
1925 it_ from other Lisp objects. Restoring a saved window configuration is
1926 the only way for a window no longer on the screen to come back to life.
1927 (*Note Deleting Windows::.)
1929 Each window has the following attributes:
1937 * window edges with respect to the frame or screen
1939 * the buffer it displays
1941 * position within the buffer at the upper left of the window
1943 * amount of horizontal scrolling, in columns
1949 * how recently the window was selected
1951 Users create multiple windows so they can look at several buffers at
1952 once. Lisp libraries use multiple windows for a variety of reasons, but
1953 most often to display related information. In Rmail, for example, you
1954 can move through a summary buffer in one window while the other window
1955 shows messages one at a time as they are reached.
1957 The meaning of "window" in XEmacs is similar to what it means in the
1958 context of general-purpose window systems such as X, but not identical.
1959 The X Window System places X windows on the screen; XEmacs uses one or
1960 more X windows as frames, and subdivides them into Emacs windows. When
1961 you use XEmacs on a character-only terminal, XEmacs treats the whole
1962 terminal screen as one frame.
1964 Most window systems support arbitrarily located overlapping windows.
1965 In contrast, Emacs windows are "tiled"; they never overlap, and
1966 together they fill the whole screen or frame. Because of the way in
1967 which XEmacs creates new windows and resizes them, you can't create
1968 every conceivable tiling of windows on an Emacs frame. *Note Splitting
1969 Windows::, and *Note Size of Window::.
1971 *Note Display::, for information on how the contents of the window's
1972 buffer are displayed in the window.
1974 - Function: windowp object
1975 This function returns `t' if OBJECT is a window.
1978 File: lispref.info, Node: Splitting Windows, Next: Deleting Windows, Prev: Basic Windows, Up: Windows
1983 The functions described here are the primitives used to split a window
1984 into two windows. Two higher level functions sometimes split a window,
1985 but not always: `pop-to-buffer' and `display-buffer' (*note Displaying
1988 The functions described here do not accept a buffer as an argument.
1989 The two "halves" of the split window initially display the same buffer
1990 previously visible in the window that was split.
1992 - Function: one-window-p &optional nomini which-frames which-devices
1993 This function returns non-`nil' if there is only one window. The
1994 argument NOMINI, if non-`nil', means don't count the minibuffer
1995 even if it is active; otherwise, the minibuffer window is
1996 included, if active, in the total number of windows which is
1997 compared against one.
1999 The remaining arguments controls which set of windows are counted,
2000 as with `next-window'.
2002 - Command: split-window &optional window size horizontal
2003 This function splits WINDOW into two windows. The original window
2004 WINDOW remains the selected window, but occupies only part of its
2005 former screen area. The rest is occupied by a newly created
2006 window which is returned as the value of this function.
2008 If HORIZONTAL is non-`nil', then WINDOW splits into two side by
2009 side windows. The original window WINDOW keeps the leftmost SIZE
2010 columns, and gives the rest of the columns to the new window.
2011 Otherwise, it splits into windows one above the other, and WINDOW
2012 keeps the upper SIZE lines and gives the rest of the lines to the
2013 new window. The original window is therefore the left-hand or
2014 upper of the two, and the new window is the right-hand or lower.
2016 If WINDOW is omitted or `nil', then the selected window is split.
2017 If SIZE is omitted or `nil', then WINDOW is divided evenly into
2018 two parts. (If there is an odd line, it is allocated to the new
2019 window.) When `split-window' is called interactively, all its
2020 arguments are `nil'.
2022 The following example starts with one window on a frame that is 50
2023 lines high by 80 columns wide; then the window is split.
2025 (setq w (selected-window))
2026 => #<window 8 on windows.texi>
2027 (window-edges) ; Edges in order:
2028 => (0 0 80 50) ; left-top-right-bottom
2030 ;; Returns window created
2031 (setq w2 (split-window w 15))
2032 => #<window 28 on windows.texi>
2034 => (0 15 80 50) ; Bottom window;
2037 => (0 0 80 15) ; Top window
2039 The frame looks like this:
2051 Next, the top window is split horizontally:
2053 (setq w3 (split-window w 35 t))
2054 => #<window 32 on windows.texi>
2056 => (35 0 80 15) ; Left edge at column 35
2058 => (0 0 35 15) ; Right edge at column 35
2060 => (0 15 80 50) ; Bottom window unchanged
2062 Now, the screen looks like this:
2075 Normally, Emacs indicates the border between two side-by-side
2076 windows with a scroll bar (*note Scroll Bars: X Frame Properties.)
2077 or `|' characters. The display table can specify alternative
2078 border characters; see *Note Display Tables::.
2080 - Command: split-window-vertically &optional size
2081 This function splits the selected window into two windows, one
2082 above the other, leaving the selected window with SIZE lines.
2084 This function is simply an interface to `split-window'. Here is
2085 the complete function definition for it:
2087 (defun split-window-vertically (&optional arg)
2088 "Split current window into two windows, one above the other."
2090 (split-window nil (and arg (prefix-numeric-value arg))))
2092 - Command: split-window-horizontally &optional size
2093 This function splits the selected window into two windows
2094 side-by-side, leaving the selected window with SIZE columns.
2096 This function is simply an interface to `split-window'. Here is
2097 the complete definition for `split-window-horizontally' (except for
2098 part of the documentation string):
2100 (defun split-window-horizontally (&optional arg)
2101 "Split selected window into two windows, side by side..."
2103 (split-window nil (and arg (prefix-numeric-value arg)) t))
2106 File: lispref.info, Node: Deleting Windows, Next: Selecting Windows, Prev: Splitting Windows, Up: Windows
2111 A window remains visible on its frame unless you "delete" it by calling
2112 certain functions that delete windows. A deleted window cannot appear
2113 on the screen, but continues to exist as a Lisp object until there are
2114 no references to it. There is no way to cancel the deletion of a
2115 window aside from restoring a saved window configuration (*note Window
2116 Configurations::). Restoring a window configuration also deletes any
2117 windows that aren't part of that configuration.
2119 When you delete a window, the space it took up is given to one
2120 adjacent sibling. (In Emacs version 18, the space was divided evenly
2121 among all the siblings.)
2123 - Function: window-live-p window
2124 This function returns `nil' if WINDOW is deleted, and `t'
2127 *Warning:* Erroneous information or fatal errors may result from
2128 using a deleted window as if it were live.
2130 - Command: delete-window &optional window force
2131 This function removes WINDOW from the display. If WINDOW is
2132 omitted, then the selected window is deleted. If window is the
2133 only one on its frame, the frame is deleted as well.
2135 Normally, you cannot delete the last non-minibuffer-only frame
2136 (you must use `save-buffers-kill-emacs' or `kill-emacs'); an error
2137 is signaled instead. However, if optional second argument FORCE is
2138 non-`nil', you can delete the last frame. (This will automatically
2139 call `save-buffers-kill-emacs'.)
2141 This function returns `nil'.
2143 When `delete-window' is called interactively, the selected window
2146 - Command: delete-other-windows &optional window
2147 This function makes WINDOW the only window on its frame, by
2148 deleting the other windows in that frame. If WINDOW is omitted or
2149 `nil', then the selected window is used by default.
2151 The result is `nil'.
2153 - Command: delete-windows-on buffer &optional which-frames
2155 This function deletes all windows showing BUFFER. If there are no
2156 windows showing BUFFER, it does nothing.
2158 `delete-windows-on' operates frame by frame. If a frame has
2159 several windows showing different buffers, then those showing
2160 BUFFER are removed, and the others expand to fill the space. If
2161 all windows in some frame are showing BUFFER (including the case
2162 where there is only one window), then the frame reverts to having a
2163 single window showing another buffer chosen with `other-buffer'.
2164 *Note The Buffer List::.
2166 The argument WHICH-FRAMES controls which frames to operate on:
2169 Delete all windows showing BUFFER in any frame.
2172 Delete only windows showing BUFFER in the selected frame.
2175 Delete all windows showing BUFFER in any visible frame.
2178 Delete all windows showing BUFFER in any visible frame.
2181 If it is a frame, delete all windows showing BUFFER in that
2184 *Warning:* This is similar to, but not identical to, the meaning
2185 of the WHICH-FRAMES argument to `next-window'; the meanings of
2186 `nil' and `t' are reversed.
2188 The optional argument WHICH-DEVICES further clarifies on which
2189 devices to search for frames as specified by WHICH-FRAMES. This
2190 value is only meaningful if WHICH-FRAMES is not `t'.
2193 Consider all devices on the selected console.
2196 Consider only the one device DEVICE.
2199 Consider all devices on CONSOLE.
2202 Consider all devices with device type DEVICE-TYPE.
2205 Consider all devices on window system consoles.
2208 Consider all devices without restriction.
2210 This function always returns `nil'.
2213 File: lispref.info, Node: Selecting Windows, Next: Cyclic Window Ordering, Prev: Deleting Windows, Up: Windows
2218 When a window is selected, the buffer in the window becomes the current
2219 buffer, and the cursor will appear in it.
2221 - Function: selected-window &optional device
2222 This function returns the selected window. This is the window in
2223 which the cursor appears and to which many commands apply. Each
2224 separate device can have its own selected window, which is
2225 remembered as focus changes from device to device. Optional
2226 argument DEVICE specifies which device to return the selected
2227 window for, and defaults to the selected device.
2229 - Function: select-window window &optional norecord
2230 This function makes WINDOW the selected window. The cursor then
2231 appears in WINDOW (on redisplay). The buffer being displayed in
2232 WINDOW is immediately designated the current buffer.
2234 If optional argument NORECORD is non-`nil' then the global and
2235 per-frame buffer orderings are not modified, as by the function
2238 The return value is WINDOW.
2240 (setq w (next-window))
2242 => #<window 65 on windows.texi>
2244 - Special Form: save-selected-window forms...
2245 This special form records the selected window, executes FORMS in
2246 sequence, then restores the earlier selected window. It does not
2247 save or restore anything about the sizes, arrangement or contents
2248 of windows; therefore, if the FORMS change them, the changes are
2251 The following functions choose one of the windows on the screen,
2252 offering various criteria for the choice.
2254 - Function: get-lru-window &optional which-frames which-devices
2255 This function returns the window least recently "used" (that is,
2256 selected). The selected window is always the most recently used
2259 The selected window can be the least recently used window if it is
2260 the only window. A newly created window becomes the least
2261 recently used window until it is selected. A minibuffer window is
2264 By default, only the windows in the selected frame are considered.
2265 The optional argument WHICH-FRAMES changes this behavior. Here
2266 are the possible values and their meanings:
2269 Consider all the windows in the selected windows's frame,
2270 plus the minibuffer used by that frame even if it lies in
2274 Consider all windows in all existing frames.
2277 Consider all windows in all visible frames. (To get useful
2278 results, you must ensure WINDOW is in a visible frame.)
2281 Consider all windows in all visible or iconified frames.
2284 Consider all windows on frame FRAME.
2287 Consider precisely the windows in the selected window's
2288 frame, and no others.
2290 The optional argument WHICH-DEVICES further clarifies on which
2291 devices to search for frames as specified by WHICH-FRAMES. This
2292 value is only meaningful if WHICH-FRAMES is non-`nil'.
2295 Consider all devices on the selected console.
2298 Consider only the one device DEVICE.
2301 Consider all devices on CONSOLE.
2304 Consider all devices with device type DEVICE-TYPE.
2307 Consider all devices on window system consoles.
2310 Consider all devices without restriction.
2313 - Function: get-largest-window &optional which-frames which-devices
2314 This function returns the window with the largest area (height
2315 times width). If there are no side-by-side windows, then this is
2316 the window with the most lines. A minibuffer window is never a
2319 If there are two windows of the same size, then the function
2320 returns the window that is first in the cyclic ordering of windows
2321 (see following section), starting from the selected window.
2323 The remaining arguments control which set of windows are
2324 considered. See `next-window', above.
2327 File: lispref.info, Node: Cyclic Window Ordering, Next: Buffers and Windows, Prev: Selecting Windows, Up: Windows
2329 Cyclic Ordering of Windows
2330 ==========================
2332 When you use the command `C-x o' (`other-window') to select the next
2333 window, it moves through all the windows on the screen in a specific
2334 cyclic order. For any given configuration of windows, this order never
2335 varies. It is called the "cyclic ordering of windows".
2337 This ordering generally goes from top to bottom, and from left to
2338 right. But it may go down first or go right first, depending on the
2339 order in which the windows were split.
2341 If the first split was vertical (into windows one above each other),
2342 and then the subwindows were split horizontally, then the ordering is
2343 left to right in the top of the frame, and then left to right in the
2344 next lower part of the frame, and so on. If the first split was
2345 horizontal, the ordering is top to bottom in the left part, and so on.
2346 In general, within each set of siblings at any level in the window tree,
2347 the order is left to right, or top to bottom.
2349 - Function: next-window &optional window minibuf which-frames
2351 This function returns the window following WINDOW in the cyclic
2352 ordering of windows. This is the window that `C-x o' would select
2353 if typed when WINDOW is selected. If WINDOW is the only window
2354 visible, then this function returns WINDOW. If omitted, WINDOW
2355 defaults to the selected window.
2357 The value of the argument MINIBUF determines whether the
2358 minibuffer is included in the window order. Normally, when
2359 MINIBUF is `nil', the minibuffer is included if it is currently
2360 active; this is the behavior of `C-x o'. (The minibuffer window
2361 is active while the minibuffer is in use. *Note Minibuffers::.)
2363 If MINIBUF is `t', then the cyclic ordering includes the
2364 minibuffer window even if it is not active.
2366 If MINIBUF is neither `t' nor `nil', then the minibuffer window is
2367 not included even if it is active.
2369 By default, only the windows in the selected frame are considered.
2370 The optional argument WHICH-FRAMES changes this behavior. Here
2371 are the possible values and their meanings:
2374 Consider all the windows in WINDOW's frame, plus the
2375 minibuffer used by that frame even if it lies in some other
2379 Consider all windows in all existing frames.
2382 Consider all windows in all visible frames. (To get useful
2383 results, you must ensure WINDOW is in a visible frame.)
2386 Consider all windows in all visible or iconified frames.
2389 Consider all windows on frame FRAME.
2392 Consider precisely the windows in WINDOW's frame, and no
2395 The optional argument WHICH-DEVICES further clarifies on which
2396 devices to search for frames as specified by WHICH-FRAMES. This
2397 value is only meaningful if WHICH-FRAMES is non-`nil'.
2400 Consider all devices on the selected console.
2403 Consider only the one device DEVICE.
2406 Consider all devices on CONSOLE.
2409 Consider all devices with device type DEVICE-TYPE.
2412 Consider all devices on window system consoles.
2415 Consider all devices without restriction.
2417 If you use consistent values for MINIBUF, WHICH-FRAMES, and
2418 WHICH-DEVICES, you can use `next-window' to iterate through the
2419 entire cycle of acceptable windows, eventually ending up back at
2420 the window you started with. `previous-window' traverses the same
2421 cycle, in the reverse order.
2423 This example assumes there are two windows, both displaying the
2424 buffer `windows.texi':
2427 => #<window 56 on windows.texi>
2428 (next-window (selected-window))
2429 => #<window 52 on windows.texi>
2430 (next-window (next-window (selected-window)))
2431 => #<window 56 on windows.texi>
2433 - Function: previous-window &optional window minibuf which-frames
2435 This function returns the window preceding WINDOW in the cyclic
2436 ordering of windows. The other arguments specify which windows to
2437 include in the cycle, as in `next-window'.
2439 - Command: other-window count &optional which-frames which-devices
2440 This function selects the COUNTth following window in the cyclic
2441 order. If COUNT is negative, then it selects the -COUNTth
2442 preceding window. It returns `nil'.
2444 In an interactive call, COUNT is the numeric prefix argument.
2446 The other arguments specify which windows to include in the cycle,
2447 as in `next-window'.
2449 - Function: walk-windows function &optional minibuf which-frames
2451 This function cycles through all windows, calling `function' once
2452 for each window with the window as its sole argument.
2454 The other arguments specify which windows to cycle through, as in
2458 File: lispref.info, Node: Buffers and Windows, Next: Displaying Buffers, Prev: Cyclic Window Ordering, Up: Windows
2463 This section describes low-level functions to examine windows or to
2464 display buffers in windows in a precisely controlled fashion. *Note
2465 Displaying Buffers::, for related functions that find a window to use
2466 and specify a buffer for it. The functions described there are easier
2467 to use than these, but they employ heuristics in choosing or creating a
2468 window; use these functions when you need complete control.
2470 - Function: set-window-buffer window buffer-or-name &optional norecord
2471 This function makes WINDOW display BUFFER-OR-NAME as its contents.
2472 BUFFER-OR-NAME can be a buffer or a buffer name.
2474 With non-`nil' optional argument NORECORD, do not modify the
2475 global or per-frame buffer ordering.
2477 This function returns `nil'.
2479 (set-window-buffer (selected-window) "foo")
2482 - Function: window-buffer &optional window
2483 This function returns the buffer that WINDOW is displaying. If
2484 WINDOW is omitted, this function returns the buffer for the
2488 => #<buffer windows.texi>
2490 - Function: get-buffer-window buffer-or-name &optional which-frames
2492 This function returns a window currently displaying
2493 BUFFER-OR-NAME, or `nil' if there is none. If there are several
2494 such windows, then the function returns the first one in the
2495 cyclic ordering of windows, starting from the selected window.
2496 *Note Cyclic Window Ordering::.
2498 The remaining arguments control which windows to consider. They
2499 have the same meaning as for `next-window'.
2502 File: lispref.info, Node: Displaying Buffers, Next: Choosing Window, Prev: Buffers and Windows, Up: Windows
2504 Displaying Buffers in Windows
2505 =============================
2507 In this section we describe convenient functions that choose a window
2508 automatically and use it to display a specified buffer. These functions
2509 can also split an existing window in certain circumstances. We also
2510 describe variables that parameterize the heuristics used for choosing a
2511 window. *Note Buffers and Windows::, for low-level functions that give
2512 you more precise control.
2514 Do not use the functions in this section in order to make a buffer
2515 current so that a Lisp program can access or modify it; they are too
2516 drastic for that purpose, since they change the display of buffers in
2517 windows, which is gratuitous and will surprise the user. Instead, use
2518 `set-buffer' (*note Current Buffer::) and `save-excursion' (*note
2519 Excursions::), which designate buffers as current for programmed access
2520 without affecting the display of buffers in windows.
2522 - Command: switch-to-buffer buffer-or-name &optional norecord
2523 This function makes BUFFER-OR-NAME the current buffer, and also
2524 displays the buffer in the selected window. This means that a
2525 human can see the buffer and subsequent keyboard commands will
2526 apply to it. Contrast this with `set-buffer', which makes
2527 BUFFER-OR-NAME the current buffer but does not display it in the
2528 selected window. *Note Current Buffer::.
2530 If BUFFER-OR-NAME does not identify an existing buffer, then a new
2531 buffer by that name is created. The major mode for the new buffer
2532 is set according to the variable `default-major-mode'. *Note Auto
2535 Normally the specified buffer is put at the front of the buffer
2536 list. This affects the operation of `other-buffer'. However, if
2537 NORECORD is non-`nil', this is not done. *Note The Buffer List::.
2539 The `switch-to-buffer' function is often used interactively, as
2540 the binding of `C-x b'. It is also used frequently in programs.
2541 It always returns `nil'.
2543 - Command: switch-to-buffer-other-window buffer-or-name
2544 This function makes BUFFER-OR-NAME the current buffer and displays
2545 it in a window not currently selected. It then selects that
2546 window. The handling of the buffer is the same as in
2549 The currently selected window is absolutely never used to do the
2550 job. If it is the only window, then it is split to make a
2551 distinct window for this purpose. If the selected window is
2552 already displaying the buffer, then it continues to do so, but
2553 another window is nonetheless found to display it in as well.
2555 - Function: pop-to-buffer buffer-or-name &optional other-window
2557 This function makes BUFFER-OR-NAME the current buffer and switches
2558 to it in some window, preferably not the window previously
2559 selected. The "popped-to" window becomes the selected window
2562 If the variable `pop-up-frames' is non-`nil', `pop-to-buffer'
2563 looks for a window in any visible frame already displaying the
2564 buffer; if there is one, it returns that window and makes it be
2565 selected within its frame. If there is none, it creates a new
2566 frame and displays the buffer in it.
2568 If `pop-up-frames' is `nil', then `pop-to-buffer' operates
2569 entirely within the selected frame. (If the selected frame has
2570 just a minibuffer, `pop-to-buffer' operates within the most
2571 recently selected frame that was not just a minibuffer.)
2573 If the variable `pop-up-windows' is non-`nil', windows may be
2574 split to create a new window that is different from the original
2575 window. For details, see *Note Choosing Window::.
2577 If OTHER-WINDOW is non-`nil', `pop-to-buffer' finds or creates
2578 another window even if BUFFER-OR-NAME is already visible in the
2579 selected window. Thus BUFFER-OR-NAME could end up displayed in
2580 two windows. On the other hand, if BUFFER-OR-NAME is already
2581 displayed in the selected window and OTHER-WINDOW is `nil', then
2582 the selected window is considered sufficient display for
2583 BUFFER-OR-NAME, so that nothing needs to be done.
2585 All the variables that affect `display-buffer' affect
2586 `pop-to-buffer' as well. *Note Choosing Window::.
2588 If BUFFER-OR-NAME is a string that does not name an existing
2589 buffer, a buffer by that name is created. The major mode for the
2590 new buffer is set according to the variable `default-major-mode'.
2591 *Note Auto Major Mode::.
2593 If ON-FRAME is non-`nil', it is the frame to pop to this buffer on.
2595 An example use of this function is found at the end of *Note
2598 - Command: replace-buffer-in-windows buffer &optional which-frames
2600 This function replaces BUFFER with some other buffer in all
2601 windows displaying it. The other buffer used is chosen with
2602 `other-buffer'. In the usual applications of this function, you
2603 don't care which other buffer is used; you just want to make sure
2604 that BUFFER is no longer displayed.
2606 The optional arguments WHICH-FRAMES and WHICH-DEVICES have the
2607 same meaning as with `delete-windows-on'.
2609 This function returns `nil'.
2612 File: lispref.info, Node: Choosing Window, Next: Window Point, Prev: Displaying Buffers, Up: Windows
2614 Choosing a Window for Display
2615 =============================
2617 This section describes the basic facility that chooses a window to
2618 display a buffer in--`display-buffer'. All the higher-level functions
2619 and commands use this subroutine. Here we describe how to use
2620 `display-buffer' and how to customize it.
2622 - Command: display-buffer buffer-or-name &optional not-this-window
2624 This command makes BUFFER-OR-NAME appear in some window, like
2625 `pop-to-buffer', but it does not select that window and does not
2626 make the buffer current. The identity of the selected window is
2627 unaltered by this function.
2629 BUFFER-OR-NAME can be a buffer or the name of one.
2631 If NOT-THIS-WINDOW is non-`nil', it means to display the specified
2632 buffer in a window other than the selected one, even if it is
2633 already on display in the selected window. This can cause the
2634 buffer to appear in two windows at once. Otherwise, if
2635 BUFFER-OR-NAME is already being displayed in any window, that is
2636 good enough, so this function does nothing.
2638 If OVERRIDE-FRAME is non-`nil', display on that frame instead of
2639 the current frame (or the dedicated frame).
2641 `display-buffer' returns the window chosen to display
2644 Precisely how `display-buffer' finds or creates a window depends on
2645 the variables described below.
2647 A window can be marked as "dedicated" to a particular buffer. Then
2648 XEmacs will not automatically change which buffer appears in the
2649 window, such as `display-buffer' might normally do.
2651 - Function: window-dedicated-p window
2652 This function returns WINDOW's dedicated object, usually `t' or
2655 - Function: set-window-buffer-dedicated window buffer
2656 This function makes WINDOW display BUFFER and be dedicated to that
2657 buffer. Then XEmacs will not automatically change which buffer
2658 appears in WINDOW. If BUFFER is `nil', this function makes WINDOW
2659 not be dedicated (but doesn't change which buffer appears in it
2662 - User Option: pop-up-windows
2663 This variable controls whether `display-buffer' makes new windows.
2664 If it is non-`nil' and there is only one window, then that window
2665 is split. If it is `nil', then `display-buffer' does not split
2666 the single window, but uses it whole.
2668 - User Option: split-height-threshold
2669 This variable determines when `display-buffer' may split a window,
2670 if there are multiple windows. `display-buffer' always splits the
2671 largest window if it has at least this many lines. If the largest
2672 window is not this tall, it is split only if it is the sole window
2673 and `pop-up-windows' is non-`nil'.
2675 - User Option: pop-up-frames
2676 This variable controls whether `display-buffer' makes new frames.
2677 If it is non-`nil', `display-buffer' looks for an existing window
2678 already displaying the desired buffer, on any visible frame. If
2679 it finds one, it returns that window. Otherwise it makes a new
2680 frame. The variables `pop-up-windows' and
2681 `split-height-threshold' do not matter if `pop-up-frames' is
2684 If `pop-up-frames' is `nil', then `display-buffer' either splits a
2685 window or reuses one.
2687 *Note Frames::, for more information.
2689 - Variable: pop-up-frame-function
2690 This variable specifies how to make a new frame if `pop-up-frames'
2693 Its value should be a function of no arguments. When
2694 `display-buffer' makes a new frame, it does so by calling that
2695 function, which should return a frame. The default value of the
2696 variable is a function that creates a frame using properties from
2697 `pop-up-frame-plist'.
2699 - Variable: pop-up-frame-plist
2700 This variable holds a plist specifying frame properties used when
2701 `display-buffer' makes a new frame. *Note Frame Properties::, for
2702 more information about frame properties.
2704 - Variable: special-display-buffer-names
2705 A list of buffer names for buffers that should be displayed
2706 specially. If the buffer's name is in this list, `display-buffer'
2707 handles the buffer specially.
2709 By default, special display means to give the buffer a dedicated
2712 If an element is a list, instead of a string, then the CAR of the
2713 list is the buffer name, and the rest of the list says how to
2714 create the frame. There are two possibilities for the rest of the
2715 list. It can be a plist, specifying frame properties, or it can
2716 contain a function and arguments to give to it. (The function's
2717 first argument is always the buffer to be displayed; the arguments
2718 from the list come after that.)
2720 - Variable: special-display-regexps
2721 A list of regular expressions that specify buffers that should be
2722 displayed specially. If the buffer's name matches any of the
2723 regular expressions in this list, `display-buffer' handles the
2726 By default, special display means to give the buffer a dedicated
2729 If an element is a list, instead of a string, then the CAR of the
2730 list is the regular expression, and the rest of the list says how
2731 to create the frame. See above, under
2732 `special-display-buffer-names'.
2734 - Variable: special-display-function
2735 This variable holds the function to call to display a buffer
2736 specially. It receives the buffer as an argument, and should
2737 return the window in which it is displayed.
2739 The default value of this variable is
2740 `special-display-popup-frame'.
2742 - Function: special-display-popup-frame buffer
2743 This function makes BUFFER visible in a frame of its own. If
2744 BUFFER is already displayed in a window in some frame, it makes
2745 the frame visible and raises it, to use that window. Otherwise, it
2746 creates a frame that will be dedicated to BUFFER.
2748 This function uses an existing window displaying BUFFER whether or
2749 not it is in a frame of its own; but if you set up the above
2750 variables in your init file, before BUFFER was created, then
2751 presumably the window was previously made by this function.
2753 - User Option: special-display-frame-plist
2754 This variable holds frame properties for
2755 `special-display-popup-frame' to use when it creates a frame.
2757 - Variable: same-window-buffer-names
2758 A list of buffer names for buffers that should be displayed in the
2759 selected window. If the buffer's name is in this list,
2760 `display-buffer' handles the buffer by switching to it in the
2763 - Variable: same-window-regexps
2764 A list of regular expressions that specify buffers that should be
2765 displayed in the selected window. If the buffer's name matches
2766 any of the regular expressions in this list, `display-buffer'
2767 handles the buffer by switching to it in the selected window.
2769 - Variable: display-buffer-function
2770 This variable is the most flexible way to customize the behavior of
2771 `display-buffer'. If it is non-`nil', it should be a function
2772 that `display-buffer' calls to do the work. The function should
2773 accept two arguments, the same two arguments that `display-buffer'
2774 received. It should choose or create a window, display the
2775 specified buffer, and then return the window.
2777 This hook takes precedence over all the other options and hooks
2780 A window can be marked as "dedicated" to its buffer. Then
2781 `display-buffer' does not try to use that window.
2783 - Function: window-dedicated-p window
2784 This function returns `t' if WINDOW is marked as dedicated;
2787 - Function: set-window-dedicated-p window flag
2788 This function marks WINDOW as dedicated if FLAG is non-`nil', and
2789 nondedicated otherwise.
2792 File: lispref.info, Node: Window Point, Next: Window Start, Prev: Choosing Window, Up: Windows
2797 Each window has its own value of point, independent of the value of
2798 point in other windows displaying the same buffer. This makes it useful
2799 to have multiple windows showing one buffer.
2801 * The window point is established when a window is first created; it
2802 is initialized from the buffer's point, or from the window point
2803 of another window opened on the buffer if such a window exists.
2805 * Selecting a window sets the value of point in its buffer to the
2806 window's value of point. Conversely, deselecting a window sets
2807 the window's value of point from that of the buffer. Thus, when
2808 you switch between windows that display a given buffer, the point
2809 value for the selected window is in effect in the buffer, while
2810 the point values for the other windows are stored in those windows.
2812 * As long as the selected window displays the current buffer, the
2813 window's point and the buffer's point always move together; they
2816 * *Note Positions::, for more details on buffer positions.
2818 As far as the user is concerned, point is where the cursor is, and
2819 when the user switches to another buffer, the cursor jumps to the
2820 position of point in that buffer.
2822 - Function: window-point &optional window
2823 This function returns the current position of point in WINDOW.
2824 For a non-selected window, this is the value point would have (in
2825 that window's buffer) if that window were selected.
2827 When WINDOW is the selected window and its buffer is also the
2828 current buffer, the value returned is the same as the value of
2829 point in that buffer.
2831 Strictly speaking, it would be more correct to return the
2832 "top-level" value of point, outside of any `save-excursion' forms.
2833 But that value is hard to find.
2835 - Function: set-window-point window position
2836 This function positions point in WINDOW at position POSITION in
2840 File: lispref.info, Node: Window Start, Next: Vertical Scrolling, Prev: Window Point, Up: Windows
2842 The Window Start Position
2843 =========================
2845 Each window contains a marker used to keep track of a buffer position
2846 that specifies where in the buffer display should start. This position
2847 is called the "display-start" position of the window (or just the
2848 "start"). The character after this position is the one that appears at
2849 the upper left corner of the window. It is usually, but not
2850 inevitably, at the beginning of a text line.
2852 - Function: window-start &optional window
2853 This function returns the display-start position of window WINDOW.
2854 If WINDOW is `nil', the selected window is used. For example,
2859 When you create a window, or display a different buffer in it, the
2860 display-start position is set to a display-start position recently
2861 used for the same buffer, or 1 if the buffer doesn't have any.
2863 For a realistic example, see the description of `count-lines' in
2866 - Function: window-end &optional window guarantee
2867 This function returns the position of the end of the display in
2868 window WINDOW. If WINDOW is `nil', the selected window is used.
2870 Simply changing the buffer text or setting `window-start' does not
2871 update the value that `window-end' returns. The value is updated
2872 only when Emacs redisplays and redisplay actually finishes.
2874 If the last redisplay of WINDOW was preempted, and did not finish,
2875 Emacs does not know the position of the end of display in that
2876 window. In that case, this function returns a value that is not
2877 correct. In a future version, `window-end' will return `nil' in
2880 If optional arg GUARANTEE is non-`nil', the return value is
2881 guaranteed to be the same as `window-end' would return at the end
2882 of the next full redisplay assuming nothing else changes in the
2883 meantime. This function is potentially much slower with this flag
2887 - Function: set-window-start window position &optional noforce
2888 This function sets the display-start position of WINDOW to
2889 POSITION in WINDOW's buffer. It returns POSITION.
2891 The display routines insist that the position of point be visible
2892 when a buffer is displayed. Normally, they change the
2893 display-start position (that is, scroll the window) whenever
2894 necessary to make point visible. However, if you specify the
2895 start position with this function using `nil' for NOFORCE, it
2896 means you want display to start at POSITION even if that would put
2897 the location of point off the screen. If this does place point
2898 off screen, the display routines move point to the left margin on
2899 the middle line in the window.
2901 For example, if point is 1 and you set the start of the window
2902 to 2, then point would be "above" the top of the window. The
2903 display routines will automatically move point if it is still 1
2904 when redisplay occurs. Here is an example:
2906 ;; Here is what `foo' looks like before executing
2907 ;; the `set-window-start' expression.
2909 ---------- Buffer: foo ----------
2910 -!-This is the contents of buffer foo.
2916 ---------- Buffer: foo ----------
2920 (1+ (window-start)))
2923 ;; Here is what `foo' looks like after executing
2924 ;; the `set-window-start' expression.
2925 ---------- Buffer: foo ----------
2926 his is the contents of buffer foo.
2932 ---------- Buffer: foo ----------
2934 If NOFORCE is non-`nil', and POSITION would place point off screen
2935 at the next redisplay, then redisplay computes a new window-start
2936 position that works well with point, and thus POSITION is not used.
2938 - Function: pos-visible-in-window-p &optional position window
2939 This function returns `t' if POSITION is within the range of text
2940 currently visible on the screen in WINDOW. It returns `nil' if
2941 POSITION is scrolled vertically out of view. The argument
2942 POSITION defaults to the current position of point; WINDOW, to the
2943 selected window. Here is an example:
2945 (or (pos-visible-in-window-p
2946 (point) (selected-window))
2949 The `pos-visible-in-window-p' function considers only vertical
2950 scrolling. If POSITION is out of view only because WINDOW has
2951 been scrolled horizontally, `pos-visible-in-window-p' returns `t'.
2952 *Note Horizontal Scrolling::.
2955 File: lispref.info, Node: Vertical Scrolling, Next: Horizontal Scrolling, Prev: Window Start, Up: Windows
2960 Vertical scrolling means moving the text up or down in a window. It
2961 works by changing the value of the window's display-start location. It
2962 may also change the value of `window-point' to keep it on the screen.
2964 In the commands `scroll-up' and `scroll-down', the directions "up"
2965 and "down" refer to the motion of the text in the buffer at which you
2966 are looking through the window. Imagine that the text is written on a
2967 long roll of paper and that the scrolling commands move the paper up
2968 and down. Thus, if you are looking at text in the middle of a buffer
2969 and repeatedly call `scroll-down', you will eventually see the
2970 beginning of the buffer.
2972 Some people have urged that the opposite convention be used: they
2973 imagine that the window moves over text that remains in place. Then
2974 "down" commands would take you to the end of the buffer. This view is
2975 more consistent with the actual relationship between windows and the
2976 text in the buffer, but it is less like what the user sees. The
2977 position of a window on the terminal does not move, and short scrolling
2978 commands clearly move the text up or down on the screen. We have chosen
2979 names that fit the user's point of view.
2981 The scrolling functions (aside from `scroll-other-window') have
2982 unpredictable results if the current buffer is different from the buffer
2983 that is displayed in the selected window. *Note Current Buffer::.
2985 - Command: scroll-up &optional lines
2986 This function scrolls the text in the selected window upward LINES
2987 lines. If LINES is negative, scrolling is actually downward.
2989 If LINES is `nil' (or omitted), then the length of scroll is
2990 `next-screen-context-lines' lines less than the usable height of
2991 the window (not counting its modeline).
2993 `scroll-up' returns `nil'.
2995 - Command: scroll-down &optional lines
2996 This function scrolls the text in the selected window downward
2997 LINES lines. If LINES is negative, scrolling is actually upward.
2999 If LINES is omitted or `nil', then the length of the scroll is
3000 `next-screen-context-lines' lines less than the usable height of
3001 the window (not counting its mode line).
3003 `scroll-down' returns `nil'.
3005 - Command: scroll-other-window &optional lines
3006 This function scrolls the text in another window upward LINES
3007 lines. Negative values of LINES, or `nil', are handled as in
3010 You can specify a buffer to scroll with the variable
3011 `other-window-scroll-buffer'. When the selected window is the
3012 minibuffer, the next window is normally the one at the top left
3013 corner. You can specify a different window to scroll with the
3014 variable `minibuffer-scroll-window'. This variable has no effect
3015 when any other window is selected. *Note Minibuffer Misc::.
3017 When the minibuffer is active, it is the next window if the
3018 selected window is the one at the bottom right corner. In this
3019 case, `scroll-other-window' attempts to scroll the minibuffer. If
3020 the minibuffer contains just one line, it has nowhere to scroll
3021 to, so the line reappears after the echo area momentarily displays
3022 the message "Beginning of buffer".
3024 - Variable: other-window-scroll-buffer
3025 If this variable is non-`nil', it tells `scroll-other-window'
3026 which buffer to scroll.
3028 - User Option: scroll-step
3029 This variable controls how scrolling is done automatically when
3030 point moves off the screen. If the value is zero, then redisplay
3031 scrolls the text to center point vertically in the window. If the
3032 value is a positive integer N, then redisplay brings point back on
3033 screen by scrolling N lines in either direction, if possible;
3034 otherwise, it centers point. The default value is zero.
3036 - User Option: scroll-conservatively
3037 This variable controls how many lines Emacs tries to scroll before
3038 recentering. If you set it to a small number, then when you move
3039 point a short distance off the screen, XEmacs will scroll the
3040 screen just far enough to bring point back on screen, provided
3041 that does not exceed `scroll-conservatively' lines. This variable
3042 overrides the redisplay preemption.
3044 - User Option: next-screen-context-lines
3045 The value of this variable is the number of lines of continuity to
3046 retain when scrolling by full screens. For example, `scroll-up'
3047 with an argument of `nil' scrolls so that this many lines at the
3048 bottom of the window appear instead at the top. The default value
3051 - Command: recenter &optional location window
3052 This function scrolls WINDOW (which defaults to the selected
3053 window) to put the text where point is located at a specified
3054 vertical position within the window.
3056 If LOCATION is a nonnegative number, it puts the line containing
3057 point LOCATION lines down from the top of the window. If LOCATION
3058 is a negative number, then it counts upward from the bottom of the
3059 window, so that -1 stands for the last usable line in the window.
3060 If LOCATION is a non-`nil' list, then it stands for the line in
3061 the middle of the window.
3063 If LOCATION is `nil', `recenter' puts the line containing point in
3064 the middle of the window, then clears and redisplays the entire
3067 When `recenter' is called interactively, LOCATION is the raw
3068 prefix argument. Thus, typing `C-u' as the prefix sets the
3069 LOCATION to a non-`nil' list, while typing `C-u 4' sets LOCATION
3070 to 4, which positions the current line four lines from the top.
3072 With an argument of zero, `recenter' positions the current line at
3073 the top of the window. This action is so handy that some people
3074 make a separate key binding to do this. For example,
3076 (defun line-to-top-of-window ()
3077 "Scroll current line to top of window.
3078 Replaces three keystroke sequence C-u 0 C-l."
3082 (global-set-key [kp-multiply] 'line-to-top-of-window)
3085 File: lispref.info, Node: Horizontal Scrolling, Next: Size of Window, Prev: Vertical Scrolling, Up: Windows
3087 Horizontal Scrolling
3088 ====================
3090 Because we read English first from top to bottom and second from left
3091 to right, horizontal scrolling is not like vertical scrolling. Vertical
3092 scrolling involves selection of a contiguous portion of text to display.
3093 Horizontal scrolling causes part of each line to go off screen. The
3094 amount of horizontal scrolling is therefore specified as a number of
3095 columns rather than as a position in the buffer. It has nothing to do
3096 with the display-start position returned by `window-start'.
3098 Usually, no horizontal scrolling is in effect; then the leftmost
3099 column is at the left edge of the window. In this state, scrolling to
3100 the right is meaningless, since there is no data to the left of the
3101 screen to be revealed by it; so this is not allowed. Scrolling to the
3102 left is allowed; it scrolls the first columns of text off the edge of
3103 the window and can reveal additional columns on the right that were
3104 truncated before. Once a window has a nonzero amount of leftward
3105 horizontal scrolling, you can scroll it back to the right, but only so
3106 far as to reduce the net horizontal scroll to zero. There is no limit
3107 to how far left you can scroll, but eventually all the text will
3108 disappear off the left edge.
3110 - Command: scroll-left &optional count
3111 This function scrolls the selected window COUNT columns to the
3112 left (or to the right if COUNT is negative). The return value is
3113 the total amount of leftward horizontal scrolling in effect after
3114 the change--just like the value returned by `window-hscroll'
3117 - Command: scroll-right &optional count
3118 This function scrolls the selected window COUNT columns to the
3119 right (or to the left if COUNT is negative). The return value is
3120 the total amount of leftward horizontal scrolling in effect after
3121 the change--just like the value returned by `window-hscroll'
3124 Once you scroll a window as far right as it can go, back to its
3125 normal position where the total leftward scrolling is zero,
3126 attempts to scroll any farther right have no effect.
3128 - Function: window-hscroll &optional window
3129 This function returns the total leftward horizontal scrolling of
3130 WINDOW--the number of columns by which the text in WINDOW is
3131 scrolled left past the left margin.
3133 The value is never negative. It is zero when no horizontal
3134 scrolling has been done in WINDOW (which is usually the case).
3136 If WINDOW is `nil', the selected window is used.
3145 - Function: set-window-hscroll window columns
3146 This function sets the number of columns from the left margin that
3147 WINDOW is scrolled to the value of COLUMNS. The argument COLUMNS
3148 should be zero or positive; if not, it is taken as zero.
3150 The value returned is COLUMNS.
3152 (set-window-hscroll (selected-window) 10)
3155 Here is how you can determine whether a given position POSITION is
3156 off the screen due to horizontal scrolling:
3158 (defun hscroll-on-screen (window position)
3160 (goto-char position)
3162 (>= (- (current-column) (window-hscroll window)) 0)
3163 (< (- (current-column) (window-hscroll window))
3164 (window-width window)))))
3167 File: lispref.info, Node: Size of Window, Next: Position of Window, Prev: Horizontal Scrolling, Up: Windows
3169 The Size of a Window
3170 ====================
3172 An Emacs window is rectangular, and its size information consists of
3173 the height (in lines or pixels) and the width (in character positions
3174 or pixels). The modeline is included in the height. The pixel width
3175 and height values include scrollbars and margins, while the
3176 line/character-position values do not.
3178 Note that the height in lines, and the width in characters, are
3179 determined by dividing the corresponding pixel value by the height or
3180 width of the default font in that window (if this is a variable-width
3181 font, the average width is used). The resulting values may or may not
3182 represent the actual number of lines in the window, or the actual number
3183 of character positions in any particular line, esp. if there are pixmaps
3184 or various different fonts in the window.
3186 The following functions return size information about a window:
3188 - Function: window-height &optional window
3189 This function returns the number of lines in WINDOW, including its
3190 modeline but not including the horizontal scrollbar, if any (this
3191 is different from `window-pixel-height'). If WINDOW is `nil', the
3192 function uses the selected window.
3196 (split-window-vertically)
3197 => #<window on "windows.texi" 0x679b>
3201 - Function: window-width &optional window
3202 This function returns the number of columns in WINDOW, not
3203 including any left margin, right margin, or vertical scrollbar
3204 (this is different from `window-pixel-width'). If WINDOW is
3205 `nil', the function uses the selected window.
3211 (split-window-horizontally)
3212 => #<window on "windows.texi" 0x7538>
3216 Note that after splitting the window into two side-by-side windows,
3217 the width of each window is less the half the width of the original
3218 window because a vertical scrollbar appeared between the windows,
3219 occupying two columns worth of space. Also, the height shrunk by one
3220 because horizontal scrollbars appeared that weren't there before.
3221 (Horizontal scrollbars appear only when lines are truncated, not when
3222 they wrap. This is usually the case for horizontally split windows but
3223 not for full-frame windows. You can change this using the variables
3224 `truncate-lines' and `truncate-partial-width-windows'.)
3226 - Function: window-pixel-height &optional window
3227 This function returns the height of WINDOW in pixels, including
3228 its modeline and horizontal scrollbar, if any. If WINDOW is
3229 `nil', the function uses the selected window.
3231 (window-pixel-height)
3233 (split-window-vertically)
3234 => #<window on "windows.texi" 0x68a6>
3235 (window-pixel-height)
3238 - Function: window-pixel-width &optional window
3239 This function returns the width of WINDOW in pixels, including any
3240 left margin, right margin, or vertical scrollbar that may be
3241 displayed alongside it. If WINDOW is `nil', the function uses the
3244 (window-pixel-width)
3246 (window-pixel-height)
3248 (split-window-horizontally)
3249 => #<window on "windows.texi" 0x7538>
3250 (window-pixel-width)
3252 (window-pixel-height)
3255 - Function: window-text-area-pixel-height &optional window
3256 This function returns the height in pixels of the text displaying
3257 portion of WINDOW, which defaults to the selected window. Unlike
3258 `window-pixel-height', the space occupied by the modeline and
3259 horizontal scrollbar, if any, is not counted.
3261 - Function: window-text-area-pixel-width &optional window
3262 This function returns the width in pixels of the text displaying
3263 portion of WINDOW, which defaults to the selected window. Unlike
3264 `window-pixel-width', the space occupied by the vertical scrollbar
3265 and divider, if any, is not counted.
3267 - Function: window-displayed-text-pixel-height &optional window
3269 This function returns the height in pixels of the text displayed in
3270 WINDOW, which defaults to the selected window. Unlike
3271 `window-text-area-pixel-height', any blank space below the end of
3272 the buffer is not included. If optional argument NOCLIPPED is
3273 non-`nil', any space occupied by clipped lines will not be
3277 File: lispref.info, Node: Position of Window, Next: Resizing Windows, Prev: Size of Window, Up: Windows
3279 The Position of a Window
3280 ========================
3282 XEmacs provides functions to determine the absolute location of windows
3283 within a frame, and the relative location of a window in comparison to
3284 other windows in the same frame.
3286 - Function: window-pixel-edges &optional window
3287 This function returns a list of the pixel edge coordinates of
3288 WINDOW. If WINDOW is `nil', the selected window is used.
3290 The order of the list is `(LEFT TOP RIGHT BOTTOM)', all elements
3291 relative to 0, 0 at the top left corner of WINDOW's frame. The
3292 element RIGHT of the value is one more than the rightmost pixel
3293 used by WINDOW (including any left margin, right margin, or
3294 vertical scrollbar displayed alongside it), and BOTTOM is one more
3295 than the bottommost pixel used by WINDOW (including any modeline
3296 or horizontal scrollbar displayed above or below it). The frame
3297 area does not include any frame menubars, toolbars, or gutters
3298 that may be displayed; thus, for example, if there is only one
3299 window on the frame, the values for LEFT and TOP will always be 0.
3301 If WINDOW is at the upper left corner of its frame, RIGHT and
3302 BOTTOM are the same as the values returned by
3303 `(window-pixel-width)' and `(window-pixel-height)' respectively,
3304 and LEFT and TOP are zero.
3306 There is no longer a function `window-edges' because it does not
3307 make sense in a world with variable-width and variable-height lines, as
3308 are allowed in XEmacs.
3310 - Function: window-highest-p window
3311 This function returns non-`nil' if WINDOW is along the top of its
3314 - Function: window-lowest-p window
3315 This function returns non-`nil' if WINDOW is along the bottom of
3318 - Function: window-text-area-pixel-edges &optional window
3319 This function allows one to determine the location of the
3320 text-displaying portion of WINDOW, which defaults to the selected
3321 window, with respect to the top left corner of the window. It
3322 returns a list of integer pixel positions `(left top right
3323 bottom)', all relative to `(0,0)' at the top left corner of the
3327 File: lispref.info, Node: Resizing Windows, Next: Window Configurations, Prev: Position of Window, Up: Windows
3329 Changing the Size of a Window
3330 =============================
3332 The window size functions fall into two classes: high-level commands
3333 that change the size of windows and low-level functions that access
3334 window size. XEmacs does not permit overlapping windows or gaps between
3335 windows, so resizing one window affects other windows.
3337 - Command: enlarge-window count &optional horizontal window
3338 This function makes the selected window COUNT lines taller,
3339 stealing lines from neighboring windows. It takes the lines from
3340 one window at a time until that window is used up, then takes from
3341 another. If a window from which lines are stolen shrinks below
3342 `window-min-height' lines, that window disappears.
3344 If HORIZONTAL is non-`nil', this function makes WINDOW wider by
3345 COUNT columns, stealing columns instead of lines. If a window
3346 from which columns are stolen shrinks below `window-min-width'
3347 columns, that window disappears.
3349 If the requested size would exceed that of the window's frame,
3350 then the function makes the window occupy the entire height (or
3351 width) of the frame.
3353 If COUNT is negative, this function shrinks the window by -COUNT
3354 lines or columns. If that makes the window smaller than the
3355 minimum size (`window-min-height' and `window-min-width'),
3356 `enlarge-window' deletes the window.
3358 If WINDOW is non-`nil', it specifies a window to change instead of
3359 the selected window.
3361 `enlarge-window' returns `nil'.
3363 - Command: enlarge-window-horizontally columns
3364 This function makes the selected window COLUMNS wider. It could
3365 be defined as follows:
3367 (defun enlarge-window-horizontally (columns)
3368 (enlarge-window columns t))
3370 - Command: enlarge-window-pixels count &optional side window
3371 This function makes the selected window COUNT pixels larger. When
3372 called from Lisp, optional second argument SIDE non-`nil' means to
3373 grow sideways COUNT pixels, and optional third argument WINDOW
3374 specifies the window to change instead of the selected window.
3376 - Command: shrink-window count &optional horizontal window
3377 This function is like `enlarge-window' but negates the argument
3378 COUNT, making the selected window smaller by giving lines (or
3379 columns) to the other windows. If the window shrinks below
3380 `window-min-height' or `window-min-width', then it disappears.
3382 If COUNT is negative, the window is enlarged by -COUNT lines or
3385 If WINDOW is non-`nil', it specifies a window to change instead of
3386 the selected window.
3388 - Command: shrink-window-horizontally columns
3389 This function makes the selected window COLUMNS narrower. It
3390 could be defined as follows:
3392 (defun shrink-window-horizontally (columns)
3393 (shrink-window columns t))
3395 - Command: shrink-window-pixels count &optional side window
3396 This function makes the selected window COUNT pixels smaller.
3397 When called from Lisp, optional second argument SIDE non-`nil'
3398 means to shrink sideways COUNT pixels, and optional third argument
3399 WINDOW specifies the window to change instead of the selected
3402 The following two variables constrain the window-size-changing
3403 functions to a minimum height and width.
3405 - User Option: window-min-height
3406 The value of this variable determines how short a window may become
3407 before it is automatically deleted. Making a window smaller than
3408 `window-min-height' automatically deletes it, and no window may be
3409 created shorter than this. The absolute minimum height is two
3410 (allowing one line for the mode line, and one line for the buffer
3411 display). Actions that change window sizes reset this variable to
3412 two if it is less than two. The default value is 4.
3414 - User Option: window-min-width
3415 The value of this variable determines how narrow a window may
3416 become before it automatically deleted. Making a window smaller
3417 than `window-min-width' automatically deletes it, and no window
3418 may be created narrower than this. The absolute minimum width is
3419 one; any value below that is ignored. The default value is 10.
3421 - Variable: window-size-change-functions
3422 This variable holds a list of functions to be called if the size
3423 of any window changes for any reason. The functions are called
3424 just once per redisplay, and just once for each frame on which
3425 size changes have occurred.
3427 Each function receives the frame as its sole argument. There is no
3428 direct way to find out which windows changed size, or precisely
3429 how; however, if your size-change function keeps track, after each
3430 change, of the windows that interest you, you can figure out what
3431 has changed by comparing the old size data with the new.
3433 Creating or deleting windows counts as a size change, and therefore
3434 causes these functions to be called. Changing the frame size also
3435 counts, because it changes the sizes of the existing windows.
3437 It is not a good idea to use `save-window-excursion' in these
3438 functions, because that always counts as a size change, and it
3439 would cause these functions to be called over and over. In most
3440 cases, `save-selected-window' is what you need here.
3443 File: lispref.info, Node: Window Configurations, Prev: Resizing Windows, Up: Windows
3445 Window Configurations
3446 =====================
3448 A "window configuration" records the entire layout of a frame--all
3449 windows, their sizes, which buffers they contain, what part of each
3450 buffer is displayed, and the values of point and the mark. You can
3451 bring back an entire previous layout by restoring a window
3452 configuration previously saved.
3454 If you want to record all frames instead of just one, use a frame
3455 configuration instead of a window configuration. *Note Frame
3458 - Function: current-window-configuration &optional frame
3459 This function returns a new object representing the current window
3460 configuration of FRAME, namely the number of windows, their sizes
3461 and current buffers, which window is the selected window, and for
3462 each window the displayed buffer, the display-start position, and
3463 the positions of point and the mark. An exception is made for
3464 point in the current buffer, whose value is not saved.
3466 FRAME defaults to the selected frame.
3468 - Function: set-window-configuration configuration
3469 This function restores the configuration of XEmacs's windows and
3470 buffers to the state specified by CONFIGURATION. The argument
3471 CONFIGURATION must be a value that was previously returned by
3472 `current-window-configuration'.
3474 This function always counts as a window size change and triggers
3475 execution of the `window-size-change-functions'. (It doesn't know
3476 how to tell whether the new configuration actually differs from
3479 Here is a way of using this function to get the same effect as
3480 `save-window-excursion':
3482 (let ((config (current-window-configuration)))
3484 (progn (split-window-vertically nil)
3486 (set-window-configuration config)))
3488 - Special Form: save-window-excursion forms...
3489 This special form records the window configuration, executes FORMS
3490 in sequence, then restores the earlier window configuration. The
3491 window configuration includes the value of point and the portion
3492 of the buffer that is visible. It also includes the choice of
3493 selected window. However, it does not include the value of point
3494 in the current buffer; use `save-excursion' if you wish to
3497 Don't use this construct when `save-selected-window' is all you
3500 Exit from `save-window-excursion' always triggers execution of the
3501 `window-size-change-functions'. (It doesn't know how to tell
3502 whether the restored configuration actually differs from the one in
3503 effect at the end of the FORMS.)
3505 The return value is the value of the final form in FORMS. For
3509 => #<window 25 on control.texi>
3510 (setq w (selected-window))
3511 => #<window 19 on control.texi>
3512 (save-window-excursion
3513 (delete-other-windows w)
3514 (switch-to-buffer "foo")
3517 ;; The frame is now split again.
3519 - Function: window-configuration-p object
3520 This function returns `t' if OBJECT is a window configuration.
3522 Primitives to look inside of window configurations would make sense,
3523 but none are implemented. It is not clear they are useful enough to be
3527 File: lispref.info, Node: Frames, Next: Consoles and Devices, Prev: Windows, Up: Top
3532 A FRAME is a rectangle on the screen that contains one or more XEmacs
3533 windows (*note Windows::). A frame initially contains a single main
3534 window (plus perhaps an echo area), which you can subdivide vertically
3535 or horizontally into smaller windows. Each window is associated with a
3536 modeline (*note Modeline Format::), and optionally two scrollbars
3537 (*note Scrollbars::). By default the vertical scrollbar is on, the
3538 horizontal scrollbar is off.
3540 The frame may also contain menubars (*note Menubar::), toolbars
3541 (*note Toolbar Intro::), and gutters (*note Gutter Intro::). By default
3542 there is one of each at the top of the frame, with menubar topmost,
3543 toolbar next, and gutter lowest, immediately above the windows.
3544 (Warning: the gutter is a new, experimental, and unstable feature of
3545 XEmacs version 21.2.)
3547 When XEmacs runs on a text-only terminal, it starts with one "TTY
3548 frame". If you create additional ones, XEmacs displays one and only
3549 one at any given time--on the terminal screen, of course.
3551 When XEmacs communicates directly with an X server, it does not have
3552 a TTY frame; instead, it starts with a single "X window frame". It can
3553 display multiple X window frames at the same time, each in its own X
3556 - Function: framep object
3557 This predicate returns `t' if OBJECT is a frame, and `nil'
3562 * Creating Frames:: Creating additional frames.
3563 * Frame Properties:: Controlling frame size, position, font, etc.
3564 * Frame Titles:: Automatic updating of frame titles.
3565 * Deleting Frames:: Frames last until explicitly deleted.
3566 * Finding All Frames:: How to examine all existing frames.
3567 * Frames and Windows:: A frame contains windows;
3568 display of text always works through windows.
3569 * Minibuffers and Frames:: How a frame finds the minibuffer to use.
3570 * Input Focus:: Specifying the selected frame.
3571 * Visibility of Frames:: Frames may be visible or invisible, or icons.
3572 * Raising and Lowering:: Raising a frame makes it hide other X windows;
3573 lowering it makes the others hide them.
3574 * Frame Configurations:: Saving the state of all frames.
3575 * Frame Hooks:: Hooks for customizing frame behavior.
3577 *Note Display::, for related information.
3580 File: lispref.info, Node: Creating Frames, Next: Frame Properties, Up: Frames
3585 To create a new frame, call the function `make-frame'.
3587 - Command: make-frame &optional props device
3588 This function creates a new frame on DEVICE, if DEVICE permits
3589 creation of frames. (An X server does; an ordinary terminal does
3590 not (yet).) DEVICE defaults to the selected device if omitted.
3591 *Note Consoles and Devices::.
3593 The argument PROPS is a property list (a list of alternating
3594 keyword-value specifications) of properties for the new frame. (An
3595 alist is accepted for backward compatibility but should not be
3596 passed in.) Any properties not mentioned in PROPS default
3597 according to the value of the variable `default-frame-plist'. For
3598 X devices, properties not specified in `default-frame-plist'
3599 default in turn from `default-x-frame-plist' and, if not specified
3600 there, from the X resources. For TTY devices,
3601 `default-tty-frame-plist' is consulted as well as
3602 `default-frame-plist'.
3604 The set of possible properties depends in principle on what kind of
3605 window system XEmacs uses to display its frames. *Note X Frame
3606 Properties::, for documentation of individual properties you can
3607 specify when creating an X window frame.
3610 File: lispref.info, Node: Frame Properties, Next: Frame Titles, Prev: Creating Frames, Up: Frames
3615 A frame has many properties that control its appearance and behavior.
3616 Just what properties a frame has depends on which display mechanism it
3619 Frame properties exist for the sake of window systems. A terminal
3620 frame has few properties, mostly for compatibility's sake; only the
3621 height, width and `buffer-predicate' properties really do something.
3625 * Property Access:: How to change a frame's properties.
3626 * Initial Properties:: Specifying frame properties when you make a frame.
3627 * X Frame Properties:: List of frame properties.
3628 * Size and Position:: Changing the size and position of a frame.
3629 * Frame Name:: The name of a frame (as opposed to its title).
3632 File: lispref.info, Node: Property Access, Next: Initial Properties, Up: Frame Properties
3634 Access to Frame Properties
3635 --------------------------
3637 These functions let you read and change the properties of a frame.
3639 - Function: frame-properties &optional frame
3640 This function returns a plist listing all the properties of FRAME
3643 - Function: frame-property frame property &optional default
3644 This function returns FRAME's value for the property PROPERTY, or
3645 DEFAULT if there is no such property.
3647 - Function: set-frame-properties frame plist
3648 This function alters the properties of frame FRAME based on the
3649 elements of property list PLIST. If you don't mention a property
3650 in PLIST, its value doesn't change.
3652 - Function: set-frame-property frame property value
3653 This function sets the property PROPERTY of frame FRAME to the
3657 File: lispref.info, Node: Initial Properties, Next: X Frame Properties, Prev: Property Access, Up: Frame Properties
3659 Initial Frame Properties
3660 ------------------------
3662 You can specify the properties for the initial startup frame by setting
3663 `initial-frame-plist' in your `.emacs' file.
3665 - Variable: initial-frame-plist
3666 This variable's value is a plist of alternating property-value
3667 pairs used when creating the initial X window frame.
3669 XEmacs creates the initial frame before it reads your `~/.emacs'
3670 file. After reading that file, XEmacs checks
3671 `initial-frame-plist', and applies the property settings in the
3672 altered value to the already created initial frame.
3674 If these settings affect the frame geometry and appearance, you'll
3675 see the frame appear with the wrong ones and then change to the
3676 specified ones. If that bothers you, you can specify the same
3677 geometry and appearance with X resources; those do take affect
3678 before the frame is created. *Note X Resources: (xemacs)Resources
3681 X resource settings typically apply to all frames. If you want to
3682 specify some X resources solely for the sake of the initial frame,
3683 and you don't want them to apply to subsequent frames, here's how
3684 to achieve this: specify properties in `default-frame-plist' to
3685 override the X resources for subsequent frames; then, to prevent
3686 these from affecting the initial frame, specify the same
3687 properties in `initial-frame-plist' with values that match the X
3690 If these properties specify a separate minibuffer-only frame via a
3691 `minibuffer' property of `nil', and you have not yet created one,
3692 XEmacs creates one for you.
3694 - Variable: minibuffer-frame-plist
3695 This variable's value is a plist of properties used when creating
3696 an initial minibuffer-only frame--if such a frame is needed,
3697 according to the properties for the main initial frame.
3699 - Variable: default-frame-plist
3700 This is a plist specifying default values of frame properties for
3701 subsequent XEmacs frames (not the initial ones).
3703 See also `special-display-frame-plist', in *Note Choosing Window::.
3705 If you use options that specify window appearance when you invoke
3706 XEmacs, they take effect by adding elements to `default-frame-plist'.
3707 One exception is `-geometry', which adds the specified position to
3708 `initial-frame-plist' instead. *Note Command Arguments:
3709 (xemacs)Command Arguments.
3712 File: lispref.info, Node: X Frame Properties, Next: Size and Position, Prev: Initial Properties, Up: Frame Properties
3714 X Window Frame Properties
3715 -------------------------
3717 Just what properties a frame has depends on what display mechanism it
3718 uses. Here is a table of the properties of an X window frame; of these,
3719 `name', `height', `width', and `buffer-predicate' provide meaningful
3720 information in non-X frames.
3723 The name of the frame. Most window managers display the frame's
3724 name in the frame's border, at the top of the frame. If you don't
3725 specify a name, and you have more than one frame, XEmacs sets the
3726 frame name based on the buffer displayed in the frame's selected
3729 If you specify the frame name explicitly when you create the
3730 frame, the name is also used (instead of the name of the XEmacs
3731 executable) when looking up X resources for the frame.
3734 The display on which to open this frame. It should be a string of
3735 the form `"HOST:DPY.SCREEN"', just like the `DISPLAY' environment
3739 The screen position of the left edge, in pixels, with respect to
3740 the left edge of the screen. The value may be a positive number
3741 POS, or a list of the form `(+ POS)' which permits specifying a
3744 A negative number -POS, or a list of the form `(- POS)', actually
3745 specifies the position of the right edge of the window with
3746 respect to the right edge of the screen. A positive value of POS
3747 counts toward the left. If the property is a negative integer
3748 -POS then POS is positive!
3751 The screen position of the top edge, in pixels, with respect to the
3752 top edge of the screen. The value may be a positive number POS,
3753 or a list of the form `(+ POS)' which permits specifying a
3756 A negative number -POS, or a list of the form `(- POS)', actually
3757 specifies the position of the bottom edge of the window with
3758 respect to the bottom edge of the screen. A positive value of POS
3759 counts toward the top. If the property is a negative integer -POS
3760 then POS is positive!
3763 The screen position of the left edge _of the frame's icon_, in
3764 pixels, counting from the left edge of the screen. This takes
3765 effect if and when the frame is iconified.
3768 The screen position of the top edge _of the frame's icon_, in
3769 pixels, counting from the top edge of the screen. This takes
3770 effect if and when the frame is iconified.
3773 Non-`nil' if the screen position of the frame was explicitly
3774 requested by the user (for example, with the `-geometry' option).
3775 Nothing automatically makes this property non-`nil'; it is up to
3776 Lisp programs that call `make-frame' to specify this property as
3777 well as specifying the `left' and `top' properties.
3780 The height of the frame contents, in characters. (To get the
3781 height in pixels, call `frame-pixel-height'; see *Note Size and
3785 The width of the frame contents, in characters. (To get the
3786 height in pixels, call `frame-pixel-width'; see *Note Size and
3790 The number of the X window for the frame.
3793 Whether this frame has its own minibuffer. The value `t' means
3794 yes, `nil' means no, `only' means this frame is just a minibuffer.
3795 If the value is a minibuffer window (in some other frame), the
3796 new frame uses that minibuffer. (Minibuffer-only and
3797 minibuffer-less frames are not yet implemented in XEmacs.)
3800 The buffer-predicate function for this frame. The function
3801 `other-buffer' uses this predicate (from the selected frame) to
3802 decide which buffers it should consider, if the predicate is not
3803 `nil'. It calls the predicate with one arg, a buffer, once for
3804 each buffer; if the predicate returns a non-`nil' value, it
3805 considers that buffer.
3808 The width of the vertical scroll bar, in pixels.
3811 The color for the cursor that shows point.
3814 The color for the border of the frame.
3817 The width in pixels of the window border.
3819 `internal-border-width'
3820 The distance in pixels between text and border.
3823 If non-`nil', this frame's window is never split automatically.
3826 The space in pixels between adjacent lines of text. (Not currently
3830 Whether the frame has a modeline.
3833 File: lispref.info, Node: Size and Position, Next: Frame Name, Prev: X Frame Properties, Up: Frame Properties
3835 Frame Size And Position
3836 -----------------------
3838 You can read or change the size and position of a frame using the frame
3839 properties `left', `top', `height', and `width'. Whatever geometry
3840 properties you don't specify are chosen by the window manager in its
3843 Here are some special features for working with sizes and positions:
3845 - Function: set-frame-position frame left top
3846 This function sets the position of the top left corner of FRAME to
3847 LEFT and TOP. These arguments are measured in pixels, and count
3848 from the top left corner of the screen. Negative property values
3849 count up or rightward from the top left corner of the screen.
3851 - Function: frame-height &optional frame
3852 - Function: frame-width &optional frame
3853 These functions return the height and width of FRAME, measured in
3854 lines and columns. If you don't supply FRAME, they use the
3857 - Function: frame-pixel-height &optional frame
3858 - Function: frame-pixel-width &optional frame
3859 These functions return the height and width of FRAME, measured in
3860 pixels. If you don't supply FRAME, they use the selected frame.
3862 - Function: set-frame-size frame cols rows &optional pretend
3863 This function sets the size of FRAME, measured in characters; COLS
3864 and ROWS specify the new width and height. (If PRETEND is
3865 non-`nil', it means that redisplay should act as if the frame's
3866 size is COLS by ROWS, but the actual size of the frame should not
3867 be changed. You should not normally use this option.)
3869 You can also use the functions `set-frame-height' and
3870 `set-frame-width' to set the height and width individually. The frame
3871 is the first argument and the size (in rows or columns) is the second.
3872 (There is an optional third argument, PRETEND, which has the same
3873 purpose as the corresponding argument in `set-frame-size'.)
3876 File: lispref.info, Node: Frame Name, Prev: Size and Position, Up: Frame Properties
3878 The Name of a Frame (As Opposed to Its Title)
3879 ---------------------------------------------
3881 Under X, every frame has a name, which is not the same as the title of
3882 the frame. A frame's name is used to look up its resources and does
3883 not normally change over the lifetime of a frame. It is perfectly
3884 allowable, and quite common, for multiple frames to have the same name.
3886 - Function: frame-name &optional frame
3887 This function returns the name of FRAME, which defaults to the
3888 selected frame if not specified. The name of a frame can also be
3889 obtained from the frame's properties. *Note Frame Properties::.
3891 - Variable: default-frame-name
3892 This variable holds the default name to assign to newly-created
3893 frames. This can be overridden by arguments to `make-frame'. This
3897 File: lispref.info, Node: Frame Titles, Next: Deleting Frames, Prev: Frame Properties, Up: Frames
3902 Every frame has a title; most window managers display the frame title at
3903 the top of the frame. You can specify an explicit title with the
3904 `name' frame property. But normally you don't specify this explicitly,
3905 and XEmacs computes the title automatically.
3907 XEmacs computes the frame title based on a template stored in the
3908 variable `frame-title-format'.
3910 - Variable: frame-title-format
3911 This variable specifies how to compute a title for a frame when
3912 you have not explicitly specified one.
3914 The variable's value is actually a modeline construct, just like
3915 `modeline-format'. *Note Modeline Data::.
3917 - Variable: frame-icon-title-format
3918 This variable specifies how to compute the title for an iconified
3919 frame, when you have not explicitly specified the frame title.
3920 This title appears in the icon itself.
3922 - Function: x-set-frame-icon-pixmap frame pixmap &optional mask
3923 This function sets the icon of the given frame to the given image
3924 instance, which should be an image instance object (as returned by
3925 `make-image-instance'), a glyph object (as returned by
3926 `make-glyph'), or `nil'. If a glyph object is given, the glyph
3927 will be instantiated on the frame to produce an image instance
3930 If the given image instance has a mask, that will be used as the
3931 icon mask; however, not all window managers support this.
3933 The window manager is also not required to support color pixmaps,
3934 only bitmaps (one plane deep).
3936 If the image instance does not have a mask, then the optional
3937 third argument may be the image instance to use as the mask (it
3938 must be one plane deep). *Note Glyphs::.
3941 File: lispref.info, Node: Deleting Frames, Next: Finding All Frames, Prev: Frame Titles, Up: Frames
3946 Frames remain potentially visible until you explicitly "delete" them.
3947 A deleted frame cannot appear on the screen, but continues to exist as
3948 a Lisp object until there are no references to it.
3950 - Command: delete-frame &optional frame force
3951 This function deletes the frame FRAME. By default, FRAME is the
3954 A frame may not be deleted if its minibuffer is used by other
3955 frames. Normally, you cannot delete the last non-minibuffer-only
3956 frame (you must use `save-buffers-kill-emacs' or `kill-emacs').
3957 However, if optional second argument FORCE is non-`nil', you can
3958 delete the last frame. (This will automatically call
3959 `save-buffers-kill-emacs'.)
3961 - Function: frame-live-p frame
3962 The function `frame-live-p' returns non-`nil' if the frame FRAME
3963 has not been deleted.
3966 File: lispref.info, Node: Finding All Frames, Next: Frames and Windows, Prev: Deleting Frames, Up: Frames
3971 - Function: frame-list
3972 The function `frame-list' returns a list of all the frames that
3973 have not been deleted. It is analogous to `buffer-list' for
3974 buffers. The list that you get is newly created, so modifying the
3975 list doesn't have any effect on the internals of XEmacs.
3977 - Function: device-frame-list &optional device
3978 This function returns a list of all frames on DEVICE. If DEVICE
3979 is `nil', the selected device will be used.
3981 - Function: visible-frame-list &optional device
3982 This function returns a list of just the currently visible frames.
3983 If DEVICE is specified only frames on that device will be returned.
3984 *Note Visibility of Frames::. (TTY frames always count as
3985 "visible", even though only the selected one is actually
3988 - Function: next-frame &optional frame which-frames which-devices
3989 The function `next-frame' lets you cycle conveniently through all
3990 the frames from an arbitrary starting point. It returns the "next"
3991 frame after FRAME in the cycle. If FRAME defaults to the selected
3994 The second argument, WHICH-FRAMES, says which frames to consider:
3997 Consider only frames that are visible.
4000 Consider only frames that are iconic.
4003 Consider only frames that are invisible (this is different
4007 Consider frames that are visible or iconic.
4010 Consider frames that are invisible or iconic.
4013 Consider all frames except minibuffer-only ones.
4016 Like `visible' but omits minibuffer-only frames.
4019 Like `iconic' but omits minibuffer-only frames.
4022 Like `invisible' but omits minibuffer-only frames.
4024 `visible-iconic-nomini'
4025 Like `visible-iconic' but omits minibuffer-only frames.
4027 `invisible-iconic-nomini'
4028 Like `invisible-iconic' but omits minibuffer-only frames.
4031 Identical to `nomini'.
4034 Consider only the window WINDOW's frame and any frame now
4035 using WINDOW as the minibuffer.
4038 Consider all frames.
4040 The optional argument WHICH-DEVICES further clarifies on which
4041 devices to search for frames as specified by WHICH-FRAMES.
4044 Consider all devices on the selected console.
4047 Consider only the one device DEVICE.
4050 Consider all devices on CONSOLE.
4053 Consider all devices with device type DEVICE-TYPE.
4056 Consider all devices on window system consoles.
4059 Consider all devices without restriction.
4061 - Function: previous-frame &optional frame which-frames which-devices
4062 Like `next-frame', but cycles through all frames in the opposite
4065 See also `next-window' and `previous-window', in *Note Cyclic Window
4069 File: lispref.info, Node: Frames and Windows, Next: Minibuffers and Frames, Prev: Finding All Frames, Up: Frames
4074 Each window is part of one and only one frame; you can get the frame
4075 with `window-frame'.
4077 - Function: frame-root-window &optional frame
4078 This returns the root window of frame FRAME. FRAME defaults to
4079 the selected frame if not specified.
4081 - Function: window-frame &optional window
4082 This function returns the frame that WINDOW is on. WINDOW
4083 defaults to the selected window if omitted.
4085 All the non-minibuffer windows in a frame are arranged in a cyclic
4086 order. The order runs from the frame's top window, which is at the
4087 upper left corner, down and to the right, until it reaches the window at
4088 the lower right corner (always the minibuffer window, if the frame has
4089 one), and then it moves back to the top.
4091 - Function: frame-highest-window &optional frame position
4092 This function returns the topmost, leftmost window of frame FRAME
4093 at position POSITION.
4095 If omitted, FRAME defaults to the currently selected frame.
4097 POSITION is used to distinguish between multiple windows that abut
4098 the top of the frame: 0 means the leftmost window abutting the top
4099 of the frame, 1 the next-leftmost, etc. POSITION can also be less
4100 than zero: -1 means the rightmost window abutting the top of the
4101 frame, -2 the next-rightmost, etc. If omitted, POSITION defaults
4102 to 0, i.e. the leftmost highest window. If there is no window at
4103 the given POSITION, `nil' is returned.
4105 The following three functions work similarly.
4107 - Function: frame-lowest-window &optional frame position
4108 This function returns the lowest window on FRAME which is at
4111 - Function: frame-leftmost-window &optional frame position
4112 This function returns the leftmost window on FRAME which is at
4115 - Function: frame-rightmost-window &optional frame position
4116 This function returns the rightmost window on FRAME which is at
4119 At any time, exactly one window on any frame is "selected within the
4120 frame". The significance of this designation is that selecting the
4121 frame also selects this window. You can get the frame's current
4122 selected window with `frame-selected-window'.
4124 - Function: frame-selected-window &optional frame
4125 This function returns the window on FRAME that is selected within
4126 FRAME. FRAME defaults to the selected frame if not specified.
4128 Conversely, selecting a window for XEmacs with `select-window' also
4129 makes that window selected within its frame. *Note Selecting Windows::.
4131 Another function that (usually) returns one of the windows in a
4132 frame is `minibuffer-window'. *Note Minibuffer Misc::.
4135 File: lispref.info, Node: Minibuffers and Frames, Next: Input Focus, Prev: Frames and Windows, Up: Frames
4137 Minibuffers and Frames
4138 ======================
4140 Normally, each frame has its own minibuffer window at the bottom, which
4141 is used whenever that frame is selected. If the frame has a minibuffer,
4142 you can get it with `minibuffer-window' (*note Minibuffer Misc::).
4144 However, you can also create a frame with no minibuffer. Such a
4145 frame must use the minibuffer window of some other frame. When you
4146 create the frame, you can specify explicitly the minibuffer window to
4147 use (in some other frame). If you don't, then the minibuffer is found
4148 in the frame which is the value of the variable
4149 `default-minibuffer-frame'. Its value should be a frame which does
4152 - Variable: default-minibuffer-frame
4153 This variable specifies the frame to use for the minibuffer
4157 File: lispref.info, Node: Input Focus, Next: Visibility of Frames, Prev: Minibuffers and Frames, Up: Frames
4162 At any time, one frame in XEmacs is the "selected frame". The selected
4163 window always resides on the selected frame. As the focus moves from
4164 device to device, the selected frame on each device is remembered and
4165 restored when the focus moves back to that device.
4167 - Function: selected-frame &optional device
4168 This function returns the selected frame on DEVICE. If DEVICE is
4169 not specified, the selected device will be used. If no frames
4170 exist on the device, `nil' is returned.
4172 The X server normally directs keyboard input to the X window that the
4173 mouse is in. Some window managers use mouse clicks or keyboard events
4174 to "shift the focus" to various X windows, overriding the normal
4175 behavior of the server.
4177 Lisp programs can switch frames "temporarily" by calling the
4178 function `select-frame'. This does not override the window manager;
4179 rather, it escapes from the window manager's control until that control
4180 is somehow reasserted.
4182 When using a text-only terminal, there is no window manager;
4183 therefore, `select-frame' is the only way to switch frames, and the
4184 effect lasts until overridden by a subsequent call to `select-frame'.
4185 Only the selected terminal frame is actually displayed on the terminal.
4186 Each terminal screen except for the initial one has a number, and the
4187 number of the selected frame appears in the mode line after the word
4188 `XEmacs' (*note Modeline Variables::).
4190 - Function: select-frame frame
4191 This function selects frame FRAME, temporarily disregarding the
4192 focus of the X server if any. The selection of FRAME lasts until
4193 the next time the user does something to select a different frame,
4194 or until the next time this function is called.
4196 Note that `select-frame' does not actually cause the window-system
4197 focus to be set to this frame, or the `select-frame-hook' or
4198 `deselect-frame-hook' to be run, until the next time that XEmacs is
4199 waiting for an event.
4201 Also note that when the variable `focus-follows-mouse' is
4202 non-`nil', the frame selection is temporary and is reverted when
4203 the current command terminates, much like the buffer selected by
4204 `set-buffer'. In order to effect a permanent focus change use
4207 - Function: focus-frame frame
4208 This function selects FRAME and gives it the window system focus.
4209 The operation of `focus-frame' is not affected by the value of
4210 `focus-follows-mouse'.
4212 - Special Form: save-selected-frame forms...
4213 This special form records the selected frame, executes FORMS in
4214 sequence, then restores the earlier selected frame. The value
4215 returned is the value of the last form.
4217 - Special Form: with-selected-frame frame forms...
4218 This special form records the selected frame, then selects FRAME
4219 and executes FORMS in sequence. After the last form is finished,
4220 the earlier selected frame is restored. The value returned is the
4221 value of the last form.
4224 File: lispref.info, Node: Visibility of Frames, Next: Raising and Lowering, Prev: Input Focus, Up: Frames
4226 Visibility of Frames
4227 ====================
4229 An frame on a window system may be "visible", "invisible", or
4230 "iconified". If it is visible, you can see its contents. If it is
4231 iconified, the frame's contents do not appear on the screen, but an icon
4232 does. If the frame is invisible, it doesn't show on the screen, not
4235 Visibility is meaningless for TTY frames, since only the selected
4236 one is actually displayed in any case.
4238 - Function: make-frame-visible &optional frame
4239 This function makes frame FRAME visible. If you omit FRAME, it
4240 makes the selected frame visible.
4242 - Function: make-frame-invisible &optional frame force
4243 This function makes frame FRAME invisible.
4245 - Command: iconify-frame &optional frame
4246 This function iconifies frame FRAME.
4248 - Function: Command deiconify-frame &optional frame
4249 This function de-iconifies frame FRAME. Under a window system,
4250 this is equivalent to `make-frame-visible'.
4252 - Function: frame-visible-p &optional frame
4253 This returns whether FRAME is currently "visible" (actually in use
4254 for display). A frame that is not visible is not updated, and, if
4255 it works through a window system, may not show at all.
4257 - Function: frame-iconified-p &optional frame
4258 This returns whether FRAME is iconified. Not all window managers
4259 use icons; some merely unmap the window, so this function is not
4260 the inverse of `frame-visible-p'. It is possible for a frame to
4261 not be visible and not be iconified either. However, if the frame
4262 is iconified, it will not be visible. (Under FSF Emacs, the
4263 functionality of this function is obtained through
4266 - Function: frame-totally-visible-p &optional frame
4267 This returns whether FRAME is not obscured by any other X windows.
4268 On TTY frames, this is the same as `frame-visible-p'.
4271 File: lispref.info, Node: Raising and Lowering, Next: Frame Configurations, Prev: Visibility of Frames, Up: Frames
4273 Raising and Lowering Frames
4274 ===========================
4276 The X Window System uses a desktop metaphor. Part of this metaphor is
4277 the idea that windows are stacked in a notional third dimension
4278 perpendicular to the screen surface, and thus ordered from "highest" to
4279 "lowest". Where two windows overlap, the one higher up covers the one
4280 underneath. Even a window at the bottom of the stack can be seen if no
4281 other window overlaps it.
4283 A window's place in this ordering is not fixed; in fact, users tend
4284 to change the order frequently. "Raising" a window means moving it
4285 "up", to the top of the stack. "Lowering" a window means moving it to
4286 the bottom of the stack. This motion is in the notional third
4287 dimension only, and does not change the position of the window on the
4290 You can raise and lower XEmacs's X windows with these functions:
4292 - Command: raise-frame &optional frame
4293 This function raises frame FRAME.
4295 - Command: lower-frame &optional frame
4296 This function lowers frame FRAME.
4298 You can also specify auto-raise (raising automatically when a frame
4299 is selected) or auto-lower (lowering automatically when it is
4300 deselected). Under X, most ICCCM-compliant window managers will have
4301 an option to do this for you, but the following variables are provided
4302 in case you're using a broken WM. (Under FSF Emacs, the same
4303 functionality is provided through the `auto-raise' and `auto-lower'
4306 - Variable: auto-raise-frame
4307 This variable's value is `t' if frames will be raised to the top
4310 - Variable: auto-lower-frame
4311 This variable's value is `t' if frames will be lowered to the
4312 bottom when no longer selected.
4314 Auto-raising and auto-lowering is implemented through functions
4315 attached to `select-frame-hook' and `deselect-frame-hook' (*note Frame
4316 Hooks::). Under normal circumstances, you should not call these
4319 - Function: default-select-frame-hook
4320 This hook function implements the `auto-raise-frame' variable; it
4321 is for use as the value of `select-frame-hook'.
4323 - Function: default-deselect-frame-hook
4324 This hook function implements the `auto-lower-frame' variable; it
4325 is for use as the value of `deselect-frame-hook'.
4328 File: lispref.info, Node: Frame Configurations, Next: Frame Hooks, Prev: Raising and Lowering, Up: Frames
4330 Frame Configurations
4331 ====================
4333 A "frame configuration" records the current arrangement of frames, all
4334 their properties, and the window configuration of each one.
4336 - Function: current-frame-configuration
4337 This function returns a frame configuration list that describes
4338 the current arrangement of frames and their contents.
4340 - Function: set-frame-configuration configuration &optional nodelete
4341 This function restores the state of frames described by
4342 CONFIGURATION, which should be the return value from a previous
4343 call to `current-frame-configuration'.
4345 Each frame listed in CONFIGURATION has its position, size, window
4346 configuration, and other properties set as specified in
4349 Ordinarily, this function deletes all existing frames not listed in
4350 CONFIGURATION. But if optional second argument NODELETE is
4351 non-`nil', the unwanted frames are iconified instead.
4354 File: lispref.info, Node: Frame Hooks, Prev: Frame Configurations, Up: Frames
4356 Hooks for Customizing Frame Behavior
4357 ====================================
4359 XEmacs provides many hooks that are called at various times during a
4360 frame's lifetime. *Note Hooks::.
4362 - Variable: create-frame-hook
4363 This hook is called each time a frame is created. The functions
4364 are called with one argument, the newly-created frame.
4366 - Variable: delete-frame-hook
4367 This hook is called each time a frame is deleted. The functions
4368 are called with one argument, the about-to-be-deleted frame.
4370 - Variable: select-frame-hook
4371 This is a normal hook that is run just after a frame is selected.
4372 The function `default-select-frame-hook', which implements
4373 auto-raising (*note Raising and Lowering::), is normally attached
4376 Note that calling `select-frame' does not necessarily set the
4377 focus: The actual window-system focus will not be changed until
4378 the next time that XEmacs is waiting for an event, and even then,
4379 the window manager may refuse the focus-change request.
4381 - Variable: deselect-frame-hook
4382 This is a normal hook that is run just before a frame is deselected
4383 (and another frame is selected). The function
4384 `default-deselect-frame-hook', which implements auto-lowering
4385 (*note Raising and Lowering::), is normally attached to this hook.
4387 - Variable: map-frame-hook
4388 This hook is called each time a frame is mapped (i.e. made
4389 visible). The functions are called with one argument, the newly
4392 - Variable: unmap-frame-hook
4393 This hook is called each time a frame is unmapped (i.e. made
4394 invisible or iconified). The functions are called with one
4395 argument, the newly unmapped frame.
4398 File: lispref.info, Node: Consoles and Devices, Next: Positions, Prev: Frames, Up: Top
4400 Consoles and Devices
4401 ********************
4403 A "console" is an object representing a single input connection to
4404 XEmacs, such as an X display or a TTY connection. It is possible for
4405 XEmacs to have frames on multiple consoles at once (even on
4406 heterogeneous types--you can simultaneously have a frame on an X
4407 display and a TTY connection). Normally, there is only one console in
4410 A "device" is an object representing a single output device, such as
4411 a particular screen on an X display. (Usually there is exactly one
4412 device per X console connection, but there may be more than one if you
4413 have a multi-headed X display. For TTY connections, there is always
4414 exactly one device per console.)
4416 Each device has one or more "frames" in which text can be displayed.
4417 For X displays and the like, a frame corresponds to the normal
4418 window-system concept of a window. Frames can overlap, be displayed at
4419 various locations within the display, be resized, etc. For TTY, only
4420 one frame can be displayed at a time, and it occupies the entire TTY
4423 However, you can still define multiple frames and switch between
4424 them. Their contents are entirely separate from each other. These
4425 sorts of frames resemble the "virtual console" capability provided
4426 under Linux or the multiple screens provided by the multiplexing program
4427 `screen' under Unix.
4429 When you start up XEmacs, an initial console and device are created
4430 to receive input and display frames on. This will either be an X
4431 display or a TTY connection, depending on what mode you started XEmacs
4432 in (this is determined by the `DISPLAY' environment variable, the
4433 `-nw', `-t' and `-display' command-line options, etc.).
4435 You can connect to other X displays and TTY connections by creating
4436 new console objects, and to other X screens on an existing display by
4437 creating new device objects, as described below. Many functions (for
4438 example the frame-creation functions) take an optional device argument
4439 specifying which device the function pertains to. If the argument is
4440 omitted, it defaults to the selected device (see below).
4442 - Function: consolep object
4443 This returns non-`nil' if OBJECT is a console.
4445 - Function: devicep object
4446 This returns non-`nil' if OBJECT is a device.
4450 * Basic Console Functions:: Functions for working with consoles.
4451 * Basic Device Functions:: Functions for working with devices.
4452 * Console Types and Device Classes::
4453 I/O and color characteristics.
4454 * Connecting to a Console or Device::
4455 * The Selected Console and Device::
4456 * Console and Device I/O:: Controlling input and output.
4459 File: lispref.info, Node: Basic Console Functions, Next: Basic Device Functions, Up: Consoles and Devices
4461 Basic Console Functions
4462 =======================
4464 - Function: console-list
4465 This function returns a list of all existing consoles.
4467 - Function: console-device-list &optional console
4468 This function returns a list of all devices on CONSOLE. If
4469 CONSOLE is `nil', the selected console will be used.
4472 File: lispref.info, Node: Basic Device Functions, Next: Console Types and Device Classes, Prev: Basic Console Functions, Up: Consoles and Devices
4474 Basic Device Functions
4475 ======================
4477 - Function: device-list
4478 This function returns a list of all existing devices.
4480 - Function: device-or-frame-p object
4481 This function returns non-`nil' if OBJECT is a device or frame.
4482 This function is useful because devices and frames are similar in
4483 many respects and many functions can operate on either one.
4485 - Function: device-frame-list &optional device
4486 This function returns a list of all frames on DEVICE. DEVICE
4487 defaults to the currently selected device.
4489 - Function: frame-device &optional frame
4490 This function returns the device that FRAME is on. FRAME defaults
4491 to the currently selected frame.
4494 File: lispref.info, Node: Console Types and Device Classes, Next: Connecting to a Console or Device, Prev: Basic Device Functions, Up: Consoles and Devices
4496 Console Types and Device Classes
4497 ================================
4499 Every device is of a particular "type", which describes how the
4500 connection to that device is made and how the device operates, and a
4501 particular "class", which describes other characteristics of the device
4502 (currently, the color capabilities of the device).
4504 The currently-defined device types are
4507 A connection to an X display (such as `willow:0').
4510 A connection to a tty (such as `/dev/ttyp3').
4513 A stdio connection. This describes a device for which input and
4514 output is only possible in a stream-like fashion, such as when
4515 XEmacs in running in batch mode. The very first device created by
4516 XEmacs is a terminal device and is used to print out messages of
4517 various sorts (for example, the help message when you use the
4518 `-help' command-line option).
4520 The currently-defined device classes are
4525 A grayscale device (a device that can display multiple shades of
4526 gray, but no color).
4529 A device that can only display two colors (e.g. black and white).
4531 - Function: device-type &optional device
4532 This function returns the type of DEVICE. This is a symbol whose
4533 name is one of the device types mentioned above. DEVICE defaults
4534 to the selected device.
4536 - Function: device-or-frame-type device-or-frame
4537 This function returns the type of DEVICE-OR-FRAME.
4539 - Function: device-class &optional device
4540 This function returns the class (color behavior) of DEVICE. This
4541 is a symbol whose name is one of the device classes mentioned
4544 - Function: valid-device-type-p device-type
4545 This function returns whether DEVICE-TYPE (which should be a
4546 symbol) specifies a valid device type.
4548 - Function: valid-device-class-p device-class
4549 This function returns whether DEVICE-CLASS (which should be a
4550 symbol) specifies a valid device class.
4552 - Variable: terminal-device
4553 This variable holds the initial terminal device object, which
4554 represents XEmacs's stdout.
4557 File: lispref.info, Node: Connecting to a Console or Device, Next: The Selected Console and Device, Prev: Console Types and Device Classes, Up: Consoles and Devices
4559 Connecting to a Console or Device
4560 =================================
4562 - Function: make-device type connection &optional props
4563 This function creates a new device.
4565 The following two functions create devices of specific types and are
4566 written in terms of `make-device'.
4568 - Function: make-tty-device &optional tty terminal-type
4569 This function creates a new tty device on TTY. This also creates
4570 the tty's first frame. TTY should be a string giving the name of
4571 a tty device file (e.g. `/dev/ttyp3' under SunOS et al.), as
4572 returned by the `tty' command issued from the Unix shell. A value
4573 of `nil' means use the stdin and stdout as passed to XEmacs from
4574 the shell. If TERMINAL-TYPE is non-`nil', it should be a string
4575 specifying the type of the terminal attached to the specified tty.
4576 If it is `nil', the terminal type will be inferred from the
4577 `TERM' environment variable.
4579 - Function: make-x-device &optional display argv-list
4580 This function creates a new device connected to DISPLAY. Optional
4581 argument ARGV-LIST is a list of strings describing command line
4584 - Function: delete-device device &optional force
4585 This function deletes DEVICE, permanently eliminating it from use.
4586 This disconnects XEmacs's connection to the device.
4588 - Variable: create-device-hook
4589 This variable, if non-`nil', should contain a list of functions,
4590 which are called when a device is created.
4592 - Variable: delete-device-hook
4593 This variable, if non-`nil', should contain a list of functions,
4594 which are called when a device is deleted.
4596 - Function: console-live-p object
4597 This function returns non-`nil' if OBJECT is a console that has
4600 - Function: device-live-p object
4601 This function returns non-`nil' if OBJECT is a device that has not
4604 - Function: device-x-display device
4605 This function returns the X display which DEVICE is connected to,
4606 if DEVICE is an X device.
4609 File: lispref.info, Node: The Selected Console and Device, Next: Console and Device I/O, Prev: Connecting to a Console or Device, Up: Consoles and Devices
4611 The Selected Console and Device
4612 ===============================
4614 - Function: select-console console
4615 This function selects the console CONSOLE. Subsequent editing
4616 commands apply to its selected device, selected frame, and selected
4617 window. The selection of CONSOLE lasts until the next time the
4618 user does something to select a different console, or until the
4619 next time this function is called.
4621 - Function: selected-console
4622 This function returns the console which is currently active.
4624 - Function: select-device device
4625 This function selects the device DEVICE.
4627 - Function: selected-device &optional console
4628 This function returns the device which is currently active. If
4629 optional CONSOLE is non-`nil', this function returns the device
4630 that would be currently active if CONSOLE were the selected
4634 File: lispref.info, Node: Console and Device I/O, Prev: The Selected Console and Device, Up: Consoles and Devices
4636 Console and Device I/O
4637 ======================
4639 - Function: console-disable-input console
4640 This function disables input on console CONSOLE.
4642 - Function: console-enable-input console
4643 This function enables input on console CONSOLE.
4645 Each device has a "baud rate" value associated with it. On most
4646 systems, changing this value will affect the amount of padding and
4647 other strategic decisions made during redisplay.
4649 - Function: device-baud-rate &optional device
4650 This function returns the output baud rate of DEVICE.
4652 - Function: set-device-baud-rate device rate
4653 This function sets the output baud rate of DEVICE to RATE.
4656 File: lispref.info, Node: Positions, Next: Markers, Prev: Consoles and Devices, Up: Top
4661 A "position" is the index of a character in the text of a buffer. More
4662 precisely, a position identifies the place between two characters (or
4663 before the first character, or after the last character), so we can
4664 speak of the character before or after a given position. However, we
4665 often speak of the character "at" a position, meaning the character
4666 after that position.
4668 Positions are usually represented as integers starting from 1, but
4669 can also be represented as "markers"--special objects that relocate
4670 automatically when text is inserted or deleted so they stay with the
4671 surrounding characters. *Note Markers::.
4675 * Point:: The special position where editing takes place.
4676 * Motion:: Changing point.
4677 * Excursions:: Temporary motion and buffer changes.
4678 * Narrowing:: Restricting editing to a portion of the buffer.
4681 File: lispref.info, Node: Point, Next: Motion, Up: Positions
4686 "Point" is a special buffer position used by many editing commands,
4687 including the self-inserting typed characters and text insertion
4688 functions. Other commands move point through the text to allow editing
4689 and insertion at different places.
4691 Like other positions, point designates a place between two characters
4692 (or before the first character, or after the last character), rather
4693 than a particular character. Usually terminals display the cursor over
4694 the character that immediately follows point; point is actually before
4695 the character on which the cursor sits.
4697 The value of point is a number between 1 and the buffer size plus 1.
4698 If narrowing is in effect (*note Narrowing::), then point is constrained
4699 to fall within the accessible portion of the buffer (possibly at one end
4702 Each buffer has its own value of point, which is independent of the
4703 value of point in other buffers. Each window also has a value of point,
4704 which is independent of the value of point in other windows on the same
4705 buffer. This is why point can have different values in various windows
4706 that display the same buffer. When a buffer appears in only one window,
4707 the buffer's point and the window's point normally have the same value,
4708 so the distinction is rarely important. *Note Window Point::, for more
4711 - Function: point &optional buffer
4712 This function returns the value of point in BUFFER, as an integer.
4713 BUFFER defaults to the current buffer if omitted.
4718 - Function: point-min &optional buffer
4719 This function returns the minimum accessible value of point in
4720 BUFFER. This is normally 1, but if narrowing is in effect, it is
4721 the position of the start of the region that you narrowed to.
4722 (*Note Narrowing::.) BUFFER defaults to the current buffer if
4725 - Function: point-max &optional buffer
4726 This function returns the maximum accessible value of point in
4727 BUFFER. This is `(1+ (buffer-size buffer))', unless narrowing is
4728 in effect, in which case it is the position of the end of the
4729 region that you narrowed to. (*note Narrowing::). BUFFER defaults
4730 to the current buffer if omitted.
4732 - Function: buffer-end flag &optional buffer
4733 This function returns `(point-min buffer)' if FLAG is less than 1,
4734 `(point-max buffer)' otherwise. The argument FLAG must be a
4735 number. BUFFER defaults to the current buffer if omitted.
4737 - Function: buffer-size &optional buffer
4738 This function returns the total number of characters in BUFFER.
4739 In the absence of any narrowing (*note Narrowing::), `point-max'
4740 returns a value one larger than this. BUFFER defaults to the
4741 current buffer if omitted.
4748 - Variable: buffer-saved-size
4749 The value of this buffer-local variable is the former length of the
4750 current buffer, as of the last time it was read in, saved or
4754 File: lispref.info, Node: Motion, Next: Excursions, Prev: Point, Up: Positions
4759 Motion functions change the value of point, either relative to the
4760 current value of point, relative to the beginning or end of the buffer,
4761 or relative to the edges of the selected window. *Note Point::.
4765 * Character Motion:: Moving in terms of characters.
4766 * Word Motion:: Moving in terms of words.
4767 * Buffer End Motion:: Moving to the beginning or end of the buffer.
4768 * Text Lines:: Moving in terms of lines of text.
4769 * Screen Lines:: Moving in terms of lines as displayed.
4770 * List Motion:: Moving by parsing lists and sexps.
4771 * Skipping Characters:: Skipping characters belonging to a certain set.
4774 File: lispref.info, Node: Character Motion, Next: Word Motion, Up: Motion
4776 Motion by Characters
4777 --------------------
4779 These functions move point based on a count of characters. `goto-char'
4780 is the fundamental primitive; the other functions use that.
4782 - Command: goto-char position &optional buffer
4783 This function sets point in `buffer' to the value POSITION. If
4784 POSITION is less than 1, it moves point to the beginning of the
4785 buffer. If POSITION is greater than the length of the buffer, it
4786 moves point to the end. BUFFER defaults to the current buffer if
4789 If narrowing is in effect, POSITION still counts from the
4790 beginning of the buffer, but point cannot go outside the accessible
4791 portion. If POSITION is out of range, `goto-char' moves point to
4792 the beginning or the end of the accessible portion.
4794 When this function is called interactively, POSITION is the
4795 numeric prefix argument, if provided; otherwise it is read from the
4798 `goto-char' returns POSITION.
4800 - Command: forward-char &optional count buffer
4801 This function moves point COUNT characters forward, towards the
4802 end of the buffer (or backward, towards the beginning of the
4803 buffer, if COUNT is negative). If the function attempts to move
4804 point past the beginning or end of the buffer (or the limits of
4805 the accessible portion, when narrowing is in effect), an error is
4806 signaled with error code `beginning-of-buffer' or `end-of-buffer'.
4807 BUFFER defaults to the current buffer if omitted.
4809 In an interactive call, COUNT is the numeric prefix argument.
4811 - Command: backward-char &optional count buffer
4812 This function moves point COUNT characters backward, towards the
4813 beginning of the buffer (or forward, towards the end of the
4814 buffer, if COUNT is negative). If the function attempts to move
4815 point past the beginning or end of the buffer (or the limits of
4816 the accessible portion, when narrowing is in effect), an error is
4817 signaled with error code `beginning-of-buffer' or `end-of-buffer'.
4818 BUFFER defaults to the current buffer if omitted.
4820 In an interactive call, COUNT is the numeric prefix argument.
4823 File: lispref.info, Node: Word Motion, Next: Buffer End Motion, Prev: Character Motion, Up: Motion
4828 These functions for parsing words use the syntax table to decide
4829 whether a given character is part of a word. *Note Syntax Tables::.
4831 - Command: forward-word &optional count buffer
4832 This function moves point forward COUNT words (or backward if
4833 COUNT is negative). Normally it returns `t'. If this motion
4834 encounters the beginning or end of the buffer, or the limits of the
4835 accessible portion when narrowing is in effect, point stops there
4836 and the value is `nil'.
4838 COUNT defaults to `1' and BUFFER defaults to the current buffer.
4840 In an interactive call, COUNT is set to the numeric prefix
4843 - Command: backward-word &optional count buffer
4844 This function is just like `forward-word', except that it moves
4845 backward until encountering the front of a word, rather than
4846 forward. BUFFER defaults to the current buffer if omitted.
4848 In an interactive call, COUNT is set to the numeric prefix
4851 - Variable: words-include-escapes
4852 This variable affects the behavior of `forward-word' and everything
4853 that uses it. If it is non-`nil', then characters in the "escape"
4854 and "character quote" syntax classes count as part of words.
4855 Otherwise, they do not.
4858 File: lispref.info, Node: Buffer End Motion, Next: Text Lines, Prev: Word Motion, Up: Motion
4860 Motion to an End of the Buffer
4861 ------------------------------
4863 To move point to the beginning of the buffer, write:
4865 (goto-char (point-min))
4867 Likewise, to move to the end of the buffer, use:
4869 (goto-char (point-max))
4871 Here are two commands that users use to do these things. They are
4872 documented here to warn you not to use them in Lisp programs, because
4873 they set the mark and display messages in the echo area.
4875 - Command: beginning-of-buffer &optional count
4876 This function moves point to the beginning of the buffer (or the
4877 limits of the accessible portion, when narrowing is in effect),
4878 setting the mark at the previous position. If COUNT is non-`nil',
4879 then it puts point COUNT tenths of the way from the beginning of
4882 In an interactive call, COUNT is the numeric prefix argument, if
4883 provided; otherwise COUNT defaults to `nil'.
4885 Don't use this function in Lisp programs!
4887 - Command: end-of-buffer &optional count
4888 This function moves point to the end of the buffer (or the limits
4889 of the accessible portion, when narrowing is in effect), setting
4890 the mark at the previous position. If COUNT is non-`nil', then it
4891 puts point COUNT tenths of the way from the end of the buffer.
4893 In an interactive call, COUNT is the numeric prefix argument, if
4894 provided; otherwise COUNT defaults to `nil'.
4896 Don't use this function in Lisp programs!
4899 File: lispref.info, Node: Text Lines, Next: Screen Lines, Prev: Buffer End Motion, Up: Motion
4901 Motion by Text Lines
4902 --------------------
4904 Text lines are portions of the buffer delimited by newline characters,
4905 which are regarded as part of the previous line. The first text line
4906 begins at the beginning of the buffer, and the last text line ends at
4907 the end of the buffer whether or not the last character is a newline.
4908 The division of the buffer into text lines is not affected by the width
4909 of the window, by line continuation in display, or by how tabs and
4910 control characters are displayed.
4912 - Command: goto-line line
4913 This function moves point to the front of the LINEth line,
4914 counting from line 1 at beginning of the buffer. If LINE is less
4915 than 1, it moves point to the beginning of the buffer. If LINE is
4916 greater than the number of lines in the buffer, it moves point to
4917 the end of the buffer--that is, the _end of the last line_ of the
4918 buffer. This is the only case in which `goto-line' does not
4919 necessarily move to the beginning of a line.
4921 If narrowing is in effect, then LINE still counts from the
4922 beginning of the buffer, but point cannot go outside the accessible
4923 portion. So `goto-line' moves point to the beginning or end of the
4924 accessible portion, if the line number specifies an inaccessible
4927 The return value of `goto-line' is the difference between LINE and
4928 the line number of the line to which point actually was able to
4929 move (in the full buffer, before taking account of narrowing).
4930 Thus, the value is positive if the scan encounters the real end of
4931 the buffer. The value is zero if scan encounters the end of the
4932 accessible portion but not the real end of the buffer.
4934 In an interactive call, LINE is the numeric prefix argument if one
4935 has been provided. Otherwise LINE is read in the minibuffer.
4937 - Command: beginning-of-line &optional count buffer
4938 This function moves point to the beginning of the current line.
4939 With an argument COUNT not `nil' or 1, it moves forward COUNT-1
4940 lines and then to the beginning of the line. BUFFER defaults to
4941 the current buffer if omitted.
4943 If this function reaches the end of the buffer (or of the
4944 accessible portion, if narrowing is in effect), it positions point
4945 there. No error is signaled.
4947 - Command: end-of-line &optional count buffer
4948 This function moves point to the end of the current line. With an
4949 argument COUNT not `nil' or 1, it moves forward COUNT-1 lines and
4950 then to the end of the line. BUFFER defaults to the current
4953 If this function reaches the end of the buffer (or of the
4954 accessible portion, if narrowing is in effect), it positions point
4955 there. No error is signaled.
4957 - Command: forward-line &optional count buffer
4958 This function moves point forward COUNT lines, to the beginning of
4959 the line. If COUNT is negative, it moves point -COUNT lines
4960 backward, to the beginning of a line. If COUNT is zero, it moves
4961 point to the beginning of the current line. BUFFER defaults to
4962 the current buffer if omitted.
4964 If `forward-line' encounters the beginning or end of the buffer (or
4965 of the accessible portion) before finding that many lines, it sets
4966 point there. No error is signaled.
4968 `forward-line' returns the difference between COUNT and the number
4969 of lines actually moved. If you attempt to move down five lines
4970 from the beginning of a buffer that has only three lines, point
4971 stops at the end of the last line, and the value will be 2.
4973 In an interactive call, COUNT is the numeric prefix argument.
4975 - Function: count-lines start end &optional ignore-invisible-lines-flag
4976 This function returns the number of lines between the positions
4977 START and END in the current buffer. If START and END are equal,
4978 then it returns 0. Otherwise it returns at least 1, even if START
4979 and END are on the same line. This is because the text between
4980 them, considered in isolation, must contain at least one line
4983 With optional IGNORE-INVISIBLE-LINES-FLAG non-`nil', lines
4984 collapsed with selective-display are excluded from the line count.
4986 *Note:* The expression to return the current line number is not
4989 (1+ (count-lines 1 (point-at-bol)))
4991 Here is an example of using `count-lines':
4993 (defun current-line ()
4994 "Return the vertical position of point..."
4995 (+ (count-lines (window-start) (point))
4996 (if (= (current-column) 0) 1 0)
4999 Also see the functions `bolp' and `eolp' in *Note Near Point::.
5000 These functions do not move point, but test whether it is already at the
5001 beginning or end of a line.
5004 File: lispref.info, Node: Screen Lines, Next: List Motion, Prev: Text Lines, Up: Motion
5006 Motion by Screen Lines
5007 ----------------------
5009 The line functions in the previous section count text lines, delimited
5010 only by newline characters. By contrast, these functions count screen
5011 lines, which are defined by the way the text appears on the screen. A
5012 text line is a single screen line if it is short enough to fit the width
5013 of the selected window, but otherwise it may occupy several screen
5016 In some cases, text lines are truncated on the screen rather than
5017 continued onto additional screen lines. In these cases,
5018 `vertical-motion' moves point much like `forward-line'. *Note
5021 Because the width of a given string depends on the flags that control
5022 the appearance of certain characters, `vertical-motion' behaves
5023 differently, for a given piece of text, depending on the buffer it is
5024 in, and even on the selected window (because the width, the truncation
5025 flag, and display table may vary between windows). *Note Usual
5028 These functions scan text to determine where screen lines break, and
5029 thus take time proportional to the distance scanned. If you intend to
5030 use them heavily, Emacs provides caches which may improve the
5031 performance of your code. *Note cache-long-line-scans: Text Lines.
5033 - Function: vertical-motion count &optional window pixels
5034 This function moves point to the start of the frame line COUNT
5035 frame lines down from the frame line containing point. If COUNT
5036 is negative, it moves up instead. The optional second argument
5037 WINDOW may be used to specify a window other than the selected
5038 window in which to perform the motion.
5040 Normally, `vertical-motion' returns the number of lines moved. The
5041 value may be less in absolute value than COUNT if the beginning or
5042 end of the buffer was reached. If the optional third argument,
5043 PIXELS is non-`nil', the vertical pixel height of the motion which
5044 took place is returned instead of the actual number of lines
5045 moved. A motion of zero lines returns the height of the current
5048 Note that `vertical-motion' sets WINDOW's buffer's point, not
5049 WINDOW's point. (This differs from FSF Emacs, which buggily always
5050 sets current buffer's point, regardless of WINDOW.)
5052 - Function: vertical-motion-pixels count &optional window how
5053 This function moves point to the start of the frame line PIXELS
5054 vertical pixels down from the frame line containing point, or up if
5055 PIXELS is negative. The optional second argument WINDOW is the
5056 window to move in, and defaults to the selected window. The
5057 optional third argument HOW specifies the stopping condition. A
5058 negative integer indicates that the motion should be no more than
5059 PIXELS. A positive value indicates that the motion should be at
5060 least PIXELS. Any other value indicates that the motion should be
5061 as close as possible to PIXELS.
5063 - Command: move-to-window-line count &optional window
5064 This function moves point with respect to the text currently
5065 displayed in WINDOW, which defaults to the selected window. It
5066 moves point to the beginning of the screen line COUNT screen lines
5067 from the top of the window. If COUNT is negative, that specifies a
5068 position -COUNT lines from the bottom (or the last line of the
5069 buffer, if the buffer ends above the specified screen position).
5071 If COUNT is `nil', then point moves to the beginning of the line
5072 in the middle of the window. If the absolute value of COUNT is
5073 greater than the size of the window, then point moves to the place
5074 that would appear on that screen line if the window were tall
5075 enough. This will probably cause the next redisplay to scroll to
5076 bring that location onto the screen.
5078 In an interactive call, COUNT is the numeric prefix argument.
5080 The value returned is the window line number point has moved to,
5081 with the top line in the window numbered 0.
5084 File: lispref.info, Node: List Motion, Next: Skipping Characters, Prev: Screen Lines, Up: Motion
5086 Moving over Balanced Expressions
5087 --------------------------------
5089 Here are several functions concerned with balanced-parenthesis
5090 expressions (also called "sexps" in connection with moving across them
5091 in XEmacs). The syntax table controls how these functions interpret
5092 various characters; see *Note Syntax Tables::. *Note Parsing
5093 Expressions::, for lower-level primitives for scanning sexps or parts of
5094 sexps. For user-level commands, see *Note Lists and Sexps:
5095 (xemacs)Lists and Sexps.
5097 - Command: forward-list &optional arg
5098 This function moves forward across ARG balanced groups of
5099 parentheses. (Other syntactic entities such as words or paired
5100 string quotes are ignored.) ARG defaults to 1 if omitted. If ARG
5101 is negative, move backward across that many groups of parentheses.
5103 - Command: backward-list &optional count
5104 This function moves backward across COUNT balanced groups of
5105 parentheses. (Other syntactic entities such as words or paired
5106 string quotes are ignored.) COUNT defaults to 1 if omitted. If
5107 COUNT is negative, move forward across that many groups of
5110 - Command: up-list &optional count
5111 This function moves forward out of COUNT levels of parentheses. A
5112 negative argument means move backward but still to a less deep
5115 - Command: down-list &optional count
5116 This function moves forward into COUNT levels of parentheses. A
5117 negative argument means move backward but still go deeper in
5118 parentheses (-COUNT levels).
5120 - Command: forward-sexp &optional count
5121 This function moves forward across COUNT balanced expressions.
5122 Balanced expressions include both those delimited by parentheses
5123 and other kinds, such as words and string constants. COUNT
5124 defaults to 1 if omitted. If COUNT is negative, move backward
5125 across that many balanced expressions. For example,
5127 ---------- Buffer: foo ----------
5128 (concat-!- "foo " (car x) y z)
5129 ---------- Buffer: foo ----------
5134 ---------- Buffer: foo ----------
5135 (concat "foo " (car x) y-!- z)
5136 ---------- Buffer: foo ----------
5138 - Command: backward-sexp &optional count
5139 This function moves backward across COUNT balanced expressions.
5140 COUNT defaults to 1 if omitted. If COUNT is negative, move
5141 forward across that many balanced expressions.
5143 - Command: beginning-of-defun &optional count
5144 This function moves back to the COUNTth beginning of a defun. If
5145 COUNT is negative, this actually moves forward, but it still moves
5146 to the beginning of a defun, not to the end of one. COUNT
5147 defaults to 1 if omitted.
5149 - Command: end-of-defun &optional count
5150 This function moves forward to the COUNTth end of a defun. If
5151 COUNT is negative, this actually moves backward, but it still
5152 moves to the end of a defun, not to the beginning of one. COUNT
5153 defaults to 1 if omitted.
5155 - User Option: defun-prompt-regexp
5156 If non-`nil', this variable holds a regular expression that
5157 specifies what text can appear before the open-parenthesis that
5158 starts a defun. That is to say, a defun begins on a line that
5159 starts with a match for this regular expression, followed by a
5160 character with open-parenthesis syntax.
5163 File: lispref.info, Node: Skipping Characters, Prev: List Motion, Up: Motion
5168 The following two functions move point over a specified set of
5169 characters. For example, they are often used to skip whitespace. For
5170 related functions, see *Note Motion and Syntax::.
5172 - Function: skip-chars-forward character-set &optional limit buffer
5173 This function moves point in BUFFER forward, skipping over a given
5174 set of characters. It examines the character following point,
5175 then advances point if the character matches CHARACTER-SET. This
5176 continues until it reaches a character that does not match. The
5177 function returns `nil'. BUFFER defaults to the current buffer if
5180 The argument CHARACTER-SET is like the inside of a `[...]' in a
5181 regular expression except that `]' is never special and `\' quotes
5182 `^', `-' or `\'. Thus, `"a-zA-Z"' skips over all letters,
5183 stopping before the first non-letter, and `"^a-zA-Z'" skips
5184 non-letters stopping before the first letter. *Note Regular
5187 If LIMIT is supplied (it must be a number or a marker), it
5188 specifies the maximum position in the buffer that point can be
5189 skipped to. Point will stop at or before LIMIT.
5191 In the following example, point is initially located directly
5192 before the `T'. After the form is evaluated, point is located at
5193 the end of that line (between the `t' of `hat' and the newline).
5194 The function skips all letters and spaces, but not newlines.
5196 ---------- Buffer: foo ----------
5197 I read "-!-The cat in the hat
5199 ---------- Buffer: foo ----------
5201 (skip-chars-forward "a-zA-Z ")
5204 ---------- Buffer: foo ----------
5205 I read "The cat in the hat-!-
5207 ---------- Buffer: foo ----------
5209 - Function: skip-chars-backward character-set &optional limit buffer
5210 This function moves point backward, skipping characters that match
5211 CHARACTER-SET, until LIMIT. It just like `skip-chars-forward'
5212 except for the direction of motion.
5215 File: lispref.info, Node: Excursions, Next: Narrowing, Prev: Motion, Up: Positions
5220 It is often useful to move point "temporarily" within a localized
5221 portion of the program, or to switch buffers temporarily. This is
5222 called an "excursion", and it is done with the `save-excursion' special
5223 form. This construct saves the current buffer and its values of point
5224 and the mark so they can be restored after the completion of the
5227 The forms for saving and restoring the configuration of windows are
5228 described elsewhere (see *Note Window Configurations:: and *note Frame
5231 - Special Form: save-excursion forms...
5232 The `save-excursion' special form saves the identity of the current
5233 buffer and the values of point and the mark in it, evaluates
5234 FORMS, and finally restores the buffer and its saved values of
5235 point and the mark. All three saved values are restored even in
5236 case of an abnormal exit via `throw' or error (*note Nonlocal
5239 The `save-excursion' special form is the standard way to switch
5240 buffers or move point within one part of a program and avoid
5241 affecting the rest of the program. It is used more than 500 times
5242 in the Lisp sources of XEmacs.
5244 `save-excursion' does not save the values of point and the mark for
5245 other buffers, so changes in other buffers remain in effect after
5246 `save-excursion' exits.
5248 Likewise, `save-excursion' does not restore window-buffer
5249 correspondences altered by functions such as `switch-to-buffer'.
5250 One way to restore these correspondences, and the selected window,
5251 is to use `save-window-excursion' inside `save-excursion' (*note
5252 Window Configurations::).
5254 The value returned by `save-excursion' is the result of the last of
5255 FORMS, or `nil' if no FORMS are given.
5260 (let ((old-buf (current-buffer))
5261 (old-pnt (point-marker))
5262 (old-mark (copy-marker (mark-marker))))
5265 (set-buffer old-buf)
5267 (set-marker (mark-marker) old-mark)))
5269 - Special Form: save-current-buffer forms...
5270 This special form is similar to `save-excursion' but it only saves
5271 and restores the current buffer. Beginning with XEmacs 20.3,
5272 `save-current-buffer' is a primitive.
5274 - Special Form: with-current-buffer buffer forms...
5275 This special form evaluates FORMS with BUFFER as the current
5276 buffer. It returns the value of the last form.
5278 - Special Form: with-temp-file filename forms...
5279 This special form creates a new buffer, evaluates FORMS there, and
5280 writes the buffer to FILENAME. It returns the value of the last
5283 - Special Form: save-selected-window forms...
5284 This special form is similar to `save-excursion' but it saves and
5285 restores the selected window and nothing else.
5288 File: lispref.info, Node: Narrowing, Prev: Excursions, Up: Positions
5293 "Narrowing" means limiting the text addressable by XEmacs editing
5294 commands to a limited range of characters in a buffer. The text that
5295 remains addressable is called the "accessible portion" of the buffer.
5297 Narrowing is specified with two buffer positions which become the
5298 beginning and end of the accessible portion. For most editing commands
5299 and most Emacs primitives, these positions replace the values of the
5300 beginning and end of the buffer. While narrowing is in effect, no text
5301 outside the accessible portion is displayed, and point cannot move
5302 outside the accessible portion.
5304 Values such as positions or line numbers, which usually count from
5305 the beginning of the buffer, do so despite narrowing, but the functions
5306 which use them refuse to operate on text that is inaccessible.
5308 The commands for saving buffers are unaffected by narrowing; they
5309 save the entire buffer regardless of any narrowing.
5311 - Command: narrow-to-region start end &optional buffer
5312 This function sets the accessible portion of BUFFER to start at
5313 START and end at END. Both arguments should be character
5314 positions. BUFFER defaults to the current buffer if omitted.
5316 In an interactive call, START and END are set to the bounds of the
5317 current region (point and the mark, with the smallest first).
5319 - Command: narrow-to-page &optional move-count
5320 This function sets the accessible portion of the current buffer to
5321 include just the current page. An optional first argument
5322 MOVE-COUNT non-`nil' means to move forward or backward by
5323 MOVE-COUNT pages and then narrow. The variable `page-delimiter'
5324 specifies where pages start and end (*note Standard Regexps::).
5326 In an interactive call, MOVE-COUNT is set to the numeric prefix
5329 - Command: widen &optional buffer
5330 This function cancels any narrowing in BUFFER, so that the entire
5331 contents are accessible. This is called "widening". It is
5332 equivalent to the following expression:
5334 (narrow-to-region 1 (1+ (buffer-size)))
5336 BUFFER defaults to the current buffer if omitted.
5338 - Special Form: save-restriction body...
5339 This special form saves the current bounds of the accessible
5340 portion, evaluates the BODY forms, and finally restores the saved
5341 bounds, thus restoring the same state of narrowing (or absence
5342 thereof) formerly in effect. The state of narrowing is restored
5343 even in the event of an abnormal exit via `throw' or error (*note
5344 Nonlocal Exits::). Therefore, this construct is a clean way to
5345 narrow a buffer temporarily.
5347 The value returned by `save-restriction' is that returned by the
5348 last form in BODY, or `nil' if no body forms were given.
5350 *Caution:* it is easy to make a mistake when using the
5351 `save-restriction' construct. Read the entire description here
5354 If BODY changes the current buffer, `save-restriction' still
5355 restores the restrictions on the original buffer (the buffer whose
5356 restrictions it saved from), but it does not restore the identity
5357 of the current buffer.
5359 `save-restriction' does _not_ restore point and the mark; use
5360 `save-excursion' for that. If you use both `save-restriction' and
5361 `save-excursion' together, `save-excursion' should come first (on
5362 the outside). Otherwise, the old point value would be restored
5363 with temporary narrowing still in effect. If the old point value
5364 were outside the limits of the temporary narrowing, this would
5365 fail to restore it accurately.
5367 The `save-restriction' special form records the values of the
5368 beginning and end of the accessible portion as distances from the
5369 beginning and end of the buffer. In other words, it records the
5370 amount of inaccessible text before and after the accessible
5373 This method yields correct results if BODY does further narrowing.
5374 However, `save-restriction' can become confused if the body widens
5375 and then make changes outside the range of the saved narrowing.
5376 When this is what you want to do, `save-restriction' is not the
5377 right tool for the job. Here is what you must use instead:
5379 (let ((start (point-min-marker))
5380 (end (point-max-marker)))
5384 (set-buffer (marker-buffer start))
5385 (narrow-to-region start end))))
5387 Here is a simple example of correct use of `save-restriction':
5389 ---------- Buffer: foo ----------
5390 This is the contents of foo
5391 This is the contents of foo
5392 This is the contents of foo-!-
5393 ---------- Buffer: foo ----------
5399 (narrow-to-region 1 (point))
5400 (goto-char (point-min))
5401 (replace-string "foo" "bar")))
5403 ---------- Buffer: foo ----------
5404 This is the contents of bar
5405 This is the contents of bar
5406 This is the contents of foo-!-
5407 ---------- Buffer: foo ----------
5410 File: lispref.info, Node: Markers, Next: Text, Prev: Positions, Up: Top
5415 A "marker" is a Lisp object used to specify a position in a buffer
5416 relative to the surrounding text. A marker changes its offset from the
5417 beginning of the buffer automatically whenever text is inserted or
5418 deleted, so that it stays with the two characters on either side of it.
5422 * Overview of Markers:: The components of a marker, and how it relocates.
5423 * Predicates on Markers:: Testing whether an object is a marker.
5424 * Creating Markers:: Making empty markers or markers at certain places.
5425 * Information from Markers:: Finding the marker's buffer or character position.
5426 * Changing Markers:: Moving the marker to a new buffer or position.
5427 * The Mark:: How ``the mark'' is implemented with a marker.
5428 * The Region:: How to access ``the region''.
5431 File: lispref.info, Node: Overview of Markers, Next: Predicates on Markers, Up: Markers
5436 A marker specifies a buffer and a position in that buffer. The marker
5437 can be used to represent a position in the functions that require one,
5438 just as an integer could be used. *Note Positions::, for a complete
5439 description of positions.
5441 A marker has two attributes: the marker position, and the marker
5442 buffer. The marker position is an integer that is equivalent (at a
5443 given time) to the marker as a position in that buffer. But the
5444 marker's position value can change often during the life of the marker.
5445 Insertion and deletion of text in the buffer relocate the marker. The
5446 idea is that a marker positioned between two characters remains between
5447 those two characters despite insertion and deletion elsewhere in the
5448 buffer. Relocation changes the integer equivalent of the marker.
5450 Deleting text around a marker's position leaves the marker between
5451 the characters immediately before and after the deleted text. Inserting
5452 text at the position of a marker normally leaves the marker in front of
5453 the new text--unless it is inserted with `insert-before-markers' (*note
5456 Insertion and deletion in a buffer must check all the markers and
5457 relocate them if necessary. This slows processing in a buffer with a
5458 large number of markers. For this reason, it is a good idea to make a
5459 marker point nowhere if you are sure you don't need it any more.
5460 Unreferenced markers are garbage collected eventually, but until then
5461 will continue to use time if they do point somewhere.
5463 Because it is common to perform arithmetic operations on a marker
5464 position, most of the arithmetic operations (including `+' and `-')
5465 accept markers as arguments. In such cases, the marker stands for its
5468 Note that you can use extents to achieve the same functionality, and
5469 more, as markers. (Markers were defined before extents, which is why
5470 they both continue to exist.) A zero-length extent with the
5471 `detachable' property removed is almost identical to a marker. (*Note
5472 Extent Endpoints::, for more information on zero-length extents.)
5476 * In order to get marker-like behavior in a zero-length extent, the
5477 `detachable' property must be removed (otherwise, the extent will
5478 disappear when text near it is deleted) and exactly one endpoint
5479 must be closed (if both endpoints are closed, the extent will
5480 expand to contain text inserted where it is located).
5482 * If a zero-length extent has the `end-open' property but not the
5483 `start-open' property (this is the default), text inserted at the
5484 extent's location causes the extent to move forward, just like a
5487 * If a zero-length extent has the `start-open' property but not the
5488 `end-open' property, text inserted at the extent's location causes
5489 the extent to remain before the text, like what happens to markers
5490 when `insert-before-markers' is used.
5492 * Markers end up after or before inserted text depending on whether
5493 `insert' or `insert-before-markers' was called. These functions
5494 do not affect zero-length extents differently; instead, the
5495 presence or absence of the `start-open' and `end-open' extent
5496 properties determines this, as just described.
5498 * Markers are automatically removed from a buffer when they are no
5499 longer in use. Extents remain around until explicitly removed
5502 * Many functions are provided for listing the extents in a buffer or
5503 in a region of a buffer. No such functions exist for markers.
5505 Here are examples of creating markers, setting markers, and moving
5508 ;; Make a new marker that initially does not point anywhere:
5509 (setq m1 (make-marker))
5510 => #<marker in no buffer>
5512 ;; Set `m1' to point between the 99th and 100th characters
5513 ;; in the current buffer:
5515 => #<marker at 100 in markers.texi>
5517 ;; Now insert one character at the beginning of the buffer:
5518 (goto-char (point-min))
5523 ;; `m1' is updated appropriately.
5525 => #<marker at 101 in markers.texi>
5527 ;; Two markers that point to the same position
5528 ;; are not `eq', but they are `equal'.
5529 (setq m2 (copy-marker m1))
5530 => #<marker at 101 in markers.texi>
5536 ;; When you are finished using a marker, make it point nowhere.
5538 => #<marker in no buffer>
5541 File: lispref.info, Node: Predicates on Markers, Next: Creating Markers, Prev: Overview of Markers, Up: Markers
5543 Predicates on Markers
5544 =====================
5546 You can test an object to see whether it is a marker, or whether it is
5547 either an integer or a marker or either an integer, a character, or a
5548 marker. The latter tests are useful in connection with the arithmetic
5549 functions that work with any of markers, integers, or characters.
5551 - Function: markerp object
5552 This function returns `t' if OBJECT is a marker, `nil' otherwise.
5553 Note that integers are not markers, even though many functions
5554 will accept either a marker or an integer.
5556 - Function: integer-or-marker-p object
5557 This function returns `t' if OBJECT is an integer or a marker,
5560 - Function: integer-char-or-marker-p object
5561 This function returns `t' if OBJECT is an integer, a character, or
5562 a marker, `nil' otherwise.
5564 - Function: number-or-marker-p object
5565 This function returns `t' if OBJECT is a number (either kind) or a
5566 marker, `nil' otherwise.
5568 - Function: number-char-or-marker-p object
5569 This function returns `t' if OBJECT is a number (either kind), a
5570 character, or a marker, `nil' otherwise.
5573 File: lispref.info, Node: Creating Markers, Next: Information from Markers, Prev: Predicates on Markers, Up: Markers
5575 Functions That Create Markers
5576 =============================
5578 When you create a new marker, you can make it point nowhere, or point
5579 to the present position of point, or to the beginning or end of the
5580 accessible portion of the buffer, or to the same place as another given
5583 - Function: make-marker
5584 This functions returns a newly created marker that does not point
5588 => #<marker in no buffer>
5590 - Function: point-marker &optional dont-copy-p buffer
5591 This function returns a marker that points to the present position
5592 of point in BUFFER, which defaults to the current buffer. *Note
5593 Point::. For an example, see `copy-marker', below.
5595 Internally, a marker corresponding to point is always maintained.
5596 Normally the marker returned by `point-marker' is a copy; you may
5597 modify it with reckless abandon. However, if optional argument
5598 DONT-COPY-P is non-`nil', then the real point-marker is returned;
5599 modifying the position of this marker will move point. It is
5600 illegal to change the buffer of it, or make it point nowhere.
5602 - Function: point-min-marker &optional buffer
5603 This function returns a new marker that points to the beginning of
5604 the accessible portion of BUFFER, which defaults to the current
5605 buffer. This will be the beginning of the buffer unless narrowing
5606 is in effect. *Note Narrowing::.
5608 - Function: point-max-marker &optional buffer
5609 This function returns a new marker that points to the end of the
5610 accessible portion of BUFFER, which defaults to the current
5611 buffer. This will be the end of the buffer unless narrowing is in
5612 effect. *Note Narrowing::.
5614 Here are examples of this function and `point-min-marker', shown in
5615 a buffer containing a version of the source file for the text of
5619 => #<marker at 1 in markers.texi>
5621 => #<marker at 15573 in markers.texi>
5623 (narrow-to-region 100 200)
5626 => #<marker at 100 in markers.texi>
5628 => #<marker at 200 in markers.texi>
5630 - Function: copy-marker marker-or-integer &optional marker-type
5631 If passed a marker as its argument, `copy-marker' returns a new
5632 marker that points to the same place and the same buffer as does
5633 MARKER-OR-INTEGER. If passed an integer as its argument,
5634 `copy-marker' returns a new marker that points to position
5635 MARKER-OR-INTEGER in the current buffer.
5637 If passed an integer argument less than 1, `copy-marker' returns a
5638 new marker that points to the beginning of the current buffer. If
5639 passed an integer argument greater than the length of the buffer,
5640 `copy-marker' returns a new marker that points to the end of the
5643 An error is signaled if MARKER-OR-INTEGER is neither a marker nor
5646 Optional second argument MARKER-TYPE specifies the insertion type
5647 of the new marker; see `marker-insertion-type'.
5649 (setq p (point-marker))
5650 => #<marker at 2139 in markers.texi>
5652 (setq q (copy-marker p))
5653 => #<marker at 2139 in markers.texi>
5665 => #<marker at 3000 in markers.texi>
5670 (setq p (point-marker t))
5671 => #<marker at 2139 in markers.texi>
5674 => #<marker at 3000 in markers.texi>
5680 => #<marker at 1 in markers.texi>
5683 => #<marker at 7572 in markers.texi>
5686 File: lispref.info, Node: Information from Markers, Next: Changing Markers, Prev: Creating Markers, Up: Markers
5688 Information from Markers
5689 ========================
5691 This section describes the functions for accessing the components of a
5694 - Function: marker-position marker
5695 This function returns the position that MARKER points to, or `nil'
5696 if it points nowhere.
5698 - Function: marker-buffer marker
5699 This function returns the buffer that MARKER points into, or `nil'
5700 if it points nowhere.
5702 (setq m (make-marker))
5703 => #<marker in no buffer>
5709 (set-marker m 3770 (current-buffer))
5710 => #<marker at 3770 in markers.texi>
5712 => #<buffer markers.texi>
5716 Two distinct markers are considered `equal' (even though not `eq')
5717 to each other if they have the same position and buffer, or if they
5721 File: lispref.info, Node: Changing Markers, Next: The Mark, Prev: Information from Markers, Up: Markers
5723 Changing Marker Positions
5724 =========================
5726 This section describes how to change the position of an existing
5727 marker. When you do this, be sure you know whether the marker is used
5728 outside of your program, and, if so, what effects will result from
5729 moving it--otherwise, confusing things may happen in other parts of
5732 - Function: set-marker marker position &optional buffer
5733 This function moves MARKER to POSITION in BUFFER. If BUFFER is
5734 not provided, it defaults to the current buffer.
5736 POSITION can be a marker, an integer or `nil'. If POSITION is an
5737 integer, `set-marker' moves MARKER to point before the POSITIONth
5738 character in BUFFER. If POSITION is `nil', MARKER is made to
5739 point nowhere. Then it no longer slows down editing in any
5740 buffer. If POSITION is less than 1, MARKER is moved to the
5741 beginning of BUFFER. If POSITION is greater than the size of
5742 BUFFER, MARKER is moved to the end of BUFFER.
5744 The value returned is MARKER.
5746 (setq m (point-marker))
5747 => #<marker at 4714 in markers.texi>
5749 => #<marker at 55 in markers.texi>
5750 (setq b (get-buffer "foo"))
5753 => #<marker at 1 in foo>
5755 - Function: move-marker marker position &optional buffer
5756 This is another name for `set-marker'.
5759 File: lispref.info, Node: The Mark, Next: The Region, Prev: Changing Markers, Up: Markers
5764 One special marker in each buffer is designated "the mark". It records
5765 a position for the user for the sake of commands such as `C-w' and `C-x
5766 <TAB>'. Lisp programs should set the mark only to values that have a
5767 potential use to the user, and never for their own internal purposes.
5768 For example, the `replace-regexp' command sets the mark to the value of
5769 point before doing any replacements, because this enables the user to
5770 move back there conveniently after the replace is finished.
5772 Once the mark "exists" in a buffer, it normally never ceases to
5773 exist. However, it may become "inactive", and usually does so after
5774 each command (other than simple motion commands and some commands that
5775 explicitly activate the mark). When the mark is active, the region
5776 between point and the mark is called the "active region" and is
5777 highlighted specially.
5779 Many commands are designed so that when called interactively they
5780 operate on the text between point and the mark. Such commands work
5781 only when an active region exists, i.e. when the mark is active. (The
5782 reason for this is to prevent you from accidentally deleting or
5783 changing large chunks of your text.) If you are writing such a command,
5784 don't examine the mark directly; instead, use `interactive' with the
5785 `r' specification. This provides the values of point and the mark as
5786 arguments to the command in an interactive call, but permits other Lisp
5787 programs to specify arguments explicitly, and automatically signals an
5788 error if the command is called interactively when no active region
5789 exists. *Note Interactive Codes::.
5791 Each buffer has its own value of the mark that is independent of the
5792 value of the mark in other buffers. (When a buffer is created, the mark
5793 exists but does not point anywhere. We consider this state as "the
5794 absence of a mark in that buffer.") However, only one active region can
5795 exist at a time. Activating the mark in one buffer automatically
5796 deactivates an active mark in any other buffer. Note that the user can
5797 explicitly activate a mark at any time by using the command
5798 `activate-region' (normally bound to `M-C-z') or by using the command
5799 `exchange-point-and-mark' (normally bound to `C-x C-x'), which has the
5800 side effect of activating the mark.
5802 Some people do not like active regions, so they disable this behavior
5803 by setting the variable `zmacs-regions' to `nil'. This makes the mark
5804 always active (except when a buffer is just created and the mark points
5805 nowhere), and turns off the highlighting of the region between point
5806 and the mark. Commands that explicitly retrieve the value of the mark
5807 should make sure that they behave correctly and consistently
5808 irrespective of the setting of `zmacs-regions'; some primitives are
5809 provided to ensure this behavior.
5811 In addition to the mark, each buffer has a "mark ring" which is a
5812 list of markers containing previous values of the mark. When editing
5813 commands change the mark, they should normally save the old value of the
5814 mark on the mark ring. The variable `mark-ring-max' specifies the
5815 maximum number of entries in the mark ring; once the list becomes this
5816 long, adding a new element deletes the last element.
5818 - Function: mark &optional force buffer
5819 This function returns BUFFER's mark position as an integer.
5820 BUFFER defaults to the current buffer if omitted.
5822 If the mark is inactive, `mark' normally returns `nil'. However,
5823 if FORCE is non-`nil', then `mark' returns the mark position
5824 anyway--or `nil', if the mark is not yet set for the buffer.
5826 (Remember that if `zmacs-regions' is `nil', the mark is always
5827 active as long as it exists, and the FORCE argument will have no
5830 If you are using this in an editing command, you are most likely
5831 making a mistake; see the documentation of `set-mark' below.
5833 - Function: mark-marker &optional force buffer
5834 This function returns BUFFER's mark. BUFFER defaults to the
5835 current buffer if omitted. This is the very marker that records
5836 the mark location inside XEmacs, not a copy. Therefore, changing
5837 this marker's position will directly affect the position of the
5838 mark. Don't do it unless that is the effect you want.
5840 If the mark is inactive, `mark-marker' normally returns `nil'.
5841 However, if FORCE is non-`nil', then `mark-marker' returns the
5843 (setq m (mark-marker))
5844 => #<marker at 3420 in markers.texi>
5846 => #<marker at 100 in markers.texi>
5848 => #<marker at 100 in markers.texi>
5850 Like any marker, this marker can be set to point at any buffer you
5851 like. We don't recommend that you make it point at any buffer
5852 other than the one of which it is the mark. If you do, it will
5853 yield perfectly consistent, but rather odd, results.
5855 - Function: set-mark position &optional buffer
5856 This function sets `buffer''s mark to POSITION, and activates the
5857 mark. BUFFER defaults to the current buffer if omitted. The old
5858 value of the mark is _not_ pushed onto the mark ring.
5860 *Please note:* Use this function only if you want the user to see
5861 that the mark has moved, and you want the previous mark position to
5862 be lost. Normally, when a new mark is set, the old one should go
5863 on the `mark-ring'. For this reason, most applications should use
5864 `push-mark' and `pop-mark', not `set-mark'.
5866 Novice XEmacs Lisp programmers often try to use the mark for the
5867 wrong purposes. The mark saves a location for the user's
5868 convenience. An editing command should not alter the mark unless
5869 altering the mark is part of the user-level functionality of the
5870 command. (And, in that case, this effect should be documented.)
5871 To remember a location for internal use in the Lisp program, store
5872 it in a Lisp variable. For example:
5874 (let ((start (point)))
5876 (delete-region start (point))).
5878 - Command: exchange-point-and-mark &optional dont-activate-region
5879 This function exchanges the positions of point and the mark. It
5880 is intended for interactive use. The mark is also activated
5881 unless DONT-ACTIVATE-REGION is non-`nil'.
5883 - Function: push-mark &optional position nomsg activate buffer
5884 This function sets BUFFER's mark to POSITION, and pushes a copy of
5885 the previous mark onto `mark-ring'. BUFFER defaults to the
5886 current buffer if omitted. If POSITION is `nil', then the value
5887 of point is used. `push-mark' returns `nil'.
5889 If the last global mark pushed was not in BUFFER, also push
5890 POSITION on the global mark ring (see below).
5892 The function `push-mark' normally _does not_ activate the mark.
5893 To do that, specify `t' for the argument ACTIVATE.
5895 A `Mark set' message is displayed unless NOMSG is non-`nil'.
5897 - Function: pop-mark
5898 This function pops off the top element of `mark-ring' and makes
5899 that mark become the buffer's actual mark. This does not move
5900 point in the buffer, and it does nothing if `mark-ring' is empty.
5901 It deactivates the mark.
5903 The return value is not meaningful.
5905 - Variable: mark-ring
5906 The value of this buffer-local variable is the list of saved former
5907 marks of the current buffer, most recent first.
5910 => (#<marker at 11050 in markers.texi>
5911 #<marker at 10832 in markers.texi>
5914 - User Option: mark-ring-max
5915 The value of this variable is the maximum size of `mark-ring'. If
5916 more marks than this are pushed onto the `mark-ring', `push-mark'
5917 discards an old mark when it adds a new one.
5919 In additional to a per-buffer mark ring, there is a "global mark
5920 ring". Marks are pushed onto the global mark ring the first time you
5921 set a mark after switching buffers.
5923 - Variable: global-mark-ring
5924 The value of this variable is the list of saved former global
5925 marks, most recent first.
5927 - User Option: mark-ring-max
5928 The value of this variable is the maximum size of
5929 `global-mark-ring'. If more marks than this are pushed onto the
5930 `global-mark-ring', `push-mark' discards an old mark when it adds
5933 - Command: pop-global-mark
5934 This function pops a mark off the global mark ring and jumps to
5938 File: lispref.info, Node: The Region, Prev: The Mark, Up: Markers
5943 The text between point and the mark is known as "the region". Various
5944 functions operate on text delimited by point and the mark, but only
5945 those functions specifically related to the region itself are described
5948 When `zmacs-regions' is non-`nil' (this is the default), the concept
5949 of an "active region" exists. The region is active when the
5950 corresponding mark is active. Note that only one active region at a
5951 time can exist--i.e. only one buffer's region is active at a time.
5952 *Note The Mark::, for more information about active regions.
5954 - User Option: zmacs-regions
5955 If non-`nil' (the default), active regions are used. *Note The
5956 Mark::, for a detailed explanation of what this means.
5958 A number of functions are provided for explicitly determining the
5959 bounds of the region and whether it is active. Few programs need to use
5960 these functions, however. A command designed to operate on a region
5961 should normally use `interactive' with the `r' specification to find
5962 the beginning and end of the region. This lets other Lisp programs
5963 specify the bounds explicitly as arguments and automatically respects
5964 the user's setting for `zmacs-regions'. (*Note Interactive Codes::.)
5966 - Function: region-beginning &optional buffer
5967 This function returns the position of the beginning of BUFFER's
5968 region (as an integer). This is the position of either point or
5969 the mark, whichever is smaller. BUFFER defaults to the current
5972 If the mark does not point anywhere, an error is signaled. Note
5973 that this function ignores whether the region is active.
5975 - Function: region-end &optional buffer
5976 This function returns the position of the end of BUFFER's region
5977 (as an integer). This is the position of either point or the mark,
5978 whichever is larger. BUFFER defaults to the current buffer if
5981 If the mark does not point anywhere, an error is signaled. Note
5982 that this function ignores whether the region is active.
5984 - Function: region-exists-p
5985 This function is non-`nil' if the region exists. If active regions
5986 are in use (i.e. `zmacs-regions' is true), this means that the
5987 region is active. Otherwise, this means that the user has pushed
5988 a mark in this buffer at some point in the past. If this function
5989 returns `nil', a function that uses the `r' interactive
5990 specification will cause an error when called interactively.
5992 - Function: region-active-p
5993 If `zmacs-regions' is true, this is equivalent to
5994 `region-exists-p'. Otherwise, this function always returns false.
5995 This function is used by commands such as
5996 `fill-paragraph-or-region' and `capitalize-region-or-word', which
5997 operate either on the active region or on something else (e.g. the
5998 word or paragraph at point).
6000 - Variable: zmacs-region-stays
6001 If a command sets this variable to true, the currently active
6002 region will remain activated when the command finishes. (Normally
6003 the region is deactivated when each command terminates.) If
6004 `zmacs-regions' is false, however, this has no effect. Under
6005 normal circumstances, you do not need to set this; use the
6006 interactive specification `_' instead, if you want the region to
6009 - Function: zmacs-activate-region
6010 This function activates the region in the current buffer (this is
6011 equivalent to activating the current buffer's mark). This will
6012 normally also highlight the text in the active region and set
6013 `zmacs-region-stays' to `t'. (If `zmacs-regions' is false,
6014 however, this function has no effect.)
6016 - Function: zmacs-deactivate-region
6017 This function deactivates the region in the current buffer (this is
6018 equivalent to deactivating the current buffer's mark). This will
6019 normally also unhighlight the text in the active region and set
6020 `zmacs-region-stays' to `nil'. (If `zmacs-regions' is false,
6021 however, this function has no effect.)
6023 - Function: zmacs-update-region
6024 This function updates the active region, if it's currently active.
6025 (If there is no active region, this function does nothing.) This
6026 has the effect of updating the highlighting on the text in the
6027 region; but you should never need to call this except under rather
6028 strange circumstances. The command loop automatically calls it
6029 when appropriate. Calling this function will call the hook
6030 `zmacs-update-region-hook', if the region is active.
6032 - Variable: zmacs-activate-region-hook
6033 This normal hook is called when a region becomes active. (Usually
6034 this happens as a result of a command that activates the region,
6035 such as `set-mark-command', `activate-region', or
6036 `exchange-point-and-mark'.) Note that calling
6037 `zmacs-activate-region' will call this hook, even if the region is
6038 already active. If `zmacs-regions' is false, however, this hook
6039 will never get called under any circumstances.
6041 - Variable: zmacs-deactivate-region-hook
6042 This normal hook is called when an active region becomes inactive.
6043 (Calling `zmacs-deactivate-region' when the region is inactive will
6044 _not_ cause this hook to be called.) If `zmacs-regions' is false,
6045 this hook will never get called.
6047 - Variable: zmacs-update-region-hook
6048 This normal hook is called when an active region is "updated" by
6049 `zmacs-update-region'. This normally gets called at the end of
6050 each command that sets `zmacs-region-stays' to `t', indicating
6051 that the region should remain activated. The motion commands do
6055 File: lispref.info, Node: Text, Next: Searching and Matching, Prev: Markers, Up: Top
6060 This chapter describes the functions that deal with the text in a
6061 buffer. Most examine, insert, or delete text in the current buffer,
6062 often in the vicinity of point. Many are interactive. All the
6063 functions that change the text provide for undoing the changes (*note
6066 Many text-related functions operate on a region of text defined by
6067 two buffer positions passed in arguments named START and END. These
6068 arguments should be either markers (*note Markers::) or numeric
6069 character positions (*note Positions::). The order of these arguments
6070 does not matter; it is all right for START to be the end of the region
6071 and END the beginning. For example, `(delete-region 1 10)' and
6072 `(delete-region 10 1)' are equivalent. An `args-out-of-range' error is
6073 signaled if either START or END is outside the accessible portion of
6074 the buffer. In an interactive call, point and the mark are used for
6077 Throughout this chapter, "text" refers to the characters in the
6078 buffer, together with their properties (when relevant).
6082 * Near Point:: Examining text in the vicinity of point.
6083 * Buffer Contents:: Examining text in a general fashion.
6084 * Comparing Text:: Comparing substrings of buffers.
6085 * Insertion:: Adding new text to a buffer.
6086 * Commands for Insertion:: User-level commands to insert text.
6087 * Deletion:: Removing text from a buffer.
6088 * User-Level Deletion:: User-level commands to delete text.
6089 * The Kill Ring:: Where removed text sometimes is saved for later use.
6090 * Undo:: Undoing changes to the text of a buffer.
6091 * Maintaining Undo:: How to enable and disable undo information.
6092 How to control how much information is kept.
6093 * Filling:: Functions for explicit filling.
6094 * Margins:: How to specify margins for filling commands.
6095 * Auto Filling:: How auto-fill mode is implemented to break lines.
6096 * Sorting:: Functions for sorting parts of the buffer.
6097 * Columns:: Computing horizontal positions, and using them.
6098 * Indentation:: Functions to insert or adjust indentation.
6099 * Case Changes:: Case conversion of parts of the buffer.
6100 * Text Properties:: Assigning Lisp property lists to text characters.
6101 * Substitution:: Replacing a given character wherever it appears.
6102 * Registers:: How registers are implemented. Accessing the text or
6103 position stored in a register.
6104 * Transposition:: Swapping two portions of a buffer.
6105 * Change Hooks:: Supplying functions to be run when text is changed.
6106 * Transformations:: MD5 and base64 support.
6109 File: lispref.info, Node: Near Point, Next: Buffer Contents, Up: Text
6111 Examining Text Near Point
6112 =========================
6114 Many functions are provided to look at the characters around point.
6115 Several simple functions are described here. See also `looking-at' in
6116 *Note Regexp Search::.
6118 Many of these functions take an optional BUFFER argument. In all
6119 such cases, the current buffer will be used if this argument is
6120 omitted. (In FSF Emacs, and earlier versions of XEmacs, these functions
6121 usually did not have these optional BUFFER arguments and always
6122 operated on the current buffer.)
6124 - Function: char-after &optional position buffer
6125 This function returns the character in the buffer at (i.e.,
6126 immediately after) position POSITION. If POSITION is out of range
6127 for this purpose, either before the beginning of the buffer, or at
6128 or beyond the end, then the value is `nil'. The default for
6129 POSITION is point. If optional argument BUFFER is `nil', the
6130 current buffer is assumed.
6132 In the following example, assume that the first character in the
6135 (char-to-string (char-after 1))
6138 - Function: char-before &optional position buffer
6139 This function returns the character in the current buffer
6140 immediately before position POSITION. If POSITION is out of range
6141 for this purpose, either at or before the beginning of the buffer,
6142 or beyond the end, then the value is `nil'. The default for
6143 POSITION is point. If optional argument BUFFER is `nil', the
6144 current buffer is assumed.
6146 - Function: following-char &optional buffer
6147 This function returns the character following point in the buffer.
6148 This is similar to `(char-after (point))'. However, if point is at
6149 the end of the buffer, then the result of `following-char' is 0.
6150 If optional argument BUFFER is `nil', the current buffer is
6153 Remember that point is always between characters, and the terminal
6154 cursor normally appears over the character following point.
6155 Therefore, the character returned by `following-char' is the
6156 character the cursor is over.
6158 In this example, point is between the `a' and the `c'.
6160 ---------- Buffer: foo ----------
6161 Gentlemen may cry ``Pea-!-ce! Peace!,''
6162 but there is no peace.
6163 ---------- Buffer: foo ----------
6165 (char-to-string (preceding-char))
6167 (char-to-string (following-char))
6170 - Function: preceding-char &optional buffer
6171 This function returns the character preceding point in the buffer.
6172 See above, under `following-char', for an example. If point is at
6173 the beginning of the buffer, `preceding-char' returns 0. If
6174 optional argument BUFFER is `nil', the current buffer is assumed.
6176 - Function: bobp &optional buffer
6177 This function returns `t' if point is at the beginning of the
6178 buffer. If narrowing is in effect, this means the beginning of the
6179 accessible portion of the text. If optional argument BUFFER is
6180 `nil', the current buffer is assumed. See also `point-min' in
6183 - Function: eobp &optional buffer
6184 This function returns `t' if point is at the end of the buffer.
6185 If narrowing is in effect, this means the end of accessible
6186 portion of the text. If optional argument BUFFER is `nil', the
6187 current buffer is assumed. See also `point-max' in *Note Point::.
6189 - Function: bolp &optional buffer
6190 This function returns `t' if point is at the beginning of a line.
6191 If optional argument BUFFER is `nil', the current buffer is
6192 assumed. *Note Text Lines::. The beginning of the buffer (or its
6193 accessible portion) always counts as the beginning of a line.
6195 - Function: eolp &optional buffer
6196 This function returns `t' if point is at the end of a line. The
6197 end of the buffer is always considered the end of a line. If
6198 optional argument BUFFER is `nil', the current buffer is assumed.
6199 The end of the buffer (or of its accessible portion) is always
6200 considered the end of a line.
6203 File: lispref.info, Node: Buffer Contents, Next: Comparing Text, Prev: Near Point, Up: Text
6205 Examining Buffer Contents
6206 =========================
6208 This section describes two functions that allow a Lisp program to
6209 convert any portion of the text in the buffer into a string.
6211 - Function: buffer-substring start end &optional buffer
6212 - Function: buffer-string start end &optional buffer
6213 These functions are equivalent and return a string containing a
6214 copy of the text of the region defined by positions START and END
6215 in the buffer. If the arguments are not positions in the
6216 accessible portion of the buffer, `buffer-substring' signals an
6217 `args-out-of-range' error. If optional argument BUFFER is `nil',
6218 the current buffer is assumed.
6220 If the region delineated by START and END contains duplicable
6221 extents, they will be remembered in the string. *Note Duplicable
6224 It is not necessary for START to be less than END; the arguments
6225 can be given in either order. But most often the smaller argument
6228 ---------- Buffer: foo ----------
6229 This is the contents of buffer foo
6231 ---------- Buffer: foo ----------
6233 (buffer-substring 1 10)
6235 (buffer-substring (point-max) 10)
6236 => "he contents of buffer foo
6240 File: lispref.info, Node: Comparing Text, Next: Insertion, Prev: Buffer Contents, Up: Text
6245 This function lets you compare portions of the text in a buffer, without
6246 copying them into strings first.
6248 - Function: compare-buffer-substrings buffer1 start1 end1 buffer2
6250 This function lets you compare two substrings of the same buffer
6251 or two different buffers. The first three arguments specify one
6252 substring, giving a buffer and two positions within the buffer.
6253 The last three arguments specify the other substring in the same
6254 way. You can use `nil' for BUFFER1, BUFFER2, or both to stand for
6257 The value is negative if the first substring is less, positive if
6258 the first is greater, and zero if they are equal. The absolute
6259 value of the result is one plus the index of the first differing
6260 characters within the substrings.
6262 This function ignores case when comparing characters if
6263 `case-fold-search' is non-`nil'. It always ignores text
6266 Suppose the current buffer contains the text `foobarbar
6267 haha!rara!'; then in this example the two substrings are `rbar '
6268 and `rara!'. The value is 2 because the first substring is greater
6269 at the second character.
6271 (compare-buffer-substring nil 6 11 nil 16 21)
6275 File: lispref.info, Node: Insertion, Next: Commands for Insertion, Prev: Comparing Text, Up: Text
6280 "Insertion" means adding new text to a buffer. The inserted text goes
6281 at point--between the character before point and the character after
6284 Insertion relocates markers that point at positions after the
6285 insertion point, so that they stay with the surrounding text (*note
6286 Markers::). When a marker points at the place of insertion, insertion
6287 normally doesn't relocate the marker, so that it points to the
6288 beginning of the inserted text; however, certain special functions such
6289 as `insert-before-markers' relocate such markers to point after the
6292 Some insertion functions leave point before the inserted text, while
6293 other functions leave it after. We call the former insertion "after
6294 point" and the latter insertion "before point".
6296 If a string with non-`nil' extent data is inserted, the remembered
6297 extents will also be inserted. *Note Duplicable Extents::.
6299 Insertion functions signal an error if the current buffer is
6302 These functions copy text characters from strings and buffers along
6303 with their properties. The inserted characters have exactly the same
6304 properties as the characters they were copied from. By contrast,
6305 characters specified as separate arguments, not part of a string or
6306 buffer, inherit their text properties from the neighboring text.
6308 - Function: insert &rest args
6309 This function inserts the strings and/or characters ARGS into the
6310 current buffer, at point, moving point forward. In other words, it
6311 inserts the text before point. An error is signaled unless all
6312 ARGS are either strings or characters. The value is `nil'.
6314 - Function: insert-before-markers &rest args
6315 This function inserts the strings and/or characters ARGS into the
6316 current buffer, at point, moving point forward. An error is
6317 signaled unless all ARGS are either strings or characters. The
6320 This function is unlike the other insertion functions in that it
6321 relocates markers initially pointing at the insertion point, to
6322 point after the inserted text.
6324 - Function: insert-string string &optional buffer
6325 This function inserts STRING into BUFFER before point. BUFFER
6326 defaults to the current buffer if omitted. This function is
6327 chiefly useful if you want to insert a string in a buffer other
6328 than the current one (otherwise you could just use `insert').
6330 - Function: insert-char character &optional count ignored buffer
6331 This function inserts COUNT instances of CHARACTER into BUFFER
6332 before point. COUNT must be a number, and CHARACTER must be a
6335 If optional argument BUFFER is `nil', the current buffer is
6336 assumed. (In FSF Emacs, the third argument is called INHERIT and
6337 refers to text properties. In XEmacs, it is always ignored.)
6339 This function always returns `nil'.
6341 - Function: insert-buffer-substring from-buffer-or-name &optional
6343 This function inserts a portion of buffer FROM-BUFFER-OR-NAME
6344 (which must already exist) into the current buffer before point.
6345 The text inserted is the region from START and END. (These
6346 arguments default to the beginning and end of the accessible
6347 portion of that buffer.) This function returns `nil'.
6349 In this example, the form is executed with buffer `bar' as the
6350 current buffer. We assume that buffer `bar' is initially empty.
6352 ---------- Buffer: foo ----------
6353 We hold these truths to be self-evident, that all
6354 ---------- Buffer: foo ----------
6356 (insert-buffer-substring "foo" 1 20)
6359 ---------- Buffer: bar ----------
6360 We hold these truth-!-
6361 ---------- Buffer: bar ----------
6364 File: lispref.info, Node: Commands for Insertion, Next: Deletion, Prev: Insertion, Up: Text
6366 User-Level Insertion Commands
6367 =============================
6369 This section describes higher-level commands for inserting text,
6370 commands intended primarily for the user but useful also in Lisp
6373 - Command: insert-buffer from-buffer-or-name
6374 This command inserts the entire contents of FROM-BUFFER-OR-NAME
6375 (which must exist) into the current buffer after point. It leaves
6376 the mark after the inserted text. The value is `nil'.
6378 - Command: self-insert-command count
6379 This command inserts the last character typed; it does so COUNT
6380 times, before point, and returns `nil'. Most printing characters
6381 are bound to this command. In routine use, `self-insert-command'
6382 is the most frequently called function in XEmacs, but programs
6383 rarely use it except to install it on a keymap.
6385 In an interactive call, COUNT is the numeric prefix argument.
6387 This command calls `auto-fill-function' whenever that is non-`nil'
6388 and the character inserted is a space or a newline (*note Auto
6391 This command performs abbrev expansion if Abbrev mode is enabled
6392 and the inserted character does not have word-constituent syntax.
6393 (*Note Abbrevs::, and *Note Syntax Class Table::.)
6395 This is also responsible for calling `blink-paren-function' when
6396 the inserted character has close parenthesis syntax (*note
6399 - Command: newline &optional count
6400 This command inserts newlines into the current buffer before point.
6401 If COUNT is supplied, that many newline characters are inserted.
6403 This function calls `auto-fill-function' if the current column
6404 number is greater than the value of `fill-column' and COUNT is
6405 `nil'. Typically what `auto-fill-function' does is insert a
6406 newline; thus, the overall result in this case is to insert two
6407 newlines at different places: one at point, and another earlier in
6408 the line. `newline' does not auto-fill if COUNT is non-`nil'.
6410 This command indents to the left margin if that is not zero.
6413 The value returned is `nil'. In an interactive call, COUNT is the
6414 numeric prefix argument.
6416 - Command: split-line
6417 This command splits the current line, moving the portion of the
6418 line after point down vertically so that it is on the next line
6419 directly below where it was before. Whitespace is inserted as
6420 needed at the beginning of the lower line, using the `indent-to'
6421 function. `split-line' returns the position of point.
6423 Programs hardly ever use this function.
6425 - Variable: overwrite-mode
6426 This variable controls whether overwrite mode is in effect: a
6427 non-`nil' value enables the mode. It is automatically made
6428 buffer-local when set in any fashion.
6431 File: lispref.info, Node: Deletion, Next: User-Level Deletion, Prev: Commands for Insertion, Up: Text
6436 Deletion means removing part of the text in a buffer, without saving it
6437 in the kill ring (*note The Kill Ring::). Deleted text can't be
6438 yanked, but can be reinserted using the undo mechanism (*note Undo::).
6439 Some deletion functions do save text in the kill ring in some special
6442 All of the deletion functions operate on the current buffer, and all
6443 return a value of `nil'.
6445 - Command: erase-buffer &optional buffer
6446 This function deletes the entire text of BUFFER, leaving it empty.
6447 If the buffer is read-only, it signals a `buffer-read-only'
6448 error. Otherwise, it deletes the text without asking for any
6449 confirmation. It returns `nil'. BUFFER defaults to the current
6452 Normally, deleting a large amount of text from a buffer inhibits
6453 further auto-saving of that buffer "because it has shrunk".
6454 However, `erase-buffer' does not do this, the idea being that the
6455 future text is not really related to the former text, and its size
6456 should not be compared with that of the former text.
6458 - Command: delete-region start end &optional buffer
6459 This command deletes the text in BUFFER in the region defined by
6460 START and END. The value is `nil'. If optional argument BUFFER
6461 is `nil', the current buffer is assumed.
6463 - Command: delete-char &optional count killp
6464 This command deletes COUNT characters directly after point, or
6465 before point if COUNT is negative. COUNT defaults to `1'. If
6466 KILLP is non-`nil', then it saves the deleted characters in the
6469 In an interactive call, COUNT is the numeric prefix argument, and
6470 KILLP is the unprocessed prefix argument. Therefore, if a prefix
6471 argument is supplied, the text is saved in the kill ring. If no
6472 prefix argument is supplied, then one character is deleted, but
6473 not saved in the kill ring.
6475 The value returned is always `nil'.
6477 - Command: delete-backward-char &optional count killp
6478 This command deletes COUNT characters directly before point, or
6479 after point if COUNT is negative. COUNT defaults to 1. If KILLP
6480 is non-`nil', then it saves the deleted characters in the kill
6483 In an interactive call, COUNT is the numeric prefix argument, and
6484 KILLP is the unprocessed prefix argument. Therefore, if a prefix
6485 argument is supplied, the text is saved in the kill ring. If no
6486 prefix argument is supplied, then one character is deleted, but
6487 not saved in the kill ring.
6489 The value returned is always `nil'.
6491 - Command: backward-delete-char-untabify count &optional killp
6492 This command deletes COUNT characters backward, changing tabs into
6493 spaces. When the next character to be deleted is a tab, it is
6494 first replaced with the proper number of spaces to preserve
6495 alignment and then one of those spaces is deleted instead of the
6496 tab. If KILLP is non-`nil', then the command saves the deleted
6497 characters in the kill ring.
6499 Conversion of tabs to spaces happens only if COUNT is positive.
6500 If it is negative, exactly -COUNT characters after point are
6503 In an interactive call, COUNT is the numeric prefix argument, and
6504 KILLP is the unprocessed prefix argument. Therefore, if a prefix
6505 argument is supplied, the text is saved in the kill ring. If no
6506 prefix argument is supplied, then one character is deleted, but
6507 not saved in the kill ring.
6509 The value returned is always `nil'.
6512 File: lispref.info, Node: User-Level Deletion, Next: The Kill Ring, Prev: Deletion, Up: Text
6514 User-Level Deletion Commands
6515 ============================
6517 This section describes higher-level commands for deleting text,
6518 commands intended primarily for the user but useful also in Lisp
6521 - Command: delete-horizontal-space
6522 This function deletes all spaces and tabs around point. It returns
6525 In the following examples, we call `delete-horizontal-space' four
6526 times, once on each line, with point between the second and third
6527 characters on the line each time.
6529 ---------- Buffer: foo ----------
6534 ---------- Buffer: foo ----------
6536 (delete-horizontal-space) ; Four times.
6539 ---------- Buffer: foo ----------
6544 ---------- Buffer: foo ----------
6546 - Command: delete-indentation &optional join-following-p
6547 This function joins the line point is on to the previous line,
6548 deleting any whitespace at the join and in some cases replacing it
6549 with one space. If JOIN-FOLLOWING-P is non-`nil',
6550 `delete-indentation' joins this line to the following line
6551 instead. The value is `nil'.
6553 If there is a fill prefix, and the second of the lines being joined
6554 starts with the prefix, then `delete-indentation' deletes the fill
6555 prefix before joining the lines. *Note Margins::.
6557 In the example below, point is located on the line starting
6558 `events', and it makes no difference if there are trailing spaces
6559 in the preceding line.
6561 ---------- Buffer: foo ----------
6562 When in the course of human
6563 -!- events, it becomes necessary
6564 ---------- Buffer: foo ----------
6566 (delete-indentation)
6569 ---------- Buffer: foo ----------
6570 When in the course of human-!- events, it becomes necessary
6571 ---------- Buffer: foo ----------
6573 After the lines are joined, the function `fixup-whitespace' is
6574 responsible for deciding whether to leave a space at the junction.
6576 - Command: fixup-whitespace
6577 This function replaces all the white space surrounding point with
6578 either one space or no space, according to the context. It
6581 At the beginning or end of a line, the appropriate amount of space
6582 is none. Before a character with close parenthesis syntax, or
6583 after a character with open parenthesis or expression-prefix
6584 syntax, no space is also appropriate. Otherwise, one space is
6585 appropriate. *Note Syntax Class Table::.
6587 In the example below, `fixup-whitespace' is called the first time
6588 with point before the word `spaces' in the first line. For the
6589 second invocation, point is directly after the `('.
6591 ---------- Buffer: foo ----------
6592 This has too many -!-spaces
6593 This has too many spaces at the start of (-!- this list)
6594 ---------- Buffer: foo ----------
6601 ---------- Buffer: foo ----------
6602 This has too many spaces
6603 This has too many spaces at the start of (this list)
6604 ---------- Buffer: foo ----------
6606 - Command: just-one-space
6607 This command replaces any spaces and tabs around point with a
6608 single space. It returns `nil'.
6610 - Command: delete-blank-lines
6611 This function deletes blank lines surrounding point. If point is
6612 on a blank line with one or more blank lines before or after it,
6613 then all but one of them are deleted. If point is on an isolated
6614 blank line, then it is deleted. If point is on a nonblank line,
6615 the command deletes all blank lines following it.
6617 A blank line is defined as a line containing only tabs and spaces.
6619 `delete-blank-lines' returns `nil'.
6622 File: lispref.info, Node: The Kill Ring, Next: Undo, Prev: User-Level Deletion, Up: Text
6627 "Kill" functions delete text like the deletion functions, but save it
6628 so that the user can reinsert it by "yanking". Most of these functions
6629 have `kill-' in their name. By contrast, the functions whose names
6630 start with `delete-' normally do not save text for yanking (though they
6631 can still be undone); these are "deletion" functions.
6633 Most of the kill commands are primarily for interactive use, and are
6634 not described here. What we do describe are the functions provided for
6635 use in writing such commands. You can use these functions to write
6636 commands for killing text. When you need to delete text for internal
6637 purposes within a Lisp function, you should normally use deletion
6638 functions, so as not to disturb the kill ring contents. *Note
6641 Killed text is saved for later yanking in the "kill ring". This is
6642 a list that holds a number of recent kills, not just the last text
6643 kill. We call this a "ring" because yanking treats it as having
6644 elements in a cyclic order. The list is kept in the variable
6645 `kill-ring', and can be operated on with the usual functions for lists;
6646 there are also specialized functions, described in this section, that
6649 Some people think this use of the word "kill" is unfortunate, since
6650 it refers to operations that specifically _do not_ destroy the entities
6651 "killed". This is in sharp contrast to ordinary life, in which death
6652 is permanent and "killed" entities do not come back to life.
6653 Therefore, other metaphors have been proposed. For example, the term
6654 "cut ring" makes sense to people who, in pre-computer days, used
6655 scissors and paste to cut up and rearrange manuscripts. However, it
6656 would be difficult to change the terminology now.
6660 * Kill Ring Concepts:: What text looks like in the kill ring.
6661 * Kill Functions:: Functions that kill text.
6662 * Yank Commands:: Commands that access the kill ring.
6663 * Low-Level Kill Ring:: Functions and variables for kill ring access.
6664 * Internals of Kill Ring:: Variables that hold kill-ring data.
6667 File: lispref.info, Node: Kill Ring Concepts, Next: Kill Functions, Up: The Kill Ring
6672 The kill ring records killed text as strings in a list, most recent
6673 first. A short kill ring, for example, might look like this:
6675 ("some text" "a different piece of text" "even older text")
6677 When the list reaches `kill-ring-max' entries in length, adding a new
6678 entry automatically deletes the last entry.
6680 When kill commands are interwoven with other commands, each kill
6681 command makes a new entry in the kill ring. Multiple kill commands in
6682 succession build up a single entry in the kill ring, which would be
6683 yanked as a unit; the second and subsequent consecutive kill commands
6684 add text to the entry made by the first one.
6686 For yanking, one entry in the kill ring is designated the "front" of
6687 the ring. Some yank commands "rotate" the ring by designating a
6688 different element as the "front." But this virtual rotation doesn't
6689 change the list itself--the most recent entry always comes first in the
6693 File: lispref.info, Node: Kill Functions, Next: Yank Commands, Prev: Kill Ring Concepts, Up: The Kill Ring
6695 Functions for Killing
6696 ---------------------
6698 `kill-region' is the usual subroutine for killing text. Any command
6699 that calls this function is a "kill command" (and should probably have
6700 `kill' in its name). `kill-region' puts the newly killed text in a new
6701 element at the beginning of the kill ring or adds it to the most recent
6702 element. It uses the `last-command' variable to determine whether the
6703 previous command was a kill command, and if so appends the killed text
6704 to the most recent entry.
6706 - Command: kill-region start end &optional verbose
6707 This function kills the text in the region defined by START and
6708 END. The text is deleted but saved in the kill ring, along with
6709 its text properties. The value is always `nil'.
6711 In an interactive call, START and END are point and the mark.
6713 If the buffer is read-only, `kill-region' modifies the kill ring
6714 just the same, then signals an error without modifying the buffer.
6715 This is convenient because it lets the user use all the kill
6716 commands to copy text into the kill ring from a read-only buffer.
6718 - Command: copy-region-as-kill start end
6719 This command saves the region defined by START and END on the kill
6720 ring (including text properties), but does not delete the text
6721 from the buffer. It returns `nil'. It also indicates the extent
6722 of the text copied by moving the cursor momentarily, or by
6723 displaying a message in the echo area.
6725 The command does not set `this-command' to `kill-region', so a
6726 subsequent kill command does not append to the same kill ring
6729 Don't call `copy-region-as-kill' in Lisp programs unless you aim to
6730 support Emacs 18. For Emacs 19, it is better to use `kill-new' or
6731 `kill-append' instead. *Note Low-Level Kill Ring::.
6734 File: lispref.info, Node: Yank Commands, Next: Low-Level Kill Ring, Prev: Kill Functions, Up: The Kill Ring
6736 Functions for Yanking
6737 ---------------------
6739 "Yanking" means reinserting an entry of previously killed text from the
6740 kill ring. The text properties are copied too.
6742 - Command: yank &optional arg
6743 This command inserts before point the text in the first entry in
6744 the kill ring. It positions the mark at the beginning of that
6745 text, and point at the end.
6747 If ARG is a list (which occurs interactively when the user types
6748 `C-u' with no digits), then `yank' inserts the text as described
6749 above, but puts point before the yanked text and puts the mark
6752 If ARG is a number, then `yank' inserts the ARGth most recently
6753 killed text--the ARGth element of the kill ring list.
6755 `yank' does not alter the contents of the kill ring or rotate it.
6758 - Command: yank-pop arg
6759 This command replaces the just-yanked entry from the kill ring
6760 with a different entry from the kill ring.
6762 This is allowed only immediately after a `yank' or another
6763 `yank-pop'. At such a time, the region contains text that was just
6764 inserted by yanking. `yank-pop' deletes that text and inserts in
6765 its place a different piece of killed text. It does not add the
6766 deleted text to the kill ring, since it is already in the kill
6769 If ARG is `nil', then the replacement text is the previous element
6770 of the kill ring. If ARG is numeric, the replacement is the ARGth
6771 previous kill. If ARG is negative, a more recent kill is the
6774 The sequence of kills in the kill ring wraps around, so that after
6775 the oldest one comes the newest one, and before the newest one
6778 The value is always `nil'.
6781 File: lispref.info, Node: Low-Level Kill Ring, Next: Internals of Kill Ring, Prev: Yank Commands, Up: The Kill Ring
6786 These functions and variables provide access to the kill ring at a lower
6787 level, but still convenient for use in Lisp programs. They take care of
6788 interaction with X Window selections. They do not exist in Emacs
6791 - Function: current-kill count &optional do-not-move
6792 The function `current-kill' rotates the yanking pointer which
6793 designates the "front" of the kill ring by COUNT places (from newer
6794 kills to older ones), and returns the text at that place in the
6797 If the optional second argument DO-NOT-MOVE is non-`nil', then
6798 `current-kill' doesn't alter the yanking pointer; it just returns
6799 the COUNTth kill, counting from the current yanking pointer.
6801 If COUNT is zero, indicating a request for the latest kill,
6802 `current-kill' calls the value of `interprogram-paste-function'
6803 (documented below) before consulting the kill ring.
6805 - Function: kill-new string &optional replace
6806 This function makes the text STRING the latest entry in the kill
6807 ring, and sets `kill-ring-yank-pointer' to point to it.
6809 Normally, STRING is added to the front of the kill ring as a new
6810 entry. However, if optional argument REPLACE is non-`nil', the
6811 entry previously at the front of the kill ring is discarded, and
6814 This function runs the functions on `kill-hooks', and also invokes
6815 the value of `interprogram-cut-function' (see below).
6817 - Function: kill-append string before-p
6818 This function appends the text STRING to the first entry in the
6819 kill ring. Normally STRING goes at the end of the entry, but if
6820 BEFORE-P is non-`nil', it goes at the beginning. This function
6821 also invokes the value of `interprogram-cut-function' (see below).
6823 - Variable: interprogram-paste-function
6824 This variable provides a way of transferring killed text from other
6825 programs, when you are using a window system. Its value should be
6826 `nil' or a function of no arguments.
6828 If the value is a function, `current-kill' calls it to get the
6829 "most recent kill". If the function returns a non-`nil' value,
6830 then that value is used as the "most recent kill". If it returns
6831 `nil', then the first element of `kill-ring' is used.
6833 The normal use of this hook is to get the X server's primary
6834 selection as the most recent kill, even if the selection belongs
6835 to another X client. *Note X Selections::.
6837 - Variable: interprogram-cut-function
6838 This variable provides a way of communicating killed text to other
6839 programs, when you are using a window system. Its value should be
6840 `nil' or a function of one argument.
6842 If the value is a function, `kill-new' and `kill-append' call it
6843 with the new first element of the kill ring as an argument.
6845 The normal use of this hook is to set the X server's primary
6846 selection to the newly killed text.
6849 File: lispref.info, Node: Internals of Kill Ring, Prev: Low-Level Kill Ring, Up: The Kill Ring
6851 Internals of the Kill Ring
6852 --------------------------
6854 The variable `kill-ring' holds the kill ring contents, in the form of a
6855 list of strings. The most recent kill is always at the front of the
6858 The `kill-ring-yank-pointer' variable points to a link in the kill
6859 ring list, whose CAR is the text to yank next. We say it identifies
6860 the "front" of the ring. Moving `kill-ring-yank-pointer' to a
6861 different link is called "rotating the kill ring". We call the kill
6862 ring a "ring" because the functions that move the yank pointer wrap
6863 around from the end of the list to the beginning, or vice-versa.
6864 Rotation of the kill ring is virtual; it does not change the value of
6867 Both `kill-ring' and `kill-ring-yank-pointer' are Lisp variables
6868 whose values are normally lists. The word "pointer" in the name of the
6869 `kill-ring-yank-pointer' indicates that the variable's purpose is to
6870 identify one element of the list for use by the next yank command.
6872 The value of `kill-ring-yank-pointer' is always `eq' to one of the
6873 links in the kill ring list. The element it identifies is the CAR of
6874 that link. Kill commands, which change the kill ring, also set this
6875 variable to the value of `kill-ring'. The effect is to rotate the ring
6876 so that the newly killed text is at the front.
6878 Here is a diagram that shows the variable `kill-ring-yank-pointer'
6879 pointing to the second entry in the kill ring `("some text" "a
6880 different piece of text" "yet older text")'.
6882 kill-ring kill-ring-yank-pointer
6884 | ___ ___ ---> ___ ___ ___ ___
6885 --> |___|___|------> |___|___|--> |___|___|--> nil
6888 | | -->"yet older text"
6890 | --> "a different piece of text"
6894 This state of affairs might occur after `C-y' (`yank') immediately
6895 followed by `M-y' (`yank-pop').
6897 - Variable: kill-ring
6898 This variable holds the list of killed text sequences, most
6899 recently killed first.
6901 - Variable: kill-ring-yank-pointer
6902 This variable's value indicates which element of the kill ring is
6903 at the "front" of the ring for yanking. More precisely, the value
6904 is a tail of the value of `kill-ring', and its CAR is the kill
6905 string that `C-y' should yank.
6907 - User Option: kill-ring-max
6908 The value of this variable is the maximum length to which the kill
6909 ring can grow, before elements are thrown away at the end. The
6910 default value for `kill-ring-max' is 30.
6913 File: lispref.info, Node: Undo, Next: Maintaining Undo, Prev: The Kill Ring, Up: Text
6918 Most buffers have an "undo list", which records all changes made to the
6919 buffer's text so that they can be undone. (The buffers that don't have
6920 one are usually special-purpose buffers for which XEmacs assumes that
6921 undoing is not useful.) All the primitives that modify the text in the
6922 buffer automatically add elements to the front of the undo list, which
6923 is in the variable `buffer-undo-list'.
6925 - Variable: buffer-undo-list
6926 This variable's value is the undo list of the current buffer. A
6927 value of `t' disables the recording of undo information.
6929 Here are the kinds of elements an undo list can have:
6932 This kind of element records a previous value of point. Ordinary
6933 cursor motion does not get any sort of undo record, but deletion
6934 commands use these entries to record where point was before the
6938 This kind of element indicates how to delete text that was
6939 inserted. Upon insertion, the text occupied the range START-END
6943 This kind of element indicates how to reinsert text that was
6944 deleted. The deleted text itself is the string TEXT. The place to
6945 reinsert it is `(abs POSITION)'.
6948 This kind of element indicates that an unmodified buffer became
6949 modified. The elements HIGH and LOW are two integers, each
6950 recording 16 bits of the visited file's modification time as of
6951 when it was previously visited or saved. `primitive-undo' uses
6952 those values to determine whether to mark the buffer as unmodified
6953 once again; it does so only if the file's modification time
6954 matches those numbers.
6956 `(nil PROPERTY VALUE START . END)'
6957 This kind of element records a change in a text property. Here's
6958 how you might undo the change:
6960 (put-text-property START END PROPERTY VALUE)
6963 This element indicates where point was at an earlier time.
6964 Undoing this element sets point to POSITION. Deletion normally
6965 creates an element of this kind as well as a reinsertion element.
6968 This element is a boundary. The elements between two boundaries
6969 are called a "change group"; normally, each change group
6970 corresponds to one keyboard command, and undo commands normally
6971 undo an entire group as a unit.
6973 - Function: undo-boundary
6974 This function places a boundary element in the undo list. The undo
6975 command stops at such a boundary, and successive undo commands undo
6976 to earlier and earlier boundaries. This function returns `nil'.
6978 The editor command loop automatically creates an undo boundary
6979 before each key sequence is executed. Thus, each undo normally
6980 undoes the effects of one command. Self-inserting input
6981 characters are an exception. The command loop makes a boundary
6982 for the first such character; the next 19 consecutive
6983 self-inserting input characters do not make boundaries, and then
6984 the 20th does, and so on as long as self-inserting characters
6987 All buffer modifications add a boundary whenever the previous
6988 undoable change was made in some other buffer. This way, a
6989 command that modifies several buffers makes a boundary in each
6992 Calling this function explicitly is useful for splitting the
6993 effects of a command into more than one unit. For example,
6994 `query-replace' calls `undo-boundary' after each replacement, so
6995 that the user can undo individual replacements one by one.
6997 - Function: primitive-undo count list
6998 This is the basic function for undoing elements of an undo list.
6999 It undoes the first COUNT elements of LIST, returning the rest of
7000 LIST. You could write this function in Lisp, but it is convenient
7003 `primitive-undo' adds elements to the buffer's undo list when it
7004 changes the buffer. Undo commands avoid confusion by saving the
7005 undo list value at the beginning of a sequence of undo operations.
7006 Then the undo operations use and update the saved value. The new
7007 elements added by undoing are not part of this saved value, so
7008 they don't interfere with continuing to undo.