diff options
| author | Richard M. Stallman | 1994-03-29 00:10:31 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-03-29 00:10:31 +0000 |
| commit | b1b12a8ee9455a0512f10ec980f0d79bf6617cd4 (patch) | |
| tree | 8e566ff9ba62823287a3595e86f7b245705a46d4 | |
| parent | 32eff0b035c0b8857f34ca2dcb0282e5e385765f (diff) | |
| download | emacs-b1b12a8ee9455a0512f10ec980f0d79bf6617cd4.tar.gz emacs-b1b12a8ee9455a0512f10ec980f0d79bf6617cd4.zip | |
Initial revision
| -rw-r--r-- | lispref/backups.texi | 621 | ||||
| -rw-r--r-- | lispref/buffers.texi | 828 | ||||
| -rw-r--r-- | lispref/windows.texi | 1592 |
3 files changed, 3041 insertions, 0 deletions
diff --git a/lispref/backups.texi b/lispref/backups.texi new file mode 100644 index 00000000000..57108105e0b --- /dev/null +++ b/lispref/backups.texi | |||
| @@ -0,0 +1,621 @@ | |||
| 1 | @c -*-texinfo-*- | ||
| 2 | @c This is part of the GNU Emacs Lisp Reference Manual. | ||
| 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | ||
| 4 | @c See the file elisp.texi for copying conditions. | ||
| 5 | @setfilename ../info/backups | ||
| 6 | @node Backups and Auto-Saving, Buffers, Files, Top | ||
| 7 | @chapter Backups and Auto-Saving | ||
| 8 | |||
| 9 | Backup files and auto-save files are two methods by which Emacs tries | ||
| 10 | to protect the user from the consequences of crashes or of the user's | ||
| 11 | own errors. Auto-saving preserves the text from earlier in the current | ||
| 12 | editing session; backup files preserve file contents prior to the | ||
| 13 | current session. | ||
| 14 | |||
| 15 | @menu | ||
| 16 | * Backup Files:: How backup files are made; how their names are chosen. | ||
| 17 | * Auto-Saving:: How auto-save files are made; how their names are chosen. | ||
| 18 | * Reverting:: @code{revert-buffer}, and how to customize what it does. | ||
| 19 | @end menu | ||
| 20 | |||
| 21 | @node Backup Files, Auto-Saving, Backups and Auto-Saving, Backups and Auto-Saving | ||
| 22 | @section Backup Files | ||
| 23 | @cindex backup file | ||
| 24 | |||
| 25 | A @dfn{backup file} is a copy of the old contents of a file you are | ||
| 26 | editing. Emacs makes a backup file the first time you save a buffer | ||
| 27 | into its visited file. Normally, this means that the backup file | ||
| 28 | contains the contents of the file as it was before the current editing | ||
| 29 | session. The contents of the backup file normally remain unchanged once | ||
| 30 | it exists. | ||
| 31 | |||
| 32 | Backups are usually made by renaming the visited file to a new name. | ||
| 33 | Optionally, you can specify that backup files should be made by copying | ||
| 34 | the visited file. This choice makes a difference for files with | ||
| 35 | multiple names; it also can affect whether the edited file remains owned | ||
| 36 | by the original owner or becomes owned by the user editing it. | ||
| 37 | |||
| 38 | By default, Emacs makes a single backup file for each file edited. | ||
| 39 | You can alternatively request numbered backups; then each new backup | ||
| 40 | file gets a new name. You can delete old numbered backups when you | ||
| 41 | don't want them any more, or Emacs can delete them automatically. | ||
| 42 | |||
| 43 | @menu | ||
| 44 | * Making Backups:: How Emacs makes backup files, and when. | ||
| 45 | * Rename or Copy:: Two alternatives: renaming the old file or copying it. | ||
| 46 | * Numbered Backups:: Keeping multiple backups for each source file. | ||
| 47 | * Backup Names:: How backup file names are computed; customization. | ||
| 48 | @end menu | ||
| 49 | |||
| 50 | @node Making Backups, Rename or Copy, Backup Files, Backup Files | ||
| 51 | @subsection Making Backup Files | ||
| 52 | |||
| 53 | @defun backup-buffer | ||
| 54 | This function makes a backup of the file visited by the current | ||
| 55 | buffer, if appropriate. It is called by @code{save-buffer} before | ||
| 56 | saving the buffer the first time. | ||
| 57 | @end defun | ||
| 58 | |||
| 59 | @defvar buffer-backed-up | ||
| 60 | This buffer-local variable indicates whether this buffer's file has | ||
| 61 | been backed up on account of this buffer. If it is non-@code{nil}, then | ||
| 62 | the backup file has been written. Otherwise, the file should be backed | ||
| 63 | up when it is next saved (if backup files are enabled). This is a | ||
| 64 | permanent local; @code{kill-local-variables} does not alter it. | ||
| 65 | @end defvar | ||
| 66 | |||
| 67 | @defopt make-backup-files | ||
| 68 | This variable determines whether or not to make backup files. If it | ||
| 69 | is non-@code{nil}, then Emacs creates a backup of each file when it is | ||
| 70 | saved for the first time. | ||
| 71 | |||
| 72 | The following example shows how to change the @code{make-backup-files} | ||
| 73 | variable only in the @file{RMAIL} buffer and not elsewhere. Setting it | ||
| 74 | @code{nil} stops Emacs from making backups of the @file{RMAIL} file, | ||
| 75 | which may save disk space. (You would put this code in your | ||
| 76 | @file{.emacs} file.) | ||
| 77 | |||
| 78 | @smallexample | ||
| 79 | @group | ||
| 80 | (add-hook 'rmail-mode-hook | ||
| 81 | (function (lambda () | ||
| 82 | (make-local-variable | ||
| 83 | 'make-backup-files) | ||
| 84 | (setq make-backup-files nil)))) | ||
| 85 | @end group | ||
| 86 | @end smallexample | ||
| 87 | @end defopt | ||
| 88 | |||
| 89 | @defvar backup-enable-predicate filename | ||
| 90 | This variable's value is a function to be called on certain occasions to | ||
| 91 | decide whether a there should be backup files for file name | ||
| 92 | @var{filename}. If it returns @code{nil}, backups are disabled. | ||
| 93 | Otherwise, the other variables in this section say whether and how to | ||
| 94 | make backups. | ||
| 95 | |||
| 96 | The default value is this: | ||
| 97 | |||
| 98 | @example | ||
| 99 | (lambda (name) | ||
| 100 | (or (< (length name) 5) | ||
| 101 | (not (string-equal "/tmp/" | ||
| 102 | (substring name 0 5))))) | ||
| 103 | @end example | ||
| 104 | @end defvar | ||
| 105 | |||
| 106 | @defvar backup-inhibited | ||
| 107 | If this variable is non-@code{nil}, backups are inhibited. It records | ||
| 108 | the result of testing @code{backup-enable-predicate} on the visited file | ||
| 109 | name. It can also coherently be used by other mechanisms that inhibit | ||
| 110 | backups based on which file is visited. Major modes should not set this | ||
| 111 | variable. | ||
| 112 | @end defvar | ||
| 113 | |||
| 114 | @node Rename or Copy, Numbered Backups, Making Backups, Backup Files | ||
| 115 | @subsection Backup by Renaming or by Copying? | ||
| 116 | @cindex backup files, how to make them | ||
| 117 | |||
| 118 | There are two ways that Emacs can make a backup file: | ||
| 119 | |||
| 120 | @itemize @bullet | ||
| 121 | @item | ||
| 122 | Emacs can rename the original file so that it becomes a backup file, and | ||
| 123 | then write the buffer being saved into a new file. After this | ||
| 124 | procedure, any other names (i.e., hard links) of the original file now | ||
| 125 | refer to the backup file. The new file is owned by the user doing the | ||
| 126 | editing, and its group is the default for new files written by the user | ||
| 127 | in that directory. | ||
| 128 | |||
| 129 | @item | ||
| 130 | Emacs can copy the original file into a backup file, and then overwrite | ||
| 131 | the original file with new contents. After this procedure, any other | ||
| 132 | names (i.e., hard links) of the original file still refer to the current | ||
| 133 | version of the file. The file's owner and group will be unchanged. | ||
| 134 | @end itemize | ||
| 135 | |||
| 136 | The first method, renaming, is the default. | ||
| 137 | |||
| 138 | The variable @code{backup-by-copying}, if non-@code{nil}, says to use | ||
| 139 | the second method, which is to copy the original file and overwrite it | ||
| 140 | with the new buffer contents. The variable @code{file-precious-flag}, | ||
| 141 | if non-@code{nil}, also has this effect (as a sideline of its main | ||
| 142 | significance). @xref{Saving Buffers}. | ||
| 143 | |||
| 144 | @defvar backup-by-copying | ||
| 145 | If this variable is non-@code{nil}, Emacs always makes backup files by | ||
| 146 | copying. | ||
| 147 | @end defvar | ||
| 148 | |||
| 149 | The following two variables, when non-@code{nil}, cause the second | ||
| 150 | method to be used in certain special cases. They have no effect on the | ||
| 151 | treatment of files that don't fall into the special cases. | ||
| 152 | |||
| 153 | @defvar backup-by-copying-when-linked | ||
| 154 | If this variable is non-@code{nil}, Emacs makes backups by copying for | ||
| 155 | files with multiple names (hard links). | ||
| 156 | |||
| 157 | This variable is significant only if @code{backup-by-copying} is | ||
| 158 | @code{nil}, since copying is always used when that variable is | ||
| 159 | non-@code{nil}. | ||
| 160 | @end defvar | ||
| 161 | |||
| 162 | @defvar backup-by-copying-when-mismatch | ||
| 163 | If this variable is non-@code{nil}, Emacs makes backups by copying in cases | ||
| 164 | where renaming would change either the owner or the group of the file. | ||
| 165 | |||
| 166 | The value has no effect when renaming would not alter the owner or | ||
| 167 | group of the file; that is, for files which are owned by the user and | ||
| 168 | whose group matches the default for a new file created there by the | ||
| 169 | user. | ||
| 170 | |||
| 171 | This variable is significant only if @code{backup-by-copying} is | ||
| 172 | @code{nil}, since copying is always used when that variable is | ||
| 173 | non-@code{nil}. | ||
| 174 | @end defvar | ||
| 175 | |||
| 176 | @node Numbered Backups, Backup Names, Rename or Copy, Backup Files | ||
| 177 | @subsection Making and Deleting Numbered Backup Files | ||
| 178 | |||
| 179 | If a file's name is @file{foo}, the names of its numbered backup | ||
| 180 | versions are @file{foo.~@var{v}~}, for various integers @var{v}, like | ||
| 181 | this: @file{foo.~1~}, @file{foo.~2~}, @file{foo.~3~}, @dots{}, | ||
| 182 | @file{foo.~259~}, and so on. | ||
| 183 | |||
| 184 | @defopt version-control | ||
| 185 | This variable controls whether to make a single non-numbered backup | ||
| 186 | file or multiple numbered backups. | ||
| 187 | |||
| 188 | @table @asis | ||
| 189 | @item @code{nil} | ||
| 190 | Make numbered backups if the visited file already has numbered backups; | ||
| 191 | otherwise, do not. | ||
| 192 | |||
| 193 | @item @code{never} | ||
| 194 | Do not make numbered backups. | ||
| 195 | |||
| 196 | @item @var{anything else} | ||
| 197 | Do make numbered backups. | ||
| 198 | @end table | ||
| 199 | @end defopt | ||
| 200 | |||
| 201 | The use of numbered backups ultimately leads to a large number of | ||
| 202 | backup versions, which must then be deleted. Emacs can do this | ||
| 203 | automatically. | ||
| 204 | |||
| 205 | @defopt kept-new-versions | ||
| 206 | The value of this variable is the number of oldest versions to keep | ||
| 207 | when a new numbered backup is made. The newly made backup is included | ||
| 208 | in the count. The default value is 2. | ||
| 209 | @end defopt | ||
| 210 | |||
| 211 | @defopt kept-old-versions | ||
| 212 | The value of this variable is the number of oldest versions to keep | ||
| 213 | when a new numbered backup is made. The default value is 2. | ||
| 214 | @end defopt | ||
| 215 | |||
| 216 | If there are backups numbered 1, 2, 3, 5, and 7, and both of these | ||
| 217 | variables have the value 2, then the backups numbered 1 and 2 are kept | ||
| 218 | as old versions and those numbered 5 and 7 are kept as new versions; | ||
| 219 | backup version 3 is deleted. The function @code{find-backup-file-name} | ||
| 220 | (@pxref{Backup Names}) is responsible for determining which backup | ||
| 221 | versions to delete, but does not delete them itself. | ||
| 222 | |||
| 223 | @defopt trim-versions-without-asking | ||
| 224 | If this variable is non-@code{nil}, then saving a file deletes excess | ||
| 225 | backup versions silently. Otherwise, it asks the user whether to delete | ||
| 226 | them. | ||
| 227 | @end defopt | ||
| 228 | |||
| 229 | @defopt dired-kept-versions | ||
| 230 | This variable specifies how many of the newest backup versions to keep | ||
| 231 | in the Dired command @kbd{.} (@code{dired-clean-directory}). That's the | ||
| 232 | same thing @code{kept-new-versions} does when you make a new backup | ||
| 233 | file. The default value is 2. | ||
| 234 | @end defopt | ||
| 235 | |||
| 236 | @node Backup Names, , Numbered Backups, Backup Files | ||
| 237 | @subsection Naming Backup Files | ||
| 238 | |||
| 239 | The functions in this section are documented mainly because you can | ||
| 240 | customize the naming conventions for backup files by redefining them. | ||
| 241 | If you change one, you probably need to change the rest. | ||
| 242 | |||
| 243 | @defun backup-file-name-p filename | ||
| 244 | This function returns a non-@code{nil} value if @var{filename} is a | ||
| 245 | possible name for a backup file. A file with the name @var{filename} | ||
| 246 | need not exist; the function just checks the name. | ||
| 247 | |||
| 248 | @smallexample | ||
| 249 | @group | ||
| 250 | (backup-file-name-p "foo") | ||
| 251 | @result{} nil | ||
| 252 | @end group | ||
| 253 | @group | ||
| 254 | (backup-file-name-p "foo~") | ||
| 255 | @result{} 3 | ||
| 256 | @end group | ||
| 257 | @end smallexample | ||
| 258 | |||
| 259 | The standard definition of this function is as follows: | ||
| 260 | |||
| 261 | @smallexample | ||
| 262 | @group | ||
| 263 | (defun backup-file-name-p (file) | ||
| 264 | "Return non-nil if FILE is a backup file \ | ||
| 265 | name (numeric or not)..." | ||
| 266 | (string-match "~$" file)) | ||
| 267 | @end group | ||
| 268 | @end smallexample | ||
| 269 | |||
| 270 | @noindent | ||
| 271 | Thus, the function returns a non-@code{nil} value if the file name ends | ||
| 272 | with a @samp{~}. (We use a backslash to split the documentation | ||
| 273 | string's first line into two lines in the text, but produce just one | ||
| 274 | line in the string itself.) | ||
| 275 | |||
| 276 | This simple expression is placed in a separate function to make it easy | ||
| 277 | to redefine for customization. | ||
| 278 | @end defun | ||
| 279 | |||
| 280 | @defun make-backup-file-name filename | ||
| 281 | This function returns a string which is the name to use for a | ||
| 282 | non-numbered backup file for file @var{filename}. On Unix, this is just | ||
| 283 | @var{filename} with a tilde appended. | ||
| 284 | |||
| 285 | The standard definition of this function is as follows: | ||
| 286 | |||
| 287 | @smallexample | ||
| 288 | @group | ||
| 289 | (defun make-backup-file-name (file) | ||
| 290 | "Create the non-numeric backup file name for FILE. | ||
| 291 | @dots{}" | ||
| 292 | (concat file "~")) | ||
| 293 | @end group | ||
| 294 | @end smallexample | ||
| 295 | |||
| 296 | You can change the backup file naming convention by redefining this | ||
| 297 | function. The following example redefines @code{make-backup-file-name} | ||
| 298 | to prepend a @samp{.} as well as appending a tilde: | ||
| 299 | |||
| 300 | @smallexample | ||
| 301 | @group | ||
| 302 | (defun make-backup-file-name (filename) | ||
| 303 | (concat "." filename "~")) | ||
| 304 | @end group | ||
| 305 | |||
| 306 | @group | ||
| 307 | (make-backup-file-name "backups.texi") | ||
| 308 | @result{} ".backups.texi~" | ||
| 309 | @end group | ||
| 310 | @end smallexample | ||
| 311 | @end defun | ||
| 312 | |||
| 313 | @defun find-backup-file-name filename | ||
| 314 | This function computes the file name for a new backup file for | ||
| 315 | @var{filename}. It may also propose certain existing backup files for | ||
| 316 | deletion. @code{find-backup-file-name} returns a list whose @sc{car} is | ||
| 317 | the name for the new backup file and whose @sc{cdr} is a list of backup | ||
| 318 | files whose deletion is proposed. | ||
| 319 | |||
| 320 | Two variables, @code{kept-old-versions} and @code{kept-new-versions}, | ||
| 321 | determine which backup versions should be kept. This function keeps | ||
| 322 | those versions by excluding them from the @sc{cdr} of the value. | ||
| 323 | @xref{Numbered Backups}. | ||
| 324 | |||
| 325 | In this example, the value says that @file{~rms/foo.~5~} is the name | ||
| 326 | to use for the new backup file, and @file{~rms/foo.~3~} is an ``excess'' | ||
| 327 | version that the caller should consider deleting now. | ||
| 328 | |||
| 329 | @smallexample | ||
| 330 | @group | ||
| 331 | (find-backup-file-name "~rms/foo") | ||
| 332 | @result{} ("~rms/foo.~5~" "~rms/foo.~3~") | ||
| 333 | @end group | ||
| 334 | @end smallexample | ||
| 335 | @end defun | ||
| 336 | |||
| 337 | @c Emacs 19 feature | ||
| 338 | @defun file-newest-backup filename | ||
| 339 | This function returns the name of the most recent backup file for | ||
| 340 | @var{filename}, or @code{nil} that file has no backup files. | ||
| 341 | |||
| 342 | Some file comparison commands use this function in order to compare | ||
| 343 | a file by default with its most recent backup. | ||
| 344 | @end defun | ||
| 345 | |||
| 346 | @node Auto-Saving, Reverting, Backup Files, Backups and Auto-Saving | ||
| 347 | @section Auto-Saving | ||
| 348 | @cindex auto-saving | ||
| 349 | |||
| 350 | Emacs periodically saves all files that you are visiting; this is | ||
| 351 | called @dfn{auto-saving}. Auto-saving prevents you from losing more | ||
| 352 | than a limited amount of work if the system crashes. By default, | ||
| 353 | auto-saves happen every 300 keystrokes, or after around 30 seconds of | ||
| 354 | idle time. @xref{Auto-Save, Auto-Save, Auto-Saving: Protection Against | ||
| 355 | Disasters, emacs, The GNU Emacs Manual}, for information on auto-save | ||
| 356 | for users. Here we describe the functions used to implement auto-saving | ||
| 357 | and the variables that control them. | ||
| 358 | |||
| 359 | @defvar buffer-auto-save-file-name | ||
| 360 | This buffer-local variable is the name of the file used for | ||
| 361 | auto-saving the current buffer. It is @code{nil} if the buffer | ||
| 362 | should not be auto-saved. | ||
| 363 | |||
| 364 | @example | ||
| 365 | @group | ||
| 366 | buffer-auto-save-file-name | ||
| 367 | => "/xcssun/users/rms/lewis/#files.texi#" | ||
| 368 | @end group | ||
| 369 | @end example | ||
| 370 | @end defvar | ||
| 371 | |||
| 372 | @deffn Command auto-save-mode arg | ||
| 373 | When used interactively without an argument, this command is a toggle | ||
| 374 | switch: it turns on auto-saving of the current buffer if it is off, and | ||
| 375 | vice-versa. With an argument @var{arg}, the command turns auto-saving | ||
| 376 | on if the value of @var{arg} is @code{t}, a nonempty list, or a positive | ||
| 377 | integer. Otherwise, it turns auto-saving off. | ||
| 378 | @end deffn | ||
| 379 | |||
| 380 | @defun auto-save-file-name-p filename | ||
| 381 | This function returns a non-@code{nil} value if @var{filename} is a | ||
| 382 | string that could be the name of an auto-save file. It works based on | ||
| 383 | knowledge of the naming convention for auto-save files: a name that | ||
| 384 | begins and ends with hash marks (@samp{#}) is a possible auto-save file | ||
| 385 | name. The argument @var{filename} should not contain a directory part. | ||
| 386 | |||
| 387 | @example | ||
| 388 | @group | ||
| 389 | (make-auto-save-file-name) | ||
| 390 | @result{} "/xcssun/users/rms/lewis/#files.texi#" | ||
| 391 | @end group | ||
| 392 | @group | ||
| 393 | (auto-save-file-name-p "#files.texi#") | ||
| 394 | @result{} 0 | ||
| 395 | @end group | ||
| 396 | @group | ||
| 397 | (auto-save-file-name-p "files.texi") | ||
| 398 | @result{} nil | ||
| 399 | @end group | ||
| 400 | @end example | ||
| 401 | |||
| 402 | The standard definition of this function is as follows: | ||
| 403 | |||
| 404 | @example | ||
| 405 | @group | ||
| 406 | (defun auto-save-file-name-p (filename) | ||
| 407 | "Return non-nil if FILENAME can be yielded by..." | ||
| 408 | (string-match "^#.*#$" filename)) | ||
| 409 | @end group | ||
| 410 | @end example | ||
| 411 | |||
| 412 | This function exists so that you can customize it if you wish to | ||
| 413 | change the naming convention for auto-save files. If you redefine it, | ||
| 414 | be sure to redefine the function @code{make-auto-save-file-name} | ||
| 415 | correspondingly. | ||
| 416 | @end defun | ||
| 417 | |||
| 418 | @defun make-auto-save-file-name | ||
| 419 | This function returns the file name to use for auto-saving the current | ||
| 420 | buffer. This is just the file name with hash marks (@samp{#}) appended | ||
| 421 | and prepended to it. This function does not look at the variable | ||
| 422 | @code{auto-save-visited-file-name}; you should check that before calling | ||
| 423 | this function. | ||
| 424 | |||
| 425 | @example | ||
| 426 | @group | ||
| 427 | (make-auto-save-file-name) | ||
| 428 | @result{} "/xcssun/users/rms/lewis/#backup.texi#" | ||
| 429 | @end group | ||
| 430 | @end example | ||
| 431 | |||
| 432 | The standard definition of this function is as follows: | ||
| 433 | |||
| 434 | @example | ||
| 435 | @group | ||
| 436 | (defun make-auto-save-file-name () | ||
| 437 | "Return file name to use for auto-saves \ | ||
| 438 | of current buffer. | ||
| 439 | @dots{}" | ||
| 440 | (if buffer-file-name | ||
| 441 | @end group | ||
| 442 | @group | ||
| 443 | (concat | ||
| 444 | (file-name-directory buffer-file-name) | ||
| 445 | "#" | ||
| 446 | (file-name-nondirectory buffer-file-name) | ||
| 447 | "#") | ||
| 448 | (expand-file-name | ||
| 449 | (concat "#%" (buffer-name) "#")))) | ||
| 450 | @end group | ||
| 451 | @end example | ||
| 452 | |||
| 453 | This exists as a separate function so that you can redefine it to | ||
| 454 | customize the naming convention for auto-save files. Be sure to | ||
| 455 | change @code{auto-save-file-name-p} in a corresponding way. | ||
| 456 | @end defun | ||
| 457 | |||
| 458 | @defvar auto-save-visited-file-name | ||
| 459 | If this variable is non-@code{nil}, Emacs auto-saves buffers in | ||
| 460 | the files they are visiting. That is, the auto-save is done in the same | ||
| 461 | file which you are editing. Normally, this variable is @code{nil}, so | ||
| 462 | auto-save files have distinct names that are created by | ||
| 463 | @code{make-auto-save-file-name}. | ||
| 464 | |||
| 465 | When you change the value of this variable, the value does not take | ||
| 466 | effect until the next time auto-save mode is reenabled in any given | ||
| 467 | buffer. If auto-save mode is already enabled, auto-saves continue to go | ||
| 468 | in the same file name until @code{auto-save-mode} is called again. | ||
| 469 | @end defvar | ||
| 470 | |||
| 471 | @defun recent-auto-save-p | ||
| 472 | This function returns @code{t} if the current buffer has been | ||
| 473 | auto-saved since the last time it was read in or saved. | ||
| 474 | @end defun | ||
| 475 | |||
| 476 | @defun set-buffer-auto-saved | ||
| 477 | This function marks the current buffer as auto-saved. The buffer will | ||
| 478 | not be auto-saved again until the buffer text is changed again. The | ||
| 479 | function returns @code{nil}. | ||
| 480 | @end defun | ||
| 481 | |||
| 482 | @defopt auto-save-interval | ||
| 483 | The value of this variable is the number of characters that Emacs | ||
| 484 | reads from the keyboard between auto-saves. Each time this many more | ||
| 485 | characters are read, auto-saving is done for all buffers in which it is | ||
| 486 | enabled. | ||
| 487 | @end defopt | ||
| 488 | |||
| 489 | @defopt auto-save-timeout | ||
| 490 | The value of this variable is the number of seconds of idle time that | ||
| 491 | should cause auto-saving. Each time the user pauses for this long, | ||
| 492 | Emacs auto-saves any buffers that need it. (Actually, the specified | ||
| 493 | timeout is multiplied by a factor depending on the size of the current | ||
| 494 | buffer.) | ||
| 495 | @end defopt | ||
| 496 | |||
| 497 | @defvar auto-save-hook | ||
| 498 | This normal hook is run whenever an auto-save is about to happen. | ||
| 499 | @end defvar | ||
| 500 | |||
| 501 | @defopt auto-save-default | ||
| 502 | If this variable is non-@code{nil}, buffers that are visiting files | ||
| 503 | have auto-saving enabled by default. Otherwise, they do not. | ||
| 504 | @end defopt | ||
| 505 | |||
| 506 | @deffn Command do-auto-save &optional no-message | ||
| 507 | This function auto-saves all buffers that need to be auto-saved. It | ||
| 508 | saves all buffers for which auto-saving is enabled and that have been | ||
| 509 | changed since the previous auto-save. | ||
| 510 | |||
| 511 | Normally, if any buffers are auto-saved, a message that says | ||
| 512 | @samp{Auto-saving...} is displayed in the echo area while auto-saving is | ||
| 513 | going on. However, if @var{no-message} is non-@code{nil}, the message | ||
| 514 | is inhibited. | ||
| 515 | @end deffn | ||
| 516 | |||
| 517 | @defun delete-auto-save-file-if-necessary | ||
| 518 | This function deletes the current buffer's auto-save file if | ||
| 519 | @code{delete-auto-save-files} is non-@code{nil}. It is called every | ||
| 520 | time a buffer is saved. | ||
| 521 | @end defun | ||
| 522 | |||
| 523 | @defvar delete-auto-save-files | ||
| 524 | This variable is used by the function | ||
| 525 | @code{delete-auto-save-file-if-necessary}. If it is non-@code{nil}, | ||
| 526 | Emacs deletes auto-save files when a true save is done (in the visited | ||
| 527 | file). This saves disk space and unclutters your directory. | ||
| 528 | @end defvar | ||
| 529 | |||
| 530 | @defun rename-auto-save-file | ||
| 531 | This function adjusts the current buffer's auto-save file name if the | ||
| 532 | visited file name has changed. It also renames an existing auto-save | ||
| 533 | file. If the visited file name has not changed, this function does | ||
| 534 | nothing. | ||
| 535 | @end defun | ||
| 536 | |||
| 537 | @node Reverting, , Auto-Saving, Backups and Auto-Saving | ||
| 538 | @section Reverting | ||
| 539 | |||
| 540 | If you have made extensive changes to a file and then change your mind | ||
| 541 | about them, you can get rid of them by reading in the previous version | ||
| 542 | of the file with the @code{revert-buffer} command. @xref{Reverting, , | ||
| 543 | Reverting a Buffer, emacs, The GNU Emacs Manual}. | ||
| 544 | |||
| 545 | @deffn Command revert-buffer &optional check-auto-save noconfirm | ||
| 546 | This command replaces the buffer text with the text of the visited | ||
| 547 | file on disk. This action undoes all changes since the file was visited | ||
| 548 | or saved. | ||
| 549 | |||
| 550 | If the argument @var{check-auto-save} is non-@code{nil}, and the | ||
| 551 | latest auto-save file is more recent than the visited file, | ||
| 552 | @code{revert-buffer} asks the user whether to use that instead. | ||
| 553 | Otherwise, it always uses the text of the visited file itself. | ||
| 554 | Interactively, @var{check-auto-save} is set if there is a numeric prefix | ||
| 555 | argument. | ||
| 556 | |||
| 557 | Normally, @code{revert-buffer} asks for confirmation before it changes | ||
| 558 | the buffer; but if the argument @var{noconfirm} is non-@code{nil}, | ||
| 559 | @code{revert-buffer} does not ask for confirmation. | ||
| 560 | |||
| 561 | Reverting tries to preserve marker positions in the buffer by using the | ||
| 562 | replacement feature of @code{insert-file-contents}. If there is no | ||
| 563 | actual difference between the buffer and the file, before reversion, | ||
| 564 | this preserves all the markers. If reversion does change the buffer, | ||
| 565 | this preserves the markers in the unchanged text (if any) at the | ||
| 566 | beginning and end of the buffer. Preserving any additional markers | ||
| 567 | would be problematical. | ||
| 568 | |||
| 569 | If the value of the @code{revert-buffer-function} variable is | ||
| 570 | non-@code{nil}, it is called as a function with no arguments to do the | ||
| 571 | work. | ||
| 572 | @end deffn | ||
| 573 | |||
| 574 | @defvar revert-buffer-function | ||
| 575 | The value of this variable is the function to use to revert this | ||
| 576 | buffer; but if the value of this variable is @code{nil}, then the | ||
| 577 | @code{revert-buffer} function carries out its default action. Modes | ||
| 578 | such as Dired mode, in which the text being edited does not consist of a | ||
| 579 | file's contents but can be regenerated in some other fashion, give this | ||
| 580 | variable a buffer-local value that is a function to regenerate the | ||
| 581 | contents. | ||
| 582 | @end defvar | ||
| 583 | |||
| 584 | @defvar revert-buffer-insert-file-contents-function | ||
| 585 | The value of this variable, if non-@code{nil}, is the function to use | ||
| 586 | to insert contents when reverting this buffer. The function receives | ||
| 587 | two arguments, first the file name to use, and second, @code{t} if the | ||
| 588 | user has asked to read the auto-save file. | ||
| 589 | @end defvar | ||
| 590 | |||
| 591 | @defvar before-revert-hook | ||
| 592 | This normal hook is run by @code{revert-buffer} before actually | ||
| 593 | inserting the modified contents---but only if | ||
| 594 | @code{revert-buffer-function} is @code{nil}. | ||
| 595 | |||
| 596 | Font Lock mode uses this hook to record that the buffer contents are no | ||
| 597 | longer fontified. | ||
| 598 | @end defvar | ||
| 599 | |||
| 600 | @defvar after-revert-hook | ||
| 601 | This normal hook is run by @code{revert-buffer} after actually inserting | ||
| 602 | the modified contents---but only if @code{revert-buffer-function} is | ||
| 603 | @code{nil}. | ||
| 604 | |||
| 605 | Font Lock mode uses this hook to recompute the fonts for the updated | ||
| 606 | buffer contents. | ||
| 607 | @end defvar | ||
| 608 | |||
| 609 | @deffn Command recover-file filename | ||
| 610 | This function visits @var{filename}, but gets the contents from its | ||
| 611 | last auto-save file. This is useful after the system has crashed, to | ||
| 612 | resume editing the same file without losing all the work done in the | ||
| 613 | previous session. | ||
| 614 | |||
| 615 | An error is signaled if there is no auto-save file for @var{filename}, | ||
| 616 | or if @var{filename} is newer than its auto-save file. If | ||
| 617 | @var{filename} does not exist, but its auto-save file does, then the | ||
| 618 | auto-save file is read as usual. This last situation may occur if you | ||
| 619 | visited a nonexistent file and never actually saved it. | ||
| 620 | @end deffn | ||
| 621 | |||
diff --git a/lispref/buffers.texi b/lispref/buffers.texi new file mode 100644 index 00000000000..6f777d7480c --- /dev/null +++ b/lispref/buffers.texi | |||
| @@ -0,0 +1,828 @@ | |||
| 1 | @c -*-texinfo-*- | ||
| 2 | @c This is part of the GNU Emacs Lisp Reference Manual. | ||
| 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | ||
| 4 | @c See the file elisp.texi for copying conditions. | ||
| 5 | @setfilename ../info/buffers | ||
| 6 | @node Buffers, Windows, Backups and Auto-Saving, Top | ||
| 7 | @chapter Buffers | ||
| 8 | @cindex buffer | ||
| 9 | |||
| 10 | A @dfn{buffer} is a Lisp object containing text to be edited. Buffers | ||
| 11 | are used to hold the contents of files that are being visited; there may | ||
| 12 | also be buffers which are not visiting files. While several buffers may | ||
| 13 | exist at one time, exactly one buffer is designated the @dfn{current | ||
| 14 | buffer} at any time. Most editing commands act on the contents of the | ||
| 15 | current buffer. Each buffer, including the current buffer, may or may | ||
| 16 | not be displayed in any windows. | ||
| 17 | |||
| 18 | @menu | ||
| 19 | * Buffer Basics:: What is a buffer? | ||
| 20 | * Buffer Names:: Accessing and changing buffer names. | ||
| 21 | * Buffer File Name:: The buffer file name indicates which file is visited. | ||
| 22 | * Buffer Modification:: A buffer is @dfn{modified} if it needs to be saved. | ||
| 23 | * Modification Time:: Determining whether the visited file was changed | ||
| 24 | ``behind Emacs's back''. | ||
| 25 | * Read Only Buffers:: Modifying text is not allowed in a read-only buffer. | ||
| 26 | * The Buffer List:: How to look at all the existing buffers. | ||
| 27 | * Creating Buffers:: Functions that create buffers. | ||
| 28 | * Killing Buffers:: Buffers exist until explicitly killed. | ||
| 29 | * Current Buffer:: Designating a buffer as current | ||
| 30 | so primitives will access its contents. | ||
| 31 | @end menu | ||
| 32 | |||
| 33 | @node Buffer Basics | ||
| 34 | @comment node-name, next, previous, up | ||
| 35 | @section Buffer Basics | ||
| 36 | |||
| 37 | @ifinfo | ||
| 38 | A @dfn{buffer} is a Lisp object containing text to be edited. Buffers | ||
| 39 | are used to hold the contents of files that are being visited; there may | ||
| 40 | also be buffers which are not visiting files. While several buffers may | ||
| 41 | exist at one time, exactly one buffer is designated the @dfn{current | ||
| 42 | buffer} at any time. Most editing commands act on the contents of the | ||
| 43 | current buffer. Each buffer, including the current buffer, may or may | ||
| 44 | not be displayed in any windows. | ||
| 45 | @end ifinfo | ||
| 46 | |||
| 47 | Buffers in Emacs editing are objects which have distinct names and | ||
| 48 | hold text that can be edited. Buffers appear to Lisp programs as a | ||
| 49 | special data type. The contents of a buffer may be viewed as an | ||
| 50 | extendable string; insertions and deletions may occur in any part of the | ||
| 51 | buffer. @xref{Text}. | ||
| 52 | |||
| 53 | A Lisp buffer object contains numerous pieces of information. Some of | ||
| 54 | this information is directly accessible to the programmer through | ||
| 55 | variables, while other information is only accessible through | ||
| 56 | special-purpose functions. For example, the visited file name is | ||
| 57 | directly accessible through a variable, while the value of point is | ||
| 58 | accessible only through a primitive function. | ||
| 59 | |||
| 60 | Buffer-specific information that is directly accessible is stored in | ||
| 61 | @dfn{buffer-local} variable bindings, which are variable values that are | ||
| 62 | effective only in a particular buffer. This feature allows each buffer | ||
| 63 | to override the values of certain variables. Most major modes override | ||
| 64 | variables such as @code{fill-column} or @code{comment-column} in this | ||
| 65 | way. For more information about buffer-local variables and functions | ||
| 66 | related to them, see @ref{Buffer-Local Variables}. | ||
| 67 | |||
| 68 | For functions and variables related to visiting files in buffers, see | ||
| 69 | @ref{Visiting Files} and @ref{Saving Buffers}. For functions and | ||
| 70 | variables related to the display of buffers in windows, see | ||
| 71 | @ref{Buffers and Windows}. | ||
| 72 | |||
| 73 | @defun bufferp object | ||
| 74 | This function returns @code{t} if @var{object} is a buffer, | ||
| 75 | @code{nil} otherwise. | ||
| 76 | @end defun | ||
| 77 | |||
| 78 | @node Buffer Names | ||
| 79 | @section Buffer Names | ||
| 80 | @cindex buffer names | ||
| 81 | |||
| 82 | Each buffer has a unique name, which is a string. Many of the | ||
| 83 | functions that work on buffers accept either a buffer or a buffer name | ||
| 84 | as an argument. Any argument called @var{buffer-or-name} is of this | ||
| 85 | sort, and an error is signaled if it is neither a string nor a buffer. | ||
| 86 | Any argument called @var{buffer} must be an actual buffer | ||
| 87 | object, not a name. | ||
| 88 | |||
| 89 | Buffers that are ephemeral and generally uninteresting to the user | ||
| 90 | have names starting with a space, so that the @code{list-buffers} or | ||
| 91 | @code{buffer-menu} commands don't mention them. A name starting with | ||
| 92 | space also initially disables recording undo information; see | ||
| 93 | @ref{Undo}. | ||
| 94 | |||
| 95 | @defun buffer-name &optional buffer | ||
| 96 | This function returns the name of @var{buffer} as a string. If | ||
| 97 | @var{buffer} is not supplied, it defaults to the current buffer. | ||
| 98 | |||
| 99 | If @code{buffer-name} returns @code{nil}, it means that @var{buffer} | ||
| 100 | has been killed. @xref{Killing Buffers}. | ||
| 101 | |||
| 102 | @example | ||
| 103 | @group | ||
| 104 | (buffer-name) | ||
| 105 | @result{} "buffers.texi" | ||
| 106 | @end group | ||
| 107 | |||
| 108 | @group | ||
| 109 | (setq foo (get-buffer "temp")) | ||
| 110 | @result{} #<buffer temp> | ||
| 111 | @end group | ||
| 112 | @group | ||
| 113 | (kill-buffer foo) | ||
| 114 | @result{} nil | ||
| 115 | @end group | ||
| 116 | @group | ||
| 117 | (buffer-name foo) | ||
| 118 | @result{} nil | ||
| 119 | @end group | ||
| 120 | @group | ||
| 121 | foo | ||
| 122 | @result{} #<killed buffer> | ||
| 123 | @end group | ||
| 124 | @end example | ||
| 125 | @end defun | ||
| 126 | |||
| 127 | @deffn Command rename-buffer newname &optional unique | ||
| 128 | This function renames the current buffer to @var{newname}. An error | ||
| 129 | is signaled if @var{newname} is not a string, or if there is already a | ||
| 130 | buffer with that name. The function returns @code{nil}. | ||
| 131 | |||
| 132 | @c Emacs 19 feature | ||
| 133 | Ordinarily, @code{rename-buffer} signals an error if @var{newname} is | ||
| 134 | already in use. However, if @var{unique} is non-@code{nil}, it modifies | ||
| 135 | @var{newname} to make a name that is not in use. Interactively, you can | ||
| 136 | make @var{unique} non-@code{nil} with a numeric prefix argument. | ||
| 137 | |||
| 138 | One application of this command is to rename the @samp{*shell*} buffer | ||
| 139 | to some other name, thus making it possible to create a second shell | ||
| 140 | buffer under the name @samp{*shell*}. | ||
| 141 | @end deffn | ||
| 142 | |||
| 143 | @defun get-buffer buffer-or-name | ||
| 144 | This function returns the buffer specified by @var{buffer-or-name}. | ||
| 145 | If @var{buffer-or-name} is a string and there is no buffer with that | ||
| 146 | name, the value is @code{nil}. If @var{buffer-or-name} is a buffer, it | ||
| 147 | is returned as given. (That is not very useful, so the argument is usually | ||
| 148 | a name.) For example: | ||
| 149 | |||
| 150 | @example | ||
| 151 | @group | ||
| 152 | (setq b (get-buffer "lewis")) | ||
| 153 | @result{} #<buffer lewis> | ||
| 154 | @end group | ||
| 155 | @group | ||
| 156 | (get-buffer b) | ||
| 157 | @result{} #<buffer lewis> | ||
| 158 | @end group | ||
| 159 | @group | ||
| 160 | (get-buffer "Frazzle-nots") | ||
| 161 | @result{} nil | ||
| 162 | @end group | ||
| 163 | @end example | ||
| 164 | |||
| 165 | See also the function @code{get-buffer-create} in @ref{Creating Buffers}. | ||
| 166 | @end defun | ||
| 167 | |||
| 168 | @c Emacs 19 feature | ||
| 169 | @defun generate-new-buffer-name starting-name | ||
| 170 | This function returns a name that would be unique for a new buffer---but | ||
| 171 | does not create the buffer. It starts with @var{starting-name}, and | ||
| 172 | produces a name not currently in use for any buffer by appending a | ||
| 173 | number inside of @samp{<@dots{}>}. | ||
| 174 | |||
| 175 | See the related function @code{generate-new-buffer} in @ref{Creating | ||
| 176 | Buffers}. | ||
| 177 | @end defun | ||
| 178 | |||
| 179 | @node Buffer File Name | ||
| 180 | @section Buffer File Name | ||
| 181 | @cindex visited file | ||
| 182 | @cindex buffer file name | ||
| 183 | @cindex file name of buffer | ||
| 184 | |||
| 185 | The @dfn{buffer file name} is the name of the file that is visited in | ||
| 186 | that buffer. When a buffer is not visiting a file, its buffer file name | ||
| 187 | is @code{nil}. Most of the time, the buffer name is the same as the | ||
| 188 | nondirectory part of the buffer file name, but the buffer file name and | ||
| 189 | the buffer name are distinct and can be set independently. | ||
| 190 | @xref{Visiting Files}. | ||
| 191 | |||
| 192 | @defun buffer-file-name &optional buffer | ||
| 193 | This function returns the absolute file name of the file that | ||
| 194 | @var{buffer} is visiting. If @var{buffer} is not visiting any file, | ||
| 195 | @code{buffer-file-name} returns @code{nil}. If @var{buffer} is not | ||
| 196 | supplied, it defaults to the current buffer. | ||
| 197 | |||
| 198 | @example | ||
| 199 | @group | ||
| 200 | (buffer-file-name (other-buffer)) | ||
| 201 | @result{} "/usr/user/lewis/manual/files.texi" | ||
| 202 | @end group | ||
| 203 | @end example | ||
| 204 | @end defun | ||
| 205 | |||
| 206 | @defvar buffer-file-name | ||
| 207 | This buffer-local variable contains the name of the file being visited | ||
| 208 | in the current buffer, or @code{nil} if it is not visiting a file. It | ||
| 209 | is a permanent local, unaffected by @code{kill-local-variables}. | ||
| 210 | |||
| 211 | @example | ||
| 212 | @group | ||
| 213 | buffer-file-name | ||
| 214 | @result{} "/usr/user/lewis/manual/buffers.texi" | ||
| 215 | @end group | ||
| 216 | @end example | ||
| 217 | |||
| 218 | It is risky to change this variable's value without doing various other | ||
| 219 | things. See the definition of @code{set-visited-file-name} in | ||
| 220 | @file{files.el}; some of the things done there, such as changing the | ||
| 221 | buffer name, are not strictly necessary, but others are essential to | ||
| 222 | avoid confusing Emacs. | ||
| 223 | @end defvar | ||
| 224 | |||
| 225 | @defvar buffer-file-truename | ||
| 226 | This buffer-local variable holds the truename of the file visited in the | ||
| 227 | current buffer, or @code{nil} if no file is visited. It is a permanent | ||
| 228 | local, unaffected by @code{kill-local-variables}. @xref{Truenames}. | ||
| 229 | @end defvar | ||
| 230 | |||
| 231 | @defvar buffer-file-number | ||
| 232 | This buffer-local variable holds the file number and directory device | ||
| 233 | number of the file visited in the current buffer, or @code{nil} if no | ||
| 234 | file or a nonexistent file is visited. It is a permanent local, | ||
| 235 | unaffected by @code{kill-local-variables}. @xref{Truenames}. | ||
| 236 | |||
| 237 | The value is normally a list of the form @code{(@var{filenum} | ||
| 238 | @var{devnum})}. This pair of numbers uniquely identifies the file among | ||
| 239 | all files accessible on the system. See the function | ||
| 240 | @code{file-attributes}, in @ref{File Attributes}, for more information | ||
| 241 | about them. | ||
| 242 | @end defvar | ||
| 243 | |||
| 244 | @defun get-file-buffer filename | ||
| 245 | This function returns the buffer visiting file @var{filename}. If | ||
| 246 | there is no such buffer, it returns @code{nil}. The argument | ||
| 247 | @var{filename}, which must be a string, is expanded (@pxref{File Name | ||
| 248 | Expansion}), then compared against the visited file names of all live | ||
| 249 | buffers. | ||
| 250 | |||
| 251 | @example | ||
| 252 | @group | ||
| 253 | (get-file-buffer "buffers.texi") | ||
| 254 | @result{} #<buffer buffers.texi> | ||
| 255 | @end group | ||
| 256 | @end example | ||
| 257 | |||
| 258 | In unusual circumstances, there can be more than one buffer visiting | ||
| 259 | the same file name. In such cases, this function returns the first | ||
| 260 | such buffer in the buffer list. | ||
| 261 | @end defun | ||
| 262 | |||
| 263 | @deffn Command set-visited-file-name filename | ||
| 264 | If @var{filename} is a non-empty string, this function changes the | ||
| 265 | name of the file visited in current buffer to @var{filename}. (If the | ||
| 266 | buffer had no visited file, this gives it one.) The @emph{next time} | ||
| 267 | the buffer is saved it will go in the newly-specified file. This | ||
| 268 | command marks the buffer as modified, since it does not (as far as Emacs | ||
| 269 | knows) match the contents of @var{filename}, even if it matched the | ||
| 270 | former visited file. | ||
| 271 | |||
| 272 | If @var{filename} is @code{nil} or the empty string, that stands for | ||
| 273 | ``no visited file''. In this case, @code{set-visited-file-name} marks | ||
| 274 | the buffer as having no visited file. | ||
| 275 | |||
| 276 | @c Wordy to avoid overfull hbox. --rjc 16mar92 | ||
| 277 | When the function @code{set-visited-file-name} is called interactively, it | ||
| 278 | prompts for @var{filename} in the minibuffer. | ||
| 279 | |||
| 280 | See also @code{clear-visited-file-modtime} and | ||
| 281 | @code{verify-visited-file-modtime} in @ref{Buffer Modification}. | ||
| 282 | @end deffn | ||
| 283 | |||
| 284 | @defvar list-buffers-directory | ||
| 285 | This buffer-local variable records a string to display in a buffer | ||
| 286 | listing in place of the visited file name, for buffers that don't have a | ||
| 287 | visited file name. Dired buffers use this variable. | ||
| 288 | @end defvar | ||
| 289 | |||
| 290 | @node Buffer Modification | ||
| 291 | @section Buffer Modification | ||
| 292 | @cindex buffer modification | ||
| 293 | @cindex modification flag (of buffer) | ||
| 294 | |||
| 295 | Emacs keeps a flag called the @dfn{modified flag} for each buffer, to | ||
| 296 | record whether you have changed the text of the buffer. This flag is | ||
| 297 | set to @code{t} whenever you alter the contents of the buffer, and | ||
| 298 | cleared to @code{nil} when you save it. Thus, the flag shows whether | ||
| 299 | there are unsaved changes. The flag value is normally shown in the mode | ||
| 300 | line (@pxref{Mode Line Variables}), and controls saving (@pxref{Saving | ||
| 301 | Buffers}) and auto-saving (@pxref{Auto-Saving}). | ||
| 302 | |||
| 303 | Some Lisp programs set the flag explicitly. For example, the function | ||
| 304 | @code{set-visited-file-name} sets the flag to @code{t}, because the text | ||
| 305 | does not match the newly-visited file, even if it is unchanged from the | ||
| 306 | file formerly visited. | ||
| 307 | |||
| 308 | The functions that modify the contents of buffers are described in | ||
| 309 | @ref{Text}. | ||
| 310 | |||
| 311 | @defun buffer-modified-p &optional buffer | ||
| 312 | This function returns @code{t} if the buffer @var{buffer} has been modified | ||
| 313 | since it was last read in from a file or saved, or @code{nil} | ||
| 314 | otherwise. If @var{buffer} is not supplied, the current buffer | ||
| 315 | is tested. | ||
| 316 | @end defun | ||
| 317 | |||
| 318 | @defun set-buffer-modified-p flag | ||
| 319 | This function marks the current buffer as modified if @var{flag} is | ||
| 320 | non-@code{nil}, or as unmodified if the flag is @code{nil}. | ||
| 321 | |||
| 322 | Another effect of calling this function is to cause unconditional | ||
| 323 | redisplay of the mode line for the current buffer. In fact, the | ||
| 324 | function @code{force-mode-line-update} works by doing this: | ||
| 325 | |||
| 326 | @example | ||
| 327 | @group | ||
| 328 | (set-buffer-modified-p (buffer-modified-p)) | ||
| 329 | @end group | ||
| 330 | @end example | ||
| 331 | @end defun | ||
| 332 | |||
| 333 | @deffn Command not-modified | ||
| 334 | This command marks the current buffer as unmodified, and not needing | ||
| 335 | to be saved. Don't use this function in programs, since it prints a | ||
| 336 | message in the echo area; use @code{set-buffer-modified-p} (above) instead. | ||
| 337 | @end deffn | ||
| 338 | |||
| 339 | @c Emacs 19 feature | ||
| 340 | @defun buffer-modified-tick &optional buffer | ||
| 341 | This function returns @var{buffer}`s modification-count. This is a | ||
| 342 | counter that increments every time the buffer is modified. If | ||
| 343 | @var{buffer} is @code{nil} (or omitted), the current buffer is used. | ||
| 344 | @end defun | ||
| 345 | |||
| 346 | @node Modification Time | ||
| 347 | @comment node-name, next, previous, up | ||
| 348 | @section Comparison of Modification Time | ||
| 349 | @cindex comparison of modification time | ||
| 350 | @cindex modification time, comparison of | ||
| 351 | |||
| 352 | Suppose that you visit a file and make changes in its buffer, and | ||
| 353 | meanwhile the file itself is changed on disk. At this point, saving the | ||
| 354 | buffer would overwrite the changes in the file. Occasionally this may | ||
| 355 | be what you want, but usually it would lose valuable information. Emacs | ||
| 356 | therefore checks the file's modification time using the functions | ||
| 357 | described below before saving the file. | ||
| 358 | |||
| 359 | @defun verify-visited-file-modtime buffer | ||
| 360 | This function compares what @var{buffer} has recorded for the | ||
| 361 | modification time of its visited file against the actual modification | ||
| 362 | time of the file as recorded by the operating system. The two should be | ||
| 363 | the same unless some other process has written the file since Emacs | ||
| 364 | visited or saved it. | ||
| 365 | |||
| 366 | The function returns @code{t} if the last actual modification time and | ||
| 367 | Emacs's recorded modification time are the same, @code{nil} otherwise. | ||
| 368 | @end defun | ||
| 369 | |||
| 370 | @defun clear-visited-file-modtime | ||
| 371 | This function clears out the record of the last modification time of | ||
| 372 | the file being visited by the current buffer. As a result, the next | ||
| 373 | attempt to save this buffer will not complain of a discrepancy in | ||
| 374 | file modification times. | ||
| 375 | |||
| 376 | This function is called in @code{set-visited-file-name} and other | ||
| 377 | exceptional places where the usual test to avoid overwriting a changed | ||
| 378 | file should not be done. | ||
| 379 | @end defun | ||
| 380 | |||
| 381 | @c Emacs 19 feature | ||
| 382 | @defun visited-file-modtime | ||
| 383 | This function returns the buffer's recorded last file modification time, | ||
| 384 | as a list of the form @code{(@var{high} . @var{low})}. (This is the | ||
| 385 | same format that @code{file-attributes} uses to return time values; see | ||
| 386 | @ref{File Attributes}.) | ||
| 387 | @end defun | ||
| 388 | |||
| 389 | @c Emacs 19 feature | ||
| 390 | @defun set-visited-file-modtime &optional time | ||
| 391 | This function updates the buffer's record of the last modification time | ||
| 392 | of the visited file, to the value specified by @var{time} if @var{time} | ||
| 393 | is not @code{nil}, and otherwise to the last modification time of the | ||
| 394 | visited file. | ||
| 395 | |||
| 396 | If @var{time} is not @code{nil}, it should have the form | ||
| 397 | @code{(@var{high} . @var{low})} or @code{(@var{high} @var{low})}, in | ||
| 398 | either case containing two integers, each of which holds 16 bits of the | ||
| 399 | time. | ||
| 400 | |||
| 401 | This function is useful if the buffer was not read from the file | ||
| 402 | normally, or if the file itself has been changed for some known benign | ||
| 403 | reason. | ||
| 404 | @end defun | ||
| 405 | |||
| 406 | @defun ask-user-about-supersession-threat fn | ||
| 407 | @cindex obsolete buffer | ||
| 408 | This function is used to ask a user how to proceed after an attempt to | ||
| 409 | modify an obsolete buffer. An @dfn{obsolete buffer} is an unmodified | ||
| 410 | buffer for which the associated file on disk is newer than the last | ||
| 411 | save-time of the buffer. This means some other program has probably | ||
| 412 | altered the file. | ||
| 413 | |||
| 414 | This function is called automatically by Emacs on the proper | ||
| 415 | occasions. It exists so you can customize Emacs by redefining it. | ||
| 416 | See the file @file{userlock.el} for the standard definition. | ||
| 417 | |||
| 418 | @kindex file-supersession | ||
| 419 | Depending on the user's answer, the function may return normally, in | ||
| 420 | which case the modification of the buffer proceeds, or it may signal a | ||
| 421 | @code{file-supersession} error with data @code{(@var{fn})}, in which | ||
| 422 | case the proposed buffer modification is not allowed. | ||
| 423 | |||
| 424 | See also the file locking mechanism in @ref{File Locks}. | ||
| 425 | @end defun | ||
| 426 | |||
| 427 | @node Read Only Buffers | ||
| 428 | @section Read-Only Buffers | ||
| 429 | @cindex read-only buffer | ||
| 430 | @cindex buffer, read-only | ||
| 431 | |||
| 432 | If a buffer is @dfn{read-only}, then you cannot change its contents, | ||
| 433 | although you may change your view of the contents by scrolling and | ||
| 434 | narrowing. | ||
| 435 | |||
| 436 | Read-only buffers are used in two kinds of situations: | ||
| 437 | |||
| 438 | @itemize @bullet | ||
| 439 | @item | ||
| 440 | A buffer visiting a write-protected file is normally read-only. | ||
| 441 | |||
| 442 | Here, the purpose is to show the user that editing the buffer with the | ||
| 443 | aim of saving it in the file may be futile or undesirable. The user who | ||
| 444 | wants to change the buffer text despite this can do so after clearing | ||
| 445 | the read-only flag with @kbd{C-M-q}. | ||
| 446 | |||
| 447 | @item | ||
| 448 | Modes such as Dired and Rmail make buffers read-only when altering the | ||
| 449 | contents with the usual editing commands is probably a mistake. | ||
| 450 | |||
| 451 | The special commands of these modes bind @code{buffer-read-only} to | ||
| 452 | @code{nil} (with @code{let}) or bind @code{inhibit-read-only} to | ||
| 453 | @code{t} around the places where they change the text. | ||
| 454 | @end itemize | ||
| 455 | |||
| 456 | @defvar buffer-read-only | ||
| 457 | This buffer-local variable specifies whether the buffer is read-only. | ||
| 458 | The buffer is read-only if this variable is non-@code{nil}. | ||
| 459 | @end defvar | ||
| 460 | |||
| 461 | @defvar inhibit-read-only | ||
| 462 | If this variable is non-@code{nil}, then read-only buffers and read-only | ||
| 463 | characters may be modified. The value of @code{buffer-read-only} does | ||
| 464 | not matter when @code{inhibit-read-only} is non-@code{nil}. | ||
| 465 | |||
| 466 | If @code{inhibit-read-only} is @code{t}, all @code{read-only} text | ||
| 467 | properties have no effect (@pxref{Special Properties}). If | ||
| 468 | @code{inhibit-read-only} is a list, then @code{read-only} text | ||
| 469 | properties are ignored if they are members of the list (comparison is | ||
| 470 | done with @code{eq}). | ||
| 471 | @end defvar | ||
| 472 | |||
| 473 | @deffn Command toggle-read-only | ||
| 474 | This command changes whether the current buffer is read-only. It is | ||
| 475 | intended for interactive use; don't use it in programs. At any given | ||
| 476 | point in a program, you should know whether you want the read-only flag | ||
| 477 | on or off; so you can set @code{buffer-read-only} explicitly to the | ||
| 478 | proper value, @code{t} or @code{nil}. | ||
| 479 | @end deffn | ||
| 480 | |||
| 481 | @defun barf-if-buffer-read-only | ||
| 482 | This function signals a @code{buffer-read-only} error if the current | ||
| 483 | buffer is read-only. @xref{Interactive Call}, for another way to | ||
| 484 | signal an error if the current buffer is read-only. | ||
| 485 | @end defun | ||
| 486 | |||
| 487 | @node The Buffer List | ||
| 488 | @section The Buffer List | ||
| 489 | @cindex buffer list | ||
| 490 | |||
| 491 | The @dfn{buffer list} is a list of all live buffers. Creating a | ||
| 492 | buffer adds it to this list, and killing a buffer deletes it. The order | ||
| 493 | of the buffers in the list is based primarily on how recently each | ||
| 494 | buffer has been displayed in the selected window. Buffers move to the | ||
| 495 | front of the list when they are selected and to the end when they are | ||
| 496 | buried. Several functions, notably @code{other-buffer}, use this | ||
| 497 | ordering. A buffer list displayed for the user also follows this order. | ||
| 498 | |||
| 499 | @defun buffer-list | ||
| 500 | This function returns a list of all buffers, including those whose names | ||
| 501 | begin with a space. The elements are actual buffers, not their names. | ||
| 502 | |||
| 503 | @example | ||
| 504 | @group | ||
| 505 | (buffer-list) | ||
| 506 | @result{} (#<buffer buffers.texi> | ||
| 507 | #<buffer *Minibuf-1*> #<buffer buffer.c> | ||
| 508 | #<buffer *Help*> #<buffer TAGS>) | ||
| 509 | @end group | ||
| 510 | |||
| 511 | @group | ||
| 512 | ;; @r{Note that the name of the minibuffer} | ||
| 513 | ;; @r{begins with a space!} | ||
| 514 | (mapcar (function buffer-name) (buffer-list)) | ||
| 515 | @result{} ("buffers.texi" " *Minibuf-1*" | ||
| 516 | "buffer.c" "*Help*" "TAGS") | ||
| 517 | @end group | ||
| 518 | @end example | ||
| 519 | |||
| 520 | This list is a copy of a list used inside Emacs; modifying it has no | ||
| 521 | effect on the ordering of buffers. | ||
| 522 | @end defun | ||
| 523 | |||
| 524 | @defun other-buffer &optional buffer-or-name visible-ok | ||
| 525 | This function returns the first buffer in the buffer list other than | ||
| 526 | @var{buffer-or-name}. Usually this is the buffer most recently shown in | ||
| 527 | the selected window, aside from @var{buffer-or-name}. Buffers whose | ||
| 528 | names start with a space are not considered. | ||
| 529 | |||
| 530 | If @var{buffer-or-name} is not supplied (or if it is not a buffer), | ||
| 531 | then @code{other-buffer} returns the first buffer on the buffer list | ||
| 532 | that is not visible in any window in a visible frame. | ||
| 533 | |||
| 534 | @c Emacs 19 feature | ||
| 535 | If @var{visible-ok} is @code{nil}, @code{other-buffer} avoids returning | ||
| 536 | a buffer visible in any window on any visible frame, except as a last | ||
| 537 | resort. If @var{visible-ok} is non-@code{nil}, then it does not matter | ||
| 538 | whether a buffer is displayed somewhere or not. | ||
| 539 | |||
| 540 | If no suitable buffer exists, the buffer @samp{*scratch*} is returned | ||
| 541 | (and created, if necessary). | ||
| 542 | @end defun | ||
| 543 | |||
| 544 | @deffn Command bury-buffer &optional buffer-or-name | ||
| 545 | This function puts @var{buffer-or-name} at the end of the buffer list | ||
| 546 | without changing the order of any of the other buffers on the list. | ||
| 547 | This buffer therefore becomes the least desirable candidate for | ||
| 548 | @code{other-buffer} to return. | ||
| 549 | |||
| 550 | If @var{buffer-or-name} is @code{nil} or omitted, this means to bury | ||
| 551 | the current buffer. In addition, this switches to some other buffer | ||
| 552 | (obtained using @code{other-buffer}) in the selected window. If the | ||
| 553 | buffer is displayed in a window other than the selected one, it remains | ||
| 554 | there. | ||
| 555 | |||
| 556 | If you wish to replace a buffer in all the windows that display it, use | ||
| 557 | @code{replace-buffer-in-windows}. @xref{Buffers and Windows}. | ||
| 558 | @end deffn | ||
| 559 | |||
| 560 | @node Creating Buffers | ||
| 561 | @section Creating Buffers | ||
| 562 | @cindex creating buffers | ||
| 563 | @cindex buffers, creating | ||
| 564 | |||
| 565 | This section describes the two primitives for creating buffers. | ||
| 566 | @code{get-buffer-create} creates a buffer if it finds no existing | ||
| 567 | buffer; @code{generate-new-buffer} always creates a new buffer, and | ||
| 568 | gives it a unique name. | ||
| 569 | |||
| 570 | Other functions you can use to create buffers include | ||
| 571 | @code{with-output-to-temp-buffer} (@pxref{Temporary Displays}) and | ||
| 572 | @code{create-file-buffer} (@pxref{Visiting Files}). Starting a | ||
| 573 | subprocess can also create a buffer (@pxref{Processes}). | ||
| 574 | |||
| 575 | @defun get-buffer-create name | ||
| 576 | This function returns a buffer named @var{name}. It returns an existing | ||
| 577 | buffer with that name, if one exists; otherwise, it creates a new | ||
| 578 | buffer. The buffer does not become the current buffer---this function | ||
| 579 | does not change which buffer is current. | ||
| 580 | |||
| 581 | An error is signaled if @var{name} is not a string. | ||
| 582 | |||
| 583 | @example | ||
| 584 | @group | ||
| 585 | (get-buffer-create "foo") | ||
| 586 | @result{} #<buffer foo> | ||
| 587 | @end group | ||
| 588 | @end example | ||
| 589 | |||
| 590 | The major mode for the new buffer is set according to the variable | ||
| 591 | @code{default-major-mode}. @xref{Auto Major Mode}. | ||
| 592 | @end defun | ||
| 593 | |||
| 594 | @defun generate-new-buffer name | ||
| 595 | This function returns a newly created, empty buffer, but does not make | ||
| 596 | it current. If there is no buffer named @var{name}, then that is the | ||
| 597 | name of the new buffer. If that name is in use, this function adds | ||
| 598 | suffixes of the form @samp{<@var{n}>} are added to @var{name}, where | ||
| 599 | @var{n} is an integer. It tries successive integers starting with 2 | ||
| 600 | until it finds an available name. | ||
| 601 | |||
| 602 | An error is signaled if @var{name} is not a string. | ||
| 603 | |||
| 604 | @example | ||
| 605 | @group | ||
| 606 | (generate-new-buffer "bar") | ||
| 607 | @result{} #<buffer bar> | ||
| 608 | @end group | ||
| 609 | @group | ||
| 610 | (generate-new-buffer "bar") | ||
| 611 | @result{} #<buffer bar<2>> | ||
| 612 | @end group | ||
| 613 | @group | ||
| 614 | (generate-new-buffer "bar") | ||
| 615 | @result{} #<buffer bar<3>> | ||
| 616 | @end group | ||
| 617 | @end example | ||
| 618 | |||
| 619 | The major mode for the new buffer is set by the value of | ||
| 620 | @code{default-major-mode}. @xref{Auto Major Mode}. | ||
| 621 | |||
| 622 | See the related function @code{generate-new-buffer-name} in @ref{Buffer | ||
| 623 | Names}. | ||
| 624 | @end defun | ||
| 625 | |||
| 626 | @node Killing Buffers | ||
| 627 | @section Killing Buffers | ||
| 628 | @cindex killing buffers | ||
| 629 | @cindex buffers, killing | ||
| 630 | |||
| 631 | @dfn{Killing a buffer} makes its name unknown to Emacs and makes its | ||
| 632 | space available for other use. | ||
| 633 | |||
| 634 | The buffer object for the buffer which has been killed remains in | ||
| 635 | existence as long as anything refers to it, but it is specially marked | ||
| 636 | so that you cannot make it current or display it. Killed buffers retain | ||
| 637 | their identity, however; two distinct buffers, when killed, remain | ||
| 638 | distinct according to @code{eq}. | ||
| 639 | |||
| 640 | If you kill a buffer that is current or displayed in a window, Emacs | ||
| 641 | automatically selects or displays some other buffer instead. This means | ||
| 642 | that killing a buffer can in general change the current buffer. | ||
| 643 | Therefore, when you kill a buffer, you should also take the precautions | ||
| 644 | associated with changing the current buffer (unless you happen to know | ||
| 645 | that the buffer being killed isn't current). @xref{Current Buffer}. | ||
| 646 | |||
| 647 | The @code{buffer-name} of a killed buffer is @code{nil}. You can use | ||
| 648 | this feature to test whether a buffer has been killed: | ||
| 649 | |||
| 650 | @example | ||
| 651 | @group | ||
| 652 | (defun buffer-killed-p (buffer) | ||
| 653 | "Return t if BUFFER is killed." | ||
| 654 | (not (buffer-name buffer))) | ||
| 655 | @end group | ||
| 656 | @end example | ||
| 657 | |||
| 658 | @deffn Command kill-buffer buffer-or-name | ||
| 659 | This function kills the buffer @var{buffer-or-name}, freeing all its | ||
| 660 | memory for use as space for other buffers. (Emacs version 18 and older | ||
| 661 | was unable to return the memory to the operating system.) It returns | ||
| 662 | @code{nil}. | ||
| 663 | |||
| 664 | Any processes that have this buffer as the @code{process-buffer} are | ||
| 665 | sent the @code{SIGHUP} signal, which normally causes them to terminate. | ||
| 666 | (The basic meaning of @code{SIGHUP} is that a dialup line has been | ||
| 667 | disconnected.) @xref{Deleting Processes}. | ||
| 668 | |||
| 669 | If the buffer is visiting a file and contains unsaved changes, | ||
| 670 | @code{kill-buffer} asks the user to confirm before the buffer is killed. | ||
| 671 | It does this even if not called interactively. To prevent the request | ||
| 672 | for confirmation, clear the modified flag before calling | ||
| 673 | @code{kill-buffer}. @xref{Buffer Modification}. | ||
| 674 | |||
| 675 | @vindex kill-buffer-query-functions | ||
| 676 | You can program additional requests for confirmation. After confirming | ||
| 677 | unsaved changes, @code{kill-buffer} calls the functions in the list | ||
| 678 | @code{kill-buffer-query-functions}, in order of appearance, with no | ||
| 679 | arguments. The buffer being killed is the current buffer when they are | ||
| 680 | called. The idea is that these functions ask for confirmation from the | ||
| 681 | user for various nonstandard reasons. If any of them returns | ||
| 682 | non-@code{nil}, the buffer is not killed. | ||
| 683 | |||
| 684 | @c Emacs 19 feature | ||
| 685 | @vindex kill-buffer-hook | ||
| 686 | Just before actually killing the buffer, after asking all questions, | ||
| 687 | @code{kill-buffer} runs the normal hook @code{kill-buffer-hook}. The | ||
| 688 | buffer to be killed is current when the hook functions run. | ||
| 689 | @xref{Hooks}. | ||
| 690 | |||
| 691 | Killing a buffer that is already dead has no effect. | ||
| 692 | |||
| 693 | @smallexample | ||
| 694 | (kill-buffer "foo.unchanged") | ||
| 695 | @result{} nil | ||
| 696 | (kill-buffer "foo.changed") | ||
| 697 | |||
| 698 | ---------- Buffer: Minibuffer ---------- | ||
| 699 | Buffer foo.changed modified; kill anyway? (yes or no) @kbd{yes} | ||
| 700 | ---------- Buffer: Minibuffer ---------- | ||
| 701 | |||
| 702 | @result{} nil | ||
| 703 | @end smallexample | ||
| 704 | @end deffn | ||
| 705 | |||
| 706 | @node Current Buffer | ||
| 707 | @section The Current Buffer | ||
| 708 | @cindex selecting a buffer | ||
| 709 | @cindex changing to another buffer | ||
| 710 | @cindex current buffer | ||
| 711 | |||
| 712 | There are, in general, many buffers in an Emacs session. At any time, | ||
| 713 | one of them is designated as the @dfn{current buffer}. This is the | ||
| 714 | buffer in which most editing takes place, because most of the primitives | ||
| 715 | for examining or changing text in a buffer operate implicitly on the | ||
| 716 | current buffer (@pxref{Text}). Normally the buffer that is displayed on | ||
| 717 | the screen in the selected window is the current buffer, but this is not | ||
| 718 | always so: a Lisp program can designate any buffer as current | ||
| 719 | temporarily in order to operate on its contents, without changing what | ||
| 720 | is displayed on the screen. | ||
| 721 | |||
| 722 | The way to designate a current buffer in a Lisp program is by calling | ||
| 723 | @code{set-buffer}. The specified buffer remains current until a new one | ||
| 724 | is designated. | ||
| 725 | |||
| 726 | When an editing command returns to the editor command loop, the | ||
| 727 | command loop designates the buffer displayed in the selected window as | ||
| 728 | current, to prevent confusion: the buffer that the cursor is in, when | ||
| 729 | Emacs reads a command, is the one to which the command will apply. | ||
| 730 | (@xref{Command Loop}.) Therefore, @code{set-buffer} is not the way to | ||
| 731 | switch visibly to a different buffer so that the user can edit it. For | ||
| 732 | this, you must use the functions described in @ref{Displaying Buffers}. | ||
| 733 | |||
| 734 | However, Lisp functions that change to a different current buffer | ||
| 735 | should not depend on the command loop to set it back afterwards. | ||
| 736 | Editing commands written in Emacs Lisp can be called from other programs | ||
| 737 | as well as from the command loop. It is convenient for the caller if | ||
| 738 | the subroutine does not change which buffer is current (unless, of | ||
| 739 | course, that is the subroutine's purpose). Therefore, you should | ||
| 740 | normally use @code{set-buffer} within a @code{save-excursion} that will | ||
| 741 | restore the current buffer when your function is done | ||
| 742 | (@pxref{Excursions}). Here is an example, the code for the command | ||
| 743 | @code{append-to-buffer} (with the documentation string abridged): | ||
| 744 | |||
| 745 | @example | ||
| 746 | @group | ||
| 747 | (defun append-to-buffer (buffer start end) | ||
| 748 | "Append to specified buffer the text of the region. | ||
| 749 | @dots{}" | ||
| 750 | (interactive "BAppend to buffer: \nr") | ||
| 751 | (let ((oldbuf (current-buffer))) | ||
| 752 | (save-excursion | ||
| 753 | (set-buffer (get-buffer-create buffer)) | ||
| 754 | (insert-buffer-substring oldbuf start end)))) | ||
| 755 | @end group | ||
| 756 | @end example | ||
| 757 | |||
| 758 | @noindent | ||
| 759 | This function binds a local variable to the current buffer, and then | ||
| 760 | @code{save-excursion} records the values of point, the mark, and the | ||
| 761 | original buffer. Next, @code{set-buffer} makes another buffer current. | ||
| 762 | Finally, @code{insert-buffer-substring} copies the string from the | ||
| 763 | original current buffer to the new current buffer. | ||
| 764 | |||
| 765 | If the buffer appended to happens to be displayed in some window, | ||
| 766 | the next redisplay will show how its text has changed. Otherwise, you | ||
| 767 | will not see the change immediately on the screen. The buffer becomes | ||
| 768 | current temporarily during the execution of the command, but this does | ||
| 769 | not cause it to be displayed. | ||
| 770 | |||
| 771 | If you make local bindings (with @code{let} or function arguments) for | ||
| 772 | a variable that may also have buffer-local bindings, make sure that the | ||
| 773 | same buffer is current at the beginning and at the end of the local | ||
| 774 | binding's scope. Otherwise you might bind it in one buffer and unbind | ||
| 775 | it in another! There are two ways to do this. In simple cases, you may | ||
| 776 | see that nothing ever changes the current buffer within the scope of the | ||
| 777 | binding. Otherwise, use @code{save-excursion} to make sure that the | ||
| 778 | buffer current at the beginning is current again whenever the variable | ||
| 779 | is unbound. | ||
| 780 | |||
| 781 | It is not reliable to change the current buffer back with | ||
| 782 | @code{set-buffer}, because that won't do the job if a quit happens while | ||
| 783 | the wrong buffer is current. Here is what not to do: | ||
| 784 | |||
| 785 | @example | ||
| 786 | @group | ||
| 787 | (let (buffer-read-only | ||
| 788 | (obuf (current-buffer))) | ||
| 789 | (set-buffer @dots{}) | ||
| 790 | @dots{} | ||
| 791 | (set-buffer obuf)) | ||
| 792 | @end group | ||
| 793 | @end example | ||
| 794 | |||
| 795 | @noindent | ||
| 796 | Using @code{save-excursion}, as shown below, handles quitting, errors | ||
| 797 | and @code{throw} as well as ordinary evaluation. | ||
| 798 | |||
| 799 | @example | ||
| 800 | @group | ||
| 801 | (let (buffer-read-only) | ||
| 802 | (save-excursion | ||
| 803 | (set-buffer @dots{}) | ||
| 804 | @dots{})) | ||
| 805 | @end group | ||
| 806 | @end example | ||
| 807 | |||
| 808 | @defun current-buffer | ||
| 809 | This function returns the current buffer. | ||
| 810 | |||
| 811 | @example | ||
| 812 | @group | ||
| 813 | (current-buffer) | ||
| 814 | @result{} #<buffer buffers.texi> | ||
| 815 | @end group | ||
| 816 | @end example | ||
| 817 | @end defun | ||
| 818 | |||
| 819 | @defun set-buffer buffer-or-name | ||
| 820 | This function makes @var{buffer-or-name} the current buffer. It does | ||
| 821 | not display the buffer in the currently selected window or in any other | ||
| 822 | window, so the user cannot necessarily see the buffer. But Lisp | ||
| 823 | programs can in any case work on it. | ||
| 824 | |||
| 825 | This function returns the buffer identified by @var{buffer-or-name}. | ||
| 826 | An error is signaled if @var{buffer-or-name} does not identify an | ||
| 827 | existing buffer. | ||
| 828 | @end defun | ||
diff --git a/lispref/windows.texi b/lispref/windows.texi new file mode 100644 index 00000000000..a859fd9cf20 --- /dev/null +++ b/lispref/windows.texi | |||
| @@ -0,0 +1,1592 @@ | |||
| 1 | @c -*-texinfo-*- | ||
| 2 | @c This is part of the GNU Emacs Lisp Reference Manual. | ||
| 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | ||
| 4 | @c See the file elisp.texi for copying conditions. | ||
| 5 | @setfilename ../info/windows | ||
| 6 | @node Windows, Frames, Buffers, Top | ||
| 7 | @chapter Windows | ||
| 8 | |||
| 9 | This chapter describes most of the functions and variables related to | ||
| 10 | Emacs windows. See @ref{Display}, for information on how text is | ||
| 11 | displayed in windows. | ||
| 12 | |||
| 13 | @menu | ||
| 14 | * Basic Windows:: Basic information on using windows. | ||
| 15 | * Splitting Windows:: Splitting one window into two windows. | ||
| 16 | * Deleting Windows:: Deleting a window gives its space to other windows. | ||
| 17 | * Selecting Windows:: The selected window is the one that you edit in. | ||
| 18 | * Cyclic Window Ordering:: Moving around the existing windows. | ||
| 19 | * Buffers and Windows:: Each window displays the contents of a buffer. | ||
| 20 | * Displaying Buffers:: Higher-lever functions for displaying a buffer | ||
| 21 | and choosing a window for it. | ||
| 22 | * Choosing Window:: How to choose a window for displaying a buffer. | ||
| 23 | * Window Point:: Each window has its own location of point. | ||
| 24 | * Window Start:: The display-start position controls which text | ||
| 25 | is on-screen in the window. | ||
| 26 | * Vertical Scrolling:: Moving text up and down in the window. | ||
| 27 | * Horizontal Scrolling:: Moving text sideways on the window. | ||
| 28 | * Size of Window:: Accessing the size of a window. | ||
| 29 | * Resizing Windows:: Changing the size of a window. | ||
| 30 | * Coordinates and Windows::Converting coordinates to windows. | ||
| 31 | * Window Configurations:: Saving and restoring the state of the screen. | ||
| 32 | @end menu | ||
| 33 | |||
| 34 | @node Basic Windows | ||
| 35 | @section Basic Concepts of Emacs Windows | ||
| 36 | @cindex window | ||
| 37 | @cindex selected window | ||
| 38 | |||
| 39 | A @dfn{window} is the physical area of the screen in which a buffer is | ||
| 40 | displayed. The term is also used to refer to a Lisp object which | ||
| 41 | represents that screen area in Emacs Lisp. It should be | ||
| 42 | clear from the context which is meant. | ||
| 43 | |||
| 44 | There is always at least one window in any frame. In each frame, at | ||
| 45 | any time, one and only one window is designated as @dfn{selected within | ||
| 46 | the frame}. The frame's cursor appears in that window. There is also | ||
| 47 | one selected frame; and the window selected within that frame is | ||
| 48 | @dfn{the selected window}. The selected window's buffer is usually the | ||
| 49 | current buffer (except when @code{set-buffer} has been used). | ||
| 50 | @xref{Current Buffer}. | ||
| 51 | |||
| 52 | For all intents, a window only exists while it is displayed on the | ||
| 53 | terminal. Once removed from the display, the window is effectively | ||
| 54 | deleted and should not be used, @emph{even though there may still be | ||
| 55 | references to it} from other Lisp objects. Restoring a saved window | ||
| 56 | configuration is the only way for a window no longer on the screen to | ||
| 57 | come back to life. (@xref{Deleting Windows}.) | ||
| 58 | |||
| 59 | Each window has the following attributes: | ||
| 60 | |||
| 61 | @itemize @bullet | ||
| 62 | @item | ||
| 63 | containing frame | ||
| 64 | |||
| 65 | @item | ||
| 66 | window height | ||
| 67 | |||
| 68 | @item | ||
| 69 | window width | ||
| 70 | |||
| 71 | @item | ||
| 72 | window edges with respect to the screen or frame | ||
| 73 | |||
| 74 | @item | ||
| 75 | the buffer it displays | ||
| 76 | |||
| 77 | @item | ||
| 78 | position within the buffer at the upper left of the window | ||
| 79 | |||
| 80 | @item | ||
| 81 | the amount of horizontal scrolling, in columns | ||
| 82 | |||
| 83 | @item | ||
| 84 | point | ||
| 85 | |||
| 86 | @item | ||
| 87 | the mark | ||
| 88 | |||
| 89 | @item | ||
| 90 | how recently the window was selected | ||
| 91 | @end itemize | ||
| 92 | |||
| 93 | @cindex multiple windows | ||
| 94 | Users create multiple windows so they can look at several buffers at | ||
| 95 | once. Lisp libraries use multiple windows for a variety of reasons, but | ||
| 96 | most often to give different views of the same information. In Rmail, | ||
| 97 | for example, you can move through a summary buffer in one window while | ||
| 98 | the other window shows messages one at a time as they are reached. | ||
| 99 | |||
| 100 | The meaning of ``window'' in Emacs is similar to what it means in the | ||
| 101 | context of general purpose window systems such as X, but not identical. | ||
| 102 | The X Window System subdivides the screen into X windows; Emacs uses one | ||
| 103 | or more X windows, called @dfn{frames} in Emacs terminology, and | ||
| 104 | subdivides each of them into (nonoverlapping) Emacs windows. When you | ||
| 105 | use Emacs on an ordinary display terminal, Emacs subdivides the terminal | ||
| 106 | screen into Emacs windows. | ||
| 107 | |||
| 108 | @cindex terminal screen | ||
| 109 | @cindex screen of terminal | ||
| 110 | @cindex tiled windows | ||
| 111 | Most window systems support arbitrarily located overlapping windows. | ||
| 112 | In contrast, Emacs windows are @dfn{tiled}; they never overlap, and | ||
| 113 | together they fill the whole of the screen or frame. Because of the way | ||
| 114 | in which Emacs creates new windows and resizes them, you can't create | ||
| 115 | every conceivable tiling of windows on an Emacs frame. @xref{Splitting | ||
| 116 | Windows}, and @ref{Size of Window}. | ||
| 117 | |||
| 118 | @xref{Display}, for information on how the contents of the | ||
| 119 | window's buffer are displayed in the window. | ||
| 120 | |||
| 121 | @defun windowp object | ||
| 122 | This function returns @code{t} if @var{object} is a window. | ||
| 123 | @end defun | ||
| 124 | |||
| 125 | @node Splitting Windows | ||
| 126 | @section Splitting Windows | ||
| 127 | @cindex splitting windows | ||
| 128 | @cindex window splitting | ||
| 129 | |||
| 130 | The functions described here are the primitives used to split a window | ||
| 131 | into two windows. Two higher level functions sometimes split a window, | ||
| 132 | but not always: @code{pop-to-buffer} and @code{display-buffer} | ||
| 133 | (@pxref{Displaying Buffers}). | ||
| 134 | |||
| 135 | The functions described here do not accept a buffer as an argument. | ||
| 136 | The two ``halves'' of the split window initially display the same buffer | ||
| 137 | previously visible in the window that was split. | ||
| 138 | |||
| 139 | @deffn Command split-window &optional window size horizontal | ||
| 140 | This function splits @var{window} into two windows. The original | ||
| 141 | window @var{window} remains the selected window, but occupies only | ||
| 142 | part of its former screen area. The rest is occupied by a newly created | ||
| 143 | window which is returned as the value of this function. | ||
| 144 | |||
| 145 | If @var{horizontal} is non-@code{nil}, then @var{window} splits into | ||
| 146 | two side by side windows. The original window @var{window} keeps the | ||
| 147 | leftmost @var{size} columns, and gives the rest of the columns to the | ||
| 148 | new window. Otherwise, it splits into windows one above the other, and | ||
| 149 | @var{window} keeps the upper @var{size} lines and gives the rest of the | ||
| 150 | lines to the new window. The original window is therefore the | ||
| 151 | right-hand or upper of the two, and the new window is the left-hand or | ||
| 152 | lower. | ||
| 153 | |||
| 154 | If @var{window} is omitted or @code{nil}, then the selected window is | ||
| 155 | split. If @var{size} is omitted or @code{nil}, then @var{window} is | ||
| 156 | divided evenly into two parts. (If there is an odd line, it is | ||
| 157 | allocated to the new window.) When @code{split-window} is called | ||
| 158 | interactively, all its arguments are @code{nil}. | ||
| 159 | |||
| 160 | The following example starts with one window on a screen that is 50 | ||
| 161 | lines high by 80 columns wide; then the window is split. | ||
| 162 | |||
| 163 | @smallexample | ||
| 164 | @group | ||
| 165 | (setq w (selected-window)) | ||
| 166 | @result{} #<window 8 on windows.texi> | ||
| 167 | (window-edges) ; @r{Edges in order:} | ||
| 168 | @result{} (0 0 80 50) ; @r{left--top--right--bottom} | ||
| 169 | @end group | ||
| 170 | |||
| 171 | @group | ||
| 172 | ;; @r{Returns window created} | ||
| 173 | (setq w2 (split-window w 15)) | ||
| 174 | @result{} #<window 28 on windows.texi> | ||
| 175 | @end group | ||
| 176 | @group | ||
| 177 | (window-edges w2) | ||
| 178 | @result{} (0 15 80 50) ; @r{Bottom window;} | ||
| 179 | ; @r{top is line 15} | ||
| 180 | @end group | ||
| 181 | @group | ||
| 182 | (window-edges w) | ||
| 183 | @result{} (0 0 80 15) ; @r{Top window} | ||
| 184 | @end group | ||
| 185 | @end smallexample | ||
| 186 | |||
| 187 | The screen looks like this: | ||
| 188 | |||
| 189 | @smallexample | ||
| 190 | @group | ||
| 191 | __________ | ||
| 192 | | | line 0 | ||
| 193 | | w | | ||
| 194 | |__________| | ||
| 195 | | | line 15 | ||
| 196 | | w2 | | ||
| 197 | |__________| | ||
| 198 | line 50 | ||
| 199 | column 0 column 80 | ||
| 200 | @end group | ||
| 201 | @end smallexample | ||
| 202 | |||
| 203 | Next, the top window is split horizontally: | ||
| 204 | |||
| 205 | @smallexample | ||
| 206 | @group | ||
| 207 | (setq w3 (split-window w 35 t)) | ||
| 208 | @result{} #<window 32 on windows.texi> | ||
| 209 | @end group | ||
| 210 | @group | ||
| 211 | (window-edges w3) | ||
| 212 | @result{} (35 0 80 15) ; @r{Left edge at column 35} | ||
| 213 | @end group | ||
| 214 | @group | ||
| 215 | (window-edges w) | ||
| 216 | @result{} (0 0 35 15) ; @r{Right edge at column 35} | ||
| 217 | @end group | ||
| 218 | @group | ||
| 219 | (window-edges w2) | ||
| 220 | @result{} (0 15 80 50) ; @r{Bottom window unchanged} | ||
| 221 | @end group | ||
| 222 | @end smallexample | ||
| 223 | |||
| 224 | Now, the screen looks like this: | ||
| 225 | |||
| 226 | @smallexample | ||
| 227 | @group | ||
| 228 | column 35 | ||
| 229 | __________ | ||
| 230 | | | | line 0 | ||
| 231 | | w | w3 | | ||
| 232 | |___|______| | ||
| 233 | | | line 15 | ||
| 234 | | w2 | | ||
| 235 | |__________| | ||
| 236 | line 50 | ||
| 237 | column 0 column 80 | ||
| 238 | @end group | ||
| 239 | @end smallexample | ||
| 240 | @end deffn | ||
| 241 | |||
| 242 | @deffn Command split-window-vertically size | ||
| 243 | This function splits the selected window into two windows, one above | ||
| 244 | the other, leaving the selected window with @var{size} lines. | ||
| 245 | |||
| 246 | This function is simply an interface to @code{split-windows}. | ||
| 247 | Here is the complete function definition for it: | ||
| 248 | |||
| 249 | @smallexample | ||
| 250 | @group | ||
| 251 | (defun split-window-vertically (&optional arg) | ||
| 252 | "Split current window into two windows, one above the other." | ||
| 253 | (interactive "P") | ||
| 254 | (split-window nil (and arg (prefix-numeric-value arg)))) | ||
| 255 | @end group | ||
| 256 | @end smallexample | ||
| 257 | @end deffn | ||
| 258 | |||
| 259 | @deffn Command split-window-horizontally size | ||
| 260 | This function splits the selected window into two windows | ||
| 261 | side-by-side, leaving the selected window with @var{size} columns. | ||
| 262 | |||
| 263 | This function is simply an interface to @code{split-windows}. Here is | ||
| 264 | the complete definition for @code{split-window-horizontally} (except for | ||
| 265 | part of the documentation string): | ||
| 266 | |||
| 267 | @smallexample | ||
| 268 | @group | ||
| 269 | (defun split-window-horizontally (&optional arg) | ||
| 270 | "Split selected window into two windows, side by side..." | ||
| 271 | (interactive "P") | ||
| 272 | (split-window nil (and arg (prefix-numeric-value arg)) t)) | ||
| 273 | @end group | ||
| 274 | @end smallexample | ||
| 275 | @end deffn | ||
| 276 | |||
| 277 | @defun one-window-p &optional no-mini all-frames | ||
| 278 | This function returns non-@code{nil} if there is only one window. The | ||
| 279 | argument @var{no-mini}, if non-@code{nil}, means don't count the | ||
| 280 | minibuffer even if it is active; otherwise, the minibuffer window is | ||
| 281 | included, if active, in the total number of windows which is compared | ||
| 282 | against one. | ||
| 283 | |||
| 284 | The argument @var{all-frames} specifies which frames to consider. Here | ||
| 285 | are the possible values and their meanings: | ||
| 286 | |||
| 287 | @table @asis | ||
| 288 | @item @code{nil} | ||
| 289 | Count the windows in the selected frame, plus the minibuffer used | ||
| 290 | by that frame even if it lies in some other frame. | ||
| 291 | |||
| 292 | @item @code{t} | ||
| 293 | Count all windows in all existing frames. | ||
| 294 | |||
| 295 | @item @code{visible} | ||
| 296 | Count all windows in all visible frames. | ||
| 297 | |||
| 298 | @item anything else | ||
| 299 | Count precisely the windows in the selected frame, and no others. | ||
| 300 | @end table | ||
| 301 | @end defun | ||
| 302 | |||
| 303 | @node Deleting Windows | ||
| 304 | @section Deleting Windows | ||
| 305 | @cindex deleting windows | ||
| 306 | |||
| 307 | A window remains visible on its frame unless you @dfn{delete} it by | ||
| 308 | calling certain functions that delete windows. A deleted window cannot | ||
| 309 | appear on the screen, but continues to exist as a Lisp object until | ||
| 310 | there are no references to it. There is no way to cancel the deletion | ||
| 311 | of a window aside from restoring a saved window configuration | ||
| 312 | (@pxref{Window Configurations}). Restoring a window configuration also | ||
| 313 | deletes any windows that aren't part of that configuration. | ||
| 314 | |||
| 315 | When you delete a window, the space it took up is given to one | ||
| 316 | adjacent sibling. (In Emacs version 18, the space was divided evenly | ||
| 317 | among all the siblings.) | ||
| 318 | |||
| 319 | @c Emacs 19 feature | ||
| 320 | @defun window-live-p window | ||
| 321 | This function returns @code{nil} if @var{window} is deleted, and | ||
| 322 | @code{t} otherwise. | ||
| 323 | |||
| 324 | @strong{Warning:} erroneous information or fatal errors may result from | ||
| 325 | using a deleted window as if it were live. | ||
| 326 | @end defun | ||
| 327 | |||
| 328 | @deffn Command delete-window &optional window | ||
| 329 | This function removes @var{window} from the display. If @var{window} | ||
| 330 | is omitted, then the selected window is deleted. An error is signaled | ||
| 331 | if there is only one window when @code{delete-window} is called. | ||
| 332 | |||
| 333 | This function returns @code{nil}. | ||
| 334 | |||
| 335 | When @code{delete-window} is called interactively, @var{window} | ||
| 336 | defaults to the selected window. | ||
| 337 | @end deffn | ||
| 338 | |||
| 339 | @deffn Command delete-other-windows &optional window | ||
| 340 | This function makes @var{window} the only window on its frame, by | ||
| 341 | deleting the other windows in that frame. If @var{window} is omitted or | ||
| 342 | @code{nil}, then the selected window is used by default. | ||
| 343 | |||
| 344 | The result is @code{nil}. | ||
| 345 | @end deffn | ||
| 346 | |||
| 347 | @deffn Command delete-windows-on buffer &optional frame | ||
| 348 | This function deletes all windows showing @var{buffer}. If there are | ||
| 349 | no windows showing @var{buffer}, it does nothing. | ||
| 350 | |||
| 351 | @code{delete-windows-on} operates frame by frame. If a frame has | ||
| 352 | several windows showing different buffers, then those showing | ||
| 353 | @var{buffer} are removed, and the others expand to fill the space. If | ||
| 354 | all windows in some frame are showing @var{buffer} (including the case | ||
| 355 | where there is only one window), then the frame reverts to having a | ||
| 356 | single window showing another buffer chosen with @code{other-buffer}. | ||
| 357 | @xref{The Buffer List}. | ||
| 358 | |||
| 359 | The argument @var{frame} controls which frames to operate on: | ||
| 360 | |||
| 361 | @itemize @bullet | ||
| 362 | @item | ||
| 363 | If it is @code{nil}, operate on the selected frame. | ||
| 364 | @item | ||
| 365 | If it is @code{t}, operate on all frames. | ||
| 366 | @item | ||
| 367 | If it is @code{visible}, operate on all visible frames. | ||
| 368 | @item | ||
| 369 | If it is a frame, operate on that frame. | ||
| 370 | @end itemize | ||
| 371 | |||
| 372 | This function always returns @code{nil}. | ||
| 373 | @end deffn | ||
| 374 | |||
| 375 | @node Selecting Windows | ||
| 376 | @section Selecting Windows | ||
| 377 | @cindex selecting windows | ||
| 378 | |||
| 379 | When a window is selected, the buffer in the window becomes the current | ||
| 380 | buffer, and the cursor will appear in it. | ||
| 381 | |||
| 382 | @defun selected-window | ||
| 383 | This function returns the selected window. This is the window in | ||
| 384 | which the cursor appears and to which many commands apply. | ||
| 385 | @end defun | ||
| 386 | |||
| 387 | @defun select-window window | ||
| 388 | This function makes @var{window} the selected window. The cursor then | ||
| 389 | appears in @var{window} (on redisplay). The buffer being displayed in | ||
| 390 | @var{window} is immediately designated the current buffer. | ||
| 391 | |||
| 392 | The return value is @var{window}. | ||
| 393 | |||
| 394 | @example | ||
| 395 | @group | ||
| 396 | (setq w (next-window)) | ||
| 397 | (select-window w) | ||
| 398 | @result{} #<window 65 on windows.texi> | ||
| 399 | @end group | ||
| 400 | @end example | ||
| 401 | @end defun | ||
| 402 | |||
| 403 | @cindex finding windows | ||
| 404 | The following functions choose one of the windows on the screen, | ||
| 405 | offering various criteria for the choice. | ||
| 406 | |||
| 407 | @defun get-lru-window &optional frame | ||
| 408 | This function returns the window least recently ``used'' (that is, | ||
| 409 | selected). The selected window is always the most recently used window. | ||
| 410 | |||
| 411 | The selected window can be the least recently used window if it is the | ||
| 412 | only window. A newly created window becomes the least recently used | ||
| 413 | window until it is selected. A minibuffer window is never a candidate. | ||
| 414 | |||
| 415 | The argument @var{frame} controls which set of windows are | ||
| 416 | considered. | ||
| 417 | |||
| 418 | @itemize @bullet | ||
| 419 | @item | ||
| 420 | If it is @code{nil}, consider windows on the selected frame. | ||
| 421 | @item | ||
| 422 | If it is @code{t}, consider windows on all frames. | ||
| 423 | @item | ||
| 424 | If it is @code{visible}, consider windows on all visible frames. | ||
| 425 | @item | ||
| 426 | If it is a frame, consider windows on that frame. | ||
| 427 | @end itemize | ||
| 428 | @end defun | ||
| 429 | |||
| 430 | @defun get-largest-window &optional frame | ||
| 431 | This function returns the window with the largest area (height times | ||
| 432 | width). If there are no side-by-side windows, then this is the window | ||
| 433 | with the most lines. A minibuffer window is never a candidate. | ||
| 434 | |||
| 435 | If there are two windows of the same size, then the function returns | ||
| 436 | the window which is first in the cyclic ordering of windows (see | ||
| 437 | following section), starting from the selected window. | ||
| 438 | |||
| 439 | The argument @var{frame} controls which set of windows are | ||
| 440 | considered. See @code{get-lru-window}, above. | ||
| 441 | @end defun | ||
| 442 | |||
| 443 | @node Cyclic Window Ordering | ||
| 444 | @comment node-name, next, previous, up | ||
| 445 | @section Cyclic Ordering of Windows | ||
| 446 | @cindex cyclic ordering of windows | ||
| 447 | @cindex ordering of windows, cyclic | ||
| 448 | @cindex window ordering, cyclic | ||
| 449 | |||
| 450 | When you use the command @kbd{C-x o} (@code{other-window}) to select | ||
| 451 | the next window, it moves through all the windows on the screen in a | ||
| 452 | specific cyclic order. For any given configuration of windows, this | ||
| 453 | order never varies. It is called the @dfn{cyclic ordering of windows}. | ||
| 454 | |||
| 455 | This ordering generally goes from top to bottom, and from left to | ||
| 456 | right. But it may go down first or go right first, depending on the | ||
| 457 | order in which the windows were split. | ||
| 458 | |||
| 459 | If the first split was vertical (into windows one above each other), | ||
| 460 | and then the subwindows were split horizontally, then the ordering is | ||
| 461 | left to right in the top of the frame, and then left to right in the | ||
| 462 | next lower part of the frame, and so on. If the first split was | ||
| 463 | horizontal, the ordering is top to bottom in the left part, and so on. | ||
| 464 | In general, within each set of siblings at any level in the window tree, | ||
| 465 | the order is left to right, or top to bottom. | ||
| 466 | |||
| 467 | @defun next-window &optional window minibuf all-frames | ||
| 468 | @cindex minibuffer window | ||
| 469 | This function returns the window following @var{window} in the cyclic | ||
| 470 | ordering of windows. This is the window which @kbd{C-x o} would select | ||
| 471 | if done when @var{window} is selected. If @var{window} is the only | ||
| 472 | window visible, then this function returns @var{window}. If omitted, | ||
| 473 | @var{window} defaults to the selected window. | ||
| 474 | |||
| 475 | The value of the argument @var{minibuf} determines whether the | ||
| 476 | minibuffer is included in the window order. Normally, when | ||
| 477 | @var{minibuf} is @code{nil}, the minibuffer is included if it is | ||
| 478 | currently active; this is the behavior of @kbd{C-x o}. (The minibuffer | ||
| 479 | window is active while the minibuffer is in use. @xref{Minibuffers}.) | ||
| 480 | |||
| 481 | If @var{minibuf} is @code{t}, then the cyclic ordering includes the | ||
| 482 | minibuffer window even if it is not active. | ||
| 483 | |||
| 484 | If @var{minibuf} is neither @code{t} nor @code{nil}, then the minibuffer | ||
| 485 | window is not included even if it is active. | ||
| 486 | |||
| 487 | The argument @var{all-frames} specifies which frames to consider. Here | ||
| 488 | are the possible values and their meanings: | ||
| 489 | |||
| 490 | @table @asis | ||
| 491 | @item @code{nil} | ||
| 492 | Consider all the windows in @var{window}'s frame, plus the minibuffer | ||
| 493 | used by that frame even if it lies in some other frame. | ||
| 494 | |||
| 495 | @item @code{t} | ||
| 496 | Consider all windows in all existing frames. | ||
| 497 | |||
| 498 | @item @code{visible} | ||
| 499 | Consider all windows in all visible frames. (To get useful results, you | ||
| 500 | must ensure @var{window} is in a visible frame.) | ||
| 501 | |||
| 502 | @item anything else | ||
| 503 | Consider precisely the windows in @var{window}'s frame, and no others. | ||
| 504 | @end table | ||
| 505 | |||
| 506 | This example assumes there are two windows, both displaying the | ||
| 507 | buffer @samp{windows.texi}: | ||
| 508 | |||
| 509 | @example | ||
| 510 | @group | ||
| 511 | (selected-window) | ||
| 512 | @result{} #<window 56 on windows.texi> | ||
| 513 | @end group | ||
| 514 | @group | ||
| 515 | (next-window (selected-window)) | ||
| 516 | @result{} #<window 52 on windows.texi> | ||
| 517 | @end group | ||
| 518 | @group | ||
| 519 | (next-window (next-window (selected-window))) | ||
| 520 | @result{} #<window 56 on windows.texi> | ||
| 521 | @end group | ||
| 522 | @end example | ||
| 523 | @end defun | ||
| 524 | |||
| 525 | @defun previous-window &optional window minibuf all-frames | ||
| 526 | This function returns the window preceding @var{window} in the cyclic | ||
| 527 | ordering of windows. The other arguments specify which windows to | ||
| 528 | include in the cycle, as in @code{next-window}. | ||
| 529 | @end defun | ||
| 530 | |||
| 531 | @deffn Command other-window count | ||
| 532 | This function selects the @var{count}th following window in the cyclic | ||
| 533 | order. If count is negative, then it selects the @minus{}@var{count}th | ||
| 534 | preceding window. It returns @code{nil}. | ||
| 535 | |||
| 536 | In an interactive call, @var{count} is the numeric prefix argument. | ||
| 537 | @end deffn | ||
| 538 | |||
| 539 | @c Emacs 19 feature | ||
| 540 | @defun walk-windows proc &optional minibuf all-frames | ||
| 541 | This function cycles through all windows, calling @code{proc} | ||
| 542 | once for each window with the window as its sole argument. | ||
| 543 | |||
| 544 | The optional arguments @var{minibuf} and @var{all-frames} specify the | ||
| 545 | set of windows to include in the scan. See @code{next-window}, above, | ||
| 546 | for details. | ||
| 547 | @end defun | ||
| 548 | |||
| 549 | @node Buffers and Windows | ||
| 550 | @section Buffers and Windows | ||
| 551 | @cindex examining windows | ||
| 552 | @cindex windows, controlling precisely | ||
| 553 | @cindex buffers, controlled in windows | ||
| 554 | |||
| 555 | This section describes low-level functions to examine windows or to | ||
| 556 | display buffers in windows in a precisely controlled fashion. | ||
| 557 | @iftex | ||
| 558 | See the following section for | ||
| 559 | @end iftex | ||
| 560 | @ifinfo | ||
| 561 | @xref{Displaying Buffers}, for | ||
| 562 | @end ifinfo | ||
| 563 | related functions that find a window to use and specify a buffer for it. | ||
| 564 | The functions described there are easier to use than these, but they | ||
| 565 | employ heuristics in choosing or creating a window; use these functions | ||
| 566 | when you need complete control. | ||
| 567 | |||
| 568 | @defun set-window-buffer window buffer-or-name | ||
| 569 | This function makes @var{window} display @var{buffer-or-name} as its | ||
| 570 | contents. It returns @code{nil}. | ||
| 571 | |||
| 572 | @example | ||
| 573 | @group | ||
| 574 | (set-window-buffer (selected-window) "foo") | ||
| 575 | @result{} nil | ||
| 576 | @end group | ||
| 577 | @end example | ||
| 578 | @end defun | ||
| 579 | |||
| 580 | @defun window-buffer &optional window | ||
| 581 | This function returns the buffer that @var{window} is displaying. If | ||
| 582 | @var{window} is omitted, this function returns the buffer for the | ||
| 583 | selected window. | ||
| 584 | |||
| 585 | @example | ||
| 586 | @group | ||
| 587 | (window-buffer) | ||
| 588 | @result{} #<buffer windows.texi> | ||
| 589 | @end group | ||
| 590 | @end example | ||
| 591 | @end defun | ||
| 592 | |||
| 593 | @defun get-buffer-window buffer-or-name &optional all-frames | ||
| 594 | This function returns a window currently displaying | ||
| 595 | @var{buffer-or-name}, or @code{nil} if there is none. If there are | ||
| 596 | several such windows, then the function returns the first one in the | ||
| 597 | cyclic ordering of windows, starting from the selected window. | ||
| 598 | @xref{Cyclic Window Ordering}. | ||
| 599 | |||
| 600 | The argument @var{all-frames} controls which windows to consider. | ||
| 601 | |||
| 602 | @itemize @bullet | ||
| 603 | @item | ||
| 604 | If it is @code{nil}, consider windows on the selected frame. | ||
| 605 | @item | ||
| 606 | If it is @code{t}, consider windows on all frames. | ||
| 607 | @item | ||
| 608 | If it is @code{visible}, consider windows on all visible frames. | ||
| 609 | @item | ||
| 610 | If it is a frame, consider windows on that frame. | ||
| 611 | @end itemize | ||
| 612 | @end defun | ||
| 613 | |||
| 614 | @deffn Command replace-buffer-in-windows buffer | ||
| 615 | This function replaces @var{buffer} with some other buffer in all | ||
| 616 | windows displaying it. The other buffer used is chosen with | ||
| 617 | @code{other-buffer}. In the usual applications of this function, you | ||
| 618 | don't care which other buffer is used; you just want to make sure that | ||
| 619 | @var{buffer} is no longer displayed. | ||
| 620 | |||
| 621 | This function returns @code{nil}. | ||
| 622 | @end deffn | ||
| 623 | |||
| 624 | @node Displaying Buffers | ||
| 625 | @section Displaying Buffers in Windows | ||
| 626 | @cindex switching to a buffer | ||
| 627 | @cindex displaying a buffer | ||
| 628 | |||
| 629 | In this section we describe convenient functions that choose a window | ||
| 630 | automatically and use it to display a specified buffer. These functions | ||
| 631 | can also split an existing window in certain circumstances. We also | ||
| 632 | describe variables that parameterize the heuristics used for choosing a | ||
| 633 | window. | ||
| 634 | @iftex | ||
| 635 | See the preceding section for | ||
| 636 | @end iftex | ||
| 637 | @ifinfo | ||
| 638 | @xref{Buffers and Windows}, for | ||
| 639 | @end ifinfo | ||
| 640 | low-level functions that give you more precise control. | ||
| 641 | |||
| 642 | Do not use the functions in this section in order to make a buffer | ||
| 643 | current so that a Lisp program can access or modify it; they are too | ||
| 644 | drastic for that purpose, since they change the display of buffers in | ||
| 645 | windows, which is gratuitous and will surprise the user. Instead, use | ||
| 646 | @code{set-buffer} (@pxref{Current Buffer}) and @code{save-excursion} | ||
| 647 | (@pxref{Excursions}), which designate buffers as current for programmed | ||
| 648 | access without affecting the display of buffers in windows. | ||
| 649 | |||
| 650 | @deffn Command switch-to-buffer buffer-or-name &optional norecord | ||
| 651 | This function makes @var{buffer-or-name} the current buffer, and also | ||
| 652 | displays the buffer in the selected window. This means that a human can | ||
| 653 | see the buffer and subsequent keyboard commands will apply to it. | ||
| 654 | Contrast this with @code{set-buffer}, which makes @var{buffer-or-name} | ||
| 655 | the current buffer but does not display it in the selected window. | ||
| 656 | @xref{Current Buffer}. | ||
| 657 | |||
| 658 | If @var{buffer-or-name} does not identify an existing buffer, then | ||
| 659 | a new buffer by that name is created. | ||
| 660 | |||
| 661 | Normally the specified buffer is put at the front of the buffer list. | ||
| 662 | This affects the operation of @code{other-buffer}. However, if | ||
| 663 | @var{norecord} is non-@code{nil}, this is not done. @xref{The Buffer | ||
| 664 | List}. | ||
| 665 | |||
| 666 | The @code{switch-to-buffer} function is often used interactively, as | ||
| 667 | the binding of @kbd{C-x b}. It is also used frequently in programs. It | ||
| 668 | always returns @code{nil}. | ||
| 669 | @end deffn | ||
| 670 | |||
| 671 | @deffn Command switch-to-buffer-other-window buffer-or-name | ||
| 672 | This function makes @var{buffer-or-name} the current buffer and | ||
| 673 | displays it in a window not currently selected. It then selects that | ||
| 674 | window. The handling of the buffer is the same as in | ||
| 675 | @code{switch-to-buffer}. | ||
| 676 | |||
| 677 | The previously selected window is absolutely never used to display the | ||
| 678 | buffer. If it is the only window, then it is split to make a distinct | ||
| 679 | window for this purpose. If the selected window is already displaying | ||
| 680 | the buffer, then it continues to do so, but another window is | ||
| 681 | nonetheless found to display it in as well. | ||
| 682 | @end deffn | ||
| 683 | |||
| 684 | @defun pop-to-buffer buffer-or-name &optional other-window | ||
| 685 | This function makes @var{buffer-or-name} the current buffer and | ||
| 686 | switches to it in some window, preferably not the window previously | ||
| 687 | selected. The ``popped-to'' window becomes the selected window within | ||
| 688 | its frame. | ||
| 689 | |||
| 690 | If the variable @code{pop-up-frames} is non-@code{nil}, | ||
| 691 | @code{pop-to-buffer} looks for a window in any visible frame already | ||
| 692 | displaying the buffer; if there is one, it returns that window and makes | ||
| 693 | it be selected within its frame. If there is none, it creates a new | ||
| 694 | frame and displays the buffer in it. | ||
| 695 | |||
| 696 | If @code{pop-up-frames} is @code{nil}, then @code{pop-to-buffer} | ||
| 697 | operates entirely within the selected frame. (If the selected frame has | ||
| 698 | just a minibuffer, @code{pop-to-buffer} operates within the most | ||
| 699 | recently selected frame that was not just a minibuffer.) | ||
| 700 | |||
| 701 | If the variable @code{pop-up-windows} is non-@code{nil}, windows may | ||
| 702 | be split to create a new window that is different from the original | ||
| 703 | window. For details, see @ref{Choosing Window}. | ||
| 704 | |||
| 705 | If @var{other-window} is non-@code{nil}, @code{pop-to-buffer} finds or | ||
| 706 | creates another window even if @var{buffer-or-name} is already visible | ||
| 707 | in the selected window. Thus @var{buffer-or-name} could end up | ||
| 708 | displayed in two windows. On the other hand, if @var{buffer-or-name} is | ||
| 709 | already displayed in the selected window and @var{other-window} is | ||
| 710 | @code{nil}, then the selected window is considered sufficient display | ||
| 711 | for @var{buffer-or-name}, so that nothing needs to be done. | ||
| 712 | |||
| 713 | If @var{buffer-or-name} is a string that does not name an existing | ||
| 714 | buffer, a buffer by that name is created. | ||
| 715 | |||
| 716 | An example use of this function is found at the end of @ref{Filter | ||
| 717 | Functions}. | ||
| 718 | @end defun | ||
| 719 | |||
| 720 | @node Choosing Window | ||
| 721 | @section Choosing a Window for Display | ||
| 722 | |||
| 723 | This section describes the basic facility which chooses a window to | ||
| 724 | display a buffer in---@code{display-buffer}. All the higher-level | ||
| 725 | functions and commands use this subroutine. Here we describe how to use | ||
| 726 | @code{display-buffer} and how to customize it. | ||
| 727 | |||
| 728 | @deffn Command display-buffer buffer-or-name &optional not-this-window | ||
| 729 | This command makes @var{buffer-or-name} appear in some window, like | ||
| 730 | @code{pop-to-buffer}, but it does not select that window and does not | ||
| 731 | make the buffer current. The identity of the selected window is | ||
| 732 | unaltered by this function. | ||
| 733 | |||
| 734 | If @var{not-this-window} is non-@code{nil}, it means to display the | ||
| 735 | specified buffer in a window other than the selected one, even if it is | ||
| 736 | already on display in the selected window. This can cause the buffer to | ||
| 737 | appear in two windows at once. Otherwise, if @var{buffer-or-name} is | ||
| 738 | already being displayed in any window, that is good enough, so this | ||
| 739 | function does nothing. | ||
| 740 | |||
| 741 | @code{display-buffer} returns the window chosen to display | ||
| 742 | @var{buffer-or-name}. | ||
| 743 | |||
| 744 | Precisely how @code{display-buffer} finds or creates a window depends on | ||
| 745 | the variables described below. | ||
| 746 | @end deffn | ||
| 747 | |||
| 748 | @defopt pop-up-windows | ||
| 749 | This variable controls whether @code{display-buffer} makes new windows. | ||
| 750 | If it is non-@code{nil} and there is only one window, then that window | ||
| 751 | is split. If it is @code{nil}, then @code{display-buffer} does not | ||
| 752 | split the single window, but uses it whole. | ||
| 753 | @end defopt | ||
| 754 | |||
| 755 | @defopt split-height-threshold | ||
| 756 | This variable determines when @code{display-buffer} may split a window, | ||
| 757 | if there are multiple windows. @code{display-buffer} always splits the | ||
| 758 | largest window if it has at least this many lines. If the largest | ||
| 759 | window is not this tall, it is split only if it is the sole window and | ||
| 760 | @code{pop-up-windows} is non-@code{nil}. | ||
| 761 | @end defopt | ||
| 762 | |||
| 763 | @c Emacs 19 feature | ||
| 764 | @defopt pop-up-frames | ||
| 765 | This variable controls whether @code{display-buffer} makes new frames. | ||
| 766 | If it is non-@code{nil}, @code{display-buffer} looks for an existing | ||
| 767 | window already displaying the desired buffer, on any visible frame. If | ||
| 768 | it finds one, it returns that window. Otherwise it makes a new frame. | ||
| 769 | The variables @code{pop-up-windows} and @code{split-height-threshold} do | ||
| 770 | not matter if @code{pop-up-frames} is non-@code{nil}. | ||
| 771 | |||
| 772 | If @code{pop-up-frames} is @code{nil}, then @code{display-buffer} either | ||
| 773 | splits a window or reuses one. | ||
| 774 | |||
| 775 | @xref{Frames}, for more information. | ||
| 776 | @end defopt | ||
| 777 | |||
| 778 | @c Emacs 19 feature | ||
| 779 | @defvar pop-up-frame-function | ||
| 780 | This variable specifies how to make a new frame if @code{pop-up-frames} | ||
| 781 | is non-@code{nil}. | ||
| 782 | |||
| 783 | Its value should be a function of no arguments. When | ||
| 784 | @code{display-buffer} makes a new frame, it does so by calling that | ||
| 785 | function, which should return a frame. The default value of the | ||
| 786 | variable is a function which creates a frame using parameters from | ||
| 787 | @code{pop-up-frame-alist}. | ||
| 788 | @end defvar | ||
| 789 | |||
| 790 | @defvar pop-up-frame-alist | ||
| 791 | This variable holds an alist specifying frame parameters used when | ||
| 792 | @code{display-buffer} makes a new frame. @xref{Frame Parameters}, for | ||
| 793 | more information about frame parameters. | ||
| 794 | @end defvar | ||
| 795 | |||
| 796 | @c Emacs 19 feature | ||
| 797 | @defvar display-buffer-function | ||
| 798 | This variable is the most flexible way to customize the behavior of | ||
| 799 | @code{display-buffer}. If it is non-@code{nil}, it should be a function | ||
| 800 | that @code{display-buffer} calls to do the work. The function should | ||
| 801 | accept two arguments, the same two arguments that @code{display-buffer} | ||
| 802 | received. It should choose or create a window, display the specified | ||
| 803 | buffer, and then return the window. | ||
| 804 | |||
| 805 | This hook takes precedence over all the other options and hooks | ||
| 806 | described above. | ||
| 807 | @end defvar | ||
| 808 | |||
| 809 | @c Emacs 19 feature | ||
| 810 | @cindex dedicated window | ||
| 811 | A window can be marked as ``dedicated'' to its buffer. Then | ||
| 812 | @code{display-buffer} does not try to use that window. | ||
| 813 | |||
| 814 | @defun window-dedicated-p window | ||
| 815 | This function returns @code{t} if @var{window} is marked as dedicated; | ||
| 816 | otherwise @code{nil}. | ||
| 817 | @end defun | ||
| 818 | |||
| 819 | @defun set-window-dedicated-p window flag | ||
| 820 | This function marks @var{window} as dedicated if @var{flag} is | ||
| 821 | non-@code{nil}, and nondedicated otherwise. | ||
| 822 | @end defun | ||
| 823 | |||
| 824 | @node Window Point | ||
| 825 | @section Windows and Point | ||
| 826 | @cindex window position | ||
| 827 | @cindex window point | ||
| 828 | @cindex position in window | ||
| 829 | @cindex point in window | ||
| 830 | |||
| 831 | Each window has its own value of point, independent of the value of | ||
| 832 | point in other windows displaying the same buffer. This makes it useful | ||
| 833 | to have multiple windows showing one buffer. | ||
| 834 | |||
| 835 | @itemize @bullet | ||
| 836 | @item | ||
| 837 | The window point is established when a window is first created; it is | ||
| 838 | initialized from the buffer's point, or from the window point of another | ||
| 839 | window opened on the buffer if such a window exists. | ||
| 840 | |||
| 841 | @item | ||
| 842 | Selecting a window sets the value of point in its buffer to the window's | ||
| 843 | value of point. Conversely, deselecting a window sets the window's | ||
| 844 | value of point from that of the buffer. Thus, when you switch between | ||
| 845 | windows that display a given buffer, the point value for the selected | ||
| 846 | window is in effect in the buffer, while the point values for the other | ||
| 847 | windows are stored in those windows. | ||
| 848 | |||
| 849 | @item | ||
| 850 | As long as the selected window displays the current buffer, the window's | ||
| 851 | point and the buffer's point always move together; they remain equal. | ||
| 852 | |||
| 853 | @item | ||
| 854 | @xref{Positions}, for more details on buffer positions. | ||
| 855 | @end itemize | ||
| 856 | |||
| 857 | As far as the user is concerned, point is where the cursor is, and | ||
| 858 | when the user switches to another buffer, the cursor jumps to the | ||
| 859 | position of point in that buffer. | ||
| 860 | |||
| 861 | @defun window-point window | ||
| 862 | This function returns the current position of point in @var{window}. | ||
| 863 | For a nonselected window, this is the value point would have (in that | ||
| 864 | window's buffer) if that window were selected. | ||
| 865 | |||
| 866 | When @var{window} is the selected window and its buffer is also the | ||
| 867 | current buffer, the value returned is the same as point in that buffer. | ||
| 868 | |||
| 869 | Strictly speaking, it would be more correct to return the | ||
| 870 | ``top-level'' value of point, outside of any @code{save-excursion} | ||
| 871 | forms. But that value is hard to find. | ||
| 872 | @end defun | ||
| 873 | |||
| 874 | @defun set-window-point window position | ||
| 875 | This function positions point in @var{window} at position | ||
| 876 | @var{position} in @var{window}'s buffer. | ||
| 877 | @end defun | ||
| 878 | |||
| 879 | @node Window Start | ||
| 880 | @section The Window Start Position | ||
| 881 | |||
| 882 | Each window contains a marker used to keep track of a buffer position | ||
| 883 | which specifies where in the buffer display should start. This position | ||
| 884 | is called the @dfn{display-start} position of the window (or just the | ||
| 885 | @dfn{start}). The character after this position is the one that appears | ||
| 886 | at the upper left corner of the window. It is usually, but not | ||
| 887 | inevitably, at the beginning of a text line. | ||
| 888 | |||
| 889 | @defun window-start &optional window | ||
| 890 | @cindex window top line | ||
| 891 | This function returns the display-start position of window | ||
| 892 | @var{window}. If @var{window} is @code{nil}, the selected window is | ||
| 893 | used. For example, | ||
| 894 | |||
| 895 | @example | ||
| 896 | @group | ||
| 897 | (window-start) | ||
| 898 | @result{} 7058 | ||
| 899 | @end group | ||
| 900 | @end example | ||
| 901 | |||
| 902 | When you create a window, or display a different buffer in it, the the | ||
| 903 | display-start position is set to a display-start position recently used | ||
| 904 | for the same buffer, or 1 if the buffer doesn't have any. | ||
| 905 | |||
| 906 | For a realistic example, see the description of @code{count-lines} in | ||
| 907 | @ref{Text Lines}. | ||
| 908 | @end defun | ||
| 909 | |||
| 910 | @defun window-end &optional window | ||
| 911 | This function returns the position of the end of the display in window | ||
| 912 | @var{window}. If @var{window} is @code{nil}, the selected window is | ||
| 913 | used. | ||
| 914 | @end defun | ||
| 915 | |||
| 916 | @defun set-window-start window position &optional noforce | ||
| 917 | This function sets the display-start position of @var{window} to | ||
| 918 | @var{position} in @var{window}'s buffer. | ||
| 919 | |||
| 920 | The display routines insist that the position of point be visible when a | ||
| 921 | buffer is displayed. Normally, they change the display-start position | ||
| 922 | (that is, scroll the window) whenever necessary to make point visible. | ||
| 923 | However, if you specify the start position with this function using | ||
| 924 | @code{nil} for @var{noforce}, it means you want display to start at | ||
| 925 | @var{position} even if that would put the location of point off the | ||
| 926 | screen. If this does place point off screen, the display routines move | ||
| 927 | point to the left margin on the middle line in the window. | ||
| 928 | |||
| 929 | For example, if point @w{is 1} and you set the start of the window @w{to | ||
| 930 | 2}, then point would be ``above'' the top of the window. The display | ||
| 931 | routines will automatically move point if it is still 1 when redisplay | ||
| 932 | occurs. Here is an example: | ||
| 933 | |||
| 934 | @example | ||
| 935 | @group | ||
| 936 | ;; @r{Here is what @samp{foo} looks like before executing} | ||
| 937 | ;; @r{the @code{set-window-start} expression.} | ||
| 938 | @end group | ||
| 939 | |||
| 940 | @group | ||
| 941 | ---------- Buffer: foo ---------- | ||
| 942 | @point{}This is the contents of buffer foo. | ||
| 943 | 2 | ||
| 944 | 3 | ||
| 945 | 4 | ||
| 946 | 5 | ||
| 947 | 6 | ||
| 948 | ---------- Buffer: foo ---------- | ||
| 949 | @end group | ||
| 950 | |||
| 951 | @group | ||
| 952 | (set-window-start | ||
| 953 | (selected-window) | ||
| 954 | (1+ (window-start))) | ||
| 955 | @result{} 2 | ||
| 956 | @end group | ||
| 957 | |||
| 958 | @group | ||
| 959 | ;; @r{Here is what @samp{foo} looks like after executing} | ||
| 960 | ;; @r{the @code{set-window-start} expression.} | ||
| 961 | ---------- Buffer: foo ---------- | ||
| 962 | his is the contents of buffer foo. | ||
| 963 | 2 | ||
| 964 | 3 | ||
| 965 | @point{}4 | ||
| 966 | 5 | ||
| 967 | 6 | ||
| 968 | ---------- Buffer: foo ---------- | ||
| 969 | @end group | ||
| 970 | @end example | ||
| 971 | |||
| 972 | If @var{noforce} is non-@code{nil}, and @var{position} would place point | ||
| 973 | off screen at the next redisplay, then redisplay computes a new window-start | ||
| 974 | position that works well with point, and thus @var{position} is not used. | ||
| 975 | |||
| 976 | This function returns @var{position}. | ||
| 977 | @end defun | ||
| 978 | |||
| 979 | @defun pos-visible-in-window-p &optional position window | ||
| 980 | This function returns @code{t} if @var{position} is within the range | ||
| 981 | of text currently visible on the screen in @var{window}. It returns | ||
| 982 | @code{nil} if @var{position} is scrolled vertically out of view. The | ||
| 983 | argument @var{position} defaults to the current position of point; | ||
| 984 | @var{window}, to the selected window. Here is an example: | ||
| 985 | |||
| 986 | @example | ||
| 987 | @group | ||
| 988 | (or (pos-visible-in-window-p | ||
| 989 | (point) (selected-window)) | ||
| 990 | (recenter 0)) | ||
| 991 | @end group | ||
| 992 | @end example | ||
| 993 | |||
| 994 | The @code{pos-visible-in-window-p} function considers only vertical | ||
| 995 | scrolling. If @var{position} is out of view only because @var{window} | ||
| 996 | has been scrolled horizontally, @code{pos-visible-in-window-p} returns | ||
| 997 | @code{t}. @xref{Horizontal Scrolling}. | ||
| 998 | @end defun | ||
| 999 | |||
| 1000 | @node Vertical Scrolling | ||
| 1001 | @section Vertical Scrolling | ||
| 1002 | @cindex vertical scrolling | ||
| 1003 | @cindex scrolling vertically | ||
| 1004 | |||
| 1005 | Vertical scrolling means moving the text up or down in a window. It | ||
| 1006 | works by changing the value of the window's display-start location. It | ||
| 1007 | may also change the value of @code{window-point} to keep it on the | ||
| 1008 | screen. | ||
| 1009 | |||
| 1010 | In the commands @code{scroll-up} and @code{scroll-down}, the directions | ||
| 1011 | ``up'' and ``down'' refer to the motion of the text in the buffer at which | ||
| 1012 | you are looking through the window. Imagine that the text is | ||
| 1013 | written on a long roll of paper and that the scrolling commands move the | ||
| 1014 | paper up and down. Thus, if you are looking at text in the middle of a | ||
| 1015 | buffer and repeatedly call @code{scroll-down}, you will eventually see | ||
| 1016 | the beginning of the buffer. | ||
| 1017 | |||
| 1018 | Some people have urged that the opposite convention be used: they | ||
| 1019 | imagine that the window moves over text that remains in place. Then | ||
| 1020 | ``down'' commands would take you to the end of the buffer. This view is | ||
| 1021 | more consistent with the actual relationship between windows and the | ||
| 1022 | text in the buffer, but it is less like what the user sees. The | ||
| 1023 | position of a window on the terminal does not move, and short scrolling | ||
| 1024 | commands clearly move the text up or down on the screen. We have chosen | ||
| 1025 | names that fit the user's point of view. | ||
| 1026 | |||
| 1027 | The scrolling functions (aside from @code{scroll-other-window}) have | ||
| 1028 | unpredictable results if the current buffer is different from the buffer | ||
| 1029 | that is displayed in the selected window. @xref{Current Buffer}. | ||
| 1030 | |||
| 1031 | @deffn Command scroll-up &optional count | ||
| 1032 | This function scrolls the text in the selected window upward | ||
| 1033 | @var{count} lines. If @var{count} is negative, scrolling is actually | ||
| 1034 | downward. | ||
| 1035 | |||
| 1036 | If @var{count} is @code{nil} (or omitted), then the length of scroll | ||
| 1037 | is @code{next-screen-context-lines} lines less than the usable height of | ||
| 1038 | the window (not counting its mode line). | ||
| 1039 | |||
| 1040 | @code{scroll-up} returns @code{nil}. | ||
| 1041 | @end deffn | ||
| 1042 | |||
| 1043 | @deffn Command scroll-down &optional count | ||
| 1044 | This function scrolls the text in the selected window downward | ||
| 1045 | @var{count} lines. If @var{count} is negative, scrolling is actually | ||
| 1046 | upward. | ||
| 1047 | |||
| 1048 | If @var{count} is omitted or @code{nil}, then the length of the scroll | ||
| 1049 | is @code{next-screen-context-lines} lines less than the usable height of | ||
| 1050 | the window. | ||
| 1051 | |||
| 1052 | @code{scroll-down} returns @code{nil}. | ||
| 1053 | @end deffn | ||
| 1054 | |||
| 1055 | @deffn Command scroll-other-window &optional count | ||
| 1056 | This function scrolls the text in another window upward @var{count} | ||
| 1057 | lines. Negative values of @var{count}, or @code{nil}, are handled | ||
| 1058 | as in @code{scroll-up}. | ||
| 1059 | |||
| 1060 | The window that is scrolled is normally the one following the selected | ||
| 1061 | window in the cyclic ordering of windows---the window that | ||
| 1062 | @code{next-window} would return. @xref{Cyclic Window Ordering}. | ||
| 1063 | |||
| 1064 | You can specify a buffer to scroll with the variable | ||
| 1065 | @code{other-window-scroll-buffer}. When the selected window is the | ||
| 1066 | minibuffer, the next window is normally the one at the top left corner. | ||
| 1067 | You can specify a different window to scroll with the variable | ||
| 1068 | @code{minibuffer-scroll-window}. This variable has no effect when any | ||
| 1069 | other window is selected. @xref{Minibuffer Misc}. | ||
| 1070 | |||
| 1071 | When the minibuffer is active, it is the next window if the selected | ||
| 1072 | window is the one at the bottom right corner. In this case, | ||
| 1073 | @code{scroll-other-window} attempts to scroll the minibuffer. If the | ||
| 1074 | minibuffer contains just one line, it has nowhere to scroll to, so the | ||
| 1075 | line reappears after the echo area momentarily displays the message | ||
| 1076 | ``Beginning of buffer''. | ||
| 1077 | @end deffn | ||
| 1078 | |||
| 1079 | @c Emacs 19 feature | ||
| 1080 | @defvar other-window-scroll-buffer | ||
| 1081 | If this variable is non-@code{nil}, it tells @code{scroll-other-window} | ||
| 1082 | which buffer to scroll. | ||
| 1083 | @end defvar | ||
| 1084 | |||
| 1085 | @defopt scroll-step | ||
| 1086 | This variable controls how scrolling is done automatically when point | ||
| 1087 | moves off the screen. If the value is zero, then redisplay scrolls the | ||
| 1088 | text to center point vertically in the window. If the value is a | ||
| 1089 | positive integer @var{n}, then redisplay brings point back on screen by | ||
| 1090 | scrolling @var{n} lines in either direction, if possible; otherwise, it | ||
| 1091 | centers point if possible. The default value is zero. | ||
| 1092 | @end defopt | ||
| 1093 | |||
| 1094 | @defopt next-screen-context-lines | ||
| 1095 | The value of this variable is the number of lines of continuity to | ||
| 1096 | retain when scrolling by full screens. For example, @code{scroll-up} | ||
| 1097 | with an argument of @code{nil} scrolls so that this many lines at the | ||
| 1098 | bottom of the window appear instead at the top. The default value is | ||
| 1099 | @code{2}. | ||
| 1100 | @end defopt | ||
| 1101 | |||
| 1102 | @deffn Command recenter &optional count | ||
| 1103 | @cindex centering point | ||
| 1104 | This function scrolls the selected window to put the text where point | ||
| 1105 | is located at a specified vertical position within the window. | ||
| 1106 | |||
| 1107 | If @var{count} is a nonnegative number, it puts the line containing | ||
| 1108 | point @var{count} lines down from the top of the window. If @var{count} | ||
| 1109 | is a negative number, then it counts upward from the bottom of the | ||
| 1110 | window, so that @minus{}1 stands for the last usable line in the window. | ||
| 1111 | If @var{count} is a non-@code{nil} list, then it stands for the line in | ||
| 1112 | the middle of the window. | ||
| 1113 | |||
| 1114 | If @var{count} is @code{nil}, @code{recenter} puts the line containing | ||
| 1115 | point in the middle of the window, then clears and redisplays the entire | ||
| 1116 | selected frame. | ||
| 1117 | |||
| 1118 | When @code{recenter} is called interactively, @var{count} is the raw | ||
| 1119 | prefix argument. Thus, typing @kbd{C-u} as the prefix sets the | ||
| 1120 | @var{count} to a non-@code{nil} list, while typing @kbd{C-u 4} sets | ||
| 1121 | @var{count} to 4, which positions the current line four lines from the | ||
| 1122 | top. | ||
| 1123 | |||
| 1124 | Typing @kbd{C-u 0 C-l} positions the current line at the top of the | ||
| 1125 | window. This action is so handy that some people bind the command to a | ||
| 1126 | function key. For example, | ||
| 1127 | |||
| 1128 | @example | ||
| 1129 | @group | ||
| 1130 | (defun line-to-top-of-window () | ||
| 1131 | "Scroll current line to top of window. | ||
| 1132 | Replaces three keystroke sequence C-u 0 C-l." | ||
| 1133 | (interactive) | ||
| 1134 | (recenter 0)) | ||
| 1135 | |||
| 1136 | (global-set-key "\C-cl" 'line-to-top-of-window) | ||
| 1137 | @end group | ||
| 1138 | @end example | ||
| 1139 | @end deffn | ||
| 1140 | |||
| 1141 | @node Horizontal Scrolling | ||
| 1142 | @section Horizontal Scrolling | ||
| 1143 | @cindex horizontal scrolling | ||
| 1144 | |||
| 1145 | Because we read English first from top to bottom and second from left | ||
| 1146 | to right, horizontal scrolling is not like vertical scrolling. Vertical | ||
| 1147 | scrolling involves selection of a contiguous portion of text to display. | ||
| 1148 | Horizontal scrolling causes part of each line to go off screen. The | ||
| 1149 | amount of horizontal scrolling is therefore specified as a number of | ||
| 1150 | columns rather than as a position in the buffer. It has nothing to do | ||
| 1151 | with the display-start position returned by @code{window-start}. | ||
| 1152 | |||
| 1153 | Usually, no horizontal scrolling is in effect; then the leftmost | ||
| 1154 | column is at the left edge of the window. In this state, scrolling to | ||
| 1155 | the right is meaningless, since there is no data to the left of the | ||
| 1156 | screen to be revealed by it; so this is not allowed. Scrolling to the | ||
| 1157 | left is allowed; it scrolls the first columns of text off the edge of | ||
| 1158 | the window and can reveal additional columns on the right that were | ||
| 1159 | truncated before. Once a window has a nonzero amount of leftward | ||
| 1160 | horizontal scrolling, you can scroll it back to the right, but only so | ||
| 1161 | far as to reduce the net horizontal scroll to zero. There is no limit | ||
| 1162 | to how far left you can scroll, but eventually all the text will | ||
| 1163 | disappear off the left edge. | ||
| 1164 | |||
| 1165 | @deffn Command scroll-left count | ||
| 1166 | This function scrolls the selected window @var{count} columns to the | ||
| 1167 | left (or to the right if @var{count} is negative). The return value is | ||
| 1168 | the total amount of leftward horizontal scrolling in effect after the | ||
| 1169 | change---just like the value returned by @code{window-hscroll}. | ||
| 1170 | @end deffn | ||
| 1171 | |||
| 1172 | @deffn Command scroll-right count | ||
| 1173 | This function scrolls the selected window @var{count} columns to the | ||
| 1174 | right (or to the left if @var{count} is negative). The return value is | ||
| 1175 | the total amount of leftward horizontal scrolling in effect after the | ||
| 1176 | change---just like the value returned by @code{window-hscroll}. | ||
| 1177 | |||
| 1178 | Once you scroll a window as far right as it can go, back to its normal | ||
| 1179 | position where the total leftward scrolling is zero, attempts to scroll | ||
| 1180 | any farther right have no effect. | ||
| 1181 | @end deffn | ||
| 1182 | |||
| 1183 | @defun window-hscroll &optional window | ||
| 1184 | This function returns the total leftward horizontal scrolling of | ||
| 1185 | @var{window}---the number of columns by which the text in @var{window} | ||
| 1186 | is scrolled left past the left margin. | ||
| 1187 | |||
| 1188 | The value is never negative. It is zero when no horizontal scrolling | ||
| 1189 | has been done in @var{window} (which is usually the case). | ||
| 1190 | |||
| 1191 | If @var{window} is @code{nil}, the selected window is used. | ||
| 1192 | |||
| 1193 | @example | ||
| 1194 | @group | ||
| 1195 | (window-hscroll) | ||
| 1196 | @result{} 0 | ||
| 1197 | @end group | ||
| 1198 | @group | ||
| 1199 | (scroll-left 5) | ||
| 1200 | @result{} 5 | ||
| 1201 | @end group | ||
| 1202 | @group | ||
| 1203 | (window-hscroll) | ||
| 1204 | @result{} 5 | ||
| 1205 | @end group | ||
| 1206 | @end example | ||
| 1207 | @end defun | ||
| 1208 | |||
| 1209 | @defun set-window-hscroll window columns | ||
| 1210 | This function sets the number of columns from the left margin that | ||
| 1211 | @var{window} is scrolled to the value of @var{columns}. The argument | ||
| 1212 | @var{columns} should be zero or positive; if not, it is taken as zero. | ||
| 1213 | |||
| 1214 | The value returned is @var{columns}. | ||
| 1215 | |||
| 1216 | @example | ||
| 1217 | @group | ||
| 1218 | (set-window-hscroll (selected-window) 10) | ||
| 1219 | @result{} 10 | ||
| 1220 | @end group | ||
| 1221 | @end example | ||
| 1222 | @end defun | ||
| 1223 | |||
| 1224 | Here is how you can determine whether a given position @var{position} | ||
| 1225 | is off the screen due to horizontal scrolling: | ||
| 1226 | |||
| 1227 | @example | ||
| 1228 | @group | ||
| 1229 | (save-excursion | ||
| 1230 | (goto-char @var{position}) | ||
| 1231 | (and | ||
| 1232 | (>= (- (current-column) (window-hscroll @var{window})) 0) | ||
| 1233 | (< (- (current-column) (window-hscroll @var{window})) | ||
| 1234 | (window-width @var{window})))) | ||
| 1235 | @end group | ||
| 1236 | @end example | ||
| 1237 | |||
| 1238 | @node Size of Window | ||
| 1239 | @section The Size of a Window | ||
| 1240 | @cindex window size | ||
| 1241 | @cindex size of window | ||
| 1242 | |||
| 1243 | An Emacs window is rectangular, and its size information consists of | ||
| 1244 | the height (the number of lines) and the width (the number of character | ||
| 1245 | positions in each line). The mode line is included in the height. But | ||
| 1246 | the width does not count the scroll bar or the column of @samp{|} | ||
| 1247 | characters separates side-by-side windows. | ||
| 1248 | |||
| 1249 | The following three functions return size information about a window: | ||
| 1250 | |||
| 1251 | @defun window-height &optional window | ||
| 1252 | This function returns the number of lines in @var{window}, including | ||
| 1253 | its mode line. If @var{window} fills its entire frame, this is one less | ||
| 1254 | than the value of @code{frame-height} on that frame (since the last line | ||
| 1255 | is always reserved for the minibuffer). | ||
| 1256 | |||
| 1257 | If @var{window} is @code{nil}, the function uses the selected window. | ||
| 1258 | |||
| 1259 | @example | ||
| 1260 | @group | ||
| 1261 | (window-height) | ||
| 1262 | @result{} 23 | ||
| 1263 | @end group | ||
| 1264 | @group | ||
| 1265 | (split-window-vertically) | ||
| 1266 | @result{} #<window 4 on windows.texi> | ||
| 1267 | @end group | ||
| 1268 | @group | ||
| 1269 | (window-height) | ||
| 1270 | @result{} 11 | ||
| 1271 | @end group | ||
| 1272 | @end example | ||
| 1273 | @end defun | ||
| 1274 | |||
| 1275 | @defun window-width &optional window | ||
| 1276 | This function returns the number of columns in @var{window}. If | ||
| 1277 | @var{window} fills its entire frame, this is the same as the value of | ||
| 1278 | @code{frame-width} on that frame. The width does not include the | ||
| 1279 | window's scroll bar or the column of @samp{|} characters that separates | ||
| 1280 | side-by-side windows. | ||
| 1281 | |||
| 1282 | If @var{window} is @code{nil}, the function uses the selected window. | ||
| 1283 | |||
| 1284 | @example | ||
| 1285 | @group | ||
| 1286 | (window-width) | ||
| 1287 | @result{} 80 | ||
| 1288 | @end group | ||
| 1289 | @end example | ||
| 1290 | @end defun | ||
| 1291 | |||
| 1292 | @defun window-edges &optional window | ||
| 1293 | This function returns a list of the edge coordinates of @var{window}. | ||
| 1294 | If @var{window} is @code{nil}, the selected window is used. | ||
| 1295 | |||
| 1296 | The order of the list is @code{(@var{left} @var{top} @var{right} | ||
| 1297 | @var{bottom})}, all elements relative to 0, 0 at the top left corner of | ||
| 1298 | the frame. The element @var{right} of the value is one more than the | ||
| 1299 | rightmost column used by @var{window}, and @var{bottom} is one more than | ||
| 1300 | the bottommost row used by @var{window} and its mode-line. | ||
| 1301 | |||
| 1302 | When you have side-by-side windows, the right edge value for a window | ||
| 1303 | with a neighbor on the right includes the width of the separator between | ||
| 1304 | the window and that neighbor. This separator may be a column of | ||
| 1305 | @samp{|} characters or it may be a scroll bar. Since the width of the | ||
| 1306 | window does not include this separator, the width does not equal the | ||
| 1307 | difference between the right and left edges in this case. | ||
| 1308 | |||
| 1309 | Here is the result obtained on a typical 24-line terminal with just one | ||
| 1310 | window: | ||
| 1311 | |||
| 1312 | @example | ||
| 1313 | @group | ||
| 1314 | (window-edges (selected-window)) | ||
| 1315 | @result{} (0 0 80 23) | ||
| 1316 | @end group | ||
| 1317 | @end example | ||
| 1318 | |||
| 1319 | If @var{window} is at the upper left corner of its frame, @var{right} | ||
| 1320 | and @var{bottom} are the same as the values returned by | ||
| 1321 | @code{(window-width)} and @code{(window-height)} respectively, and | ||
| 1322 | @var{top} and @var{bottom} are zero. For example, the edges of the | ||
| 1323 | following window are @w{@samp{0 0 5 8}}. Assuming that the frame has | ||
| 1324 | more than 8 columns, the last column of the window (column 7) holds a | ||
| 1325 | border rather than text. The last row (row 4) holds the mode line, | ||
| 1326 | shown here with @samp{xxxxxxxxx}. | ||
| 1327 | |||
| 1328 | @example | ||
| 1329 | @group | ||
| 1330 | 0 | ||
| 1331 | _______ | ||
| 1332 | 0 | | | ||
| 1333 | | | | ||
| 1334 | | | | ||
| 1335 | | | | ||
| 1336 | xxxxxxxxx 4 | ||
| 1337 | |||
| 1338 | 7 | ||
| 1339 | @end group | ||
| 1340 | @end example | ||
| 1341 | |||
| 1342 | When there are side-by-side windows, any window not at the right edge of | ||
| 1343 | its frame has a separator in its last column or columns. The separator | ||
| 1344 | counts as one or two columns in the width of the window. A window never | ||
| 1345 | includes a separator on its left, since that belongs to the window to | ||
| 1346 | the left. | ||
| 1347 | |||
| 1348 | In the following example, let's suppose that the frame is 7 | ||
| 1349 | columns wide. Then the edges of the left window are @w{@samp{0 0 4 3}} | ||
| 1350 | and the edges of the right window are @w{@samp{4 0 7 3}}. | ||
| 1351 | |||
| 1352 | @example | ||
| 1353 | @group | ||
| 1354 | ___ ___ | ||
| 1355 | | | | | ||
| 1356 | | | | | ||
| 1357 | xxxxxxxxx | ||
| 1358 | |||
| 1359 | 0 34 7 | ||
| 1360 | @end group | ||
| 1361 | @end example | ||
| 1362 | @end defun | ||
| 1363 | |||
| 1364 | @node Resizing Windows | ||
| 1365 | @section Changing the Size of a Window | ||
| 1366 | @cindex window resizing | ||
| 1367 | @cindex changing window size | ||
| 1368 | @cindex window size, changing | ||
| 1369 | |||
| 1370 | The window size functions fall into two classes: high-level commands | ||
| 1371 | that change the size of windows and low-level functions that access | ||
| 1372 | window size. Emacs does not permit overlapping windows or gaps between | ||
| 1373 | windows, so resizing one window affects other windows. | ||
| 1374 | |||
| 1375 | @deffn Command enlarge-window size &optional horizontal | ||
| 1376 | This function makes the selected window @var{size} lines bigger, | ||
| 1377 | stealing lines from neighboring windows. It takes the lines from one | ||
| 1378 | window at a time until that window is used up, then takes from another. | ||
| 1379 | If a window from which lines are stolen shrinks below | ||
| 1380 | @code{window-min-height} lines, that window disappears. | ||
| 1381 | |||
| 1382 | If @var{horizontal} is non-@code{nil}, this function makes | ||
| 1383 | @var{window} wider by @var{size} columns, stealing columns instead of | ||
| 1384 | lines. If a window from which columns are stolen shrinks below | ||
| 1385 | @code{window-min-width} columns, that window disappears. | ||
| 1386 | |||
| 1387 | If the window's frame is smaller than @var{size} lines (or columns), | ||
| 1388 | then the function makes the window occupy the entire height (or width) | ||
| 1389 | of the frame. | ||
| 1390 | |||
| 1391 | If @var{size} is negative, this function shrinks the window by | ||
| 1392 | @minus{}@var{size} lines or columns. If that makes the window smaller | ||
| 1393 | than the minimum size (@code{window-min-height} and | ||
| 1394 | @code{window-min-width}), @code{enlarge-window} deletes the window. | ||
| 1395 | |||
| 1396 | @code{enlarge-window} returns @code{nil}. | ||
| 1397 | @end deffn | ||
| 1398 | |||
| 1399 | @deffn Command enlarge-window-horizontally columns | ||
| 1400 | This function makes the selected window @var{columns} wider. | ||
| 1401 | It could be defined as follows: | ||
| 1402 | |||
| 1403 | @example | ||
| 1404 | @group | ||
| 1405 | (defun enlarge-window-horizontally (columns) | ||
| 1406 | (enlarge-window columns t)) | ||
| 1407 | @end group | ||
| 1408 | @end example | ||
| 1409 | @end deffn | ||
| 1410 | |||
| 1411 | @deffn Command shrink-window size &optional horizontal | ||
| 1412 | This function is like @code{enlarge-window} but negates the argument | ||
| 1413 | @var{size}, making the selected window smaller by giving lines (or | ||
| 1414 | columns) to the other windows. If the window shrinks below | ||
| 1415 | @code{window-min-height} or @code{window-min-width}, then it disappears. | ||
| 1416 | |||
| 1417 | If @var{size} is negative, the window is enlarged by @minus{}@var{size} | ||
| 1418 | lines or columns. | ||
| 1419 | @end deffn | ||
| 1420 | |||
| 1421 | @deffn Command shrink-window-horizontally columns | ||
| 1422 | This function makes the selected window @var{columns} narrower. | ||
| 1423 | It could be defined as follows: | ||
| 1424 | |||
| 1425 | @example | ||
| 1426 | @group | ||
| 1427 | (defun shrink-window-horizontally (columns) | ||
| 1428 | (shrink-window columns t)) | ||
| 1429 | @end group | ||
| 1430 | @end example | ||
| 1431 | @end deffn | ||
| 1432 | |||
| 1433 | @cindex minimum window size | ||
| 1434 | The following two variables constrain the window size changing | ||
| 1435 | functions to a minimum height and width. | ||
| 1436 | |||
| 1437 | @defopt window-min-height | ||
| 1438 | The value of this variable determines how short a window may become | ||
| 1439 | before it is automatically deleted. Making a window smaller than | ||
| 1440 | @code{window-min-height} automatically deletes it, and no window may be | ||
| 1441 | created shorter than this. The absolute minimum height is two (allowing | ||
| 1442 | one line for the mode line, and one line for the buffer display). | ||
| 1443 | Actions which change window sizes reset this variable to two if it is | ||
| 1444 | less than two. The default value is 4. | ||
| 1445 | @end defopt | ||
| 1446 | |||
| 1447 | @defopt window-min-width | ||
| 1448 | The value of this variable determines how narrow a window may become | ||
| 1449 | before it automatically deleted. Making a window smaller than | ||
| 1450 | @code{window-min-width} automatically deletes it, and no window may be | ||
| 1451 | created narrower than this. The absolute minimum width is one; any | ||
| 1452 | value below that is ignored. The default value is 10. | ||
| 1453 | @end defopt | ||
| 1454 | |||
| 1455 | @node Coordinates and Windows | ||
| 1456 | @section Coordinates and Windows | ||
| 1457 | |||
| 1458 | This section describes how to compare screen coordinates with windows. | ||
| 1459 | |||
| 1460 | @defun window-at x y &optional frame | ||
| 1461 | This function returns the window containing the specified cursor | ||
| 1462 | position in the frame @var{frame}. The coordinates @var{x} and @var{y} | ||
| 1463 | are measured in characters and count from the top left corner of the | ||
| 1464 | frame. If they are out of range, @code{window-at} returns @code{nil}. | ||
| 1465 | |||
| 1466 | If you omit @var{frame}, the selected frame is used. | ||
| 1467 | @end defun | ||
| 1468 | |||
| 1469 | @defun coordinates-in-window-p coordinates window | ||
| 1470 | This function checks whether a particular frame position falls within | ||
| 1471 | the window @var{window}. | ||
| 1472 | |||
| 1473 | The argument @var{coordinates} is a cons cell of this form: | ||
| 1474 | |||
| 1475 | @example | ||
| 1476 | (@var{x} . @var{y}) | ||
| 1477 | @end example | ||
| 1478 | |||
| 1479 | @noindent | ||
| 1480 | The coordinates @var{x} and @var{y} are measured in characters, and | ||
| 1481 | count from the top left corner of the screen or frame. | ||
| 1482 | |||
| 1483 | The value of @code{coordinates-in-window-p} is non-@code{nil} if the | ||
| 1484 | coordinates are inside @var{window}. The value also indicates what part | ||
| 1485 | of the window the position is in, as follows: | ||
| 1486 | |||
| 1487 | @table @code | ||
| 1488 | @item (@var{relx} . @var{rely}) | ||
| 1489 | The coordinates are inside @var{window}. The numbers @var{relx} and | ||
| 1490 | @var{rely} are the equivalent window-relative coordinates for the | ||
| 1491 | specified position, counting from 0 at the top left corner of the | ||
| 1492 | window. | ||
| 1493 | |||
| 1494 | @item mode-line | ||
| 1495 | The coordinates are in the mode line of @var{window}. | ||
| 1496 | |||
| 1497 | @item vertical-split | ||
| 1498 | The coordinates are in the vertical line between @var{window} and its | ||
| 1499 | neighbor to the right. This value occurs only if the window doesn't | ||
| 1500 | have a scroll bar; positions in a scroll bar are considered outside the | ||
| 1501 | window. | ||
| 1502 | |||
| 1503 | @item nil | ||
| 1504 | The coordinates are not in any part of @var{window}. | ||
| 1505 | @end table | ||
| 1506 | |||
| 1507 | The function @code{coordinates-in-window-p} does not require a frame as | ||
| 1508 | argument because it always uses the frame that @var{window} is on. | ||
| 1509 | @end defun | ||
| 1510 | |||
| 1511 | @node Window Configurations | ||
| 1512 | @section Window Configurations | ||
| 1513 | @cindex window configurations | ||
| 1514 | @cindex saving window information | ||
| 1515 | |||
| 1516 | A @dfn{window configuration} records the entire layout of a | ||
| 1517 | frame---all windows, their sizes, which buffers they contain, what part | ||
| 1518 | of each buffer is displayed, and the values of point and the mark. You | ||
| 1519 | can bring back an entire previous layout by restoring a window | ||
| 1520 | configuration previously saved. | ||
| 1521 | |||
| 1522 | If you want to record all frames instead of just one, use a frame | ||
| 1523 | configuration instead of a window configuration. @xref{Frame | ||
| 1524 | Configurations}. | ||
| 1525 | |||
| 1526 | @defun current-window-configuration | ||
| 1527 | This function returns a new object representing Emacs's current window | ||
| 1528 | configuration, namely the number of windows, their sizes and current | ||
| 1529 | buffers, which window is the selected window, and for each window the | ||
| 1530 | displayed buffer, the display-start position, and the positions of point | ||
| 1531 | and the mark. An exception is made for point in the current buffer, | ||
| 1532 | whose value is not saved. | ||
| 1533 | @end defun | ||
| 1534 | |||
| 1535 | @defun set-window-configuration configuration | ||
| 1536 | This function restores the configuration of Emacs's windows and | ||
| 1537 | buffers to the state specified by @var{configuration}. The argument | ||
| 1538 | @var{configuration} must be a value that was previously returned by | ||
| 1539 | @code{current-window-configuration}. | ||
| 1540 | |||
| 1541 | Here is a way of using this function to get the same effect | ||
| 1542 | as @code{save-window-excursion}: | ||
| 1543 | |||
| 1544 | @example | ||
| 1545 | @group | ||
| 1546 | (let ((config (current-window-configuration))) | ||
| 1547 | (unwind-protect | ||
| 1548 | (progn (split-window-vertically nil) | ||
| 1549 | @dots{}) | ||
| 1550 | (set-window-configuration config))) | ||
| 1551 | @end group | ||
| 1552 | @end example | ||
| 1553 | @end defun | ||
| 1554 | |||
| 1555 | @defspec save-window-excursion forms@dots{} | ||
| 1556 | This special form records the window configuration, executes @var{forms} | ||
| 1557 | in sequence, then restores the earlier window configuration. The window | ||
| 1558 | configuration includes the value of point and the portion of the buffer | ||
| 1559 | which is visible. It also includes the choice of selected window. | ||
| 1560 | However, it does not include the value of point in the current buffer; | ||
| 1561 | use @code{save-excursion} if you wish to preserve that. | ||
| 1562 | |||
| 1563 | The return value is the value of the final form in @var{forms}. | ||
| 1564 | For example: | ||
| 1565 | |||
| 1566 | @example | ||
| 1567 | @group | ||
| 1568 | (split-window) | ||
| 1569 | @result{} #<window 25 on control.texi> | ||
| 1570 | @end group | ||
| 1571 | @group | ||
| 1572 | (setq w (selected-window)) | ||
| 1573 | @result{} #<window 19 on control.texi> | ||
| 1574 | @end group | ||
| 1575 | @group | ||
| 1576 | (save-window-excursion | ||
| 1577 | (delete-other-windows w) | ||
| 1578 | (switch-to-buffer "foo") | ||
| 1579 | 'do-something) | ||
| 1580 | @result{} do-something | ||
| 1581 | ;; @r{The screen is now split again.} | ||
| 1582 | @end group | ||
| 1583 | @end example | ||
| 1584 | @end defspec | ||
| 1585 | |||
| 1586 | @defun window-configuration-p object | ||
| 1587 | This function returns @code{t} if @var{object} is a window configuration. | ||
| 1588 | @end defun | ||
| 1589 | |||
| 1590 | Primitives to look inside of window configurations would make sense, | ||
| 1591 | but none are implemented. It is not clear they are useful enough to be | ||
| 1592 | worth implementing. | ||